# #!/usr/bin/env bash
# # After following the instructions in DEVELOPERS.md run this script to install dependencies relevant to MediaSearch
# set -eu
git clone https://gerrit.wikimedia.org/r/mediawiki/skins/Vector ./skins/Vector
git clone https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue ./skins/MinervaNeue
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/CirrusSearch ./extensions/CirrusSearch
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite ./extensions/Cite
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/CommonsMetadata ./extensions/CommonsMetadata
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo ./extensions/Echo
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Elastica ./extensions/Elastica
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/EventBus ./extensions/EventBus
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/EventLogging ./extensions/EventLogging
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/EventStreamConfig ./extensions/EventStreamConfig
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/JsonConfig ./extensions/JsonConfig
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/MediaSearch ./extensions/MediaSearch
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/MobileFrontend ./extensions/MobileFrontend
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/ParserFunctions ./extensions/ParserFunctions
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto ./extensions/Scribunto
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData ./extensions/TemplateData
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateStyles ./extensions/TemplateStyles
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/UniversalLanguageSelector ./extensions/UniversalLanguageSelector
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Wikibase ./extensions/Wikibase
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/WikibaseCirrusSearch ./extensions/WikibaseCirrusSearch
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/WikibaseMediaInfo ./extensions/WikibaseMediaInfo
# Save the default settings from the Mediawiki installation to be added back later.
defaultSettings=`cat LocalSettings.php`
cat <<EOL >> LocalSettings.php
wfLoadSkin( 'Vector' );
wfLoadSkin( 'MinervaNeue' );
wfLoadExtension( 'CirrusSearch' );
wfLoadExtension( 'Elastica' );
wfLoadExtension( 'MobileFrontend' );
wfLoadExtension( 'UniversalLanguageSelector' );
\$wgDisableSearchUpdate = true;
require_once "\$IP/extensions/CirrusSearch/tests/jenkins/FullyFeaturedConfig.php";
\$wgCirrusSearchServers = [ "elasticsearch" ];
EOL
# Search
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/Elastica install
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/CirrusSearch install
docker compose exec mediawiki php maintenance/run.php update.php
# Configure the search index and populate it with content
docker compose exec mediawiki php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php
echo "$defaultSettings" > LocalSettings.php
cat <<EOL >> LocalSettings.php
wfLoadSkin( 'Vector' );
wfLoadSkin( 'MinervaNeue' );
wfLoadExtension( 'CirrusSearch' );
wfLoadExtension( 'Elastica' );
wfLoadExtension( 'MobileFrontend' );
wfLoadExtension( 'UniversalLanguageSelector' );
require_once "\$IP/extensions/CirrusSearch/tests/jenkins/FullyFeaturedConfig.php";
\$wgCirrusSearchServers = [ "elasticsearch" ];
EOL
docker compose exec mediawiki php extensions/CirrusSearch/maintenance/forceSearchIndex.php --skipLinks --indexOnSkip
docker compose exec mediawiki php extensions/CirrusSearch/maintenance/forceSearchIndex.php --skipParse
# Process the job queue. You need to do this any time you add/update content and want it updated in ElasticSearch
docker compose exec mediawiki php maintenance/runJobs.php
cat <<EOL >> LocalSettings.php
\$wgSearchType = 'CirrusSearch';
EOL
# Wikibase
touch composer.local.json
cat > composer.local.json <<EOL
{
"extra": {
"merge-plugin": {
"include": [
"extensions/Wikibase/composer.json"
]
}
}
}
EOL
docker compose exec mediawiki composer require wikimedia/composer-merge-plugin:2.0.1
docker compose exec mediawiki php maintenance/run.php update.php
# Create final LocalSettings file with default settings and (organized) custom settings.
echo "$defaultSettings" > LocalSettings.php
cat <<EOL >> LocalSettings.php
wfLoadSkin( 'Vector' );
wfLoadSkin( 'MinervaNeue' );
wfLoadExtension( 'CirrusSearch' );
wfLoadExtension( 'Cite' );
wfLoadExtension( 'CommonsMetadata' );
wfLoadExtension( 'Echo' );
wfLoadExtension( 'Elastica' );
wfLoadExtension( 'EventLogging' );
wfLoadExtension( 'EventStreamConfig' );
wfLoadExtension( 'JsonConfig' );
wfLoadExtension( 'MediaSearch' );
wfLoadExtension( 'MobileFrontend' );
wfLoadExtension( 'ParserFunctions' );
wfLoadExtension( 'Scribunto' );
wfLoadExtension( 'TemplateData' );
wfLoadExtension( 'TemplateStyles' );
wfLoadExtension( 'UniversalLanguageSelector' );
wfLoadExtension( 'WikibaseCirrusSearch' );
wfLoadExtension( 'WikibaseMediaInfo' );
\$wgUseInstantCommons = true;
\$wgEnableUploads = true;
\$wgUseImageMagick = true;
\$wgScribuntoDefaultEngine = 'luastandalone';
\$wgMediaViewerEnableByDefault = true;
\$wgPFEnableStringFunctions = true;
\$wgApiFrameOptions = 'SAMEORIGIN';
\$wgCacheDirectory = "\$IP/cache";
// Cirrus Search
require_once "\$IP/extensions/CirrusSearch/tests/jenkins/FullyFeaturedConfig.php";
\$wgCirrusSearchServers = [ "elasticsearch" ];
\$wgSearchType = 'CirrusSearch';
// Wikibase
wfLoadExtension( 'WikibaseRepository', "\$IP/extensions/Wikibase/extension-repo.json" );
require_once "\$IP/extensions/Wikibase/repo/ExampleSettings.php";
wfLoadExtension( 'WikibaseClient', "\$IP/extensions/Wikibase/extension-client.json" );
require_once "\$IP/extensions/Wikibase/client/ExampleSettings.php";
\$wgEnableWikibaseRepo = true;
\$wgEnableWikibaseClient = true;
\$wgWBClientSettings['dataBridgeEnabled'] = true;
\$wgWBClientSettings['dataBridgeHrefRegExp'] = '[/=]((?:Item:)?(Q[1-9][0-9]*)).*#(P[1-9][0-9]*)$';
\$wgWBClientSettings['dataBridgeEditTags'] = [ 'Data Bridge' ];
\$wgWBRepoSettings['dataBridgeEnabled'] = true;
\$wgWBRepoSettings['taintedReferencesEnabled'] = true;
\$wgWBRepoSettings['termboxEnabled'] = true;
// WikibaseMediaInfo
\$wgMediaInfoEnableFilePageDepicts = true;
\$wgMediaInfoEnableOtherStatements = true;
\$wgMediaInfoShowQualifiers = true;
\$wgMediaInfoProperties = [
'depicts' => 'P1',
];
\$wgDepictsQualifierProperties = [
'depicts' => 'P1',
];
\$wgUseImageMagick = true;
// MediaSearch
\$useProductionSearchApi = true;
\$wgMediaSearchExternalSearchUri = \$useProductionSearchApi ? 'https://commons.wikimedia.org/w/api.php' : '';
\$wgMediaSearchExternalEntitySearchBaseUri = \$useProductionSearchApi ? 'https://www.wikidata.org/w/api.php' : '';
EOL
cd extensions/Wikibase
git submodule update --init --recursive
cd ../..
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/WikibaseCirrusSearch install
docker compose exec mediawiki php maintenance/run.php update.php
docker compose exec mediawiki php extensions/Wikibase/lib/maintenance/populateSitesTable.php
docker compose exec mediawiki php extensions/Wikibase/repo/maintenance/rebuildItemsPerSite.php
docker compose exec mediawiki php extensions/Wikibase/client/maintenance/populateInterwiki.php
# Other extensions
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/CommonsMetadata install
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/Echo install
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/EventLogging install
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/EventStreamConfig install
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/JsonConfig install
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/MediaSearch install
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/MobileFrontend install
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/ParserFunctions install
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/Scribunto install
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/TemplateData install
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/TemplateStyles install
docker compose exec mediawiki composer --working-dir=/var/www/html/w/extensions/UniversalLanguageSelector install