summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'MLEB/Translate/scripts')
-rw-r--r--MLEB/Translate/scripts/characterEditStats.php83
-rw-r--r--MLEB/Translate/scripts/create-language-models.php51
-rw-r--r--MLEB/Translate/scripts/createCheckIndex.php25
-rw-r--r--MLEB/Translate/scripts/createMessageIndex.php6
-rw-r--r--MLEB/Translate/scripts/export.php19
-rw-r--r--MLEB/Translate/scripts/fallbacks-graph.php30
-rw-r--r--MLEB/Translate/scripts/fuzzy.php137
-rw-r--r--MLEB/Translate/scripts/groupStatistics.php222
-rw-r--r--MLEB/Translate/scripts/languageeditstats.php10
-rw-r--r--MLEB/Translate/scripts/magic-export.php126
-rw-r--r--MLEB/Translate/scripts/migrate-schema2.php14
-rw-r--r--MLEB/Translate/scripts/mwcore-export.php10
-rw-r--r--MLEB/Translate/scripts/plural-comparison.php18
-rw-r--r--MLEB/Translate/scripts/poimport.php28
-rw-r--r--MLEB/Translate/scripts/populateFuzzy.php37
-rw-r--r--MLEB/Translate/scripts/processMessageChanges.php69
-rw-r--r--MLEB/Translate/scripts/refresh-translatable-pages.php30
-rw-r--r--MLEB/Translate/scripts/sync-group.php28
-rw-r--r--MLEB/Translate/scripts/translator-stats-process.php26
-rw-r--r--MLEB/Translate/scripts/translator-stats.php64
-rw-r--r--MLEB/Translate/scripts/ttmserver-export.php51
-rw-r--r--MLEB/Translate/scripts/yaml-tests.php20
22 files changed, 660 insertions, 444 deletions
diff --git a/MLEB/Translate/scripts/characterEditStats.php b/MLEB/Translate/scripts/characterEditStats.php
index 782d0086..69db5a27 100644
--- a/MLEB/Translate/scripts/characterEditStats.php
+++ b/MLEB/Translate/scripts/characterEditStats.php
@@ -3,8 +3,8 @@
* Show number of characters translated over a given period of time.
*
* @author Santhosh Thottingal
- * @copyright Copyright 2013 Santhosh Thottingal
- * @license GPL-2.0+
+ * @copyright Copyright © 2013 Santhosh Thottingal
+ * @license GPL-2.0-or-later
* @file
* @ingroup Script Stats
*/
@@ -30,20 +30,11 @@ class CharacterEditStats extends Maintenance {
);
$this->addOption(
'days',
- '(optional) Calculate for given number of days (default: 30) ' .
- '(capped by the max age of recent changes on the wiki)',
+ '(optional) Calculate for given number of days (default: 30)',
false, /*required*/
true /*has arg*/
);
$this->addOption(
- 'bots',
- '(optional) Include bot edits'
- );
- $this->addOption(
- 'diff',
- '(optional) Count the edit diffs alone'
- );
- $this->addOption(
'ns',
'(optional) Comma separated list of namespace IDs',
false, /*required*/
@@ -52,16 +43,12 @@ class CharacterEditStats extends Maintenance {
}
public function execute() {
- global $wgTranslateFuzzyBotName, $wgSitename;
+ global $wgTranslateFuzzyBotName, $wgSitename, $wgTranslateMessageNamespaces;
$days = (int)$this->getOption( 'days', 30 );
- $hours = $days * 24;
-
$top = (int)$this->getOption( 'top', -1 );
- $bots = $this->hasOption( 'bots' );
-
- $namespaces = array();
+ $namespaces = [];
if ( $this->hasOption( 'ns' ) ) {
$input = explode( ',', $this->getOption( 'ns' ) );
@@ -70,35 +57,30 @@ class CharacterEditStats extends Maintenance {
$namespaces[] = $namespace;
}
}
+ } else {
+ $namespaces = $wgTranslateMessageNamespaces;
}
// Select set of edits to report on
+ $rows = self::getRevisionsFromHistory( $days, $namespaces );
- // Fetch some extrac fields that normally TranslateUtils::translationChanges wont
- $extraFields = array( 'rc_old_len', 'rc_new_len' );
- $rows = TranslateUtils::translationChanges( $hours, $bots, $namespaces, $extraFields );
// Get counts for edits per language code after filtering out edits by FuzzyBot
- $codes = array();
+ $codes = [];
foreach ( $rows as $_ ) {
// Filter out edits by $wgTranslateFuzzyBotName
- if ( $_->rc_user_text === $wgTranslateFuzzyBotName ) {
+ if ( $_->user_text === $wgTranslateFuzzyBotName ) {
continue;
}
- $handle = new MessageHandle( Title::newFromText( $_->rc_title ) );
+ $handle = new MessageHandle( Title::newFromText( $_->title ) );
$code = $handle->getCode();
if ( !isset( $codes[$code] ) ) {
$codes[$code] = 0;
}
- if ( $this->hasOption( 'diff' ) ) {
- $diff = abs( $_->rc_new_len - $_->rc_old_len );
- } else {
- $diff = $_->rc_new_len;
- }
- $codes[$code] += $diff;
+ $codes[$code] += $_->length;
}
// Sort counts and report descending up to $top rows.
@@ -118,13 +100,52 @@ class CharacterEditStats extends Maintenance {
continue;
}
$charRatio = mb_strlen( $language, 'UTF-8' ) / strlen( $language );
- $num = intval( $num * $charRatio );
+ $num = (int)( $num * $charRatio );
$total += $num;
$this->output( "$code\t$language\t$num\n" );
}
$this->output( "-----------------------\n" );
$this->output( "Total\t\t$total\n" );
}
+
+ private function getRevisionsFromHistory( $days, array $namespaces ) {
+ $dbr = wfGetDB( DB_REPLICA );
+ $cutoff = $dbr->addQuotes( $dbr->timestamp( time() - $days * 24 * 3600 ) );
+
+ // The field renames are to be compatible with recentchanges table query
+ if ( is_callable( Revision::class, 'getQueryInfo' ) ) {
+ $revQuery = Revision::getQueryInfo( [ 'page' ] );
+ $revUserText = isset( $revQuery['fields']['rev_user_text'] )
+ ? $revQuery['fields']['rev_user_text']
+ : 'rev_user_text';
+ } else {
+ $revQuery = [
+ 'tables' => [ 'revision', 'page' ],
+ 'joins' => [
+ 'page' => [ 'JOIN', 'rev_page = page_id' ],
+ ]
+ ];
+ $revUserText = 'rev_user_text';
+ }
+ $conds = [
+ "rev_timestamp > $cutoff",
+ 'page_namespace' => $namespaces,
+ ];
+
+ $res = $dbr->select(
+ $revQuery['tables'],
+ [
+ 'title' => 'page_title',
+ 'user_text' => $revUserText,
+ 'length' => 'rev_len',
+ ],
+ $conds,
+ __METHOD__,
+ [],
+ $revQuery['joins']
+ );
+ return iterator_to_array( $res );
+ }
}
$maintClass = 'CharacterEditStats';
diff --git a/MLEB/Translate/scripts/create-language-models.php b/MLEB/Translate/scripts/create-language-models.php
index dfc6216f..7be45a58 100644
--- a/MLEB/Translate/scripts/create-language-models.php
+++ b/MLEB/Translate/scripts/create-language-models.php
@@ -6,7 +6,7 @@
* @author Niklas Laxström
*
* @copyright Copyright © 2013, Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -20,7 +20,7 @@ if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
require_once "$IP/maintenance/Maintenance.php";
class LanguageModelCreator extends Maintenance {
- protected $changes = array();
+ protected $changes = [];
public function __construct() {
parent::__construct();
@@ -43,19 +43,19 @@ TXT;
$languages = TranslateUtils::getLanguageNames( 'en' );
$cache = wfGetCache( CACHE_DB );
- $key = wfMemckey( __METHOD__, $messages );
+ $key = wfMemcKey( __METHOD__, $messages );
$pages = $cache->get( $key );
if ( !is_array( $pages ) ) {
- $dbr = wfGetDB( DB_SLAVE );
- $conds = array();
+ $dbr = wfGetDB( DB_REPLICA );
+ $conds = [];
$conds[] = 'page_title' . $dbr->buildLike( $dbr->anyString(), '/', $dbr->anyString() );
$conds['page_namespace'] = $wgTranslateMessageNamespaces;
echo "Before query\n";
$res = $dbr->select(
- array( 'page' ),
- array( 'page_title, page_id' ),
+ [ 'page' ],
+ [ 'page_title, page_id' ],
$conds,
__METHOD__
);
@@ -93,7 +93,7 @@ TXT;
echo "After sort map\n";
- $cache->set( $key, $pages, 3600*24 );
+ $cache->set( $key, $pages, 3600 * 24 );
echo "After set map\n";
}
@@ -102,14 +102,14 @@ TXT;
unset( $pages['nl-informal'] );
unset( $pages['en-gb'] );
- $pids = array();
+ $pids = [];
$threads = 2;
foreach ( $pages as $code => $pageids ) {
$pid = ( $threads > 1 ) ? pcntl_fork() : -1;
if ( $pid === 0 ) {
// Child, reseed because there is no bug in PHP:
- // http://bugs.php.net/bug.php?id=42465
+ // https://bugs.php.net/bug.php?id=42465
mt_srand( getmypid() );
$this->analyzeLanguage( $code, $pageids );
exit();
@@ -136,8 +136,8 @@ TXT;
$this->output( "Combining languages\n" );
- $huge = array();
- foreach ( glob( "temp-*.json" ) as $file ) {
+ $huge = [];
+ foreach ( glob( 'temp-*.json' ) as $file ) {
$contents = file_get_contents( $file );
$json = FormatJson::decode( $contents, true );
@@ -164,7 +164,7 @@ TXT;
$config->useMb( true );
$c = new LanguageDetector\Learn( $config );
$c->addSample( $code, $text );
- $c->addStepCallback( function( $lang, $status ) {
+ $c->addStepCallback( function ( $lang, $status ) {
echo "Learning {$lang}: $status\n";
} );
@@ -174,11 +174,10 @@ TXT;
protected function cacheSourceText( $code, $ids ) {
$cache = wfGetCache( CACHE_DB );
- $key = wfMemckey( __CLASS__, 'cc', $code );
+ $key = wfMemcKey( __CLASS__, 'cc', $code );
$text = $cache->get( $key );
if ( !is_string( $text ) ) {
-
- $snippets = array();
+ $snippets = [];
$ids = explode( '|', $ids );
@@ -194,23 +193,21 @@ TXT;
$time = microtime( true );
foreach ( $ids as $id ) {
- $params = new FauxRequest( array(
+ $params = new FauxRequest( [
'pageid' => $id,
'action' => 'parse',
'prop' => 'text',
'disablepp' => 'true',
- ) );
+ ] );
$api = new ApiMain( $params );
$api->execute();
- if ( defined( 'ApiResult::META_CONTENT' ) ) {
- $result = $api->getResult()->getResultData( null, array(
- 'BC' => array(),
- ) );
- } else {
- $result = $api->getResultData();
- }
+ $result = $api->getResult()->getResultData(
+ null,
+ [ 'BC' => [] ]
+ );
+
$text = $result['parse']['text']['*'];
$text = strip_tags( $text );
$text = str_replace( '!!FUZZY!!', '', $text );
@@ -220,8 +217,8 @@ TXT;
$snippets[] = $text;
}
- $text = implode( " ", $snippets );
- $cache->set( $key, $text, 3600*24 );
+ $text = implode( ' ', $snippets );
+ $cache->set( $key, $text, 3600 * 24 );
$delta = microtime( true ) - $time;
$this->output( "$code TOOK $delta\n" );
diff --git a/MLEB/Translate/scripts/createCheckIndex.php b/MLEB/Translate/scripts/createCheckIndex.php
index b98318db..d215bbbd 100644
--- a/MLEB/Translate/scripts/createCheckIndex.php
+++ b/MLEB/Translate/scripts/createCheckIndex.php
@@ -5,7 +5,7 @@
* @author Niklas Laxström
* @author Siebrand Mazeland
* @copyright Copyright © 2008-2013, Niklas Laxström, Siebrand Mazeland
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -87,7 +87,7 @@ class CreateCheckIndex extends Maintenance {
foreach ( $langCodes as $code ) {
$this->output( "$code ", $id );
- $problematic = array();
+ $problematic = [];
$collection->resetForNewLanguage( $code );
$collection->loadTranslations();
@@ -97,7 +97,6 @@ class CreateCheckIndex extends Maintenance {
foreach ( $collection as $key => $message ) {
$prob = $checker->checkMessageFast( $message, $code );
if ( $prob ) {
-
if ( $verbose ) {
// Print it
$nsText = $wgContLang->getNsText( $g->namespaces[0] );
@@ -105,7 +104,7 @@ class CreateCheckIndex extends Maintenance {
}
// Add it to the array
- $problematic[] = array( $g->namespaces[0], "$key/$code" );
+ $problematic[] = [ $g->namespaces[0], "$key/$code" ];
}
}
@@ -114,27 +113,27 @@ class CreateCheckIndex extends Maintenance {
}
}
- static function tagFuzzy( $problematic ) {
+ public static function tagFuzzy( $problematic ) {
if ( !count( $problematic ) ) {
return;
}
- $db = wfGetDB( DB_MASTER );
+ $dbw = wfGetDB( DB_MASTER );
foreach ( $problematic as $p ) {
$title = Title::makeTitleSafe( $p[0], $p[1] );
- $titleText = $title->getDBKey();
- $res = $db->select( 'page', array( 'page_id', 'page_latest' ),
- array( 'page_namespace' => $p[0], 'page_title' => $titleText ), __METHOD__ );
+ $titleText = $title->getDBkey();
+ $res = $dbw->select( 'page', [ 'page_id', 'page_latest' ],
+ [ 'page_namespace' => $p[0], 'page_title' => $titleText ], __METHOD__ );
- $inserts = array();
+ $inserts = [];
foreach ( $res as $r ) {
- $inserts = array(
+ $inserts = [
'rt_page' => $r->page_id,
'rt_revision' => $r->page_latest,
'rt_type' => RevTag::getType( 'fuzzy' )
- );
+ ];
}
- $db->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ );
+ $dbw->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ );
}
}
}
diff --git a/MLEB/Translate/scripts/createMessageIndex.php b/MLEB/Translate/scripts/createMessageIndex.php
index ff1e2ca8..72a3f4f2 100644
--- a/MLEB/Translate/scripts/createMessageIndex.php
+++ b/MLEB/Translate/scripts/createMessageIndex.php
@@ -5,7 +5,7 @@
* is no other way to know which message group a message belongs to.
*
* @author Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -25,10 +25,10 @@ class CreateMessageIndex extends Maintenance {
}
public function execute() {
- MessageGroups::clearCache();
+ MessageGroups::singleton()->recache();
MessageIndex::singleton()->rebuild();
}
}
$maintClass = 'CreateMessageIndex';
-require_once DO_MAINTENANCE;
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/MLEB/Translate/scripts/export.php b/MLEB/Translate/scripts/export.php
index 6553adc9..867359d0 100644
--- a/MLEB/Translate/scripts/export.php
+++ b/MLEB/Translate/scripts/export.php
@@ -5,7 +5,7 @@
* @author Niklas Laxström
* @author Siebrand Mazeland
* @copyright Copyright © 2008-2013, Niklas Laxström, Siebrand Mazeland
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -107,7 +107,7 @@ class CommandlineExport extends Maintenance {
$noLocation = '--no-location ';
};
- $skip = array();
+ $skip = [];
if ( $this->hasOption( 'skip' ) ) {
$skip = array_map( 'trim', explode( ',', $this->getOption( 'skip' ) ) );
}
@@ -141,13 +141,13 @@ class CommandlineExport extends Maintenance {
}
if ( !count( $groups ) ) {
- $this->error( "EE1: No valid message groups identified.", 1 );
+ $this->error( 'EE1: No valid message groups identified.', 1 );
}
$changeFilter = false;
$hours = $this->getOption( 'hours' );
if ( $hours ) {
- $namespaces = array();
+ $namespaces = [];
/** @var FileBasedMessageGroup $group */
foreach ( $groups as $group ) {
@@ -157,7 +157,7 @@ class CommandlineExport extends Maintenance {
$namespaces = array_keys( $namespaces );
$bots = true;
- $changeFilter = array();
+ $changeFilter = [];
$rows = TranslateUtils::translationChanges( $hours, $bots, $namespaces );
foreach ( $rows as $row ) {
$title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
@@ -173,7 +173,7 @@ class CommandlineExport extends Maintenance {
}
}
- $skipGroups = array();
+ $skipGroups = [];
if ( $this->hasOption( 'skipgroup' ) ) {
$skipGroups = array_map( 'trim', explode( ',', $this->getOption( 'skipgroup' ) ) );
}
@@ -205,6 +205,7 @@ class CommandlineExport extends Maintenance {
foreach ( $langs as $index => $code ) {
if ( !isset( $stats[$code] ) ) {
unset( $langs[$index] );
+ continue;
}
$total = $stats[$code][MessageGroupStats::TOTAL];
@@ -250,7 +251,7 @@ class CommandlineExport extends Maintenance {
$whitelist = $group->getTranslatableLanguages();
foreach ( $langs as $lang ) {
- // Do not export languges that are blacklisted (or not whitelisted).
+ // Do not export languages that are blacklisted (or not whitelisted).
// Also check that whitelist is not null, which means that all
// languages are allowed for translation and export.
if ( is_array( $whitelist ) && !isset( $whitelist[$lang] ) ) {
@@ -278,8 +279,8 @@ class CommandlineExport extends Maintenance {
if ( $definitionFile ) {
if ( is_file( $definitionFile ) ) {
$targetFileName = $ffs->getWritePath() .
- "/" . $group->getTargetFilename( $collection->code );
- $cmd = "msgmerge --quiet " . $noLocation . "--output-file=" .
+ '/' . $group->getTargetFilename( $collection->code );
+ $cmd = 'msgmerge --quiet ' . $noLocation . '--output-file=' .
$targetFileName . ' ' . $targetFileName . ' ' . $definitionFile;
wfShellExec( $cmd, $ret );
diff --git a/MLEB/Translate/scripts/fallbacks-graph.php b/MLEB/Translate/scripts/fallbacks-graph.php
index 2af3bfcb..0209747c 100644
--- a/MLEB/Translate/scripts/fallbacks-graph.php
+++ b/MLEB/Translate/scripts/fallbacks-graph.php
@@ -4,8 +4,7 @@
*
* @author Niklas Laxström
*
- * @copyright Copyright © 2012-2013, Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -44,11 +43,10 @@ $1
XML;
$langs = Language::fetchLanguageNames( null, 'mw' );
- $nodes = $edges = array();
+ $nodes = $edges = [];
foreach ( $langs as $code => $name ) {
-
$fallbacks = Language::getFallbacksFor( $code );
- if ( $fallbacks === array( 'en' ) ) {
+ if ( $fallbacks === [ 'en' ] ) {
continue;
}
@@ -57,7 +55,7 @@ XML;
$prev = $code;
foreach ( $fallbacks as $fb ) {
$nodes[$fb] = $this->createNode( $fb );
- $edges[$fb . $prev] = Xml::element( 'edge', array( 'source' => $prev, 'target' => $fb ) );
+ $edges[$fb . $prev] = Xml::element( 'edge', [ 'source' => $prev, 'target' => $fb ] );
$prev = $fb;
}
}
@@ -68,16 +66,22 @@ XML;
}
protected function createNode( $code ) {
- return
- Xml::openElement( 'node', array( 'id' => $code ) )
- . Xml::openElement( 'data', array( 'key' => "code" ) )
- . Xml::openElement( 'y:Shpapenode' )
- . Xml::element( 'y:NodeLabel', array(), $code )
- . Xml::closeElement( 'y:Shpapenode' )
+ return Xml::openElement( 'node', [ 'id' => $code ] )
+ . Xml::openElement( 'data', [ 'key' => 'code' ] )
+ . Xml::openElement( 'y:Shapenode' )
+ . Xml::element(
+ 'y:Geometry',
+ [ 'height' => 30, 'width' => max( 30, 10 * strlen( $code ) ) ],
+ ''
+ )
+ . Xml::element( 'y:NodeLabel', [], $code )
+ . Xml::element( 'y:BorderStyle', [ 'hasColor' => 'false' ], '' )
+ . Xml::element( 'y:Fill', [ 'hasColor' => 'false' ], '' )
+ . Xml::closeElement( 'y:Shapenode' )
. Xml::closeElement( 'data' )
. Xml::closeElement( 'node' );
}
}
$maintClass = 'FallbacksCompare';
-require_once DO_MAINTENANCE;
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/MLEB/Translate/scripts/fuzzy.php b/MLEB/Translate/scripts/fuzzy.php
index d00c9088..977011c3 100644
--- a/MLEB/Translate/scripts/fuzzy.php
+++ b/MLEB/Translate/scripts/fuzzy.php
@@ -6,7 +6,7 @@
* @author Niklas Laxström
* @author Siebrand Mazeland
* @copyright Copyright © 2007-2013, Niklas Laxström, Siebrand Mazeland
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
*/
// Standard boilerplate to define $IP
@@ -26,8 +26,8 @@ class Fuzzy extends Maintenance {
parent::__construct();
$this->mDescription = 'Fuzzy bot command line script.';
$this->addArg(
- 'messages',
- 'Message to fuzzy'
+ 'arg',
+ 'Title pattern or username if user option is provided.'
);
$this->addOption(
'really',
@@ -45,21 +45,34 @@ class Fuzzy extends Maintenance {
false, /*required*/
true /*has arg*/
);
+ $this->addOption(
+ 'user',
+ '(optional) Fuzzy the translations made by user given as an argument.',
+ false, /*required*/
+ false /*has arg*/
+ );
}
public function execute() {
- $bot = new FuzzyScript( $this->getArg( 0 ) );
-
+ $skipLanguages = [];
if ( $this->hasOption( 'skiplanguages' ) ) {
- $bot->skipLanguages = array_map(
+ $skipLanguages = array_map(
'trim',
explode( ',', $this->getOption( 'skiplanguages' ) )
);
}
+ if ( $this->hasOption( 'user' ) ) {
+ $user = User::newFromName( $this->getArg( 0 ) );
+ $pages = FuzzyScript::getPagesForUser( $user, $skipLanguages );
+ } else {
+ $pages = FuzzyScript::getPagesForPattern( $this->getArg( 0 ), $skipLanguages );
+ }
+
+ $bot = new FuzzyScript( $pages );
$bot->comment = $this->getOption( 'comment' );
$bot->dryrun = !$this->hasOption( 'really' );
- $bot->setProgressCallback( array( $this, 'myOutput' ) );
+ $bot->setProgressCallback( [ $this, 'myOutput' ] );
$bot->execute();
}
@@ -67,7 +80,7 @@ class Fuzzy extends Maintenance {
* Public alternative for protected Maintenance::output() as we need to get
* messages from the ChangeSyncer class to the commandline.
* @param string $text The text to show to the user
- * @param string $channel Unique identifier for the channel.
+ * @param string|null $channel Unique identifier for the channel.
* @param bool $error Whether this is an error message
*/
public function myOutput( $text, $channel = null, $error = false ) {
@@ -84,11 +97,6 @@ class Fuzzy extends Maintenance {
*/
class FuzzyScript {
/**
- /* @var string[] List of patterns to mark.
- */
- private $titles = array();
-
- /**
* @var bool Check for configuration problems.
*/
private $allclear = false;
@@ -104,18 +112,13 @@ class FuzzyScript {
/**
* @var string Edit summary.
*/
- public $comment = null;
+ public $comment;
/**
- * string[] List of language codes to skip.
+ * @param array $pages
*/
- public $skipLanguages = array();
-
- /**
- * @param string[] $titles
- */
- public function __construct( $titles ) {
- $this->titles = (array)$titles;
+ public function __construct( $pages ) {
+ $this->pages = $pages;
$this->allclear = true;
}
@@ -136,7 +139,7 @@ class FuzzyScript {
return;
}
- $msgs = $this->getPages();
+ $msgs = $this->pages;
$count = count( $msgs );
$this->reportProgress( "Found $count pages to update.", 'pagecount' );
@@ -148,51 +151,99 @@ class FuzzyScript {
}
/// Searches pages that match given patterns
- private function getPages() {
+ public static function getPagesForPattern( $pattern, $skipLanguages = [] ) {
global $wgTranslateMessageNamespaces;
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_REPLICA );
- $search = array();
- foreach ( $this->titles as $title ) {
+ $search = [];
+ foreach ( (array)$pattern as $title ) {
$title = Title::newFromText( $title );
$ns = $title->getNamespace();
if ( !isset( $search[$ns] ) ) {
- $search[$ns] = array();
+ $search[$ns] = [];
}
- $search[$ns][] = 'page_title' . $dbr->buildLike( $title->getDBKey(), $dbr->anyString() );
+ $search[$ns][] = 'page_title' . $dbr->buildLike( $title->getDBkey(), $dbr->anyString() );
}
- $title_conds = array();
+ $title_conds = [];
foreach ( $search as $ns => $names ) {
- if ( $ns == NS_MAIN ) {
+ if ( $ns === NS_MAIN ) {
$ns = $wgTranslateMessageNamespaces;
}
$titles = $dbr->makeList( $names, LIST_OR );
- $title_conds[] = $dbr->makeList( array( 'page_namespace' => $ns, $titles ), LIST_AND );
+ $title_conds[] = $dbr->makeList( [ 'page_namespace' => $ns, $titles ], LIST_AND );
}
- $conds = array(
+ $conds = [
'page_latest=rev_id',
'rev_text_id=old_id',
$dbr->makeList( $title_conds, LIST_OR ),
- );
+ ];
- if ( count( $this->skipLanguages ) ) {
- $skiplist = $dbr->makeList( $this->skipLanguages );
+ if ( count( $skipLanguages ) ) {
+ $skiplist = $dbr->makeList( $skipLanguages );
$conds[] = "substring_index(page_title, '/', -1) NOT IN ($skiplist)";
}
$rows = $dbr->select(
- array( 'page', 'revision', 'text' ),
- array( 'page_title', 'page_namespace', 'old_text', 'old_flags' ),
+ [ 'page', 'revision', 'text' ],
+ [ 'page_title', 'page_namespace', 'old_text', 'old_flags' ],
$conds,
__METHOD__
);
- $messagesContents = array();
+ $messagesContents = [];
+ foreach ( $rows as $row ) {
+ $title = Title::makeTitle( $row->page_namespace, $row->page_title );
+ $messagesContents[] = [ $title, Revision::getRevisionText( $row ) ];
+ }
+
+ $rows->free();
+
+ return $messagesContents;
+ }
+
+ public static function getPagesForUser( User $user, $skipLanguages = [] ) {
+ global $wgTranslateMessageNamespaces;
+ $dbr = wfGetDB( DB_REPLICA );
+
+ if ( class_exists( ActorMigration::class ) ) {
+ $revWhere = ActorMigration::newMigration()->getWhere( $dbr, 'rev_user', $user );
+ } else {
+ $revWhere = [
+ 'tables' => [],
+ 'conds' => 'rev_user = ' . (int)$user->getId(),
+ 'joins' => [],
+ ];
+ }
+
+ $conds = [
+ $revWhere['conds'],
+ 'page_namespace' => $wgTranslateMessageNamespaces,
+ 'page_title' . $dbr->buildLike( $dbr->anyString(), '/', $dbr->anyString() ),
+ ];
+
+ if ( count( $skipLanguages ) ) {
+ $skiplist = $dbr->makeList( $skipLanguages );
+ $conds[] = "substring_index(page_title, '/', -1) NOT IN ($skiplist)";
+ }
+
+ $rows = $dbr->select(
+ [ 'page', 'revision', 'text' ] + $revWhere['tables'],
+ [ 'page_title', 'page_namespace', 'old_text', 'old_flags' ],
+ $conds,
+ __METHOD__,
+ [],
+ [
+ 'revision' => [ 'JOIN', 'page_latest=rev_id' ],
+ 'text' => [ 'JOIN', 'rev_text_id=old_id' ],
+ ] + $revWhere['joins']
+ );
+
+ $messagesContents = [];
foreach ( $rows as $row ) {
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
- $messagesContents[] = array( $title, Revision::getRevisionText( $row ) );
+ $messagesContents[] = [ $title, Revision::getRevisionText( $row ) ];
}
$rows->free();
@@ -212,20 +263,20 @@ class FuzzyScript {
$this->reportProgress( "Updating {$title->getPrefixedText()}... ", $title );
if ( !$title instanceof Title ) {
- $this->reportProgress( "INVALID TITLE!", $title );
+ $this->reportProgress( 'INVALID TITLE!', $title );
return;
}
$items = explode( '/', $title->getText(), 2 );
if ( isset( $items[1] ) && $items[1] === $wgTranslateDocumentationLanguageCode ) {
- $this->reportProgress( "IGNORED!", $title );
+ $this->reportProgress( 'IGNORED!', $title );
return;
}
if ( $dryrun ) {
- $this->reportProgress( "DRY RUN!", $title );
+ $this->reportProgress( 'DRY RUN!', $title );
return;
}
diff --git a/MLEB/Translate/scripts/groupStatistics.php b/MLEB/Translate/scripts/groupStatistics.php
index d4f560a3..0cec6bea 100644
--- a/MLEB/Translate/scripts/groupStatistics.php
+++ b/MLEB/Translate/scripts/groupStatistics.php
@@ -8,7 +8,7 @@
* @author Niklas Laxström
* @author Siebrand Mazeland
* @copyright Copyright © 2007-2013, Niklas Laxström, Siebrand Mazeland
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
*/
// Standard boilerplate to define $IP
@@ -23,7 +23,7 @@ require_once "$IP/maintenance/Maintenance.php";
class GroupStatistics extends Maintenance {
/**
* Array of the most spoken languages in the world.
- * Source: http://stats.wikimedia.org/EN/Sitemap.htm.
+ * Source: https://stats.wikimedia.org/EN/Sitemap.htm.
*
* Key value pairs of:
* [MediaWiki localisation code] => array(
@@ -32,62 +32,62 @@ class GroupStatistics extends Maintenance {
* [continent where localisation is spoken]
* )
*/
- public $mostSpokenLanguages = array(
- 'en' => array( 1, 1500, 'multiple' ),
- 'zh-hans' => array( 2, 1300, 'asia' ),
- 'zh-hant' => array( 2, 1300, 'asia' ),
- 'hi' => array( 3, 550, 'asia' ),
- 'ar' => array( 4, 530, 'multiple' ),
- 'es' => array( 5, 500, 'multiple' ),
- 'ms' => array( 6, 300, 'asia' ),
- 'pt' => array( 7, 290, 'multiple' ),
- 'pt-br' => array( 7, 290, 'america' ),
- 'ru' => array( 8, 278, 'multiple' ),
- 'id' => array( 9, 250, 'asia' ),
- 'bn' => array( 10, 230, 'asia' ),
- 'fr' => array( 11, 200, 'multiple' ),
- 'de' => array( 12, 185, 'europe' ),
- 'ja' => array( 13, 132, 'asia' ),
- 'fa' => array( 14, 107, 'asia' ),
- 'pnb' => array( 15, 104, 'asia' ), // Most spoken variant
- 'tl' => array( 16, 90, 'asia' ),
- 'mr' => array( 17, 90, 'asia' ),
- 'vi' => array( 18, 80, 'asia' ),
- 'jv' => array( 19, 80, 'asia' ),
- 'te' => array( 20, 80, 'asia' ),
- 'ko' => array( 21, 78, 'asia' ),
- 'wuu' => array( 22, 77, 'asia' ),
- 'arz' => array( 23, 76, 'africa' ),
- 'th' => array( 24, 73, 'asia' ),
- 'yue' => array( 25, 71, 'asia' ),
- 'tr' => array( 26, 70, 'multiple' ),
- 'it' => array( 27, 70, 'europe' ),
- 'ta' => array( 28, 66, 'asia' ),
- 'ur' => array( 29, 60, 'asia' ),
- 'my' => array( 30, 52, 'asia' ),
- 'sw' => array( 31, 50, 'africa' ),
- 'nan' => array( 32, 49, 'asia' ),
- 'kn' => array( 33, 47, 'asia' ),
- 'gu' => array( 34, 46, 'asia' ),
- 'uk' => array( 35, 45, 'europe' ),
- 'pl' => array( 36, 43, 'europe' ),
- 'sd' => array( 37, 41, 'asia' ),
- 'ha' => array( 38, 39, 'africa' ),
- 'ml' => array( 39, 37, 'asia' ),
- 'gan-hans' => array( 40, 35, 'asia' ),
- 'gan-hant' => array( 40, 35, 'asia' ),
- 'hak' => array( 41, 34, 'asia' ),
- 'or' => array( 42, 31, 'asia' ),
- 'ne' => array( 43, 30, 'asia' ),
- 'ro' => array( 44, 28, 'europe' ),
- 'su' => array( 45, 27, 'asia' ),
- 'az' => array( 46, 27, 'asia' ),
- 'nl' => array( 47, 27, 'europe' ),
- 'zu' => array( 48, 26, 'africa' ),
- 'ps' => array( 49, 26, 'asia' ),
- 'ckb' => array( 50, 26, 'asia' ),
- 'ku-latn' => array( 50, 26, 'asia' ),
- );
+ public $mostSpokenLanguages = [
+ 'en' => [ 1, 1500, 'multiple' ],
+ 'zh-hans' => [ 2, 1300, 'asia' ],
+ 'zh-hant' => [ 2, 1300, 'asia' ],
+ 'hi' => [ 3, 550, 'asia' ],
+ 'ar' => [ 4, 530, 'multiple' ],
+ 'es' => [ 5, 500, 'multiple' ],
+ 'ms' => [ 6, 300, 'asia' ],
+ 'pt' => [ 7, 290, 'multiple' ],
+ 'pt-br' => [ 7, 290, 'america' ],
+ 'ru' => [ 8, 278, 'multiple' ],
+ 'id' => [ 9, 250, 'asia' ],
+ 'bn' => [ 10, 230, 'asia' ],
+ 'fr' => [ 11, 200, 'multiple' ],
+ 'de' => [ 12, 185, 'europe' ],
+ 'ja' => [ 13, 132, 'asia' ],
+ 'fa' => [ 14, 107, 'asia' ],
+ 'pnb' => [ 15, 104, 'asia' ], // Most spoken variant
+ 'tl' => [ 16, 90, 'asia' ],
+ 'mr' => [ 17, 90, 'asia' ],
+ 'vi' => [ 18, 80, 'asia' ],
+ 'jv' => [ 19, 80, 'asia' ],
+ 'te' => [ 20, 80, 'asia' ],
+ 'ko' => [ 21, 78, 'asia' ],
+ 'wuu' => [ 22, 77, 'asia' ],
+ 'arz' => [ 23, 76, 'africa' ],
+ 'th' => [ 24, 73, 'asia' ],
+ 'yue' => [ 25, 71, 'asia' ],
+ 'tr' => [ 26, 70, 'multiple' ],
+ 'it' => [ 27, 70, 'europe' ],
+ 'ta' => [ 28, 66, 'asia' ],
+ 'ur' => [ 29, 60, 'asia' ],
+ 'my' => [ 30, 52, 'asia' ],
+ 'sw' => [ 31, 50, 'africa' ],
+ 'nan' => [ 32, 49, 'asia' ],
+ 'kn' => [ 33, 47, 'asia' ],
+ 'gu' => [ 34, 46, 'asia' ],
+ 'uk' => [ 35, 45, 'europe' ],
+ 'pl' => [ 36, 43, 'europe' ],
+ 'sd' => [ 37, 41, 'asia' ],
+ 'ha' => [ 38, 39, 'africa' ],
+ 'ml' => [ 39, 37, 'asia' ],
+ 'gan-hans' => [ 40, 35, 'asia' ],
+ 'gan-hant' => [ 40, 35, 'asia' ],
+ 'hak' => [ 41, 34, 'asia' ],
+ 'or' => [ 42, 31, 'asia' ],
+ 'ne' => [ 43, 30, 'asia' ],
+ 'ro' => [ 44, 28, 'europe' ],
+ 'su' => [ 45, 27, 'asia' ],
+ 'az' => [ 46, 27, 'asia' ],
+ 'nl' => [ 47, 27, 'europe' ],
+ 'zu' => [ 48, 26, 'africa' ],
+ 'ps' => [ 49, 26, 'asia' ],
+ 'ckb' => [ 50, 26, 'asia' ],
+ 'ku-latn' => [ 50, 26, 'asia' ],
+ ];
/**
* Variable with key-value pairs with a named index and an array of key-value
@@ -97,32 +97,32 @@ class GroupStatistics extends Maintenance {
* Definitions in this variable can be used to report weighted meta localisation
* scores for the 50 most spoken languages.
*
- * @todo Allow weighted reporting for all available languges.
+ * @todo Allow weighted reporting for all available languages.
*/
- public $localisedWeights = array(
- 'wikimedia' => array(
- //'core-0-mostused' => 40,
+ public $localisedWeights = [
+ 'wikimedia' => [
+ // 'core-0-mostused' => 40,
'core' => 50,
'ext-0-wikimedia' => 50
- ),
- 'fundraiser' => array(
+ ],
+ 'fundraiser' => [
'ext-di-di' => 16,
'ext-di-pfpg' => 84,
- ),
- 'mediawiki' => array(
- //'core-0-mostused' => 30,
+ ],
+ 'mediawiki' => [
+ // 'core-0-mostused' => 30,
'core' => 50,
'ext-0-wikimedia' => 25,
'ext-0-all' => 25
- )
- );
+ ]
+ ];
/**
* Code map to map localisation codes to Wikimedia project codes. Only
* exclusion and remapping is defined here. It is assumed that the first part
* of the localisation code is the WMF project name otherwise (zh-hans -> zh).
*/
- public $wikimediaCodeMap = array(
+ public $wikimediaCodeMap = [
// Codes containing a dash
'bat-smg' => 'bat-smg',
'cbk-zam' => 'cbk-zam',
@@ -181,12 +181,12 @@ class GroupStatistics extends Maintenance {
'zh-cn' => '', // zh
'zh-sg' => '', // zh
'zh-hk' => '', // zh
- 'zh-min-nan' => '', //
+ 'zh-min-nan' => '', // nan
'zh-mo' => '', // zh
'zh-my' => '', // zh
'zh-tw' => '', // zh
'zh-yue' => '', // yue
- );
+ ];
public function __construct() {
parent::__construct();
@@ -288,7 +288,7 @@ class GroupStatistics extends Maintenance {
$out = new TranslateStatsOutput();
}
- $skipLanguages = array();
+ $skipLanguages = [];
if ( $this->hasOption( 'skiplanguages' ) ) {
$skipLanguages = array_map(
'trim',
@@ -299,7 +299,7 @@ class GroupStatistics extends Maintenance {
$reportScore = false;
// Check if score should be reported and prepare weights
$most = $this->getOption( 'most' );
- $weights = array();
+ $weights = [];
if ( $most && isset( $this->localisedWeights[$most] ) ) {
$reportScore = true;
@@ -319,7 +319,7 @@ class GroupStatistics extends Maintenance {
$wmfscore = $this->hasOption( 'wmfscore' );
// Get groups from input
- $groups = array();
+ $groups = [];
if ( $reportScore ) {
$reqGroups = array_keys( $this->localisedWeights[$most] );
} elseif ( $wmfscore ) {
@@ -347,11 +347,11 @@ class GroupStatistics extends Maintenance {
$out = new CsvStatsOutput();
$reportScore = true;
- $weights = array();
+ $weights = [];
foreach ( $this->localisedWeights['wikimedia'] as $weight ) {
$weights[] = $weight;
}
- $wmfscores = array();
+ $wmfscores = [];
}
if ( !count( $groups ) ) {
@@ -364,7 +364,7 @@ class GroupStatistics extends Maintenance {
ksort( $languages );
if ( $this->hasOption( 'legenddetail' ) ) {
- $out->addFreeText( "{{" . $this->getOption( 'legenddetail' ) . "}}\n" );
+ $out->addFreeText( '{{' . $this->getOption( 'legenddetail' ) . "}}\n" );
}
$totalWeight = 0;
@@ -388,22 +388,22 @@ class GroupStatistics extends Maintenance {
$out->blockstart();
if ( $most ) {
- $out->element( ( $l10n ? "{{int:translate-gs-pos}}" : 'Pos.' ), true );
+ $out->element( ( $l10n ? '{{int:translate-gs-pos}}' : 'Pos.' ), true );
}
- $out->element( ( $l10n ? "{{int:translate-gs-code}}" : 'Code' ), true );
- $out->element( ( $l10n ? "{{int:translate-page-language}}" : 'Language' ), true );
+ $out->element( ( $l10n ? '{{int:translate-gs-code}}' : 'Code' ), true );
+ $out->element( ( $l10n ? '{{int:translate-page-language}}' : 'Language' ), true );
if ( $showContinent ) {
- $out->element( ( $l10n ? "{{int:translate-gs-continent}}" : 'Continent' ), true );
+ $out->element( ( $l10n ? '{{int:translate-gs-continent}}' : 'Continent' ), true );
}
if ( $most && $this->hasOption( 'speakers' ) ) {
- $out->element( ( $l10n ? "{{int:translate-gs-speakers}}" : 'Speakers' ), true );
+ $out->element( ( $l10n ? '{{int:translate-gs-speakers}}' : 'Speakers' ), true );
}
if ( $reportScore ) {
$out->element(
- ( $l10n ? "{{int:translate-gs-score}}" : 'Score' ) . ' (' . $totalWeight . ')',
+ ( $l10n ? '{{int:translate-gs-score}}' : 'Score' ) . ' (' . $totalWeight . ')',
true
);
}
@@ -415,26 +415,26 @@ class GroupStatistics extends Maintenance {
// Add unprocessed description of group as heading
if ( $reportScore ) {
$gid = $g->getId();
- $heading = $g->getLabel() . " (" . $this->localisedWeights[$most][$gid] . ")";
+ $heading = $g->getLabel() . ' (' . $this->localisedWeights[$most][$gid] . ')';
} else {
$heading = $g->getLabel();
}
$out->element( $heading, true );
if ( !$reportScore && $this->hasOption( 'fuzzy' ) ) {
- $out->element( ( $l10n ? "{{int:translate-percentage-fuzzy}}" : 'Fuzzy' ), true );
+ $out->element( ( $l10n ? '{{int:translate-percentage-fuzzy}}' : 'Fuzzy' ), true );
}
}
$out->blockend();
}
- $rows = array();
+ $rows = [];
foreach ( $languages as $code => $name ) {
// Skip list
if ( in_array( $code, $skipLanguages ) ) {
continue;
}
- $rows[$code] = array();
+ $rows[$code] = [];
}
foreach ( $groups as $groupName => $g ) {
@@ -449,7 +449,7 @@ class GroupStatistics extends Maintenance {
// Do not calculate if we do not need it for anything.
if ( $wmfscore && isset( $this->wikimediaCodeMap[$code] )
- && $this->wikimediaCodeMap[$code] == ''
+ && $this->wikimediaCodeMap[$code] === ''
) {
continue;
}
@@ -463,10 +463,10 @@ class GroupStatistics extends Maintenance {
$translated = $stats[$code][MessageGroupStats::TRANSLATED];
$fuzzy = $stats[$code][MessageGroupStats::FUZZY];
- $rows[$code][] = array( false, $translated, $total );
+ $rows[$code][] = [ false, $translated, $total ];
if ( $this->hasOption( 'fuzzy' ) ) {
- $rows[$code][] = array( true, $fuzzy, $total );
+ $rows[$code][] = [ true, $fuzzy, $total ];
}
}
@@ -477,7 +477,7 @@ class GroupStatistics extends Maintenance {
$summarise = false;
if ( $this->hasOption( 'summary' ) ) {
$summarise = true;
- $summary = array();
+ $summary = [];
}
foreach ( $languages as $code => $name ) {
@@ -488,7 +488,7 @@ class GroupStatistics extends Maintenance {
// Skip unneeded
if ( $wmfscore && isset( $this->wikimediaCodeMap[$code] )
- && $this->wikimediaCodeMap[$code] == ''
+ && $this->wikimediaCodeMap[$code] === ''
) {
continue;
}
@@ -502,7 +502,7 @@ class GroupStatistics extends Maintenance {
$allZero = true;
foreach ( $columns as $fields ) {
- if ( intval( $fields[1] ) !== 0 ) {
+ if ( (int)$fields[1] !== 0 ) {
$allZero = false;
}
}
@@ -512,7 +512,7 @@ class GroupStatistics extends Maintenance {
continue;
}
- // Output the the row
+ // Output the row
if ( !$wmfscore ) {
$out->blockstart();
}
@@ -528,7 +528,7 @@ class GroupStatistics extends Maintenance {
$out->element( $code );
if ( $l10n && function_exists( 'efI18nTagsInit' ) ) {
- $out->element( "{{#languagename:" . $code . "}}" );
+ $out->element( '{{#languagename:' . $code . '}}' );
} else {
$out->element( $name );
}
@@ -536,11 +536,11 @@ class GroupStatistics extends Maintenance {
// Fill continent field
if ( $showContinent ) {
- if ( $this->mostSpokenLanguages[$code][2] == 'multiple' ) {
- $continent = ( $l10n ? "{{int:translate-gs-multiple}}" : 'Multiple' );
+ if ( $this->mostSpokenLanguages[$code][2] === 'multiple' ) {
+ $continent = ( $l10n ? '{{int:translate-gs-multiple}}' : 'Multiple' );
} else {
$continent = $l10n ?
- "{{int:timezoneregion-" . $this->mostSpokenLanguages[$code][2] . "}}" :
+ '{{int:timezoneregion-' . $this->mostSpokenLanguages[$code][2] . '}}' :
ucfirst( $this->mostSpokenLanguages[$code][2] );
}
@@ -579,7 +579,7 @@ class GroupStatistics extends Maintenance {
$newscore = $score;
}
- $summary[$continent] = array( $newcount, $newscore );
+ $summary[$continent] = [ $newcount, $newscore ];
}
if ( $wmfscore ) {
@@ -598,9 +598,9 @@ class GroupStatistics extends Maintenance {
$tmpWmfScore = (int)$wmfscores[$wmfcode]['score'];
$tmpWmfCount = (int)$wmfscores[$wmfcode]['count'];
$score = ( ( $tmpWmfCount * $tmpWmfScore ) + (int)$score ) / $count;
- $wmfscores[$wmfcode] = array( 'score' => $score, 'count' => $count );
+ $wmfscores[$wmfcode] = [ 'score' => $score, 'count' => $count ];
} else {
- $wmfscores[$wmfcode] = array( 'score' => $score, 'count' => 1 );
+ $wmfscores[$wmfcode] = [ 'score' => $score, 'count' => 1 ];
}
} else {
$out->element( $score );
@@ -623,30 +623,30 @@ class GroupStatistics extends Maintenance {
if ( $reportScore && $this->hasOption( 'summary' ) ) {
if ( $reportScore && $this->hasOption( 'legendsummary' ) ) {
- $out->addFreeText( "{{" . $this->getOption( 'legendsummary' ) . "}}\n" );
+ $out->addFreeText( '{{' . $this->getOption( 'legendsummary' ) . "}}\n" );
}
$out->summaryheading();
$out->blockstart();
- $out->element( $l10n ? "{{int:translate-gs-continent}}" : 'Continent', true );
- $out->element( $l10n ? "{{int:translate-gs-count}}" : 'Count', true );
- $out->element( $l10n ? "{{int:translate-gs-avgscore}}" : 'Avg. score', true );
+ $out->element( $l10n ? '{{int:translate-gs-continent}}' : 'Continent', true );
+ $out->element( $l10n ? '{{int:translate-gs-count}}' : 'Count', true );
+ $out->element( $l10n ? '{{int:translate-gs-avgscore}}' : 'Avg. score', true );
$out->blockend();
ksort( $summary );
- $totals = array( 0, 0 );
+ $totals = [ 0, 0 ];
foreach ( $summary as $key => $values ) {
$out->blockstart();
- if ( $key == 'multiple' ) {
- $out->element( $l10n ? "{{int:translate-gs-multiple}}" : 'Multiple' );
+ if ( $key === 'multiple' ) {
+ $out->element( $l10n ? '{{int:translate-gs-multiple}}' : 'Multiple' );
} else {
- $out->element( $l10n ? "{{int:timezoneregion-" . $key . "}}" : ucfirst( $key ) );
+ $out->element( $l10n ? '{{int:timezoneregion-' . $key . '}}' : ucfirst( $key ) );
}
$out->element( $values[0] );
$out->element( number_format( $values[1] / $values[0] ) );
@@ -658,7 +658,7 @@ class GroupStatistics extends Maintenance {
}
$out->blockstart();
- $out->element( $l10n ? "{{int:translate-gs-total}}" : 'Total' );
+ $out->element( $l10n ? '{{int:translate-gs-total}}' : 'Total' );
$out->element( $totals[0] );
$out->element( number_format( $totals[1] / $totals[0] ) );
$out->blockend();
diff --git a/MLEB/Translate/scripts/languageeditstats.php b/MLEB/Translate/scripts/languageeditstats.php
index 053627ad..1c177a17 100644
--- a/MLEB/Translate/scripts/languageeditstats.php
+++ b/MLEB/Translate/scripts/languageeditstats.php
@@ -5,7 +5,7 @@
* @author Niklas Laxström
* @author Siebrand Mazeland
* @copyright Copyright © 2008-2010 Niklas Laxström, Siebrand Mazeland
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
* @ingroup Script Stats
*/
@@ -19,7 +19,7 @@ if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
}
require_once "$IP/maintenance/Maintenance.php";
-class LanguageEditStats extends Maintenance {
+class Languageeditstats extends Maintenance {
public function __construct() {
parent::__construct();
$this->mDescription = 'Script to show number of edits per language for all message groups.';
@@ -56,7 +56,7 @@ class LanguageEditStats extends Maintenance {
$bots = $this->hasOption( 'bots' );
- $namespaces = array();
+ $namespaces = [];
if ( $this->hasOption( 'ns' ) ) {
$input = explode( ',', $this->getOption( 'ns' ) );
@@ -75,7 +75,7 @@ class LanguageEditStats extends Maintenance {
/**
* Get counts for edits per language code after filtering out edits by FuzzyBot
*/
- $codes = array();
+ $codes = [];
global $wgTranslateFuzzyBotName;
foreach ( $rows as $_ ) {
// Filter out edits by $wgTranslateFuzzyBotName
@@ -107,5 +107,5 @@ class LanguageEditStats extends Maintenance {
}
}
-$maintClass = 'LanguageEditStats';
+$maintClass = 'Languageeditstats';
require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/MLEB/Translate/scripts/magic-export.php b/MLEB/Translate/scripts/magic-export.php
index cd3c9a91..371b4d66 100644
--- a/MLEB/Translate/scripts/magic-export.php
+++ b/MLEB/Translate/scripts/magic-export.php
@@ -5,11 +5,17 @@
* @author Robert Leverington <robert@rhl.me.uk>
*
* @copyright Copyright © 2010 Robert Leverington
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
-require dirname( dirname( dirname( __DIR__ ) ) ) . '/maintenance/Maintenance.php';
+// Standard boilerplate to define $IP
+if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
+ $IP = getenv( 'MW_INSTALL_PATH' );
+} else {
+ $IP = __DIR__ . '/../../../';
+}
+require_once "$IP/maintenance/Maintenance.php";
/**
* Maintenance class for the fast export of special page aliases and magic words.
@@ -18,8 +24,9 @@ class MagicExport extends Maintenance {
protected $type;
protected $target;
- protected $handles = array();
- protected $messagesOld = array();
+ protected $handles = [];
+ protected $messagesOld = [];
+ protected $extraInformation = [];
public function __construct() {
parent::__construct();
@@ -93,7 +100,13 @@ class MagicExport extends Maintenance {
}
$inFile = $group->replaceVariables( $inFile, 'en' );
- $outFile = $this->target . '/' . $outFile;
+ $outFile = $this->target . '/' . $outFile;
+ $varName = null;
+
+ if ( !is_readable( $inFile ) ) {
+ $this->error( "File '$inFile' not readable." );
+ continue;
+ }
include $inFile;
switch ( $this->type ) {
@@ -101,9 +114,11 @@ class MagicExport extends Maintenance {
if ( isset( $aliases ) ) {
$this->messagesOld[$group->getId()] = $aliases;
unset( $aliases );
+ $varName = '$aliases';
} elseif ( isset( $specialPageAliases ) ) {
$this->messagesOld[$group->getId()] = $specialPageAliases;
unset( $specialPageAliases );
+ $varName = '$specialPageAliases';
} else {
$this->error( "File '$inFile' does not contain an aliases array." );
continue;
@@ -116,51 +131,83 @@ class MagicExport extends Maintenance {
}
$this->messagesOld[$group->getId()] = $magicWords;
unset( $magicWords );
+ $varName = '$magicWords';
break;
}
wfMkdirParents( dirname( $outFile ), null, __METHOD__ );
$this->handles[$group->getId()] = fopen( $outFile, 'w' );
- fwrite( $this->handles[$group->getId()], $this->readHeader( $inFile ) );
+ $headerInformation = $this->readHeader( $inFile, $varName );
+ fwrite( $this->handles[$group->getId()], $headerInformation['fileBegin'] );
+ $this->extraInformation[$group->getId()] = $headerInformation;
$this->output( "\t{$group->getId()}\n" );
}
}
- protected function readHeader( $file ) {
+ protected function readHeader( $file, $varName ) {
$data = file_get_contents( $file );
// Seek first '*/'.
- $end = strpos( $data, '*/' ) + 2;
+ $end = strpos( $data, '*/' );
+
+ // But not when it is the english comment
+ $varPos = strpos( $data, $varName );
+ if ( $varPos && $end && $varPos <= $end ) {
+ $end = false;
+ }
if ( $end === false ) {
- return "<?php\n";
+ $fileBegin = "<?php\n";
+ } else {
+ // Grab header.
+ $fileBegin = substr( $data, 0, $end + 2 );
}
- // Grab header.
- return substr( $data, 0, $end );
+ // preserve the phpcs codingStandardsIgnoreFile, if exists
+ $preserveIgnoreTag = strpos( $data, '@codingStandardsIgnoreFile' ) !== false;
+
+ // preserve the long array syntax, if varName is written with it
+ $preserveLongArraySyntax = preg_match(
+ '/' . preg_quote( $varName, '/' ) . '\s*=\s*array\s*\(\s*\)\s*;/',
+ $data
+ );
+
+ // avoid difference by the last character
+ $preserveNewlineAtEnd = substr( $data, -1 ) === "\n";
+
+ return [
+ 'fileBegin' => $fileBegin,
+ 'preserveIgnoreTag' => $preserveIgnoreTag,
+ 'preserveLongArraySyntax' => $preserveLongArraySyntax,
+ 'preserveNewlineAtEnd' => $preserveNewlineAtEnd,
+ ];
}
/**
* Write the opening of the files for each output file handle.
*/
protected function writeHeaders() {
- foreach ( $this->handles as $handle ) {
+ foreach ( $this->handles as $group => $handle ) {
+ $arraySyntax = $this->extraInformation[$group]['preserveLongArraySyntax']
+ ? 'array()'
+ : '[]';
switch ( $this->type ) {
case 'special':
+ $ignoreTag = $this->extraInformation[$group]['preserveIgnoreTag']
+ ? "\n// @codingStandardsIgnoreFile"
+ : '';
fwrite( $handle, <<<PHP
+$ignoreTag
-// @codingStandardsIgnoreFile
-
-\$specialPageAliases = array();
+\$specialPageAliases = $arraySyntax;
PHP
);
break;
case 'magic':
fwrite( $handle, <<<PHP
-
-\$magicWords = array();
+\$magicWords = $arraySyntax;
PHP
);
break;
@@ -176,7 +223,7 @@ PHP
protected function writeFiles() {
$langs = TranslateUtils::parseLanguageCodes( '*' );
unset( $langs[array_search( 'en', $langs )] );
- $langs = array_merge( array( 'en' ), $langs );
+ $langs = array_merge( [ 'en' ], $langs );
foreach ( $langs as $l ) {
// Load message page.
switch ( $this->type ) {
@@ -194,7 +241,7 @@ PHP
if ( !$title || !$title->exists() ) {
$this->output( "Skiping $l...\n" );
- $messagesNew = array();
+ $messagesNew = [];
} else {
$this->output( "Processing $l...\n" );
@@ -208,7 +255,7 @@ PHP
array_shift( $segments );
unset( $segments[count( $segments ) - 1] );
unset( $segments[count( $segments ) - 1] );
- $messagesNew = array();
+ $messagesNew = [];
foreach ( $segments as $segment ) {
$parts = explode( ' = ', $segment );
$key = array_shift( $parts );
@@ -223,7 +270,7 @@ PHP
foreach ( $this->handles as $group => $handle ) {
// Find messages to write to this handle.
- $messagesOut = array();
+ $messagesOut = [];
if ( !isset( $this->messagesOld[$group] ) ) {
continue;
}
@@ -235,42 +282,53 @@ PHP
$messagesOut[$key] = $this->messagesOld[$group][$l][$key];
}
}
+ if ( $this->extraInformation[$group]['preserveLongArraySyntax'] ) {
+ $arrayStart = 'array(';
+ $arrayEnd = ')';
+ } else {
+ $arrayStart = '[';
+ $arrayEnd = ']';
+ }
// If there are messages to write, write them.
- if ( count( $messagesOut ) > 0 ) {
+ if ( $messagesOut !== [] ) {
$out = '';
switch ( $this->type ) {
case 'special':
$out .= "\n\n/** {$namesEn[$l]} ({$namesNative[$l]}) " .
- "*/\n\$specialPageAliases['{$l}'] = array(\n";
+ "*/\n\$specialPageAliases['{$l}'] = {$arrayStart}\n";
break;
case 'magic':
$out .= "\n\n/** {$namesEn[$l]} ({$namesNative[$l]}) *" .
- "/\n\$magicWords['{$l}'] = array(\n";
+ "/\n\$magicWords['{$l}'] = {$arrayStart}\n";
break;
}
foreach ( $messagesOut as $key => $translations ) {
+ if ( !is_array( $translations ) ) {
+ $this->error( "$l in $group has not an array..." );
+ continue;
+ }
foreach ( $translations as $id => $translation ) {
$translations[$id] = addslashes( $translation );
- if ( $this->type === 'magic' && $translation == '0' ) {
+ if ( $this->type === 'magic' && $translation === 0 ) {
unset( $translations[$id] );
}
}
$translations = implode( "', '", $translations );
switch ( $this->type ) {
case 'special':
- $out .= "\t'$key' => array( '$translations' ),\n";
+ $out .= "\t'$key' => $arrayStart '$translations' $arrayEnd,\n";
break;
case 'magic':
if ( $this->messagesOld[$group]['en'][$key][0] === 0 ) {
- $out .= "\t'$key' => array( 0, '$translations' ),\n";
+ $out .= "\t'$key' => $arrayStart 0, '$translations' $arrayEnd,\n";
} else {
- $out .= "\t'$key' => array( '$translations' ),\n";
+ $out .= "\t'$key' => $arrayStart '$translations' $arrayEnd,\n";
}
break;
}
}
- $out .= ");";
+ $out .= "$arrayEnd;";
fwrite( $handle, $out );
}
}
@@ -282,6 +340,12 @@ PHP
*/
protected function writeFooters() {
$this->output( "Writing file footers...\n" );
+ foreach ( $this->handles as $group => $handle ) {
+ if ( $this->extraInformation[$group]['preserveNewlineAtEnd'] ) {
+ // php files should end with a newline
+ fwrite( $handle, "\n" );
+ }
+ }
}
/**
@@ -295,5 +359,5 @@ PHP
}
}
-$maintClass = "MagicExport";
-require_once DO_MAINTENANCE;
+$maintClass = 'MagicExport';
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/MLEB/Translate/scripts/migrate-schema2.php b/MLEB/Translate/scripts/migrate-schema2.php
index 02abd0be..1314f0a9 100644
--- a/MLEB/Translate/scripts/migrate-schema2.php
+++ b/MLEB/Translate/scripts/migrate-schema2.php
@@ -4,7 +4,7 @@
*
* @author Niklas Laxström
* @copyright Copyright © 2011, Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -40,7 +40,7 @@ class TSchema2 extends Maintenance {
}
if ( $dbw->getType() !== 'mysql' ) {
- $this->error( "This migration script only supports mysql. Please help " .
+ $this->error( 'This migration script only supports mysql. Please help ' .
"us to write routine for {$dbw->getType()}.", 1 );
}
@@ -49,16 +49,16 @@ class TSchema2 extends Maintenance {
$res = $dbw->select(
'revtag_type',
- array( 'rtt_id', 'rtt_name' ),
- array(),
+ [ 'rtt_id', 'rtt_name' ],
+ [],
__METHOD__
);
foreach ( $res as $row ) {
$dbw->update(
'revtag',
- array( 'rt_type' => $row->rtt_name ),
- array( 'rt_type' => (string)$row->rtt_id ),
+ [ 'rt_type' => $row->rtt_name ],
+ [ 'rt_type' => (string)$row->rtt_id ],
__METHOD__
);
}
@@ -68,4 +68,4 @@ class TSchema2 extends Maintenance {
}
$maintClass = 'TSchema2';
-require_once DO_MAINTENANCE;
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/MLEB/Translate/scripts/mwcore-export.php b/MLEB/Translate/scripts/mwcore-export.php
index 31ce058a..8ef3d552 100644
--- a/MLEB/Translate/scripts/mwcore-export.php
+++ b/MLEB/Translate/scripts/mwcore-export.php
@@ -5,7 +5,7 @@
* @author Niklas Laxström
* @author Siebrand Mazeland
* @copyright Copyright © 2009-2013, Niklas Laxström, Siebrand Mazeland
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -73,7 +73,7 @@ class MwCoreExport extends Maintenance {
continue;
}
- $matches = array();
+ $matches = [];
preg_match( '~^(\$[a-zA-Z]+)\s*=~m', $export, $matches );
if ( !isset( $matches[1] ) ) {
@@ -89,7 +89,7 @@ class MwCoreExport extends Maintenance {
$variable = preg_quote( $matches[1], '~' );
- /// @var FileBasedMessageGroup $group
+ /** @var FileBasedMessageGroup $group */
$file = $group->getSourceFilePath( $l );
// bandage
$real = Language::getFileName( '/messages/Messages', $l );
@@ -114,9 +114,9 @@ class MwCoreExport extends Maintenance {
file_put_contents( $outFile, $data );
} else {
$this->error( "Adding new entry to $outFile, please double check location." );
- $pos = strpos( $data, "*/" );
+ $pos = strpos( $data, '*/' );
if ( $pos === false ) {
- $this->error( ". FAILED! Totally new file? No header?" );
+ $this->error( '. FAILED! Totally new file? No header?' );
} else {
$pos += 3;
}
diff --git a/MLEB/Translate/scripts/plural-comparison.php b/MLEB/Translate/scripts/plural-comparison.php
index dc41b986..66c69ed7 100644
--- a/MLEB/Translate/scripts/plural-comparison.php
+++ b/MLEB/Translate/scripts/plural-comparison.php
@@ -5,7 +5,7 @@
* @author Niklas Laxström
*
* @copyright Copyright © 2010, Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -13,8 +13,7 @@
if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
$IP = getenv( 'MW_INSTALL_PATH' );
} else {
- $dir = __DIR__;
- $IP = "$dir/../../..";
+ $IP = __DIR__ . '/../../..';
}
require_once "$IP/maintenance/Maintenance.php";
@@ -111,12 +110,12 @@ class PluralCompare extends Maintenance {
protected function loadPluralFile( $fileName ) {
$doc = new DOMDocument;
$doc->load( $fileName );
- $rulesets = $doc->getElementsByTagName( "pluralRules" );
- $plurals = array();
+ $rulesets = $doc->getElementsByTagName( 'pluralRules' );
+ $plurals = [];
foreach ( $rulesets as $ruleset ) {
$codes = $ruleset->getAttribute( 'locales' );
- $rules = array();
- $ruleElements = $ruleset->getElementsByTagName( "pluralRule" );
+ $rules = [];
+ $ruleElements = $ruleset->getElementsByTagName( 'pluralRule' );
foreach ( $ruleElements as $elt ) {
$rules[] = $elt->nodeValue;
}
@@ -136,6 +135,7 @@ class PluralCompare extends Maintenance {
public function loadMediaWiki() {
global $IP;
+
$rules = $this->loadPluralFile( "$IP/languages/data/plurals.xml" );
$rulesMW = $this->loadPluralFile( "$IP/languages/data/plurals-mediawiki.xml" );
@@ -144,7 +144,7 @@ class PluralCompare extends Maintenance {
public function loadGettext() {
$gtData = file_get_contents( __DIR__ . '/../data/plural-gettext.txt' );
- $gtLanguages = array();
+ $gtLanguages = [];
foreach ( preg_split( '/\n|\r/', $gtData, -1, PREG_SPLIT_NO_EMPTY ) as $line ) {
list( $code, $rule ) = explode( "\t", $line );
$rule = preg_replace( '/^.*?plural=/', '', $rule );
@@ -156,4 +156,4 @@ class PluralCompare extends Maintenance {
}
$maintClass = 'PluralCompare';
-require_once DO_MAINTENANCE;
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/MLEB/Translate/scripts/poimport.php b/MLEB/Translate/scripts/poimport.php
index da2d058a..cb057917 100644
--- a/MLEB/Translate/scripts/poimport.php
+++ b/MLEB/Translate/scripts/poimport.php
@@ -5,7 +5,7 @@
* @author Niklas Laxström
* @author Siebrand Mazeland
* @copyright Copyright © 2007-2013 Niklas Laxström, Siebrand Mazeland
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -18,7 +18,7 @@ if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
}
require_once "$IP/maintenance/Maintenance.php";
-class PoImport extends Maintenance {
+class Poimport extends Maintenance {
public function __construct() {
parent::__construct();
$this->mDescription = 'Po file importer (does not make changes unless specified).';
@@ -45,7 +45,7 @@ class PoImport extends Maintenance {
public function execute() {
// Parse the po file.
$p = new PoImporter( $this->getOption( 'file' ) );
- $p->setProgressCallback( array( $this, 'myOutput' ) );
+ $p->setProgressCallback( [ $this, 'myOutput' ] );
list( $changes, $group ) = $p->parse();
if ( !count( $changes ) ) {
@@ -61,7 +61,7 @@ class PoImport extends Maintenance {
!$this->hasOption( 'really' )
);
- $w->setProgressCallback( array( $this, 'myOutput' ) );
+ $w->setProgressCallback( [ $this, 'myOutput' ] );
$w->execute();
}
@@ -69,7 +69,7 @@ class PoImport extends Maintenance {
* Public alternative for protected Maintenance::output() as we need to get
* messages from the ChangeSyncer class to the commandline.
* @param string $text The text to show to the user
- * @param string $channel Unique identifier for the channel.
+ * @param string|null $channel Unique identifier for the channel.
* @param bool $error Whether this is an error message
*/
public function myOutput( $text, $channel = null, $error = false ) {
@@ -138,7 +138,7 @@ class PoImporter {
$data = file_get_contents( $this->file );
$data = str_replace( "\r\n", "\n", $data );
- $matches = array();
+ $matches = [];
if ( preg_match( '/X-Language-Code:\s+(.*)\\\n/', $data, $matches ) ) {
$code = $matches[1];
$this->reportProgress( "Detected language as $code", 'code' );
@@ -165,9 +165,9 @@ class PoImporter {
$quotePattern = '/(^"|"$\n?)/m';
$sections = preg_split( '/\n{2,}/', $data );
- $changes = array();
+ $changes = [];
foreach ( $sections as $section ) {
- $matches = array();
+ $matches = [];
if ( preg_match( "/^msgctxt\s($poformat)/mx", $section, $matches ) ) {
// Remove quoting
$key = preg_replace( $quotePattern, '', $matches[1] );
@@ -179,7 +179,7 @@ class PoImporter {
} else {
continue;
}
- $matches = array();
+ $matches = [];
if ( preg_match( "/^msgstr\s($poformat)/mx", $section, $matches ) ) {
// Remove quoting
$translation = preg_replace( $quotePattern, '', $matches[1] );
@@ -210,7 +210,7 @@ class PoImporter {
}
}
- return array( $changes, $groupId );
+ return [ $changes, $groupId ];
}
}
@@ -223,7 +223,7 @@ class WikiWriter {
protected $user;
- private $changes = array();
+ private $changes = [];
private $dryrun = true;
private $group = null;
@@ -257,13 +257,13 @@ class WikiWriter {
*/
public function execute() {
if ( !$this->group ) {
- $this->reportProgress( "Given group does not exist.", 'groupId', 'error' );
+ $this->reportProgress( 'Given group does not exist.', 'groupId', 'error' );
return;
}
if ( !$this->user->idForName() ) {
- $this->reportProgress( "Given user does not exist.", 'user', 'error' );
+ $this->reportProgress( 'Given user does not exist.', 'user', 'error' );
return;
}
@@ -318,5 +318,5 @@ class WikiWriter {
}
}
-$maintClass = 'PoImport';
+$maintClass = 'Poimport';
require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/MLEB/Translate/scripts/populateFuzzy.php b/MLEB/Translate/scripts/populateFuzzy.php
index 401e4b4e..dab8f15b 100644
--- a/MLEB/Translate/scripts/populateFuzzy.php
+++ b/MLEB/Translate/scripts/populateFuzzy.php
@@ -4,7 +4,7 @@
*
* @author Niklas Laxström
* @copyright Copyright © 2009-2013, Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -34,31 +34,32 @@ class PopulateFuzzy extends Maintenance {
global $wgTranslateMessageNamespaces;
$namespace = $this->getOption( 'namespace', $wgTranslateMessageNamespaces );
- if ( is_string( $namespace ) ) {
- if ( !MWNamespace::exists( $namespace ) ) {
- $namespace = MWNamespace::getCanonicalIndex( $namespace );
- if ( $namespace === null ) {
- $this->error( 'Bad namespace', true );
- }
+ if ( is_string( $namespace ) &&
+ !MWNamespace::exists( $namespace )
+ ) {
+ $namespace = MWNamespace::getCanonicalIndex( $namespace );
+
+ if ( $namespace === null ) {
+ $this->error( 'Bad namespace', true );
}
}
- $db = wfGetDB( DB_MASTER );
- $tables = array( 'page', 'text', 'revision' );
- $fields = array( 'page_id', 'page_title', 'page_namespace', 'rev_id', 'old_text', 'old_flags' );
- $conds = array(
+ $dbw = wfGetDB( DB_MASTER );
+ $tables = [ 'page', 'text', 'revision' ];
+ $fields = [ 'page_id', 'page_title', 'page_namespace', 'rev_id', 'old_text', 'old_flags' ];
+ $conds = [
'page_latest = rev_id',
'old_id = rev_text_id',
'page_namespace' => $namespace,
- );
+ ];
$limit = 100;
$offset = 0;
while ( true ) {
- $inserts = array();
+ $inserts = [];
$this->output( '.', 0 );
- $options = array( 'LIMIT' => $limit, 'OFFSET' => $offset );
- $res = $db->select( $tables, $fields, $conds, __METHOD__, $options );
+ $options = [ 'LIMIT' => $limit, 'OFFSET' => $offset ];
+ $res = $dbw->select( $tables, $fields, $conds, __METHOD__, $options );
if ( !$res->numRows() ) {
break;
@@ -67,17 +68,17 @@ class PopulateFuzzy extends Maintenance {
foreach ( $res as $r ) {
$text = Revision::getRevisionText( $r );
if ( strpos( $text, TRANSLATE_FUZZY ) !== false ) {
- $inserts[] = array(
+ $inserts[] = [
'rt_page' => $r->page_id,
'rt_revision' => $r->rev_id,
'rt_type' => RevTag::getType( 'fuzzy' ),
- );
+ ];
}
}
$offset += $limit;
- $db->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ );
+ $dbw->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ );
}
}
}
diff --git a/MLEB/Translate/scripts/processMessageChanges.php b/MLEB/Translate/scripts/processMessageChanges.php
index 48343bab..45313530 100644
--- a/MLEB/Translate/scripts/processMessageChanges.php
+++ b/MLEB/Translate/scripts/processMessageChanges.php
@@ -5,7 +5,7 @@
* @author Niklas Laxström
*
* @copyright Copyright © 2012-2013, Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -28,7 +28,7 @@ require_once "$IP/maintenance/Maintenance.php";
* @since 2012-04-23
*/
class ProcessMessageChanges extends Maintenance {
- protected $changes = array();
+ protected $changes = [];
/**
* @var int
@@ -52,29 +52,64 @@ class ProcessMessageChanges extends Maintenance {
false, /*required*/
true /*has arg*/
);
+ $this->addOption(
+ 'name',
+ '(optional) Unique name to avoid conflicts with multiple invocations of this script.',
+ false, /*required*/
+ true /*has arg*/
+ );
+ $this->addOption(
+ 'safe-import',
+ '(optional) Import "safe" changes: message additions when no other kind of changes.',
+ false, /*required*/
+ false /*has arg*/
+ );
}
public function execute() {
$groups = $this->getGroups();
- $changes = array();
+ $changes = [];
$comparator = new ExternalMessageSourceStateComparator();
+ $scripted = $this->hasOption( 'safe-import' );
+
/** @var FileBasedMessageGroup $group */
foreach ( $groups as $id => $group ) {
- $this->output( "Processing $id\n" );
+ if ( !$scripted ) {
+ $this->output( "Processing $id\n" );
+ }
$changes[$id] = $comparator->processGroup( $group, $comparator::ALL_LANGUAGES );
}
// Remove all groups without changes
$changes = array_filter( $changes );
- if ( count( $changes ) ) {
- ExternalMessageSourceStateComparator::writeChanges( $changes );
- $url = SpecialPage::getTitleFor( 'ManageMessageGroups' )->getFullUrl();
- $this->output( "Process changes at $url\n" );
- } else {
- $this->output( "No changes found\n" );
+ if ( $changes === [] ) {
+ if ( !$scripted ) {
+ $this->output( "No changes found\n" );
+ }
+
+ return;
}
+
+ if ( $this->hasOption( 'safe-import' ) ) {
+ $importer = new ExternalMessageSourceStateImporter();
+ $info = $importer->importSafe( $changes );
+ $this->printChangeInfo( $info );
+
+ return;
+ }
+
+ $name = $this->getOption( 'name', MessageChangeStorage::DEFAULT_NAME );
+ if ( !MessageChangeStorage::isValidCdbName( $name ) ) {
+ $this->error( 'Invalid name', 1 );
+ }
+
+ $file = MessageChangeStorage::getCdbPath( $name );
+
+ MessageChangeStorage::writeChanges( $changes, $file );
+ $url = SpecialPage::getTitleFor( 'ManageMessageGroups', $name )->getFullURL();
+ $this->output( "Process changes at $url\n" );
}
/**
@@ -82,7 +117,6 @@ class ProcessMessageChanges extends Maintenance {
* @return MessageGroup[]
*/
protected function getGroups() {
- /// @var $groups MessageGroup[]
$groups = MessageGroups::getGroupsByType( 'FileBasedMessageGroup' );
// Include all if option not given
@@ -111,6 +145,19 @@ class ProcessMessageChanges extends Maintenance {
return $groups;
}
+
+ protected function printChangeInfo( array $info ) {
+ foreach ( $info['processed'] as $group => $count ) {
+ $this->output( "Imported $count new messages or translations for $group.\n" );
+ }
+
+ if ( $info['skipped'] !== [] ) {
+ $skipped = implode( ', ', array_keys( $info['skipped'] ) );
+ $this->output( "There are changes to check for groups $skipped.\n" );
+ $url = SpecialPage::getTitleFor( 'ManageMessageGroups', $info['name'] )->getFullURL();
+ $this->output( "You can process them at $url\n" );
+ }
+ }
}
$maintClass = 'ProcessMessageChanges';
diff --git a/MLEB/Translate/scripts/refresh-translatable-pages.php b/MLEB/Translate/scripts/refresh-translatable-pages.php
index 37021e12..7fe536f9 100644
--- a/MLEB/Translate/scripts/refresh-translatable-pages.php
+++ b/MLEB/Translate/scripts/refresh-translatable-pages.php
@@ -3,7 +3,7 @@
* Script to ensure all translation pages are up to date.
*
* @author Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -24,10 +24,14 @@ class RefreshTranslatablePages extends Maintenance {
public function __construct() {
parent::__construct();
$this->mDescription = 'Ensure all translation pages are up to date.';
+ $this->setBatchSize( 300 );
+ $this->addOption( 'jobqueue', 'Use JobQueue (asynchronous)' );
}
public function execute() {
$groups = MessageGroups::singleton()->getGroups();
+ $counter = 0;
+ $useJobQueue = $this->hasOption( 'jobqueue' );
/** @var MessageGroup $group */
foreach ( $groups as $group ) {
@@ -35,15 +39,27 @@ class RefreshTranslatablePages extends Maintenance {
continue;
}
- // Get all translation subpages and refresh each one of them
- $page = TranslatablePage::newFromTitle( $group->getTitle() );
- $translationPages = $page->getTranslationPages();
+ $counter++;
+ if ( ( $counter % $this->mBatchSize ) === 0 ) {
+ wfWaitForSlaves();
+ }
- foreach ( $translationPages as $subpage ) {
- $job = TranslateRenderJob::newJob( $subpage );
- $job->run();
+ $page = TranslatablePage::newFromTitle( $group->getTitle() );
+ $jobs = TranslationsUpdateJob::getRenderJobs( $page );
+ if ( $useJobQueue ) {
+ JobQueueGroup::singleton()->push( $jobs );
+ } else {
+ foreach ( $jobs as $job ) {
+ $job->run();
+ }
}
}
+
+ if ( $useJobQueue ) {
+ $this->output( "Queued refresh for $counter translatable pages.\n" );
+ } else {
+ $this->output( "Refreshed $counter translatable pages.\n" );
+ }
}
}
diff --git a/MLEB/Translate/scripts/sync-group.php b/MLEB/Translate/scripts/sync-group.php
index 5990eef1..dcd5f674 100644
--- a/MLEB/Translate/scripts/sync-group.php
+++ b/MLEB/Translate/scripts/sync-group.php
@@ -7,7 +7,7 @@
* @author Siebrand Mazeland
* @copyright Copyright © 2007-2013, Niklas Laxström
* @copyright Copyright © 2009-2013, Siebrand Mazeland
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -85,13 +85,13 @@ class SyncGroup extends Maintenance {
$groups = MessageGroups::getGroupsById( $groupIds );
if ( !count( $groups ) ) {
- $this->error( "ESG2: No valid message groups identified.", 1 );
+ $this->error( 'ESG2: No valid message groups identified.', 1 );
}
$start = $this->getOption( 'start' ) ? strtotime( $this->getOption( 'start' ) ) : false;
$end = $this->getOption( 'end' ) ? strtotime( $this->getOption( 'end' ) ) : false;
- $this->output( "Conflict times: " . wfTimestamp( TS_ISO_8601, $start ) . " - " .
+ $this->output( 'Conflict times: ' . wfTimestamp( TS_ISO_8601, $start ) . ' - ' .
wfTimestamp( TS_ISO_8601, $end ) . "\n" );
$codes = array_filter( array_map( 'trim', explode( ',', $this->getOption( 'lang' ) ) ) );
@@ -115,7 +115,7 @@ class SyncGroup extends Maintenance {
foreach ( $codes as $code ) {
// No sync possible for unsupported language codes.
if ( !in_array( $code, $supportedCodes ) ) {
- $this->output( "Unsupported code " . $code . ": skipping.\n" );
+ $this->output( 'Unsupported code ' . $code . ": skipping.\n" );
continue;
}
@@ -130,7 +130,7 @@ class SyncGroup extends Maintenance {
}
$cs = new ChangeSyncer( $group, $this );
- $cs->setProgressCallback( array( $this, 'myOutput' ) );
+ $cs->setProgressCallback( [ $this, 'myOutput' ] );
$cs->interactive = !$this->hasOption( 'noask' );
$cs->nocolor = $this->hasOption( 'nocolor' );
$cs->norc = $this->hasOption( 'norc' );
@@ -161,7 +161,7 @@ class SyncGroup extends Maintenance {
* Public alternative for protected Maintenance::output() as we need to get
* messages from the ChangeSyncer class to the commandline.
* @param string $text The text to show to the user
- * @param string $channel Unique identifier for the channel.
+ * @param string|null $channel Unique identifier for the channel.
* @param bool $error Whether this is an error message
*/
public function myOutput( $text, $channel = null, $error = false ) {
@@ -227,7 +227,7 @@ class ChangeSyncer {
return false;
}
- $matches = array();
+ $matches = [];
// PHP doesn't allow foo || return false;
// Thank
// you
@@ -299,7 +299,7 @@ class ChangeSyncer {
}
// @todo Temporary exception. Should be fixed elsewhere more generically.
- if ( $translation == '{{PLURAL:GETTEXT|}}' ) {
+ if ( $translation === '{{PLURAL:GETTEXT|}}' ) {
return;
}
@@ -319,7 +319,7 @@ class ChangeSyncer {
continue;
}
- $this->reportProgress( "Conflict in " . $this->color( 'bold', $page ) . "!", $page );
+ $this->reportProgress( 'Conflict in ' . $this->color( 'bold', $page ) . '!', $page );
$iso = 'xnY-xnm-xnd"T"xnH:xni:xns';
$lang = RequestContext::getMain()->getLanguage();
@@ -350,10 +350,10 @@ class ChangeSyncer {
if ( $changeTs ) {
if ( $wikiTs > $startTs && $changeTs <= $endTs ) {
- $this->reportProgress( " →Changed in wiki after export: IGNORE", $page );
+ $this->reportProgress( ' →Changed in wiki after export: IGNORE', $page );
continue;
} elseif ( !$wikiTs || ( $changeTs > $endTs && $wikiTs < $startTs ) ) {
- $this->reportProgress( " →Changed in source after export: IMPORT", $page );
+ $this->reportProgress( ' →Changed in source after export: IMPORT', $page );
$this->import(
$title,
$translation,
@@ -367,14 +367,14 @@ class ChangeSyncer {
continue;
}
- $this->reportProgress( " →Needs manual resolution", $page );
+ $this->reportProgress( ' →Needs manual resolution', $page );
$this->reportProgress( "Source translation at $changeDate:", 'source' );
$this->reportProgress( $this->color( 'blue', $translation ), 'source' );
$this->reportProgress( "Wiki translation at $wikiDate:", 'translation' );
$this->reportProgress( $this->color( 'green', $current ), 'translation' );
do {
- $this->reportProgress( "Resolution: [S]kip [I]mport [C]onflict: ", 'foo' );
+ $this->reportProgress( 'Resolution: [S]kip [I]mport [C]onflict: ', 'foo' );
// @todo Find an elegant way to use Maintenance::readconsole().
$action = fgets( STDIN );
$action = strtoupper( trim( $action ) );
@@ -440,7 +440,7 @@ class ChangeSyncer {
break;
}
- if ( $revision->getRawUserText() === $wgTranslateFuzzyBotName ) {
+ if ( $revision->getUserText( Revision::RAW ) === $wgTranslateFuzzyBotName ) {
$revision = $revision->getPrevious();
continue;
}
diff --git a/MLEB/Translate/scripts/translator-stats-process.php b/MLEB/Translate/scripts/translator-stats-process.php
index 042039f0..c70b0cdf 100644
--- a/MLEB/Translate/scripts/translator-stats-process.php
+++ b/MLEB/Translate/scripts/translator-stats-process.php
@@ -3,7 +3,7 @@
* Script to gather translator stats.
*
* @author Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -27,17 +27,17 @@ class TSP extends Maintenance {
);
}
- function median( $a ) {
+ protected function median( $a ) {
sort( $a );
$len = count( $a );
if ( $len === 0 ) {
return 0;
- } elseif( $len === 1 ) {
+ } elseif ( $len === 1 ) {
return $a[0];
} elseif ( $len % 2 === 0 ) {
- return $a[$len/2];
+ return $a[$len / 2];
} else {
- return ( $a[floor( $len/2 )] + $a[ceil( $len/2 )] ) / 2;
+ return ( $a[floor( $len / 2 )] + $a[ceil( $len / 2 )] ) / 2;
}
}
@@ -46,8 +46,13 @@ class TSP extends Maintenance {
// remove heading
fgets( $handle );
- $data = array();
- while ( ( $l = fgets( $handle ) ) !== false ) {
+ $data = [];
+ while ( true ) {
+ $l = fgets( $handle );
+ if ( $l === false ) {
+ break;
+ }
+
$fields = explode( "\t", trim( $l, "\n" ) );
list( $name, $reg, $edits, $translator, $promoted, $method ) = $fields;
$month = substr( $reg, 0, 4 ) . '-' . substr( $reg, 4, 2 ) . '-01';
@@ -65,10 +70,9 @@ class TSP extends Maintenance {
$total = 0;
$promoted = 0;
$good = 0;
- $delay = array();
- $median = 0;
+ $delay = [];
$avg = 'N/A';
- $sbar = array();
+ $sbar = [];
foreach ( $period as $p ) {
list( $name, $reg, $edits, $translator, $promtime, $method ) = $p;
@@ -100,7 +104,7 @@ class TSP extends Maintenance {
$avg = round( array_sum( $delay ) / count( $delay ) / 3600 );
}
- if ( $sbar === array() ) {
+ if ( $sbar === [] ) {
$sbar = 'N/A';
} else {
$sbar = count( array_filter( $sbar ) ) / count( $sbar );
diff --git a/MLEB/Translate/scripts/translator-stats.php b/MLEB/Translate/scripts/translator-stats.php
index 8c5f8634..6ee2c312 100644
--- a/MLEB/Translate/scripts/translator-stats.php
+++ b/MLEB/Translate/scripts/translator-stats.php
@@ -3,7 +3,7 @@
* Script to gather translator stats.
*
* @author Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -24,42 +24,50 @@ class TS extends Maintenance {
}
public function execute() {
- $dbr = wfGetDB( DB_SLAVE );
+ global $wgDisableUserGroupExpiry;
+
+ $dbr = wfGetDB( DB_REPLICA );
$users = $dbr->select(
- array( 'user', 'user_groups' ),
- array(
+ [ 'user', 'user_groups' ],
+ [
'user_name',
'user_registration',
'user_editcount',
'ug_group',
- ),
- array(
+ ],
+ [
'user_registration is not null'
- ),
+ ],
__METHOD__,
- array(
+ [
'ORDER BY' => 'user_id ASC',
- ),
- array(
- 'user_groups' => array(
+ ],
+ [
+ 'user_groups' => [
'LEFT JOIN',
- array( 'user_id=ug_user', 'ug_group' => 'translator' )
- )
- )
+ [
+ 'user_id=ug_user',
+ 'ug_group' => 'translator',
+ ( isset( $wgDisableUserGroupExpiry ) && !$wgDisableUserGroupExpiry ) ?
+ 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() ) :
+ ''
+ ]
+ ]
+ ]
);
echo "username\tregistration ts\tedit count\tis translator?\tpromoted ts\tmethod\n";
$rejected = $dbr->select(
- array( 'logging' ),
- array(
+ [ 'logging' ],
+ [
'log_title',
'log_timestamp',
- ),
- array(
+ ],
+ [
'log_type' => 'translatorsandbox',
'log_action' => 'rejected',
- ),
+ ],
__METHOD__
);
@@ -70,20 +78,20 @@ class TS extends Maintenance {
foreach ( $users as $u ) {
$logs = $dbr->select(
'logging',
- array(
+ [
'log_type',
'log_action',
'log_timestamp',
'log_params',
- ),
- array(
+ ],
+ [
'log_title' => $u->user_name,
- 'log_type' => array( 'rights', 'translatorsandbox' ),
- ),
+ 'log_type' => [ 'rights', 'translatorsandbox' ],
+ ],
__METHOD__,
- array(
+ [
'ORDER BY' => 'log_id ASC',
- )
+ ]
);
$promoted = null;
@@ -94,9 +102,9 @@ class TS extends Maintenance {
$method = 'sandbox';
break;
} elseif ( $log->log_action === 'rights' ) {
- wfSuppressWarnings();
+ MediaWiki\suppressWarnings();
$data = unserialize( $log->log_params );
- wfRestoreWarnings();
+ MediaWiki\restoreWarnings();
if ( $data === false ) {
$lines = explode( "\n", $log->log_params );
if ( strpos( $lines[1], 'translator' ) !== false ) {
diff --git a/MLEB/Translate/scripts/ttmserver-export.php b/MLEB/Translate/scripts/ttmserver-export.php
index 5ecd7fd7..8722feff 100644
--- a/MLEB/Translate/scripts/ttmserver-export.php
+++ b/MLEB/Translate/scripts/ttmserver-export.php
@@ -3,7 +3,7 @@
* Script to bootstrap TTMServer translation memory
*
* @author Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -21,9 +21,9 @@ require_once "$IP/maintenance/Maintenance.php";
* @since 2012-01-26
*/
class TTMServerBootstrap extends Maintenance {
- /// @var Array Configuration of requested TTMServer
- protected $config;
- // Option for reindexing
+ /**
+ * @var bool Option for reindexing
+ */
protected $reindex;
public function __construct() {
@@ -51,19 +51,19 @@ class TTMServerBootstrap extends Maintenance {
}
public function statusLine( $text, $channel = null ) {
- $pid = sprintf( "%5s", getmypid() );
- $prefix = sprintf( "%6.2f", microtime( true ) - $this->start );
- $mem = sprintf( "%5.1fM", ( memory_get_usage( true ) / ( 1024 * 1024 ) ) );
+ $pid = sprintf( '%5s', getmypid() );
+ $prefix = sprintf( '%6.2f', microtime( true ) - $this->start );
+ $mem = sprintf( '%5.1fM', ( memory_get_usage( true ) / ( 1024 * 1024 ) ) );
$this->output( "$pid $prefix $mem $text", $channel );
}
public function execute() {
- global $wgTranslateTranslationServices;
+ global $wgTranslateTranslationServices,
+ $wgTranslateTranslationDefaultService;
- // TTMServer is the id of the enabled-by-default instance
- $configKey = $this->getOption( 'ttmserver', 'TTMServer' );
+ $configKey = $this->getOption( 'ttmserver', $wgTranslateTranslationDefaultService );
if ( !isset( $wgTranslateTranslationServices[$configKey] ) ) {
- $this->error( "Translation memory is not configured properly", 1 );
+ $this->error( 'Translation memory is not configured properly', 1 );
}
$config = $wgTranslateTranslationServices[$configKey];
@@ -84,10 +84,14 @@ class TTMServerBootstrap extends Maintenance {
$this->statusLine( "Forked thread $pid to handle bootstrapping\n" );
$status = 0;
pcntl_waitpid( $pid, $status );
+ // beginBootStrap probably failed, give up.
+ if ( $status !== 0 ) {
+ $this->error( 'Boostrap failed.', 1 );
+ }
}
$threads = $this->getOption( 'threads', 1 );
- $pids = array();
+ $pids = [];
$groups = MessageGroups::singleton()->getGroups();
foreach ( $groups as $id => $group ) {
@@ -131,9 +135,12 @@ class TTMServerBootstrap extends Maintenance {
}
protected function beginBootStrap( $config ) {
- $this->statusLine( "Cleaning up old entries...\n" );
$server = TTMServer::factory( $config );
$server->setLogger( $this );
+ if ( $server->isFrozen() ) {
+ $this->error( "The service is frozen, giving up.", 1 );
+ }
+ $this->statusLine( "Cleaning up old entries...\n" );
if ( $this->reindex ) {
$server->doMappingUpdate();
}
@@ -162,18 +169,18 @@ class TTMServerBootstrap extends Maintenance {
$server->beginBatch();
- $inserts = array();
+ $inserts = [];
foreach ( $collection->keys() as $mkey => $title ) {
$handle = new MessageHandle( $title );
- $inserts[] = array( $handle, $sourceLanguage, $collection[$mkey]->definition() );
+ $inserts[] = [ $handle, $sourceLanguage, $collection[$mkey]->definition() ];
}
- while ( $inserts !== array() ) {
+ while ( $inserts !== [] ) {
$batch = array_splice( $inserts, 0, $this->mBatchSize );
$server->batchInsertDefinitions( $batch );
}
- $inserts = array();
+ $inserts = [];
foreach ( $stats as $targetLanguage => $numbers ) {
if ( $targetLanguage === $sourceLanguage ) {
continue;
@@ -189,7 +196,7 @@ class TTMServerBootstrap extends Maintenance {
foreach ( $collection->keys() as $mkey => $title ) {
$handle = new MessageHandle( $title );
- $inserts[] = array( $handle, $sourceLanguage, $collection[$mkey]->translation() );
+ $inserts[] = [ $handle, $sourceLanguage, $collection[$mkey]->translation() ];
}
while ( count( $inserts ) >= $this->mBatchSize ) {
@@ -198,7 +205,7 @@ class TTMServerBootstrap extends Maintenance {
}
}
- while ( $inserts !== array() ) {
+ while ( $inserts !== [] ) {
$batch = array_splice( $inserts, 0, $this->mBatchSize );
$server->batchInsertTranslations( $batch );
}
@@ -207,13 +214,9 @@ class TTMServerBootstrap extends Maintenance {
}
protected function resetStateForFork() {
- // Child, reseed because there is no bug in PHP:
- // http://bugs.php.net/bug.php?id=42465
- mt_srand( getmypid() );
-
// Make sure all existing connections are dead,
// we can't use them in forked children.
- LBFactory::destroyInstance();
+ MediaWiki\MediaWikiServices::resetChildProcessServices();
}
}
diff --git a/MLEB/Translate/scripts/yaml-tests.php b/MLEB/Translate/scripts/yaml-tests.php
index 905b8a71..c0bd3dee 100644
--- a/MLEB/Translate/scripts/yaml-tests.php
+++ b/MLEB/Translate/scripts/yaml-tests.php
@@ -5,7 +5,7 @@
* @author Niklas Laxström
*
* @copyright Copyright © 2010, Niklas Laxström
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
* @file
*/
@@ -26,17 +26,17 @@ class YamlTests extends Maintenance {
public function execute() {
global $wgTranslateGroupFiles, $wgTranslateYamlLibrary;
- $documents = array();
- $times = array();
- $mems = array();
- $mempeaks = array();
+ $documents = [];
+ $times = [];
+ $mems = [];
+ $mempeaks = [];
- foreach ( array( 'syck', 'spyc', 'phpyaml' ) as $driver ) {
+ foreach ( [ 'syck', 'spyc', 'phpyaml' ] as $driver ) {
$mempeaks[$driver] = -memory_get_peak_usage( true );
$mems[$driver] = -memory_get_usage( true );
$times[$driver] = -microtime( true );
$wgTranslateYamlLibrary = $driver;
- $documents[$driver] = array();
+ $documents[$driver] = [];
foreach ( $wgTranslateGroupFiles as $file ) {
foreach ( self::parseGroupFile( $file ) as $id => $docu ) {
$documents[$driver]["$file-$id"] = $docu;
@@ -59,7 +59,7 @@ class YamlTests extends Maintenance {
public static function parseGroupFile( $filename ) {
$data = file_get_contents( $filename );
$documents = preg_split( "/^---$/m", $data, -1, PREG_SPLIT_NO_EMPTY );
- $groups = array();
+ $groups = [];
$template = false;
foreach ( $documents as $document ) {
$document = TranslateYaml::loadString( $document );
@@ -67,7 +67,7 @@ class YamlTests extends Maintenance {
$template = $document['TEMPLATE'];
} else {
if ( !isset( $document['BASIC']['id'] ) ) {
- trigger_error( "No path ./BASIC/id (group id not defined) " .
+ trigger_error( 'No path ./BASIC/id (group id not defined) ' .
"in yaml document located in $filename" );
continue;
}
@@ -76,7 +76,7 @@ class YamlTests extends Maintenance {
}
foreach ( $groups as $i => $group ) {
- $groups[$i] = TranslateYaml::mergeTemplate( $template, $group );
+ $groups[$i] = MessageGroupConfigurationParser::mergeTemplate( $template, $group );
}
return $groups;