FROM mediawiki:latest AS base
ENV DEBIAN_FRONTEND="noninteractive"
COPY ./config.json /tmp/config.json
COPY ./build /tmp
RUN apt update && apt install --yes wget gpg \
&& wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg \
&& echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | tee /etc/apt/sources.list.d/elastic-8.x.list \
&& apt update && apt install elasticsearch
# download extensions
RUN apt install wget \
&& wget -P /tmp/mediawiki_extensions https://extdist.wmflabs.org/dist/extensions/AdvancedSearch-REL1_40-e27dbab.tar.gz \
&& wget -P /tmp/mediawiki_extensions https://extdist.wmflabs.org/dist/extensions/CirrusSearch-REL1_40-16afc65.tar.gz \
&& wget -P /tmp/mediawiki_extensions https://extdist.wmflabs.org/dist/extensions/DynamicSidebar-REL1_40-4a15372.tar.gz \
&& wget -P /tmp/mediawiki_extensions https://extdist.wmflabs.org/dist/extensions/Elastica-REL1_40-3e076c7.tar.gz \
&& wget -P /tmp/mediawiki_extensions https://extdist.wmflabs.org/dist/extensions/MobileFrontend-REL1_40-8ba9809.tar.gz \
#&& wget -P /tmp/mediawiki_extensions https://extdist.wmflabs.org/dist/extensions/Mpdf-REL1_40-7d3b6b2.tar.gz \
&& wget -P /tmp/mediawiki_extensions https://extdist.wmflabs.org/dist/extensions/Popups-REL1_40-03a758f.tar.gz \
&& wget -P /tmp/mediawiki_extensions https://extdist.wmflabs.org/dist/extensions/TimedMediaHandler-REL1_40-cc6a469.tar.gz \
&& wget -P /tmp/mediawiki_extensions https://extdist.wmflabs.org/dist/extensions/UserFunctions-REL1_40-9ac3bb6.tar.gz
RUN find /tmp/mediawiki_extensions -name "*.tar.gz" -exec sh -c 'tar -xzf {} -C /var/www/html/extensions' \; \
&& find /tmp/mediawiki_skins -name "*.tar.gz" -exec sh -c 'tar -xzf {} -C /var/www/html/skins' \; \
&& find /tmp/mediawiki_override -type f -exec php /tmp/scripts/config_placeholder_replace.php "/tmp/config.json" "{}" \; \
&& cp -R /tmp/mediawiki_override/* /var/www/html \
&& chown www-data:www-data /var/www/html/extensions/ -R \
&& rm -R /tmp/*