summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Evans <grknight@gentoo.org>2021-07-19 15:20:22 -0400
committerBrian Evans <grknight@gentoo.org>2021-07-19 15:20:22 -0400
commit9f092345e6bbecfde8c19e6d1490a6031a35f61f (patch)
tree2abb2398cd0df686e8608e15097ddc58b8995615 /MLEB/Translate/scripts
parentOAuth: Update for fixes and security (diff)
downloadextensions-9f092345e6bbecfde8c19e6d1490a6031a35f61f.tar.gz
extensions-9f092345e6bbecfde8c19e6d1490a6031a35f61f.tar.bz2
extensions-9f092345e6bbecfde8c19e6d1490a6031a35f61f.zip
Update to MLEB 2021.06
Signed-off-by: Brian Evans <grknight@gentoo.org>
Diffstat (limited to 'MLEB/Translate/scripts')
-rw-r--r--MLEB/Translate/scripts/__bootstrap.php19
-rw-r--r--MLEB/Translate/scripts/characterEditStats.php19
-rw-r--r--MLEB/Translate/scripts/cleanupTranslationProgressStats.php6
-rw-r--r--MLEB/Translate/scripts/clearGroupSyncCache.php6
-rw-r--r--MLEB/Translate/scripts/completeExternalTranslation.php10
-rw-r--r--MLEB/Translate/scripts/createCheckIndex.php2
-rw-r--r--MLEB/Translate/scripts/deleteEqualTranslations.php6
-rw-r--r--MLEB/Translate/scripts/export.php389
-rw-r--r--MLEB/Translate/scripts/exportTtmServerDump.php6
-rw-r--r--MLEB/Translate/scripts/fallbacks-graph.php8
-rw-r--r--MLEB/Translate/scripts/findUnsynchronizedDefinitions.php6
-rw-r--r--MLEB/Translate/scripts/fuzzy.php34
-rw-r--r--MLEB/Translate/scripts/groupStatistics.php6
-rw-r--r--MLEB/Translate/scripts/languageeditstats.php2
-rw-r--r--MLEB/Translate/scripts/moveTranslatablePage.php6
-rw-r--r--MLEB/Translate/scripts/poimport.php33
-rw-r--r--MLEB/Translate/scripts/populateFuzzy.php5
-rw-r--r--MLEB/Translate/scripts/processMessageChanges.php11
-rw-r--r--MLEB/Translate/scripts/queryGroupSyncCache.php6
-rw-r--r--MLEB/Translate/scripts/sync-group.php8
-rw-r--r--MLEB/Translate/scripts/translator-stats.php5
-rw-r--r--MLEB/Translate/scripts/ttmserver-export.php33
-rw-r--r--MLEB/Translate/scripts/updateTranslatorActivity.php10
23 files changed, 140 insertions, 496 deletions
diff --git a/MLEB/Translate/scripts/__bootstrap.php b/MLEB/Translate/scripts/__bootstrap.php
new file mode 100644
index 00000000..d401adaa
--- /dev/null
+++ b/MLEB/Translate/scripts/__bootstrap.php
@@ -0,0 +1,19 @@
+<?php
+declare( strict_types = 1 );
+
+/*
+ * Boilerpate code for bootstrapping maintenance scripts.
+ *
+ * This code must be in global scope. Callers must define $class;
+ */
+$env = getenv( 'MW_INSTALL_PATH' );
+$IP = $env !== false ? $env : __DIR__ . '/../../..';
+require_once "$IP/maintenance/Maintenance.php";
+// Manually load required classes, as autoloader is not available until RUN_MAINTENANCE_IF_MAIN
+require_once __DIR__ . '/../src/Utilities/BaseMaintenanceScript.php';
+// $maintClass must be after Maintenance.php
+// @phan-suppress-next-line PhanUndeclaredGlobalVariable
+$maintClass = $class;
+$file = strtr( $maintClass, [ 'MediaWiki\\Extension\\Translate\\' => '', '\\' => '/' ] );
+require_once __DIR__ . "/../src/$file.php";
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/MLEB/Translate/scripts/characterEditStats.php b/MLEB/Translate/scripts/characterEditStats.php
index 05a75331..d8a3d87b 100644
--- a/MLEB/Translate/scripts/characterEditStats.php
+++ b/MLEB/Translate/scripts/characterEditStats.php
@@ -10,7 +10,8 @@
*/
// Standard boilerplate to define $IP
-use MediaWiki\Extensions\Translate\SystemUsers\FuzzyBot;
+use MediaWiki\Extension\Translate\SystemUsers\FuzzyBot;
+use MediaWiki\MediaWikiServices;
if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
$IP = getenv( 'MW_INSTALL_PATH' );
@@ -115,19 +116,9 @@ class CharacterEditStats extends Maintenance {
$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 = $revQuery['fields']['rev_user_text'] ?? 'rev_user_text';
- } else {
- $revQuery = [
- 'tables' => [ 'revision', 'page' ],
- 'joins' => [
- 'page' => [ 'JOIN', 'rev_page = page_id' ],
- ]
- ];
- $revUserText = 'rev_user_text';
- }
+ $revQuery = MediaWikiServices::getInstance()->getRevisionStore()->getQueryInfo( [ 'page' ] );
+ $revUserText = $revQuery['fields']['rev_user_text'] ?? 'rev_user_text';
+
$conds = [
"rev_timestamp > $cutoff",
'page_namespace' => $namespaces,
diff --git a/MLEB/Translate/scripts/cleanupTranslationProgressStats.php b/MLEB/Translate/scripts/cleanupTranslationProgressStats.php
new file mode 100644
index 00000000..ce636628
--- /dev/null
+++ b/MLEB/Translate/scripts/cleanupTranslationProgressStats.php
@@ -0,0 +1,6 @@
+<?php
+
+use MediaWiki\Extension\Translate\Statistics\CleanupTranslationProgressStatsMaintenanceScript;
+
+$class = CleanupTranslationProgressStatsMaintenanceScript::class;
+require_once '__bootstrap.php';
diff --git a/MLEB/Translate/scripts/clearGroupSyncCache.php b/MLEB/Translate/scripts/clearGroupSyncCache.php
new file mode 100644
index 00000000..2492f18f
--- /dev/null
+++ b/MLEB/Translate/scripts/clearGroupSyncCache.php
@@ -0,0 +1,6 @@
+<?php
+
+use MediaWiki\Extension\Translate\Synchronization\ClearGroupSyncCacheMaintenanceScript;
+
+$class = ClearGroupSyncCacheMaintenanceScript::class;
+require_once '__bootstrap.php';
diff --git a/MLEB/Translate/scripts/completeExternalTranslation.php b/MLEB/Translate/scripts/completeExternalTranslation.php
index b25ca59e..cf6bb6db 100644
--- a/MLEB/Translate/scripts/completeExternalTranslation.php
+++ b/MLEB/Translate/scripts/completeExternalTranslation.php
@@ -1,10 +1,6 @@
<?php
-use MediaWiki\Extensions\Translate\Synchronization\CompleteExternalTranslationMaintenanceScript;
+use MediaWiki\Extension\Translate\Synchronization\CompleteExternalTranslationMaintenanceScript;
-$env = getenv( 'MW_INSTALL_PATH' );
-$IP = $env !== false ? $env : __DIR__ . '/../../..';
-require_once "$IP/maintenance/Maintenance.php";
-require_once __DIR__ . '/../src/Synchronization/CompleteExternalTranslationMaintenanceScript.php';
-$maintClass = CompleteExternalTranslationMaintenanceScript::class;
-require_once RUN_MAINTENANCE_IF_MAIN;
+$class = CompleteExternalTranslationMaintenanceScript::class;
+require_once '__bootstrap.php';
diff --git a/MLEB/Translate/scripts/createCheckIndex.php b/MLEB/Translate/scripts/createCheckIndex.php
index 24e2ae4a..a21a60d1 100644
--- a/MLEB/Translate/scripts/createCheckIndex.php
+++ b/MLEB/Translate/scripts/createCheckIndex.php
@@ -36,7 +36,7 @@ class CreateCheckIndex extends Maintenance {
'verbose',
'(optional) Enable verbose logging. Default: off',
false, /*required*/
- false /*has arg*/
+ false /*has arg*/
);
$this->requireExtension( 'Translate' );
}
diff --git a/MLEB/Translate/scripts/deleteEqualTranslations.php b/MLEB/Translate/scripts/deleteEqualTranslations.php
new file mode 100644
index 00000000..c85e775d
--- /dev/null
+++ b/MLEB/Translate/scripts/deleteEqualTranslations.php
@@ -0,0 +1,6 @@
+<?php
+
+use MediaWiki\Extension\Translate\Diagnostics\DeleteEqualTranslationsMaintenanceScript;
+
+$class = DeleteEqualTranslationsMaintenanceScript::class;
+require_once '__bootstrap.php';
diff --git a/MLEB/Translate/scripts/export.php b/MLEB/Translate/scripts/export.php
index b0bc314d..ed802ff4 100644
--- a/MLEB/Translate/scripts/export.php
+++ b/MLEB/Translate/scripts/export.php
@@ -1,389 +1,6 @@
<?php
-/**
- * Script to export translations of one message group to file(s).
- *
- * @author Niklas Laxström
- * @author Siebrand Mazeland
- * @copyright Copyright © 2008-2013, Niklas Laxström, Siebrand Mazeland
- * @license GPL-2.0-or-later
- * @file
- */
-// Standard boilerplate to define $IP
-if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
- $IP = getenv( 'MW_INSTALL_PATH' );
-} else {
- $dir = __DIR__;
- $IP = "$dir/../../..";
-}
-require_once "$IP/maintenance/Maintenance.php";
+use MediaWiki\Extension\Translate\Synchronization\ExportTranslationsMaintenanceScript;
-class CommandlineExport extends Maintenance {
- private const EXPORT_LOG_FILE = 'translation-exports';
-
- public function __construct() {
- parent::__construct();
- $this->addDescription( 'Message exporter.' );
- $this->addOption(
- 'group',
- 'Comma separated list of group IDs (can use * as wildcard)',
- true, /*required*/
- true /*has arg*/
- );
- $this->addOption(
- 'lang',
- 'Comma separated list of language codes or *',
- true, /*required*/
- true /*has arg*/
- );
- $this->addOption(
- 'target',
- 'Target directory for exported files',
- true, /*required*/
- true /*has arg*/
- );
- $this->addOption(
- 'skip',
- '(optional) Languages to skip, comma separated list',
- false, /*required*/
- true /*has arg*/
- );
- $this->addOption(
- 'skipgroup',
- '(optional) Comma separated list of group IDs that should not be exported',
- false, /*required*/
- true /*has arg*/
- );
- $this->addOption(
- 'threshold',
- '(optional) Do not export under this percentage translated',
- false, /*required*/
- true /*has arg*/
- );
- $this->addOption(
- 'hours',
- '(optional) Only export languages with changes in the last given number of hours',
- false, /*required*/
- true /*has arg*/
- );
- $this->addOption(
- 'ppgettext',
- '(optional) Group root path for checkout of product. "msgmerge" will post ' .
- 'process on the export result based on the current source file ' .
- 'in that location (from sourcePattern or definitionFile)',
- false, /*required*/
- true /*has arg*/
- );
- $this->addOption(
- 'no-location',
- '(optional) Only used combined with "ppgettext". This option will rebuild ' .
- 'the gettext file without location information',
- false, /*required*/
- false /*has arg*/
- );
- $this->addOption(
- 'no-fuzzy',
- '(optional) Do not include any messages marked as fuzzy/outdated',
- false, /*required*/
- false /*has arg*/
- );
- $this->addOption(
- 'codemaponly',
- '(optional) Only export languages that have a codeMap entry',
- false, /*required*/
- false /*has arg*/
- );
-
- $this->addOption(
- 'offline-gettext-format',
- '(optional) Export languages in offline Gettext format. Give a file pattern with '
- . '%GROUPID% and %CODE%. Empty pattern defaults to %GROUPID%/%CODE%.po.',
- false, /*required*/
- true /*has arg*/
- );
- $this->requireExtension( 'Translate' );
- }
-
- public function execute() {
- wfDebugLog( self::EXPORT_LOG_FILE, 'Starting exports for groups - '
- . $this->getOption( 'group' ) . '... ' );
- $exportStartTime = microtime( true );
-
- $target = $this->getOption( 'target' );
- if ( !is_writable( $target ) ) {
- $this->fatalError( "Target directory is not writable ($target)." );
- }
-
- $threshold = $this->getOption( 'threshold' );
- $noFuzzy = $this->hasOption( 'no-fuzzy' );
-
- $noLocation = '';
- if ( $this->hasOption( 'no-location' ) ) {
- $noLocation = '--no-location ';
- }
-
- $skip = [];
- if ( $this->hasOption( 'skip' ) ) {
- $skip = array_map( 'trim', explode( ',', $this->getOption( 'skip' ) ) );
- }
-
- $reqLangs = TranslateUtils::parseLanguageCodes( $this->getOption( 'lang' ) );
- $reqLangs = array_flip( $reqLangs );
- foreach ( $skip as $skipLang ) {
- unset( $reqLangs[$skipLang] );
- }
- $reqLangs = array_flip( $reqLangs );
-
- $codemapOnly = $this->hasOption( 'codemaponly' );
- $forOffline = $this->hasOption( 'offline-gettext-format' );
- $offlineTargetPattern = $this->getOption( 'offline-gettext-format' ) ?: "%GROUPID%/%CODE%.po";
-
- $groupIds = explode( ',', trim( $this->getOption( 'group' ) ) );
- $groupIds = MessageGroups::expandWildcards( $groupIds );
- $groups = MessageGroups::getGroupsById( $groupIds );
- '@phan-var FileBasedMessageGroup[] $groups';
-
- /** @var FileBasedMessageGroup $group */
- foreach ( $groups as $groupId => $group ) {
- if ( $group->isMeta() ) {
- $this->output( "Skipping meta message group $groupId.\n" );
- unset( $groups[$groupId] );
- continue;
- }
-
- if ( !$forOffline && !$group instanceof FileBasedMessageGroup ) {
- $this->output( "EE2: Unexportable message group $groupId.\n" );
- unset( $groups[$groupId] );
- continue;
- }
- }
-
- if ( !count( $groups ) ) {
- $this->fatalError( 'EE1: No valid message groups identified.' );
- }
-
- $changeFilter = false;
- $hours = $this->getOption( 'hours' );
- if ( $hours ) {
- $namespaces = [];
-
- /** @var FileBasedMessageGroup $group */
- foreach ( $groups as $group ) {
- $namespaces[$group->getNamespace()] = true;
- }
-
- $namespaces = array_keys( $namespaces );
- $bots = true;
-
- $changeFilter = [];
- $rows = TranslateUtils::translationChanges( $hours, $bots, $namespaces );
- foreach ( $rows as $row ) {
- $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
- $handle = new MessageHandle( $title );
- $code = $handle->getCode();
- if ( !$code ) {
- continue;
- }
- $groupIds = $handle->getGroupIds();
- foreach ( $groupIds as $groupId ) {
- $changeFilter[$groupId][$code] = true;
- }
- }
- }
-
- $skipGroups = [];
- if ( $this->hasOption( 'skipgroup' ) ) {
- $skipGroups = array_map( 'trim', explode( ',', $this->getOption( 'skipgroup' ) ) );
- }
-
- foreach ( $groups as $groupId => $group ) {
- if ( in_array( $groupId, $skipGroups ) ) {
- $this->output( "Group $groupId is in skipgroup.\n" );
- continue;
- }
-
- // No changes to this group at all
- if ( is_array( $changeFilter ) && !isset( $changeFilter[$groupId] ) ) {
- $this->output( "No recent changes to $groupId.\n" );
- continue;
- }
-
- $langs = $reqLangs;
-
- if ( $codemapOnly ) {
- foreach ( $langs as $index => $code ) {
- if ( $group->mapCode( $code ) === $code ) {
- unset( $langs[$index] );
- }
- }
- }
-
- if ( $threshold ) {
- wfDebugLog( self::EXPORT_LOG_FILE, "Calculating stats for group $groupId" );
- $tStartTime = microtime( true );
- $stats = MessageGroupStats::forGroup( $groupId );
- $emptyLangs = [];
- foreach ( $langs as $index => $code ) {
- if ( !isset( $stats[$code] ) ) {
- unset( $langs[$index] );
- continue;
- }
-
- $total = $stats[$code][MessageGroupStats::TOTAL];
- $translated = $stats[$code][MessageGroupStats::TRANSLATED];
-
- if ( $total === 0 ) {
- $emptyLangs[] = $code;
- unset( $langs[$index] );
- continue;
- }
-
- if ( $translated / $total * 100 < $threshold ) {
- unset( $langs[$index] );
- }
- }
-
- if ( $emptyLangs !== [] ) {
- $this->output(
- "Message group $groupId doesn't contain messages in language(s): " .
- implode( ', ', $emptyLangs ) . "."
- );
- }
-
- $tEndTime = microtime( true );
- wfDebugLog( self::EXPORT_LOG_FILE,
- "Finished calculating stats for group $groupId. Time: "
- . ( $tEndTime - $tStartTime ) . ' secs.' );
- }
-
- // Filter out unchanged languages from requested languages
- if ( is_array( $changeFilter ) ) {
- $langs = array_intersect( $langs, array_keys( $changeFilter[$groupId] ) );
- }
-
- if ( !count( $langs ) ) {
- continue;
- }
-
- $this->output( 'Exporting ' . count( $langs ) . " languages for group $groupId" );
-
- if ( $forOffline ) {
- $fileBasedGroup = FileBasedMessageGroup::newFromMessageGroup( $group, $offlineTargetPattern );
- $ffs = new GettextFFS( $fileBasedGroup );
- $ffs->setOfflineMode( true );
- } else {
- $ffs = $group->getFFS();
- }
-
- $ffs->setWritePath( $target );
- $sourceLanguage = $group->getSourceLanguage();
- $collection = $group->initCollection( $sourceLanguage );
-
- $definitionFile = false;
-
- if ( $this->hasOption( 'ppgettext' ) && $ffs instanceof GettextFFS ) {
- global $wgMaxShellMemory, $wgTranslateGroupRoot;
-
- // Need more shell memory for msgmerge.
- $wgMaxShellMemory = 402400;
-
- $path = $group->getSourceFilePath( $sourceLanguage );
- $definitionFile = str_replace(
- $wgTranslateGroupRoot,
- $this->getOption( 'ppgettext' ),
- $path
- );
- }
-
- $whitelist = $group->getTranslatableLanguages();
-
- wfDebugLog(
- self::EXPORT_LOG_FILE, 'Exporting languages ('
- . count( $langs ) . ") for group - $groupId."
- );
-
- $langExportTimes = [
- 'collection' => 0,
- 'ffs' => 0,
- 'definitionFile' => 0
- ];
- $langStartTime = microtime( true );
- foreach ( $langs as $lang ) {
- // 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] ) ) {
- continue;
- }
-
- $startTime = microtime( true );
- $collection->resetForNewLanguage( $lang );
- $collection->loadTranslations();
- // Don't export ignored, unless it is the source language
- // or message documentation
- global $wgTranslateDocumentationLanguageCode;
- if ( $lang !== $wgTranslateDocumentationLanguageCode
- && $lang !== $sourceLanguage
- ) {
- $collection->filter( 'ignored' );
- }
-
- if ( $noFuzzy ) {
- $collection->filter( 'fuzzy' );
- }
- $endTime = microtime( true );
- $langExportTimes['collection'] += ( $endTime - $startTime );
-
- $startTime = microtime( true );
- $ffs->write( $collection );
- $endTime = microtime( true );
- $langExportTimes['ffs'] += ( $endTime - $startTime );
-
- // Do post processing if requested.
- if ( $definitionFile ) {
- $startTime = microtime( true );
- if ( is_file( $definitionFile ) ) {
- $targetFileName = $ffs->getWritePath() .
- '/' . $group->getTargetFilename( $collection->code );
- $cmd = 'msgmerge --quiet ' . $noLocation . '--output-file=' .
- $targetFileName . ' ' . $targetFileName . ' ' . $definitionFile;
- wfShellExec( $cmd, $ret );
-
- // Report on errors.
- if ( $ret ) {
- $this->error( "ERROR: $ret" );
- }
- } else {
- $this->fatalError( "$definitionFile does not exist for group $groupId." );
- }
- $endTime = microtime( true );
- $langExportTimes['definitionFile'] += ( $endTime - $startTime );
- }
- }
- $langEndTime = microtime( true );
-
- wfDebugLog(
- self::EXPORT_LOG_FILE,
- "Done exporting languages for group - $groupId. " .
- 'Time taken - ' . ( $langEndTime - $langStartTime ) . ' secs.'
- );
-
- foreach ( $langExportTimes as $type => $time ) {
- wfDebugLog(
- self::EXPORT_LOG_FILE,
- "Time taken by '$type' for group $groupId - $time secs."
- );
- }
- }
-
- $exportEndTime = microtime( true );
- wfDebugLog(
- self::EXPORT_LOG_FILE, 'Finished export process for groups - ' .
- $this->getOption( 'group' ) .
- '. Time: ' . ( $exportEndTime - $exportStartTime ) . ' secs.'
- );
- }
-}
-
-$maintClass = CommandlineExport::class;
-require_once RUN_MAINTENANCE_IF_MAIN;
+$class = ExportTranslationsMaintenanceScript::class;
+require_once '__bootstrap.php';
diff --git a/MLEB/Translate/scripts/exportTtmServerDump.php b/MLEB/Translate/scripts/exportTtmServerDump.php
new file mode 100644
index 00000000..0fc921ba
--- /dev/null
+++ b/MLEB/Translate/scripts/exportTtmServerDump.php
@@ -0,0 +1,6 @@
+<?php
+
+use MediaWiki\Extension\Translate\TtmServer\ExportTtmServerDumpMaintenanceScript;
+
+$class = ExportTtmServerDumpMaintenanceScript::class;
+require_once '__bootstrap.php';
diff --git a/MLEB/Translate/scripts/fallbacks-graph.php b/MLEB/Translate/scripts/fallbacks-graph.php
index 769e30b8..e55c907e 100644
--- a/MLEB/Translate/scripts/fallbacks-graph.php
+++ b/MLEB/Translate/scripts/fallbacks-graph.php
@@ -45,8 +45,8 @@ XML;
$langs = Language::fetchLanguageNames( null, 'mw' );
$nodes = $edges = [];
foreach ( $langs as $code => $name ) {
- $fallbacks = Language::getFallbacksFor( $code );
- if ( $fallbacks === [ 'en' ] ) {
+ $fallbacks = Language::getFallbacksFor( $code, Language::STRICT_FALLBACKS );
+ if ( $fallbacks === [] ) {
continue;
}
@@ -71,10 +71,10 @@ XML;
. Xml::openElement( 'y:Shapenode' )
. Xml::element(
'y:Geometry',
- [ 'height' => 30, 'width' => max( 30, 10 * strlen( $code ) ) ],
+ [ 'height' => 40, 'width' => max( 40, 20 * strlen( $code ) ) ],
''
)
- . Xml::element( 'y:NodeLabel', [], $code )
+ . Xml::element( 'y:NodeLabel', [ 'fontSize' => '24' ], $code )
. Xml::element( 'y:BorderStyle', [ 'hasColor' => 'false' ], '' )
. Xml::element( 'y:Fill', [ 'hasColor' => 'false' ], '' )
. Xml::closeElement( 'y:Shapenode' )
diff --git a/MLEB/Translate/scripts/findUnsynchronizedDefinitions.php b/MLEB/Translate/scripts/findUnsynchronizedDefinitions.php
new file mode 100644
index 00000000..a82664d0
--- /dev/null
+++ b/MLEB/Translate/scripts/findUnsynchronizedDefinitions.php
@@ -0,0 +1,6 @@
+<?php
+
+use MediaWiki\Extension\Translate\Diagnostics\FindUnsynchronizedDefinitionsMaintenanceScript;
+
+$class = FindUnsynchronizedDefinitionsMaintenanceScript::class;
+require_once '__bootstrap.php';
diff --git a/MLEB/Translate/scripts/fuzzy.php b/MLEB/Translate/scripts/fuzzy.php
index 549409bf..1244f2e2 100644
--- a/MLEB/Translate/scripts/fuzzy.php
+++ b/MLEB/Translate/scripts/fuzzy.php
@@ -10,7 +10,7 @@
*/
// Standard boilerplate to define $IP
-use MediaWiki\Extensions\Translate\SystemUsers\FuzzyBot;
+use MediaWiki\Extension\Translate\SystemUsers\FuzzyBot;
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\SlotRecord;
use Wikimedia\Rdbms\IResultWrapper;
@@ -97,35 +97,20 @@ class Fuzzy extends Maintenance {
* Class for marking translation fuzzy.
*/
class FuzzyScript {
- /**
- * @var bool Check for configuration problems.
- */
- private $allclear = false;
-
+ /** @var bool Check for configuration problems. */
+ private $allclear = true;
/** @var callable Function to report progress updates */
protected $progressCallback;
-
- /**
- * @var bool Dont do anything unless confirmation is given
- */
+ /** @var bool Dont do anything unless confirmation is given */
public $dryrun = true;
-
- /**
- * @var string Edit summary.
- */
+ /** @var string Edit summary. */
public $comment;
-
- /**
- * @var array[]
- */
+ /** @var array[] */
public $pages;
- /**
- * @param array $pages
- */
+ /** @param array $pages */
public function __construct( $pages ) {
$this->pages = $pages;
- $this->allclear = true;
}
public function setProgressCallback( $callback ) {
@@ -163,10 +148,7 @@ class FuzzyScript {
private static function getMessageContentsFromRows( $rows ) {
$revStore = MediaWikiServices::getInstance()->getRevisionStore();
$messagesContents = [];
- $slots = [];
- if ( is_callable( [ $revStore, 'getContentBlobsForBatch' ] ) ) {
- $slots = $revStore->getContentBlobsForBatch( $rows, [ SlotRecord::MAIN ] )->getValue();
- }
+ $slots = $revStore->getContentBlobsForBatch( $rows, [ SlotRecord::MAIN ] )->getValue();
foreach ( $rows as $row ) {
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
if ( isset( $slots[$row->rev_id] ) ) {
diff --git a/MLEB/Translate/scripts/groupStatistics.php b/MLEB/Translate/scripts/groupStatistics.php
index d69e110e..34bf0489 100644
--- a/MLEB/Translate/scripts/groupStatistics.php
+++ b/MLEB/Translate/scripts/groupStatistics.php
@@ -88,7 +88,6 @@ class GroupStatistics extends Maintenance {
'ckb' => [ 50, 26, 'asia' ],
'ku-latn' => [ 50, 26, 'asia' ],
];
-
/**
* Variable with key-value pairs with a named index and an array of key-value
* pairs where the key is a MessageGroup ID and the value is a weight of the
@@ -116,7 +115,6 @@ class GroupStatistics extends Maintenance {
'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
@@ -409,9 +407,7 @@ class GroupStatistics extends Maintenance {
);
}
- /**
- * @var MessageGroup $g
- */
+ /** @var MessageGroup $g */
foreach ( $groups as $g ) {
// Add unprocessed description of group as heading
if ( $reportScore ) {
diff --git a/MLEB/Translate/scripts/languageeditstats.php b/MLEB/Translate/scripts/languageeditstats.php
index 5aa11676..2cea8ed0 100644
--- a/MLEB/Translate/scripts/languageeditstats.php
+++ b/MLEB/Translate/scripts/languageeditstats.php
@@ -11,7 +11,7 @@
*/
// Standard boilerplate to define $IP
-use MediaWiki\Extensions\Translate\SystemUsers\FuzzyBot;
+use MediaWiki\Extension\Translate\SystemUsers\FuzzyBot;
if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
$IP = getenv( 'MW_INSTALL_PATH' );
diff --git a/MLEB/Translate/scripts/moveTranslatablePage.php b/MLEB/Translate/scripts/moveTranslatablePage.php
new file mode 100644
index 00000000..060eb7cb
--- /dev/null
+++ b/MLEB/Translate/scripts/moveTranslatablePage.php
@@ -0,0 +1,6 @@
+<?php
+
+use MediaWiki\Extension\Translate\PageTranslation\MoveTranslatablePageMaintenanceScript;
+
+$class = MoveTranslatablePageMaintenanceScript::class;
+require_once '__bootstrap.php';
diff --git a/MLEB/Translate/scripts/poimport.php b/MLEB/Translate/scripts/poimport.php
index af7de0d5..4c411270 100644
--- a/MLEB/Translate/scripts/poimport.php
+++ b/MLEB/Translate/scripts/poimport.php
@@ -88,17 +88,14 @@ class Poimport extends Maintenance {
*/
class PoImporter {
/** @var callable Function to report progress updates */
- protected $progressCallback;
-
+ private $progressCallback;
/**
* Path to file to parse.
- * @var bool|string
+ * @var string
*/
- private $file = false;
+ private $file;
- /**
- * @param string $file File to import
- */
+ /** @param string $file File to import */
public function __construct( $file ) {
$this->file = $file;
}
@@ -219,22 +216,24 @@ class PoImporter {
* Import changes to wiki as given user
*/
class WikiWriter {
- /** @var callable Function to report progress updates */
- protected $progressCallback;
-
- protected $user;
-
- private $changes = [];
- private $dryrun = true;
- private $group = null;
+ /** @var callable|null Function to report progress updates */
+ private $progressCallback;
+ /** @var User */
+ private $user;
+ /** @var string[] */
+ private $changes;
+ /** @var bool */
+ private $dryrun;
+ /** @var MessageGroup|null */
+ private $group;
/**
- * @param array $changes Array of key/langcode => translation.
+ * @param string[] $changes Array of key/langcode => translation.
* @param string $groupId Group ID.
* @param string $user User who makes the edits in wiki.
* @param bool $dryrun Do not do anything that affects the database.
*/
- public function __construct( $changes, $groupId, $user, $dryrun = true ) {
+ public function __construct( array $changes, $groupId, $user, $dryrun = true ) {
$this->changes = $changes;
$this->group = MessageGroups::getGroup( $groupId );
$this->user = User::newFromName( $user );
diff --git a/MLEB/Translate/scripts/populateFuzzy.php b/MLEB/Translate/scripts/populateFuzzy.php
index 43c491d0..75451d27 100644
--- a/MLEB/Translate/scripts/populateFuzzy.php
+++ b/MLEB/Translate/scripts/populateFuzzy.php
@@ -74,10 +74,7 @@ class PopulateFuzzy extends Maintenance {
break;
}
- $slots = [];
- if ( is_callable( [ $revStore, 'getContentBlobsForBatch' ] ) ) {
- $slots = $revStore->getContentBlobsForBatch( $res, [ SlotRecord::MAIN ] )->getValue();
- }
+ $slots = $revStore->getContentBlobsForBatch( $res, [ SlotRecord::MAIN ] )->getValue();
foreach ( $res as $r ) {
if ( isset( $slots[$r->rev_id] ) ) {
$text = $slots[$r->rev_id][SlotRecord::MAIN]->blob_data;
diff --git a/MLEB/Translate/scripts/processMessageChanges.php b/MLEB/Translate/scripts/processMessageChanges.php
index 5be54c7c..78459cd4 100644
--- a/MLEB/Translate/scripts/processMessageChanges.php
+++ b/MLEB/Translate/scripts/processMessageChanges.php
@@ -18,8 +18,8 @@ if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
}
require_once "$IP/maintenance/Maintenance.php";
-use MediaWiki\Extensions\Translate\MessageSync\MessageSourceChange;
-use MediaWiki\Extensions\Translate\Utilities\StringComparators\SimpleStringComparator;
+use MediaWiki\Extension\Translate\MessageSync\MessageSourceChange;
+use MediaWiki\Extension\Translate\Utilities\StringComparators\SimpleStringComparator;
/**
* Script for processing message changes in file based message groups.
@@ -31,13 +31,6 @@ use MediaWiki\Extensions\Translate\Utilities\StringComparators\SimpleStringCompa
* @since 2012-04-23
*/
class ProcessMessageChanges extends Maintenance {
- protected $changes = [];
-
- /**
- * @var int
- */
- protected $counter;
-
public function __construct() {
parent::__construct();
$this->addDescription( 'Script for processing message changes in file based message groups' );
diff --git a/MLEB/Translate/scripts/queryGroupSyncCache.php b/MLEB/Translate/scripts/queryGroupSyncCache.php
new file mode 100644
index 00000000..f8b0fce0
--- /dev/null
+++ b/MLEB/Translate/scripts/queryGroupSyncCache.php
@@ -0,0 +1,6 @@
+<?php
+
+use MediaWiki\Extension\Translate\Synchronization\QueryGroupSyncCacheMaintenanceScript;
+
+$class = QueryGroupSyncCacheMaintenanceScript::class;
+require_once '__bootstrap.php';
diff --git a/MLEB/Translate/scripts/sync-group.php b/MLEB/Translate/scripts/sync-group.php
index 4e43a86b..8ab81524 100644
--- a/MLEB/Translate/scripts/sync-group.php
+++ b/MLEB/Translate/scripts/sync-group.php
@@ -11,7 +11,7 @@
* @file
*/
-use MediaWiki\Extensions\Translate\SystemUsers\FuzzyBot;
+use MediaWiki\Extension\Translate\SystemUsers\FuzzyBot;
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Shell\Shell;
@@ -186,16 +186,12 @@ class SyncGroup extends Maintenance {
class ChangeSyncer {
/** @var callable Function to report progress updates */
protected $progressCallback;
-
- /** @var bool Don't list changes in recent changes table. */
+ /** @var bool Don't list changes in recent changes table. */
public $norc = false;
-
/** @var bool Whether the script can ask questions. */
public $interactive = true;
-
/** @var bool Disable color output. */
public $nocolor = false;
-
/** @var MessageGroup */
protected $group;
diff --git a/MLEB/Translate/scripts/translator-stats.php b/MLEB/Translate/scripts/translator-stats.php
index 77fe3c72..9a24e657 100644
--- a/MLEB/Translate/scripts/translator-stats.php
+++ b/MLEB/Translate/scripts/translator-stats.php
@@ -102,9 +102,8 @@ class TS extends Maintenance {
$method = 'sandbox';
break;
} elseif ( $log->log_action === 'rights' ) {
- Wikimedia\suppressWarnings();
- $data = unserialize( $log->log_params );
- Wikimedia\restoreWarnings();
+ // phpcs:disable Generic.PHP.NoSilencedErrors.Discouraged
+ $data = @unserialize( $log->log_params );
if ( $data === false ) {
$lines = explode( "\n", $log->log_params, 3 );
if ( strpos( $lines[1], 'translator' ) !== false ) {
diff --git a/MLEB/Translate/scripts/ttmserver-export.php b/MLEB/Translate/scripts/ttmserver-export.php
index 05c20298..7b331cc4 100644
--- a/MLEB/Translate/scripts/ttmserver-export.php
+++ b/MLEB/Translate/scripts/ttmserver-export.php
@@ -21,9 +21,7 @@ require_once "$IP/maintenance/Maintenance.php";
* @since 2012-01-26
*/
class TTMServerBootstrap extends Maintenance {
- /**
- * @var int
- */
+ /** @var int */
private $start;
public function __construct() {
@@ -48,7 +46,7 @@ class TTMServerBootstrap extends Maintenance {
);
$this->addOption(
'dry-run',
- 'Do not make any actualy changes in the index.'
+ 'Do not make any changes to the index.'
);
$this->addOption(
'verbose',
@@ -102,11 +100,12 @@ class TTMServerBootstrap extends Maintenance {
$status = 0;
pcntl_waitpid( $pid, $status );
// beginBootstrap probably failed, give up.
- if ( $status !== 0 ) {
- $this->fatalError( 'Boostrap failed.' );
+ if ( !$this->verifyChildStatus( $pid, $status ) ) {
+ $this->fatalError( 'Bootstrap failed.' );
}
}
+ $hasErrors = false;
$threads = $this->getOption( 'threads', 1 );
$pids = [];
@@ -137,6 +136,7 @@ class TTMServerBootstrap extends Maintenance {
if ( count( $pids ) >= $threads ) {
$status = 0;
$pid = pcntl_wait( $status );
+ $hasErrors = $hasErrors || !$this->verifyChildStatus( $pid, $status );
unset( $pids[$pid] );
}
}
@@ -146,10 +146,15 @@ class TTMServerBootstrap extends Maintenance {
foreach ( array_keys( $pids ) as $pid ) {
$status = 0;
pcntl_waitpid( $pid, $status );
+ $hasErrors = $hasErrors || !$this->verifyChildStatus( $pid, $status );
}
// It's okay to do this in the main thread as it is the last thing
$this->endBootstrap( $server );
+
+ if ( $hasErrors ) {
+ $this->fatalError( '!!! Some threads failed. Review the script output !!!' );
+ }
}
private function getServer( array $config ): WritableTTMServer {
@@ -283,6 +288,22 @@ class TTMServerBootstrap extends Maintenance {
// we can't use them in forked children.
MediaWiki\MediaWikiServices::resetChildProcessServices();
}
+
+ private function verifyChildStatus( int $pid, int $status ): bool {
+ if ( pcntl_wifexited( $status ) ) {
+ $code = pcntl_wexitstatus( $status );
+ if ( $code ) {
+ $this->output( "Pid $pid exited with status $code !!\n" );
+ return false;
+ }
+ } elseif ( pcntl_wifsignaled( $status ) ) {
+ $signum = pcntl_wtermsig( $status );
+ $this->output( "Pid $pid terminated by signal $signum !!\n" );
+ return false;
+ }
+
+ return true;
+ }
}
$maintClass = TTMServerBootstrap::class;
diff --git a/MLEB/Translate/scripts/updateTranslatorActivity.php b/MLEB/Translate/scripts/updateTranslatorActivity.php
index a4d7a852..30921ffa 100644
--- a/MLEB/Translate/scripts/updateTranslatorActivity.php
+++ b/MLEB/Translate/scripts/updateTranslatorActivity.php
@@ -1,10 +1,6 @@
<?php
-use MediaWiki\Extensions\Translate\Statistics\UpdateTranslatorActivityMaintenanceScript;
+use MediaWiki\Extension\Translate\Statistics\UpdateTranslatorActivityMaintenanceScript;
-$env = getenv( 'MW_INSTALL_PATH' );
-$IP = $env !== false ? $env : __DIR__ . '/../../..';
-require_once "$IP/maintenance/Maintenance.php";
-require_once __DIR__ . '/../src/Statistics/UpdateTranslatorActivityMaintenanceScript.php';
-$maintClass = UpdateTranslatorActivityMaintenanceScript::class;
-require_once RUN_MAINTENANCE_IF_MAIN;
+$class = UpdateTranslatorActivityMaintenanceScript::class;
+require_once '__bootstrap.php';