MediaWiki  1.33.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->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 
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  // 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 
93 require_once RUN_MAINTENANCE_IF_MAIN;
Update\logError
logError( $msg)
Definition: update.php:87
Update\__construct
__construct()
Default constructor.
Definition: update.php:10
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
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:115
Language\getLocalisationCache
static getLocalisationCache()
Get the LocalisationCache instance.
Definition: Language.php:447
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:248
$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:619
$maintClass
$maintClass
Definition: update.php:92
LocalisationUpdate\getFilename
static getFilename( $language)
Returns a filename where updated translations are stored.
Definition: LocalisationUpdate.php:70
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:57
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:283
$wgExtensionMessagesFiles
$wgExtensionMessagesFiles['ExtensionNameMagic']
Definition: magicword.txt:43
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
$updater
$page->newPageUpdater($user) $updater
Definition: pageupdater.txt:63
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:462
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:434
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
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
Update
Definition: update.php:9
Update\logInfo
logInfo( $msg)
Definition: update.php:83