36require_once __DIR__ .
'/Maintenance.php';
45 parent::__construct();
47 $this->
addOption(
'force',
'Rebuild all files, even ones not out of date' );
48 $this->
addOption(
'threads',
'Fork more than one thread',
false,
true );
49 $this->
addOption(
'outdir',
'Override the output directory (normally $wgCacheDirectory)',
51 $this->
addOption(
'lang',
'Only rebuild these languages, comma separated.',
56 # This script needs to be run to build the inital l10n cache. But if
57 # $wgLanguageCode is not 'en', it won't be able to run because there is
58 # no l10n cache. Break the cycle by forcing $wgLanguageCode = 'en'.
68 $threads = $this->
getOption(
'threads', 1 );
69 if ( $threads < 1 || $threads != intval( $threads ) ) {
70 $this->
output(
"Invalid thread count specified; running single-threaded.\n" );
74 $this->
output(
"Threaded rebuild is not supported on Windows; running single-threaded.\n" );
77 if ( $threads > 1 && !function_exists(
'pcntl_fork' ) ) {
78 $this->
output(
"PHP pcntl extension is not present; running single-threaded.\n" );
83 $conf[
'manualRecache'] =
false;
84 $conf[
'forceRecache'] = $force || !empty( $conf[
'forceRecache'] );
86 $conf[
'storeDirectory'] = $this->
getOption(
'outdir' );
89 $services = MediaWikiServices::getInstance();
92 LocalisationCache::CONSTRUCTOR_OPTIONS,
94 $services->getMainConfig()
97 LoggerFactory::getInstance(
'localisation' ),
98 [ function () use ( $services ) {
101 $services->getLanguageNameUtils()
104 $allCodes = array_keys( $services
105 ->getLanguageNameUtils()
106 ->getLanguageNames(
null,
'mwfile' ) );
108 # Validate requested languages
109 $codes = array_intersect( $allCodes,
110 explode(
',', $this->
getOption(
'lang' ) ) );
111 # Bailed out if nothing is left
112 if ( count( $codes ) == 0 ) {
113 $this->
fatalError(
'None of the languages specified exists.' );
116 # By default get all languages
123 $total = count( $codes );
124 $chunks = array_chunk( $codes, ceil( count( $codes ) / $threads ) );
127 foreach ( $chunks as $codes ) {
129 $pid = ( $threads > 1 ) ? pcntl_fork() : -1;
134 mt_srand( getmypid() );
138 } elseif ( $pid === -1 ) {
140 $numRebuilt += $this->
doRebuild( $codes, $lc, $force );
147 foreach ( $pids as $pid ) {
149 pcntl_waitpid( $pid, $status );
150 if ( pcntl_wexitstatus( $status ) ) {
152 $parentStatus = pcntl_wexitstatus( $status );
157 $this->
output(
"$numRebuilt languages rebuilt out of $total\n" );
158 if ( $numRebuilt === 0 ) {
159 $this->
output(
"Use --force to rebuild the caches which are still fresh.\n" );
162 if ( $parentStatus ) {
163 exit( $parentStatus );
177 foreach ( $codes as $code ) {
178 if ( $force || $lc->isExpired( $code ) ) {
179 $this->
output(
"Rebuilding $code...\n" );
180 $lc->recache( $code );
194 $this->mOptions[
'force'] = $forced;
$wgLanguageCode
Site language code.
$wgCacheDirectory
Directory for caching data in the local filesystem.
$wgLocalisationCacheConf
Localisation cache configuration.
wfIsWindows()
Check if the operating system is Windows.
const RUN_MAINTENANCE_IF_MAIN
A localisation cache optimised for loading large amounts of data for many languages.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option exists.
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.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
static clearGlobalCacheEntry(WANObjectCache $cache)
Invalidate cache keys for all known modules.
Maintenance script to rebuild the localisation cache.
execute()
Do the actual work.
__construct()
Default constructor.
finalSetup()
Handle some last-minute setup here.
setForce( $forced=true)
Sets whether a run of this maintenance script has the force parameter set.
doRebuild( $codes, $lc, $force)
Helper function to rebuild list of languages codes.