MediaWiki REL1_32
update.php
Go to the documentation of this file.
1<?php
2
3$IP = strval( getenv( 'MW_INSTALL_PATH' ) ) !== ''
4 ? getenv( 'MW_INSTALL_PATH' )
5 : realpath( __DIR__ . '/../../' );
6
7require "$IP/maintenance/Maintenance.php";
8
9class Update extends Maintenance {
10 public function __construct() {
11 parent::__construct();
12 $this->mDescription = 'Fetches translation updates to MediaWiki core, skins and extensions.';
13 $this->addOption(
14 'repoid',
15 'Fetch translations from repositories identified by this',
16 false, /*required*/
17 true /*has arg*/
18 );
19
20 $this->requireExtension( 'LocalisationUpdate' );
21 }
22
23 public function execute() {
24 // Prevent the script from timing out
25 set_time_limit( 0 );
26 ini_set( "max_execution_time", 0 );
27 ini_set( 'memory_limit', -1 );
28
29 global $IP;
31 global $wgLocalisationUpdateRepositories;
32 global $wgLocalisationUpdateRepository;
33
34 $dir = LocalisationUpdate::getDirectory();
35 if ( !$dir ) {
36 $this->error( "No cache directory configured", true );
37 return;
38 }
39
40 $lc = Language::getLocalisationCache();
41 $messagesDirs = $lc->getMessagesDirs();
42
43 $finder = new LocalisationUpdate\Finder( $wgExtensionMessagesFiles, $messagesDirs, $IP );
44 $readerFactory = new LocalisationUpdate\ReaderFactory();
45 $fetcherFactory = new LocalisationUpdate\FetcherFactory();
46
47 $repoid = $this->getOption( 'repoid', $wgLocalisationUpdateRepository );
48 if ( !isset( $wgLocalisationUpdateRepositories[$repoid] ) ) {
49 $known = implode( ', ', array_keys( $wgLocalisationUpdateRepositories ) );
50 $this->error( "Unknown repoid $repoid; known: $known", true );
51 return;
52 }
53 $repos = $wgLocalisationUpdateRepositories[$repoid];
54
55 // output and error methods are protected, hence we add logInfo and logError
56 // public methods, that hopefully won't conflict in the future with the base class.
57 $logger = $this;
58
59 // Do it ;)
61 $updatedMessages = $updater->execute(
62 $finder,
63 $readerFactory,
64 $fetcherFactory,
65 $repos,
66 $logger
67 );
68
69 // Store it ;)
70 $count = array_sum( array_map( 'count', $updatedMessages ) );
71 if ( !$count ) {
72 $this->output( "Found no new translations\n" );
73 return;
74 }
75
76 foreach ( $updatedMessages as $language => $messages ) {
77 $filename = "$dir/" . LocalisationUpdate::getFilename( $language );
78 file_put_contents( $filename, FormatJson::encode( $messages, true ) );
79 }
80 $this->output( "Saved $count new translations\n" );
81 }
82
83 public function logInfo( $msg ) {
84 $this->output( $msg . "\n" );
85 }
86
87 public function logError( $msg ) {
88 $this->error( $msg );
89 }
90}
91
92$maintClass = Update::class;
93require_once RUN_MAINTENANCE_IF_MAIN;
$messages
Constructs fetchers based on the repository urls.
Interface for classes which provide list of components, which should be included for l10n updates.
Definition Finder.php:14
Constructs readers for files based on the names.
Executes the localisation update.
Definition Updater.php:13
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
requireExtension( $name)
Indicate that the specified extension must be loaded before the script can run.
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
logInfo( $msg)
Definition update.php:83
logError( $msg)
Definition update.php:87
__construct()
Default constructor.
Definition update.php:10
execute()
Do the actual work.
Definition update.php:23
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
Definition hooks.txt:2683
$IP
Definition update.php:3
$maintClass
Definition update.php:92
$wgExtensionMessagesFiles['ExtensionNameMagic']
Definition magicword.txt:43
require_once RUN_MAINTENANCE_IF_MAIN
$page->newPageUpdater($user) $updater