diff options
Diffstat (limited to 'extensions/LocalisationUpdate')
-rw-r--r-- | extensions/LocalisationUpdate/KNOWN_ISSUES.txt | 11 | ||||
-rw-r--r-- | extensions/LocalisationUpdate/LocalisationUpdate.class.php | 113 | ||||
-rw-r--r-- | extensions/LocalisationUpdate/LocalisationUpdate.i18n.php | 14 | ||||
-rw-r--r-- | extensions/LocalisationUpdate/LocalisationUpdate.php | 14 | ||||
-rw-r--r-- | extensions/LocalisationUpdate/QuickArrayReader.php | 199 | ||||
-rw-r--r-- | extensions/LocalisationUpdate/README | 34 | ||||
-rw-r--r-- | extensions/LocalisationUpdate/README_FIRST.txt | 8 | ||||
-rw-r--r-- | extensions/LocalisationUpdate/tests/tokenTest.php | 61 | ||||
-rw-r--r-- | extensions/LocalisationUpdate/update.php | 5 |
9 files changed, 281 insertions, 178 deletions
diff --git a/extensions/LocalisationUpdate/KNOWN_ISSUES.txt b/extensions/LocalisationUpdate/KNOWN_ISSUES.txt deleted file mode 100644 index 7ce14cd0..00000000 --- a/extensions/LocalisationUpdate/KNOWN_ISSUES.txt +++ /dev/null @@ -1,11 +0,0 @@ -- Only works with SVN revision 50605 or later of the - MediaWiki core - - - -Key issues at the moment: -* Seems to want to store a copy of the localization updates in each local database. -We've got hundreds of wikis run from the same installation set; we don't want to multiply our effort by 1000. - -* It doesn't seem to be using available memcached stuff; unsure yet whether this is taken care of -by the general message caching or if we're going to end up making extra hits we don't need. diff --git a/extensions/LocalisationUpdate/LocalisationUpdate.class.php b/extensions/LocalisationUpdate/LocalisationUpdate.class.php index 66b63232..24620545 100644 --- a/extensions/LocalisationUpdate/LocalisationUpdate.class.php +++ b/extensions/LocalisationUpdate/LocalisationUpdate.class.php @@ -3,7 +3,7 @@ /** * Class for localization updates. * - * TODO: refactor code to remove duplication + * @todo Refactor code to remove duplication */ class LocalisationUpdate { @@ -60,7 +60,7 @@ class LocalisationUpdate { $skipCore = isset( $options['skip-core'] ); $skipExtensions = isset( $options['skip-extensions'] ); - if( isset( $options['outdir'] ) ) { + if ( isset( $options['outdir'] ) ) { $wgLocalisationUpdateDirectory = $options['outdir']; } @@ -82,25 +82,25 @@ class LocalisationUpdate { $result = 0; // Update all MW core messages. - if( !$skipCore ) { + if ( !$skipCore ) { $result = self::updateMediawikiMessages( $verbose, $coreUrl ); } // Update all Extension messages. - if( !$skipExtensions ) { - if( $all ) { + if ( !$skipExtensions ) { + if ( $all ) { global $IP; $extFiles = array(); // Look in extensions/ for all available items... - // TODO: add support for $wgExtensionAssetsPath + // @todo Add support for $wgExtensionAssetsPath $dirs = new RecursiveDirectoryIterator( "$IP/extensions/" ); // I ain't kidding... RecursiveIteratorIterator. - foreach( new RecursiveIteratorIterator( $dirs ) as $pathname => $item ) { + foreach ( new RecursiveIteratorIterator( $dirs ) as $pathname => $item ) { $filename = basename( $pathname ); $matches = array(); - if( preg_match( '/^(.*)\.i18n\.php$/', $filename, $matches ) ) { + if ( preg_match( '/^(.*)\.i18n\.php$/', $filename, $matches ) ) { $group = $matches[1]; $extFiles[$group] = $pathname; } @@ -187,7 +187,14 @@ class LocalisationUpdate { ); // Compare the files. - $changedCount += self::compareFiles( $repoUrl, $localUrl, $verbose, $changedEnglishStrings, false, true ); + $changedCount += self::compareFiles( + $repoUrl, + $localUrl, + $verbose, + $changedEnglishStrings, + false, + true + ); } // Log some nice info. @@ -218,7 +225,7 @@ class LocalisationUpdate { preg_match_all( '/\$messages(.*\s)*?\);/', $contents, $results ); // But we want them all in one string. - if( !empty( $results[0] ) && is_array( $results[0] ) ) { + if ( !empty( $results[0] ) && is_array( $results[0] ) ) { $contents = implode( "\n\n", $results[0] ); } else { $contents = ''; @@ -245,8 +252,8 @@ class LocalisationUpdate { // Use cURL to get the SVN contents. if ( preg_match( "/^http/", $file ) ) { - while( !$filecontents && $attempts <= $wgLocalisationUpdateRetryAttempts ) { - if( $attempts > 0 ) { + while ( !$filecontents && $attempts <= $wgLocalisationUpdateRetryAttempts ) { + if ( $attempts > 0 ) { $delay = 1; self::myLog( 'Failed to download ' . $file . "; retrying in ${delay}s..." ); sleep( $delay ); @@ -257,11 +264,13 @@ class LocalisationUpdate { } if ( !$filecontents ) { self::myLog( 'Cannot get the contents of ' . $file . ' (curl)' ); + return false; } - } else {// otherwise try file_get_contents + } else { // otherwise try file_get_contents if ( !( $filecontents = file_get_contents( $file ) ) ) { self::myLog( 'Cannot get the contents of ' . $file ); + return false; } } @@ -281,16 +290,20 @@ class LocalisationUpdate { * * @return array */ - public static function loadFilesToCompare( $tag, $file1, $file2, $verbose, $alwaysGetResult = true ) { + public static function loadFilesToCompare( $tag, $file1, $file2, $verbose, + $alwaysGetResult = true + ) { $file1contents = self::getFileContents( $file1 ); if ( $file1contents === false || $file1contents === '' ) { self::myLog( "Failed to read $file1" ); + return array( null, null ); } $file2contents = self::getFileContents( $file2 ); if ( $file2contents === false || $file2contents === '' ) { self::myLog( "Failed to read $file2" ); + return array( null, null ); } @@ -304,7 +317,11 @@ class LocalisationUpdate { // Check if the file has changed since our last update. if ( !$alwaysGetResult ) { if ( !self::checkHash( $file1, $file1hash ) && !self::checkHash( $file2, $file2hash ) ) { - self::myLog( "Skipping {$tag} since the files haven't changed since our last update", $verbose ); + self::myLog( + "Skipping {$tag} since the files haven't changed since our last update", + $verbose + ); + return array( null, null ); } } @@ -318,6 +335,7 @@ class LocalisationUpdate { } else { // Broken file? Report and bail self::myLog( "Failed to parse $file1" ); + return array( null, null ); } } @@ -330,6 +348,7 @@ class LocalisationUpdate { $messages2 = array(); } else { self::myLog( "Failed to parse $file2" ); + return array( null, null ); } } @@ -353,7 +372,9 @@ class LocalisationUpdate { * * @return array|int */ - private static function compareLanguageArrays( $langcode, $old_messages, $new_messages, $verbose, $forbiddenKeys, $saveResults ) { + private static function compareLanguageArrays( $langcode, $old_messages, + $new_messages, $verbose, $forbiddenKeys, $saveResults + ) { // Get the currently-cached messages, if any $cur_messages = self::readFile( $langcode ); @@ -369,7 +390,6 @@ class LocalisationUpdate { ); } - if ( $saveResults ) { // If anything has changed from the saved version, save the new version if ( $new_messages != $cur_messages ) { @@ -384,10 +404,12 @@ class LocalisationUpdate { } else { $updates = 0; } + return $updates; } else { // Find all deleted or changed messages $changedStrings = array_diff_assoc( $old_messages, $new_messages ); + return $changedStrings; } } @@ -404,7 +426,9 @@ class LocalisationUpdate { * * @return array|int */ - public static function compareFiles( $newfile, $oldfile, $verbose, array $forbiddenKeys = array(), $alwaysGetResult = true, $saveResults = false ) { + public static function compareFiles( $newfile, $oldfile, $verbose, + array $forbiddenKeys = array(), $alwaysGetResult = true, $saveResults = false + ) { // Get the languagecode. $langcode = Language::getCodeFromFileName( $newfile, 'Messages' ); @@ -415,7 +439,14 @@ class LocalisationUpdate { return $saveResults ? 0 : array(); } - return self::compareLanguageArrays( $langcode, $old_messages, $new_messages, $verbose, $forbiddenKeys, $saveResults ); + return self::compareLanguageArrays( + $langcode, + $old_messages, + $new_messages, + $verbose, + $forbiddenKeys, + $saveResults + ); } /** @@ -449,7 +480,14 @@ class LocalisationUpdate { } // Find the changed english strings. - $forbiddenKeys = self::compareLanguageArrays( 'en', $old_messages['en'], $new_messages['en'], $verbose, array(), false ); + $forbiddenKeys = self::compareLanguageArrays( + 'en', + $old_messages['en'], + $new_messages['en'], + $verbose, + array(), + false + ); // Do an update for each language. foreach ( $new_messages as $language => $messages ) { @@ -461,7 +499,14 @@ class LocalisationUpdate { $old_messages[$language] = array(); } - $updates += self::compareLanguageArrays( $language, $old_messages[$language], $messages, $verbose, $forbiddenKeys, true ); + $updates += self::compareLanguageArrays( + $language, + $old_messages[$language], + $messages, + $verbose, + $forbiddenKeys, + true + ); } // And log some stuff. @@ -473,7 +518,7 @@ class LocalisationUpdate { /** * Checks whether a messages file has a certain hash. * - * TODO: Swap return values, this is insane + * @todo Swap return values, this is insane * * @param $file string Filename * @param $hash string Hash @@ -482,7 +527,12 @@ class LocalisationUpdate { */ public static function checkHash( $file, $hash ) { $hashes = self::readFile( 'hashes' ); - return @$hashes[$file] !== $hash; + + wfSuppressWarnings(); + $return = $hashes[$file] !== $hash; + wfRestoreWarnings(); + + return $return; } /** @@ -514,7 +564,7 @@ class LocalisationUpdate { if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) { wfDebug( $log . "\n" ); } else { - print( $log . "\n" ); + print "$log\n"; } } @@ -525,10 +575,12 @@ class LocalisationUpdate { */ public static function parsePHP( $php, $varname ) { try { - $reader = new QuickArrayReader("<?php $php"); + $reader = new QuickArrayReader( "<?php $php" ); + return $reader->getVar( $varname ); - } catch( Exception $e ) { + } catch ( Exception $e ) { self::myLog( "Failed to read file: " . $e ); + return false; } } @@ -559,7 +611,9 @@ class LocalisationUpdate { public static function readFile( $lang ) { if ( !isset( self::$filecache[$lang] ) ) { $file = self::filename( $lang ); - $contents = @file_get_contents( $file ); + wfSuppressWarnings(); + $contents = file_get_contents( $file ); + wfRestoreWarnings(); if ( $contents === false ) { wfDebug( "Failed to read file '$file'\n" ); @@ -586,11 +640,12 @@ class LocalisationUpdate { public static function writeFile( $lang, $var ) { $file = self::filename( $lang ); - if ( !@file_put_contents( $file, serialize( $var ) ) ) { + wfSuppressWarnings(); + if ( !file_put_contents( $file, serialize( $var ) ) ) { throw new MWException( "Failed to write to file '$file'" ); } + wfRestoreWarnings(); self::$filecache[$lang] = $var; } - } diff --git a/extensions/LocalisationUpdate/LocalisationUpdate.i18n.php b/extensions/LocalisationUpdate/LocalisationUpdate.i18n.php index c45af9e2..0e73e3bc 100644 --- a/extensions/LocalisationUpdate/LocalisationUpdate.i18n.php +++ b/extensions/LocalisationUpdate/LocalisationUpdate.i18n.php @@ -5,7 +5,7 @@ * @file * @ingroup Extensions */ - + $messages = array(); /** English @@ -102,7 +102,14 @@ $messages['ca'] = array( 'localisationupdate-desc' => 'Manté els missatges localitzats tan actualitzats com sigui possible', ); -/** Czech (česky) +/** Chechen (нохчийн) + * @author Умар + */ +$messages['ce'] = array( + 'localisationupdate-desc' => 'Таро ма хуьйла хаамашан болх бан гӀо до', +); + +/** Czech (čeština) * @author Mormegil */ $messages['cs'] = array( @@ -304,9 +311,10 @@ $messages['ksh'] = array( /** Luxembourgish (Lëtzebuergesch) * @author Robby + * @author Soued031 */ $messages['lb'] = array( - 'localisationupdate-desc' => 'hält déi lokaliséiert Messagen esou aktuell wéi méiglech.', + 'localisationupdate-desc' => 'hält déi lokaliséiert Messagen sou aktuell wéi méiglech.', ); /** Macedonian (македонски) diff --git a/extensions/LocalisationUpdate/LocalisationUpdate.php b/extensions/LocalisationUpdate/LocalisationUpdate.php index abec5406..f73304cd 100644 --- a/extensions/LocalisationUpdate/LocalisationUpdate.php +++ b/extensions/LocalisationUpdate/LocalisationUpdate.php @@ -11,7 +11,6 @@ */ $wgLocalisationUpdateDirectory = false; - /** * These should point to either an HTTP-accessible file or local file system. * $1 is the name of the repo (for extensions) and $2 is the name of file in the repo. @@ -19,7 +18,8 @@ $wgLocalisationUpdateDirectory = false; */ $wgLocalisationUpdateCoreURL = "https://git.wikimedia.org/raw/mediawiki%2Fcore.git/HEAD/$4"; -$wgLocalisationUpdateExtensionURL = "https://git.wikimedia.org/raw/mediawiki%2Fextensions%2F$3.git/HEAD/$4"; +$wgLocalisationUpdateExtensionURL = + "https://git.wikimedia.org/raw/mediawiki%2Fextensions%2F$3.git/HEAD/$4"; /// Deprecated $wgLocalisationUpdateSVNURL = false; @@ -28,11 +28,11 @@ $wgLocalisationUpdateRetryAttempts = 5; // Info about me! $wgExtensionCredits['other'][] = array( - 'path' => __FILE__, - 'name' => 'LocalisationUpdate', - 'author' => array( 'Tom Maaswinkel', 'Niklas Laxström', 'Roan Kattouw' ), - 'version' => '1.0', - 'url' => 'https://www.mediawiki.org/wiki/Extension:LocalisationUpdate', + 'path' => __FILE__, + 'name' => 'LocalisationUpdate', + 'author' => array( 'Tom Maaswinkel', 'Niklas Laxström', 'Roan Kattouw' ), + 'version' => '1.0', + 'url' => 'https://www.mediawiki.org/wiki/Extension:LocalisationUpdate', 'descriptionmsg' => 'localisationupdate-desc', ); diff --git a/extensions/LocalisationUpdate/QuickArrayReader.php b/extensions/LocalisationUpdate/QuickArrayReader.php index 214d5a61..453032f2 100644 --- a/extensions/LocalisationUpdate/QuickArrayReader.php +++ b/extensions/LocalisationUpdate/QuickArrayReader.php @@ -8,7 +8,7 @@ * order of magnitude slower than eval(). */ class QuickArrayReader { - var $vars = array(); + private $vars = array(); /** * @param $string string @@ -27,96 +27,100 @@ class QuickArrayReader { ); $tokens = token_get_all( $string ); $count = count( $tokens ); - for( $i = 0; $i < $count; ) { - while( isset($skipTypes[$tokens[$i][0]] ) ) { + for ( $i = 0; $i < $count; ) { + while ( isset( $skipTypes[$tokens[$i][0]] ) ) { $i++; } - switch( $tokens[$i][0] ) { - case T_OPEN_TAG: - $i++; - continue; - case T_VARIABLE: - // '$messages' -> 'messages' - $varname = trim( substr( $tokens[$i][1], 1 ) ); - $varindex = null; - - while( isset($skipTypes[$tokens[++$i][0]] ) ); + switch ( $tokens[$i][0] ) { + case T_OPEN_TAG: + $i++; + continue; + case T_VARIABLE: + // '$messages' -> 'messages' + $varname = trim( substr( $tokens[$i][1], 1 ) ); + $varindex = null; + + while ( isset( $skipTypes[$tokens[++$i][0]] ) ); + + if ( $tokens[$i] === '[' ) { + while ( isset( $skipTypes[$tokens[++$i][0]] ) ); + + if ( isset( $scalarTypes[$tokens[$i][0]] ) ) { + $varindex = $this->parseScalar( $tokens[$i] ); + } else { + throw $this->except( $tokens[$i], 'scalar index' ); + } + while ( isset( $skipTypes[$tokens[++$i][0]] ) ); - if( $tokens[$i] === '[' ) { - while( isset($skipTypes[$tokens[++$i][0]] ) ); + if ( $tokens[$i] !== ']' ) { + throw $this->except( $tokens[$i], ']' ); + } + while ( isset( $skipTypes[$tokens[++$i][0]] ) ); + } - if( isset($scalarTypes[$tokens[$i][0]] ) ) { - $varindex = $this->parseScalar( $tokens[$i] ); + if ( $tokens[$i] !== '=' ) { + throw $this->except( $tokens[$i], '=' ); + } + while ( isset( $skipTypes[$tokens[++$i][0]] ) ); + + if ( isset( $scalarTypes[$tokens[$i][0]] ) ) { + $buildval = $this->parseScalar( $tokens[$i] ); + } elseif ( $tokens[$i][0] === T_ARRAY ) { + while ( isset( $skipTypes[$tokens[++$i][0]] ) ); + if ( $tokens[$i] !== '(' ) { + throw $this->except( $tokens[$i], '(' ); + } + $buildval = array(); + do { + while ( isset( $skipTypes[$tokens[++$i][0]] ) ); + + if ( $tokens[$i] === ')' ) { + break; + } + if ( isset( $scalarTypes[$tokens[$i][0]] ) ) { + $key = $this->parseScalar( $tokens[$i] ); + } + while ( isset( $skipTypes[$tokens[++$i][0]] ) ); + + if ( $tokens[$i][0] !== T_DOUBLE_ARROW ) { + throw $this->except( $tokens[$i], '=>' ); + } + while ( isset( $skipTypes[$tokens[++$i][0]] ) ); + + if ( isset( $scalarTypes[$tokens[$i][0]] ) ) { + $val = $this->parseScalar( $tokens[$i] ); + } + wfSuppressWarnings(); + $buildval[$key] = $val; + wfRestoreWarnings(); + while ( isset( $skipTypes[$tokens[++$i][0]] ) ); + + if ( $tokens[$i] === ',' ) { + continue; + } elseif ( $tokens[$i] === ')' ) { + break; + } else { + throw $this->except( $tokens[$i], ', or )' ); + } + } while ( true ); } else { - throw $this->except( $tokens[$i], 'scalar index' ); + throw $this->except( $tokens[$i], 'scalar or array' ); } - while( isset($skipTypes[$tokens[++$i][0]] ) ); - - if( $tokens[$i] !== ']' ) { - throw $this->except( $tokens[$i], ']' ); + if ( is_null( $varindex ) ) { + $this->vars[$varname] = $buildval; + } else { + wfSuppressWarnings(); + $this->vars[$varname][$varindex] = $buildval; + wfRestoreWarnings(); } - while( isset($skipTypes[$tokens[++$i][0]] ) ); - } - - if( $tokens[$i] !== '=' ) { - throw $this->except( $tokens[$i], '=' ); - } - while( isset($skipTypes[$tokens[++$i][0]] ) ); - - if( isset($scalarTypes[$tokens[$i][0]] ) ) { - $buildval = $this->parseScalar( $tokens[$i] ); - } elseif( $tokens[$i][0] === T_ARRAY ) { - while( isset($skipTypes[$tokens[++$i][0]] ) ); - if( $tokens[$i] !== '(' ) { - throw $this->except( $tokens[$i], '(' ); + while ( isset( $skipTypes[$tokens[++$i][0]] ) ); + if ( $tokens[$i] !== ';' ) { + throw $this->except( $tokens[$i], ';' ); } - $buildval = array(); - do { - while( isset($skipTypes[$tokens[++$i][0]] ) ); - - if( $tokens[$i] === ')' ) { - break; - } - if( isset($scalarTypes[$tokens[$i][0]] ) ) { - $key = $this->parseScalar( $tokens[$i] ); - } - while( isset($skipTypes[$tokens[++$i][0]] ) ); - - if( $tokens[$i][0] !== T_DOUBLE_ARROW ) { - throw $this->except( $tokens[$i], '=>' ); - } - while( isset($skipTypes[$tokens[++$i][0]] ) ); - - if( isset($scalarTypes[$tokens[$i][0]] ) ) { - $val = $this->parseScalar( $tokens[$i] ); - } - @$buildval[$key] = $val; - while( isset($skipTypes[$tokens[++$i][0]] ) ); - - if( $tokens[$i] === ',' ) { - continue; - } elseif( $tokens[$i] === ')' ) { - break; - } else { - throw $this->except( $tokens[$i], ', or )' ); - } - } while(true); - } else { - throw $this->except( $tokens[$i], 'scalar or array' ); - } - if( is_null( $varindex ) ) { - $this->vars[$varname] = $buildval; - } else { - @$this->vars[$varname][$varindex] = $buildval; - } - while( isset($skipTypes[$tokens[++$i][0]] ) ); - if( $tokens[$i] !== ';' ) { - throw $this->except($tokens[$i], ';'); - } - $i++; - break; - default: - throw $this->except($tokens[$i], 'open tag, whitespace, or variable.'); + $i++; + break; + default: + throw $this->except( $tokens[$i], 'open tag, whitespace, or variable.' ); } } } @@ -127,11 +131,12 @@ class QuickArrayReader { * @return Exception */ private function except( $got, $expected ) { - if( is_array( $got ) ) { + if ( is_array( $got ) ) { $got = token_name( $got[0] ) . " ('" . $got[1] . "')"; } else { $got = "'" . $got . "'"; } + return new Exception( "Expected $expected, got $got" ); } @@ -143,30 +148,42 @@ class QuickArrayReader { * @return mixed Parsed value */ function parseScalar( $token ) { - if( is_array( $token ) ) { + if ( is_array( $token ) ) { $str = $token[1]; } else { $str = $token; } - if ( $str !== '' && $str[0] == '\'' ) + if ( $str !== '' && $str[0] == '\'' ) { // Single-quoted string // @fixme trim() call is due to mystery bug where whitespace gets // appended to the token; without it we ended up reading in the // extra quote on the end! return strtr( substr( trim( $str ), 1, -1 ), array( '\\\'' => '\'', '\\\\' => '\\' ) ); - if ( $str !== '' && @$str[0] == '"' ) + } + + wfSuppressWarnings(); + if ( $str !== '' && $str[0] == '"' ) { // Double-quoted string // @fixme trim() call is due to mystery bug where whitespace gets // appended to the token; without it we ended up reading in the // extra quote on the end! return stripcslashes( substr( trim( $str ), 1, -1 ) ); - if ( substr( $str, 0, 4 ) === 'true' ) + } + wfRestoreWarnings(); + + if ( substr( $str, 0, 4 ) === 'true' ) { return true; - if ( substr( $str, 0, 5 ) === 'false' ) + } + + if ( substr( $str, 0, 5 ) === 'false' ) { return false; - if ( substr( $str, 0, 4 ) === 'null' ) + } + + if ( substr( $str, 0, 4 ) === 'null' ) { return null; + } + // Must be some kind of numeric value, so let PHP's weak typing // be useful for a change return $str; @@ -177,7 +194,7 @@ class QuickArrayReader { * @return null|string */ function getVar( $varname ) { - if( isset( $this->vars[$varname] ) ) { + if ( isset( $this->vars[$varname] ) ) { return $this->vars[$varname]; } else { return null; diff --git a/extensions/LocalisationUpdate/README b/extensions/LocalisationUpdate/README new file mode 100644 index 00000000..3df784b5 --- /dev/null +++ b/extensions/LocalisationUpdate/README @@ -0,0 +1,34 @@ +== Localisation Update == +Localisation Update extension can update the MediaWiki messages at any time, +without needing to upgrade the MediaWiki software. + +For more information see: + https://www.mediawiki.org/wiki/Extension:LocalisationUpdate + +== Installation == +1. Add the following to LocalSettings.php of your MediaWiki setup: + + require_once "$IP/extensions/LocalisationUpdate/LocalisationUpdate.php"; + $wgLocalisationUpdateDirectory = "$IP/cache"; + +2. Create a cache folder in the installation directory, and be sure the server +has permissions to write on it. + +If localization updates don't seem to come through, you may need to run, + + php maintenance/rebuildLocalisationCache.php --force. + +3. Whenever you want to run an update, run, + + php extensions/LocalisationUpdate/update.php + +For detailed help, see: + + php extensions/LocalisationUpdate/update.php --help + +4. If you are on Unix like system, you should add LocalisationUpdate to +crontab: + + crontab -e + # Add the following line + @daily php /path/to/your/wiki/extensions/LocalisationUpdate/update.php --quiet diff --git a/extensions/LocalisationUpdate/README_FIRST.txt b/extensions/LocalisationUpdate/README_FIRST.txt deleted file mode 100644 index 3973c435..00000000 --- a/extensions/LocalisationUpdate/README_FIRST.txt +++ /dev/null @@ -1,8 +0,0 @@ -To install this extension first include -LocalisationUpdate/LocalisationUpdate.php in your LocalSettings.php - -Then add the required new tables to your database by running -php maintenance/update.php on the command line. - -Whenever you want to run an update, run -php extensions/LocalisationUpdate/update.php on the command line. diff --git a/extensions/LocalisationUpdate/tests/tokenTest.php b/extensions/LocalisationUpdate/tests/tokenTest.php index 1112313c..2b71cc46 100644 --- a/extensions/LocalisationUpdate/tests/tokenTest.php +++ b/extensions/LocalisationUpdate/tests/tokenTest.php @@ -4,47 +4,53 @@ $IP = strval( getenv( 'MW_INSTALL_PATH' ) ) !== '' ? getenv( 'MW_INSTALL_PATH' ) : realpath( dirname( __FILE__ ) . "/../../../" ); -require_once( "$IP/maintenance/commandLine.inc" ); +require_once "$IP/maintenance/commandLine.inc"; function evalExtractArray( $php, $varname ) { eval( $php ); - return @$$varname; + wfSuppressWarnings(); + + return $$varname; + wfRestoreWarnings(); } function confExtractArray( $php, $varname ) { try { - $ce = new ConfEditor("<?php $php"); + $ce = new ConfEditor( "<?php $php" ); $vars = $ce->getVars(); - $retval = @$vars[$varname]; - } catch( Exception $e ) { + wfSuppressWarnings(); + $retval = $vars[$varname]; + wfRestoreWarnings(); + } catch ( Exception $e ) { print $e . "\n"; $retval = null; } + return $retval; } function quickTokenExtractArray( $php, $varname ) { - $reader = new QuickArrayReader("<?php $php"); + $reader = new QuickArrayReader( "<?php $php" ); + return $reader->getVar( $varname ); } - -if( count( $args ) ) { +if ( count( $args ) ) { $sources = $args; } else { $sources = array_merge( - glob("$IP/extensions/*/*.i18n.php"), - glob("$IP/languages/messages/Messages*.php") ); + glob( "$IP/extensions/*/*.i18n.php" ), + glob( "$IP/languages/messages/Messages*.php" ) ); } -foreach( $sources as $sourceFile ) { +foreach ( $sources as $sourceFile ) { $rel = basename( $sourceFile ); $out = str_replace( '/', '-', $rel ); $sourceData = file_get_contents( $sourceFile ); - if( preg_match( '!extensions/!', $sourceFile ) ) { + if ( preg_match( '!extensions/!', $sourceFile ) ) { $sourceData = LocalisationUpdate::cleanupExtensionFile( $sourceData ); $items = 'langs'; } else { @@ -54,30 +60,33 @@ foreach( $sources as $sourceFile ) { file_put_contents( "$out.txt", $sourceData ); - $start = microtime(true); + $start = microtime( true ); $eval = evalExtractArray( $sourceData, 'messages' ); - $deltaEval = microtime(true) - $start; + $deltaEval = microtime( true ) - $start; - $start = microtime(true); + $start = microtime( true ); $quick = quickTokenExtractArray( $sourceData, 'messages' ); - $deltaQuick = microtime(true) - $start; + $deltaQuick = microtime( true ) - $start; - $start = microtime(true); + $start = microtime( true ); $token = confExtractArray( $sourceData, 'messages' ); - $deltaToken = microtime(true) - $start; + $deltaToken = microtime( true ) - $start; - $hashEval = md5(serialize($eval)); - $hashToken = md5(serialize($token)); - $hashQuick = md5(serialize($quick)); - $countEval = count( (array)$eval); + $hashEval = md5( serialize( $eval ) ); + $hashToken = md5( serialize( $token ) ); + $hashQuick = md5( serialize( $quick ) ); + $countEval = count( (array)$eval ); $countToken = count( (array)$token ); $countQuick = count( (array)$quick ); - printf( "%s %s %d $items - %0.1fms - eval\n", $rel, $hashEval, $countEval, $deltaEval * 1000 ); - printf( "%s %s %d $items - %0.1fms - QuickArrayReader\n", $rel, $hashQuick, $countQuick, $deltaQuick * 1000 ); - printf( "%s %s %d $items - %0.1fms - ConfEditor\n", $rel, $hashToken, $countToken, $deltaToken * 1000 ); + printf( "%s %s %d $items - %0.1fms - eval\n", + $rel, $hashEval, $countEval, $deltaEval * 1000 ); + printf( "%s %s %d $items - %0.1fms - QuickArrayReader\n", + $rel, $hashQuick, $countQuick, $deltaQuick * 1000 ); + printf( "%s %s %d $items - %0.1fms - ConfEditor\n", + $rel, $hashToken, $countToken, $deltaToken * 1000 ); - if( $hashEval !== $hashToken || $hashEval !== $hashQuick ) { + if ( $hashEval !== $hashToken || $hashEval !== $hashQuick ) { echo "FAILED on $rel\n"; file_put_contents( "$out-eval.txt", var_export( $eval, true ) ); file_put_contents( "$out-token.txt", var_export( $token, true ) ); diff --git a/extensions/LocalisationUpdate/update.php b/extensions/LocalisationUpdate/update.php index 750fc4f2..04ea64c7 100644 --- a/extensions/LocalisationUpdate/update.php +++ b/extensions/LocalisationUpdate/update.php @@ -5,9 +5,9 @@ $IP = strval( getenv( 'MW_INSTALL_PATH' ) ) !== '' : realpath( dirname( __FILE__ ) . "/../../" ); // TODO: migrate to maintenance class -require_once( "$IP/maintenance/commandLine.inc" ); +require_once "$IP/maintenance/commandLine.inc"; -if( isset( $options['help'] ) ) { +if ( isset( $options['help'] ) ) { print "Fetches updated localisation files from MediaWiki development SVN\n"; print "and saves into local database to merge with release defaults.\n"; print "\n"; @@ -23,7 +23,6 @@ if( isset( $options['help'] ) ) { exit( 0 ); } - $starttime = microtime( true ); // Prevent the script from timing out |