MediaWiki REL1_34
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->addDescription( '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;
30 global $wgLocalisationUpdateRepositories;
31 global $wgLocalisationUpdateRepository;
32
33 $dir = LocalisationUpdate::getDirectory();
34 if ( !$dir ) {
35 $this->error( "No cache directory configured", true );
36 return;
37 }
38
39 $lc = Language::getLocalisationCache();
40 $messagesDirs = $lc->getMessagesDirs();
41
42 $finder = new LocalisationUpdate\Finder( $messagesDirs, $IP );
43 $readerFactory = new LocalisationUpdate\ReaderFactory();
44 $fetcherFactory = new LocalisationUpdate\FetcherFactory();
45
46 $repoid = $this->getOption( 'repoid', $wgLocalisationUpdateRepository );
47 if ( !isset( $wgLocalisationUpdateRepositories[$repoid] ) ) {
48 $known = implode( ', ', array_keys( $wgLocalisationUpdateRepositories ) );
49 $this->error( "Unknown repoid $repoid; known: $known", true );
50 return;
51 }
52 $repos = $wgLocalisationUpdateRepositories[$repoid];
53
54 // output and error methods are protected, hence we add logInfo and logError
55 // public methods, that hopefully won't conflict in the future with the base class.
56 $logger = $this;
57
58 // Do it ;)
59 $updater = new LocalisationUpdate\Updater();
60 $updatedMessages = $updater->execute(
61 $finder,
62 $readerFactory,
63 $fetcherFactory,
64 $repos,
65 $logger
66 );
67
68 // Store it ;)
69 $count = array_sum( array_map( 'count', $updatedMessages ) );
70 if ( !$count ) {
71 $this->output( "Found no new translations\n" );
72 return;
73 }
74
75 foreach ( $updatedMessages as $language => $messages ) {
76 $filename = "$dir/" . LocalisationUpdate::getFilename( $language );
77 file_put_contents( $filename, FormatJson::encode( $messages, true ) );
78 }
79 $this->output( "Saved $count new translations\n" );
80 }
81
82 public function logInfo( $msg ) {
83 $this->output( $msg . "\n" );
84 }
85
86 public function logError( $msg ) {
87 $this->error( $msg );
88 }
89}
90
91$maintClass = Update::class;
92require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
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...
error( $err, $die=0)
Throw an error to the user.
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.
addDescription( $text)
Set the description text.
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:82
logError( $msg)
Definition update.php:86
__construct()
Default constructor.
Definition update.php:10
execute()
Do the actual work.
Definition update.php:23
$IP
Definition update.php:3
$maintClass
Definition update.php:91