MediaWiki  1.34.0
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 
7 require "$IP/maintenance/Maintenance.php";
8 
9 class 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 
34  if ( !$dir ) {
35  $this->error( "No cache directory configured", true );
36  return;
37  }
38 
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;
92 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Update\logError
logError( $msg)
Definition: update.php:86
Update\__construct
__construct()
Default constructor.
Definition: update.php:10
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
LocalisationUpdate\FetcherFactory
Constructs fetchers based on the repository urls.
Definition: FetcherFactory.php:13
FormatJson\encode
static encode( $value, $pretty=false, $escaping=0)
Returns the JSON representation of a value.
Definition: FormatJson.php:115
Language\getLocalisationCache
static getLocalisationCache()
Get the LocalisationCache instance.
Definition: Language.php:426
LocalisationUpdate\Updater
Executes the localisation update.
Definition: Updater.php:13
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:267
$IP
$IP
Definition: update.php:3
Maintenance\requireExtension
requireExtension( $name)
Indicate that the specified extension must be loaded before the script can run.
Definition: Maintenance.php:638
$maintClass
$maintClass
Definition: update.php:91
LocalisationUpdate\getFilename
static getFilename( $language)
Returns a filename where updated translations are stored.
Definition: LocalisationUpdate.php:64
LocalisationUpdate\ReaderFactory
Constructs readers for files based on the names.
Definition: ReaderFactory.php:13
LocalisationUpdate\getDirectory
static getDirectory()
Returns a directory where updated translations are stored.
Definition: LocalisationUpdate.php:51
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:302
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:481
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453
Update\execute
execute()
Do the actual work.
Definition: update.php:23
LocalisationUpdate\Finder
Interface for classes which provide list of components, which should be included for l10n updates.
Definition: Finder.php:14
Update
Definition: update.php:9
Update\logInfo
logInfo( $msg)
Definition: update.php:82