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.',
55 'Override the LC store class (normally $wgLocalisationCacheConf[\'storeClass\'])',
61 'EXPERIMENTAL: Disable the database backend. Setting this option will result in an error ' .
62 'if you have extensions or use site configuration that need the database. This is an ' .
63 'experimental feature to allow offline building of the localisation cache. Known limitations:' .
65 '* Incompatible with LCStoreDB, which always requires a database. ' .
"\n" .
66 '* The message purge may require a database. See --skip-message-purge.'
72 'Skip purging of MessageBlobStore. The purge operation may require a database, depending ' .
73 'on the configuration and extensions on this wiki. If skipping the purge now, you need to ' .
74 'run purgeMessageBlobStore.php shortly after deployment.'
79 # This script needs to be run to build the initial l10n cache. But if
80 # $wgLanguageCode is not 'en', it won't be able to run because there is
81 # no l10n cache. Break the cycle by forcing $wgLanguageCode = 'en'.
91 $threads = $this->
getOption(
'threads', 1 );
92 if ( $threads < 1 || $threads != intval( $threads ) ) {
93 $this->
output(
"Invalid thread count specified; running single-threaded.\n" );
97 $this->
output(
"Threaded rebuild is not supported on Windows; running single-threaded.\n" );
100 if ( $threads > 1 && !function_exists(
'pcntl_fork' ) ) {
101 $this->
output(
"PHP pcntl extension is not present; running single-threaded.\n" );
107 $conf[
'manualRecache'] =
false;
108 $conf[
'forceRecache'] = $force || !empty( $conf[
'forceRecache'] );
110 $conf[
'storeDirectory'] = $this->
getOption(
'outdir' );
113 if ( $this->
hasOption(
'store-class' ) ) {
114 $conf[
'storeClass'] = $this->
getOption(
'store-class' );
118 $services = MediaWikiServices::getInstance();
121 LocalisationCache::CONSTRUCTOR_OPTIONS,
123 $services->getMainConfig()
126 LoggerFactory::getInstance(
'localisation' ),
127 $this->hasOption(
'skip-message-purge' ) ? [] :
128 [
static function () use ( $services ) {
131 $services->getLanguageNameUtils(),
132 $services->getHookContainer()
135 $allCodes = array_keys( $services
136 ->getLanguageNameUtils()
137 ->getLanguageNames(
null,
'mwfile' ) );
139 # Validate requested languages
140 $codes = array_intersect( $allCodes,
141 explode(
',', $this->
getOption(
'lang' ) ) );
142 # Bailed out if nothing is left
143 if ( count( $codes ) == 0 ) {
144 $this->
fatalError(
'None of the languages specified exists.' );
147 # By default get all languages
154 $total = count( $codes );
155 $chunks = array_chunk( $codes, ceil( count( $codes ) / $threads ) );
158 foreach ( $chunks as $codes ) {
160 $pid = ( $threads > 1 ) ? pcntl_fork() : -1;
165 mt_srand( getmypid() );
169 } elseif ( $pid === -1 ) {
171 $numRebuilt += $this->
doRebuild( $codes, $lc, $force );
178 foreach ( $pids as $pid ) {
180 pcntl_waitpid( $pid, $status );
182 if ( pcntl_wifexited( $status ) ) {
183 $code = pcntl_wexitstatus( $status );
185 $this->
output(
"Pid $pid exited with status $code !!\n" );
188 $parentStatus |= $code;
189 } elseif ( pcntl_wifsignaled( $status ) ) {
190 $signum = pcntl_wtermsig( $status );
191 $this->
output(
"Pid $pid terminated by signal $signum !!\n" );
197 $this->
output(
"$numRebuilt languages rebuilt out of $total\n" );
198 if ( $numRebuilt === 0 ) {
199 $this->
output(
"Use --force to rebuild the caches which are still fresh.\n" );
202 if ( $parentStatus ) {
203 $this->
fatalError(
'Failed.', $parentStatus );
217 foreach ( $codes as $code ) {
218 if ( $force || $lc->isExpired( $code ) ) {
219 $this->
output(
"Rebuilding $code...\n" );
220 $lc->recache( $code );
230 if ( $this->
hasOption(
'no-database' ) ) {
234 return parent::getDbType();
243 $this->mOptions[
'force'] = $forced;
248require_once RUN_MAINTENANCE_IF_MAIN;
$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.
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...
const DB_NONE
Constants for DB access type.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
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.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
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.