4 * Rebuild the localisation cache. Useful if you disabled automatic updates
5 * using $wgLocalisationCacheConf['manualRecache'] = true;
8 * php rebuildLocalisationCache.php [--force]
10 * Use --force to rebuild all files, even the ones that are not out of date.
11 * Use --threads=N to fork more threads.
14 require( dirname(__FILE__
).'/commandLine.inc' );
15 ini_set( 'memory_limit', '200M' );
17 $force = isset( $options['force'] );
18 $threads = intval( isset( $options['threads'] ) ?
$options['threads'] : 1 );
20 $conf = $wgLocalisationCacheConf;
21 $conf['manualRecache'] = false; // Allow fallbacks to create CDB files
23 $conf['forceRecache'] = true;
25 $lc = new LocalisationCache_BulkLoad( $conf );
27 $codes = array_keys( Language
::getLanguageNames( true ) );
30 // Initialise and split into chunks
32 $total = count($codes);
33 $chunks = array_chunk( $codes, ceil(count($codes)/$threads) );
36 foreach ( $chunks as $codes ) {
37 // Do not fork for only one thread
38 $pid = ( $threads > 1 ) ?
pcntl_fork() : -1;
42 doRebuild( $codes, $numRebuilt, $lc, $force );
44 } elseif ($pid === -1) {
45 // Fork failed or one thread, do it serialized
46 doRebuild( $codes, $numRebuilt, $lc, $force );
53 // Wait for all children
54 foreach ( $pids as $pid ) pcntl_waitpid($pid, $status);
56 echo "$numRebuilt languages rebuilt out of $total.\n";
57 if ( $numRebuilt == 0 ) {
58 echo "Use --force to rebuild the caches which are still fresh.\n";
61 function doRebuild( $codes, &$numRebuilt, $lc, $force ) {
62 foreach ( $codes as $code ) {
63 if ( $force ||
$lc->isExpired( $code ) ) {
64 echo "Rebuilding $code...\n";
65 $lc->recache( $code );