X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/extensions/LocalisationUpdate/update.php diff --git a/extensions/LocalisationUpdate/update.php b/extensions/LocalisationUpdate/update.php new file mode 100644 index 00000000..593a5258 --- /dev/null +++ b/extensions/LocalisationUpdate/update.php @@ -0,0 +1,80 @@ +mDescription = 'Fetches translation updates to MediaWiki core, skins and extensions.'; + $this->addOption( + 'repoid', + 'Fetch translations from repositories identified by this', + false, /*required*/ + true /*has arg*/ + ); + } + + public function execute() { + // Prevent the script from timing out + set_time_limit( 0 ); + ini_set( "max_execution_time", 0 ); + ini_set( 'memory_limit', -1 ); + + // @codingStandardsIgnoreStart Ignore MediaWiki.NamingConventions.ValidGlobalName.wgPrefix + global $IP; + // @codingStandardsIgnoreEnd + global $wgExtensionMessagesFiles; + global $wgLocalisationUpdateRepositories; + global $wgLocalisationUpdateRepository; + + $dir = LocalisationUpdate::getDirectory(); + if ( !$dir ) { + $this->error( "No cache directory configured", true ); + return; + } + + $lc = Language::getLocalisationCache(); + $messagesDirs = $lc->getMessagesDirs(); + + $finder = new LocalisationUpdate\Finder( $wgExtensionMessagesFiles, $messagesDirs, $IP ); + $readerFactory = new LocalisationUpdate\ReaderFactory(); + $fetcherFactory = new LocalisationUpdate\FetcherFactory(); + + $repoid = $this->getOption( 'repoid', $wgLocalisationUpdateRepository ); + if ( !isset( $wgLocalisationUpdateRepositories[$repoid] ) ) { + $known = implode( ', ', array_keys( $wgLocalisationUpdateRepositories ) ); + $this->error( "Unknown repoid $repoid; known: $known", true ); + return; + } + $repos = $wgLocalisationUpdateRepositories[$repoid]; + + // Do it ;) + $updater = new LocalisationUpdate\Updater(); + $updatedMessages = $updater->execute( + $finder, + $readerFactory, + $fetcherFactory, + $repos + ); + + // Store it ;) + $count = array_sum( array_map( 'count', $updatedMessages ) ); + if ( !$count ) { + $this->output( "Found no new translations\n" ); + return; + } + + foreach ( $updatedMessages as $language => $messages ) { + $filename = "$dir/" . LocalisationUpdate::getFilename( $language ); + file_put_contents( $filename, FormatJson::encode( $messages, true ) ); + } + $this->output( "Saved $count new translations\n" ); + } +} + +$maintClass = 'LU'; +require_once RUN_MAINTENANCE_IF_MAIN;