MediaWiki  1.30.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 LU 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 
21  public function execute() {
22  // Prevent the script from timing out
23  set_time_limit( 0 );
24  ini_set( "max_execution_time", 0 );
25  ini_set( 'memory_limit', -1 );
26 
27  // @codingStandardsIgnoreStart Ignore MediaWiki.NamingConventions.ValidGlobalName.wgPrefix
28  global $IP;
29  // @codingStandardsIgnoreEnd
31  global $wgLocalisationUpdateRepositories;
32  global $wgLocalisationUpdateRepository;
33 
35  if ( !$dir ) {
36  $this->error( "No cache directory configured", true );
37  return;
38  }
39 
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  // Do it ;)
56  $updater = new LocalisationUpdate\Updater();
57  $updatedMessages = $updater->execute(
58  $finder,
59  $readerFactory,
60  $fetcherFactory,
61  $repos
62  );
63 
64  // Store it ;)
65  $count = array_sum( array_map( 'count', $updatedMessages ) );
66  if ( !$count ) {
67  $this->output( "Found no new translations\n" );
68  return;
69  }
70 
71  foreach ( $updatedMessages as $language => $messages ) {
72  $filename = "$dir/" . LocalisationUpdate::getFilename( $language );
73  file_put_contents( $filename, FormatJson::encode( $messages, true ) );
74  }
75  $this->output( "Saved $count new translations\n" );
76  }
77 }
78 
79 $maintClass = 'LU';
80 require_once RUN_MAINTENANCE_IF_MAIN;
LU\execute
execute()
Do the actual work.
Definition: update.php:21
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
LU\__construct
__construct()
Default constructor.
Definition: update.php:10
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
$messages
$messages
Definition: LogTests.i18n.php:8
LocalisationUpdate\FetcherFactory
Constructs fetchers based on the repository urls.
Definition: FetcherFactory.php:13
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
FormatJson\encode
static encode( $value, $pretty=false, $escaping=0)
Returns the JSON representation of a value.
Definition: FormatJson.php:127
Language\getLocalisationCache
static getLocalisationCache()
Get the LocalisationCache instance.
Definition: Language.php:406
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:215
$IP
$IP
Definition: update.php:3
$maintClass
$maintClass
Definition: update.php:79
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
LocalisationUpdate::getFilename
static getFilename( $language)
Returns a filename where updated translations are stored.
Definition: LocalisationUpdate.class.php:62
$dir
$dir
Definition: Autoload.php:8
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.class.php:49
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:250
$wgExtensionMessagesFiles
$wgExtensionMessagesFiles['ExtensionNameMagic']
Definition: magicword.txt:43
LU
Definition: update.php:9
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:392
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
LocalisationUpdate\Finder
Interface for classes which provide list of components, which should be included for l10n updates.
Definition: Finder.php:14