summaryrefslogtreecommitdiff
path: root/extensions/LocalisationUpdate
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2014-03-12 18:12:23 +0100
committerPierre Schmitz <pierre@archlinux.de>2014-03-12 18:12:23 +0100
commitd417de70fcf39e0a7a15ba780b597914d16ca0f7 (patch)
tree06ef8c333473660350b995abc03e18f3f85359eb /extensions/LocalisationUpdate
parenta4edbfa031eb4cd72678051f1510afde4f77951e (diff)
Update to MediaWiki 1.22.4
Diffstat (limited to 'extensions/LocalisationUpdate')
-rw-r--r--extensions/LocalisationUpdate/.gitreview5
-rw-r--r--extensions/LocalisationUpdate/KNOWN_ISSUES.txt11
-rw-r--r--extensions/LocalisationUpdate/LocalisationUpdate.class.php113
-rw-r--r--extensions/LocalisationUpdate/LocalisationUpdate.i18n.php14
-rw-r--r--extensions/LocalisationUpdate/LocalisationUpdate.php14
-rw-r--r--extensions/LocalisationUpdate/QuickArrayReader.php199
-rw-r--r--extensions/LocalisationUpdate/README34
-rw-r--r--extensions/LocalisationUpdate/README_FIRST.txt8
-rw-r--r--extensions/LocalisationUpdate/tests/tokenTest.php100
-rw-r--r--extensions/LocalisationUpdate/update.php5
10 files changed, 152 insertions, 351 deletions
diff --git a/extensions/LocalisationUpdate/.gitreview b/extensions/LocalisationUpdate/.gitreview
deleted file mode 100644
index da37d04d..00000000
--- a/extensions/LocalisationUpdate/.gitreview
+++ /dev/null
@@ -1,5 +0,0 @@
-[gerrit]
-host=gerrit.wikimedia.org
-port=29418
-project=mediawiki/extensions/LocalisationUpdate.git
-defaultbranch=master
diff --git a/extensions/LocalisationUpdate/KNOWN_ISSUES.txt b/extensions/LocalisationUpdate/KNOWN_ISSUES.txt
new file mode 100644
index 00000000..7ce14cd0
--- /dev/null
+++ b/extensions/LocalisationUpdate/KNOWN_ISSUES.txt
@@ -0,0 +1,11 @@
+- 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 24620545..66b63232 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,14 +187,7 @@ 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.
@@ -225,7 +218,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 = '';
@@ -252,8 +245,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 );
@@ -264,13 +257,11 @@ 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;
}
}
@@ -290,20 +281,16 @@ 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 );
}
@@ -317,11 +304,7 @@ 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 );
}
}
@@ -335,7 +318,6 @@ class LocalisationUpdate {
} else {
// Broken file? Report and bail
self::myLog( "Failed to parse $file1" );
-
return array( null, null );
}
}
@@ -348,7 +330,6 @@ class LocalisationUpdate {
$messages2 = array();
} else {
self::myLog( "Failed to parse $file2" );
-
return array( null, null );
}
}
@@ -372,9 +353,7 @@ 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 );
@@ -390,6 +369,7 @@ class LocalisationUpdate {
);
}
+
if ( $saveResults ) {
// If anything has changed from the saved version, save the new version
if ( $new_messages != $cur_messages ) {
@@ -404,12 +384,10 @@ class LocalisationUpdate {
} else {
$updates = 0;
}
-
return $updates;
} else {
// Find all deleted or changed messages
$changedStrings = array_diff_assoc( $old_messages, $new_messages );
-
return $changedStrings;
}
}
@@ -426,9 +404,7 @@ 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' );
@@ -439,14 +415,7 @@ 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 );
}
/**
@@ -480,14 +449,7 @@ 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 ) {
@@ -499,14 +461,7 @@ 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.
@@ -518,7 +473,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
@@ -527,12 +482,7 @@ class LocalisationUpdate {
*/
public static function checkHash( $file, $hash ) {
$hashes = self::readFile( 'hashes' );
-
- wfSuppressWarnings();
- $return = $hashes[$file] !== $hash;
- wfRestoreWarnings();
-
- return $return;
+ return @$hashes[$file] !== $hash;
}
/**
@@ -564,7 +514,7 @@ class LocalisationUpdate {
if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
wfDebug( $log . "\n" );
} else {
- print "$log\n";
+ print( $log . "\n" );
}
}
@@ -575,12 +525,10 @@ 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;
}
}
@@ -611,9 +559,7 @@ class LocalisationUpdate {
public static function readFile( $lang ) {
if ( !isset( self::$filecache[$lang] ) ) {
$file = self::filename( $lang );
- wfSuppressWarnings();
- $contents = file_get_contents( $file );
- wfRestoreWarnings();
+ $contents = @file_get_contents( $file );
if ( $contents === false ) {
wfDebug( "Failed to read file '$file'\n" );
@@ -640,12 +586,11 @@ class LocalisationUpdate {
public static function writeFile( $lang, $var ) {
$file = self::filename( $lang );
- wfSuppressWarnings();
- if ( !file_put_contents( $file, serialize( $var ) ) ) {
+ 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 0e73e3bc..c45af9e2 100644
--- a/extensions/LocalisationUpdate/LocalisationUpdate.i18n.php
+++ b/extensions/LocalisationUpdate/LocalisationUpdate.i18n.php
@@ -5,7 +5,7 @@
* @file
* @ingroup Extensions
*/
-
+
$messages = array();
/** English
@@ -102,14 +102,7 @@ $messages['ca'] = array(
'localisationupdate-desc' => 'Manté els missatges localitzats tan actualitzats com sigui possible',
);
-/** Chechen (нохчийн)
- * @author Умар
- */
-$messages['ce'] = array(
- 'localisationupdate-desc' => 'Таро ма хуьйла хаамашан болх бан гӀо до',
-);
-
-/** Czech (čeština)
+/** Czech (česky)
* @author Mormegil
*/
$messages['cs'] = array(
@@ -311,10 +304,9 @@ $messages['ksh'] = array(
/** Luxembourgish (Lëtzebuergesch)
* @author Robby
- * @author Soued031
*/
$messages['lb'] = array(
- 'localisationupdate-desc' => 'hält déi lokaliséiert Messagen sou aktuell wéi méiglech.',
+ 'localisationupdate-desc' => 'hält déi lokaliséiert Messagen esou aktuell wéi méiglech.',
);
/** Macedonian (македонски)
diff --git a/extensions/LocalisationUpdate/LocalisationUpdate.php b/extensions/LocalisationUpdate/LocalisationUpdate.php
index f73304cd..abec5406 100644
--- a/extensions/LocalisationUpdate/LocalisationUpdate.php
+++ b/extensions/LocalisationUpdate/LocalisationUpdate.php
@@ -11,6 +11,7 @@
*/
$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.
@@ -18,8 +19,7 @@ $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 453032f2..214d5a61 100644
--- a/extensions/LocalisationUpdate/QuickArrayReader.php
+++ b/extensions/LocalisationUpdate/QuickArrayReader.php
@@ -8,7 +8,7 @@
* order of magnitude slower than eval().
*/
class QuickArrayReader {
- private $vars = array();
+ var $vars = array();
/**
* @param $string string
@@ -27,100 +27,96 @@ 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]] ) );
-
- 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]] ) );
+ switch( $tokens[$i][0] ) {
+ case T_OPEN_TAG:
+ $i++;
+ continue;
+ case T_VARIABLE:
+ // '$messages' -> 'messages'
+ $varname = trim( substr( $tokens[$i][1], 1 ) );
+ $varindex = null;
- if ( $tokens[$i] !== ']' ) {
- throw $this->except( $tokens[$i], ']' );
- }
- while ( isset( $skipTypes[$tokens[++$i][0]] ) );
- }
+ 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], '(' );
- }
- $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 );
+ 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 or array' );
+ throw $this->except( $tokens[$i], 'scalar index' );
}
- 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 ( $tokens[$i] !== ';' ) {
- throw $this->except( $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]] ) ) {
+ $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], '(' );
}
- $i++;
- break;
- default:
- throw $this->except( $tokens[$i], 'open tag, whitespace, or variable.' );
+ $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.');
}
}
}
@@ -131,12 +127,11 @@ 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" );
}
@@ -148,42 +143,30 @@ 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( '\\\'' => '\'', '\\\\' => '\\' ) );
- }
-
- wfSuppressWarnings();
- if ( $str !== '' && $str[0] == '"' ) {
+ 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 ) );
- }
- wfRestoreWarnings();
-
- if ( substr( $str, 0, 4 ) === 'true' ) {
+ 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;
@@ -194,7 +177,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
deleted file mode 100644
index 3df784b5..00000000
--- a/extensions/LocalisationUpdate/README
+++ /dev/null
@@ -1,34 +0,0 @@
-== 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
new file mode 100644
index 00000000..3973c435
--- /dev/null
+++ b/extensions/LocalisationUpdate/README_FIRST.txt
@@ -0,0 +1,8 @@
+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
deleted file mode 100644
index 2b71cc46..00000000
--- a/extensions/LocalisationUpdate/tests/tokenTest.php
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-
-$IP = strval( getenv( 'MW_INSTALL_PATH' ) ) !== ''
- ? getenv( 'MW_INSTALL_PATH' )
- : realpath( dirname( __FILE__ ) . "/../../../" );
-
-require_once "$IP/maintenance/commandLine.inc";
-
-function evalExtractArray( $php, $varname ) {
- eval( $php );
- wfSuppressWarnings();
-
- return $$varname;
- wfRestoreWarnings();
-}
-
-function confExtractArray( $php, $varname ) {
- try {
- $ce = new ConfEditor( "<?php $php" );
- $vars = $ce->getVars();
- wfSuppressWarnings();
- $retval = $vars[$varname];
- wfRestoreWarnings();
- } catch ( Exception $e ) {
- print $e . "\n";
- $retval = null;
- }
-
- return $retval;
-}
-
-function quickTokenExtractArray( $php, $varname ) {
- $reader = new QuickArrayReader( "<?php $php" );
-
- return $reader->getVar( $varname );
-}
-
-if ( count( $args ) ) {
- $sources = $args;
-} else {
- $sources =
- array_merge(
- glob( "$IP/extensions/*/*.i18n.php" ),
- glob( "$IP/languages/messages/Messages*.php" ) );
-}
-
-foreach ( $sources as $sourceFile ) {
- $rel = basename( $sourceFile );
- $out = str_replace( '/', '-', $rel );
-
- $sourceData = file_get_contents( $sourceFile );
-
- if ( preg_match( '!extensions/!', $sourceFile ) ) {
- $sourceData = LocalisationUpdate::cleanupExtensionFile( $sourceData );
- $items = 'langs';
- } else {
- $sourceData = LocalisationUpdate::cleanupFile( $sourceData );
- $items = 'messages';
- }
-
- file_put_contents( "$out.txt", $sourceData );
-
- $start = microtime( true );
- $eval = evalExtractArray( $sourceData, 'messages' );
- $deltaEval = microtime( true ) - $start;
-
- $start = microtime( true );
- $quick = quickTokenExtractArray( $sourceData, 'messages' );
- $deltaQuick = microtime( true ) - $start;
-
- $start = microtime( true );
- $token = confExtractArray( $sourceData, 'messages' );
- $deltaToken = microtime( true ) - $start;
-
- $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 );
-
- 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 ) );
- file_put_contents( "$out-quick.txt", var_export( $quick, true ) );
- #die("check eval.txt and token.txt\n");
- }
- echo "\n";
-}
-
-echo "ok\n";
-
diff --git a/extensions/LocalisationUpdate/update.php b/extensions/LocalisationUpdate/update.php
index 04ea64c7..750fc4f2 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,6 +23,7 @@ if ( isset( $options['help'] ) ) {
exit( 0 );
}
+
$starttime = microtime( true );
// Prevent the script from timing out