FROM mediawiki:1.42.1

RUN apt update \
    && apt install -y unzip wget clamav clamav-daemon make

# Install extensions
WORKDIR /var/www/html/extensions

RUN git clone --depth 1 \
    https://gerrit.wikimedia.org/r/mediawiki/extensions/MobileFrontend

RUN git clone --depth 1 \
    https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror

RUN git clone --depth 1 \
    https://gerrit.wikimedia.org/r/mediawiki/extensions/Elastica
RUN git clone --depth 1 \
    https://gerrit.wikimedia.org/r/mediawiki/extensions/CirrusSearch
RUN git clone --depth 1 \
    https://gerrit.wikimedia.org/r/mediawiki/extensions/AdvancedSearch

RUN git clone --depth 1 \
    https://github.com/edwardspec/mediawiki-aws-s3.git \
    /AWS

RUN git clone --depth 1 \
    https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscordRCFeed

RUN git clone --depth 1 \
    https://gerrit.wikimedia.org/r/mediawiki/extensions/DismissableSiteNotice

RUN git clone --depth 1 \
    https://gerrit.wikimedia.org/r/mediawiki/extensions/cldr
RUN git clone --depth 1 \
    https://gerrit.wikimedia.org/r/mediawiki/extensions/CookieWarning

RUN git clone --depth 1 \
    https://gerrit.wikimedia.org/r/mediawiki/extensions/CreateUserPage

RUN git clone --depth 1 \
    https://gerrit.wikimedia.org/r/mediawiki/extensions/Disambiguator

RUN git clone --depth 1 \
    https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups

# Install skins and tarballed extensions
WORKDIR /var/www/html

RUN wget https://github.com/StarCitizenTools/mediawiki-skins-Citizen/archive/main.zip \
    && unzip main.zip \
    && mkdir -p /var/www/html/skins/Citizen \
    && mv mediawiki-skins-Citizen-main/* /var/www/html/skins/Citizen \
    && rm main.zip

RUN wget https://github.com/StarCitizenWiki/mediawiki-extensions-EmbedVideo/archive/refs/tags/v3.4.2.tar.gz \
    && tar -xvf v3.4.2.tar.gz \
    && mkdir -p /var/www/html/extensions/EmbedVideo \
    && mv mediawiki-extensions-EmbedVideo-3.4.2/* /var/www/html/extensions/EmbedVideo \
    && rm v3.4.2.tar.gz

COPY *.tar.gz .

RUN for file in *.tar.gz; do \
        tar -xvf "$file" --directory /var/www/html/extensions/ && rm "$file"; \
    done

# Set executable permissions for SyntaxHighlighting
RUN chmod a+x /var/www/html/extensions/SyntaxHighlight_GeSHi/pygments/pygmentize

# Install composer (AWS S3 & CheckUser extensions)
RUN wget https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer -O - -q | php -- --quiet \
    && mv composer.phar /usr/local/bin/composer

RUN mv /var/www/html/composer.local.json-sample /var/www/html/composer.local.json

ENV COMPOSER_ALLOW_SUPERUSER=1

RUN composer update -d /var/www/html

COPY short-url.conf /etc/apache2/conf-enabled/short-url.conf

RUN mkdir /var/log/mediawiki && chown www-data:www-data /var/log/mediawiki
