summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'MLEB/Translate/api')
-rw-r--r--MLEB/Translate/api/ApiAggregateGroups.php20
-rw-r--r--MLEB/Translate/api/ApiGroupReview.php6
-rw-r--r--MLEB/Translate/api/ApiManageMessageGroups.php20
-rw-r--r--MLEB/Translate/api/ApiQueryLanguageStats.php22
-rw-r--r--MLEB/Translate/api/ApiQueryManageMessageGroups.php2
-rw-r--r--MLEB/Translate/api/ApiQueryMessageCollection.php65
-rw-r--r--MLEB/Translate/api/ApiQueryMessageGroupStats.php16
-rw-r--r--MLEB/Translate/api/ApiQueryMessageGroups.php25
-rw-r--r--MLEB/Translate/api/ApiQueryMessageTranslations.php5
-rw-r--r--MLEB/Translate/api/ApiStatsQuery.php7
-rw-r--r--MLEB/Translate/api/ApiTranslateSandbox.php25
-rw-r--r--MLEB/Translate/api/ApiTranslationAids.php133
-rw-r--r--MLEB/Translate/api/ApiTranslationReview.php12
-rw-r--r--MLEB/Translate/api/ApiTranslationStash.php2
14 files changed, 137 insertions, 223 deletions
diff --git a/MLEB/Translate/api/ApiAggregateGroups.php b/MLEB/Translate/api/ApiAggregateGroups.php
index 7e403d84..581fb70c 100644
--- a/MLEB/Translate/api/ApiAggregateGroups.php
+++ b/MLEB/Translate/api/ApiAggregateGroups.php
@@ -8,6 +8,8 @@
* @license GPL-2.0-or-later
*/
+use MediaWiki\Logger\LoggerFactory;
+
/**
* API module for managing aggregate message groups
* Only supports aggregate message groups defined inside the wiki.
@@ -39,8 +41,6 @@ class ApiAggregateGroups extends ApiBase {
// means the group does not exist or something has gone wrong.
$this->dieWithError( 'apierror-translate-invalidaggregategroup', 'invalidaggregategroup' );
- // For static analysers
- $subgroups = [];
}
$subgroupId = $params['group'];
@@ -89,9 +89,21 @@ class ApiAggregateGroups extends ApiBase {
if ( !isset( $params['aggregategroup'] ) ) {
$this->dieWithError( [ 'apierror-missingparam', 'aggregategroup' ] );
}
- TranslateMetadata::deleteGroup( $params['aggregategroup'] );
- // @todo Logging
+ $aggregateGroupId = $params['aggregategroup'];
+ $group = MessageGroups::getGroup( $aggregateGroupId );
+ if ( !$group || !( $group instanceof AggregateMessageGroup ) ) {
+ $this->dieWithError(
+ 'apierror-translate-invalidaggregategroupname', 'invalidaggregategroupname'
+ );
+ }
+
+ TranslateMetadata::deleteGroup( $params['aggregategroup'] );
+ $logger = LoggerFactory::getInstance( 'Translate' );
+ $logger->info(
+ 'Aggregate group {groupId} has been deleted.',
+ [ 'groupId' => $aggregateGroupId ]
+ );
} elseif ( $action === 'add' ) {
if ( !isset( $params['groupname'] ) ) {
$this->dieWithError( [ 'apierror-missingparam', 'groupname' ] );
diff --git a/MLEB/Translate/api/ApiGroupReview.php b/MLEB/Translate/api/ApiGroupReview.php
index bcac0a02..73f84656 100644
--- a/MLEB/Translate/api/ApiGroupReview.php
+++ b/MLEB/Translate/api/ApiGroupReview.php
@@ -63,7 +63,7 @@ class ApiGroupReview extends ApiBase {
}
public static function getState( MessageGroup $group, $code ) {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = wfGetDB( DB_PRIMARY );
$table = 'translate_groupreviews';
$field = 'tgr_state';
@@ -82,14 +82,14 @@ class ApiGroupReview extends ApiBase {
}
$table = 'translate_groupreviews';
- $index = [ 'tgr_group', 'tgr_language' ];
+ $index = [ 'tgr_group', 'tgr_lang' ];
$row = [
'tgr_group' => $group->getId(),
'tgr_lang' => $code,
'tgr_state' => $newState,
];
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = wfGetDB( DB_PRIMARY );
$dbw->replace( $table, [ $index ], $row, __METHOD__ );
$entry = new ManualLogEntry( 'translationreview', 'group' );
diff --git a/MLEB/Translate/api/ApiManageMessageGroups.php b/MLEB/Translate/api/ApiManageMessageGroups.php
index aa031b8f..dbb38d00 100644
--- a/MLEB/Translate/api/ApiManageMessageGroups.php
+++ b/MLEB/Translate/api/ApiManageMessageGroups.php
@@ -32,7 +32,7 @@ class ApiManageMessageGroups extends ApiBase {
$renameKey = null;
if ( !MessageChangeStorage::isValidCdbName( $name ) ) {
- return $this->dieWithError(
+ $this->dieWithError(
[ 'apierror-translate-invalid-changeset-name', wfEscapeWikiText( $name ) ],
'invalidchangeset'
);
@@ -41,24 +41,24 @@ class ApiManageMessageGroups extends ApiBase {
if ( !MessageChangeStorage::isModifiedSince( $cdbPath, $changesetModifiedTime ) ) {
// Changeset file has been modified since the time the page was generated.
- return $this->dieWithError( [ 'apierror-translate-changeset-modified' ] );
+ $this->dieWithError( [ 'apierror-translate-changeset-modified' ] );
}
if ( $op === 'rename' ) {
if ( !isset( $params['renameMessageKey'] ) ) {
- return $this->dieWithError( [ 'apierror-missingparam', 'renameMessageKey' ] );
+ $this->dieWithError( [ 'apierror-missingparam', 'renameMessageKey' ] );
}
$renameKey = $params['renameMessageKey'];
}
$sourceChanges = MessageChangeStorage::getGroupChanges( $cdbPath, $groupId );
if ( $sourceChanges->getAllModifications() === [] ) {
- return $this->dieWithError( [ 'apierror-translate-smg-nochanges' ] );
+ $this->dieWithError( [ 'apierror-translate-smg-nochanges' ] );
}
$group = MessageGroups::getGroup( $groupId );
if ( $group === null ) {
- return $this->dieWithError( 'apierror-translate-invalidgroup', 'invalidgroup' );
+ $this->dieWithError( 'apierror-translate-invalidgroup', 'invalidgroup' );
}
try {
@@ -69,7 +69,7 @@ class ApiManageMessageGroups extends ApiBase {
} elseif ( $op === 'new' ) {
$this->handleNew( $sourceChanges, $msgKey, $group->getSourceLanguage() );
} else {
- return $this->dieWithError(
+ $this->dieWithError(
[ 'apierror-translate-invalid-operation', wfEscapeWikiText( $op ),
wfEscapeWikiText( implode( '/', [ 'new' , 'rename' ] ) ) ],
'invalidoperation'
@@ -223,21 +223,23 @@ class ApiManageMessageGroups extends ApiBase {
);
if ( $msg === null || $renameMsg === null ) {
- return $this->dieWithError( 'apierror-translate-rename-key-invalid' );
+ $this->dieWithError( 'apierror-translate-rename-key-invalid' );
}
if ( $msgState === MessageSourceChange::RENAME ) {
+ // @phan-suppress-next-line PhanTypeArraySuspiciousNullable T240141
$msgState = $sourceChanges->breakRename( $code, $msg['key'] );
}
if ( $renameMsgState === MessageSourceChange::RENAME ) {
+ // @phan-suppress-next-line PhanTypeArraySuspiciousNullable T240141
$renameMsgState = $sourceChanges->breakRename( $code, $renameMsg['key'] );
}
// Ensure that one of them is an ADDITION, and one is DELETION
if ( $msgState !== MessageSourceChange::ADDITION ||
$renameMsgState !== MessageSourceChange::DELETION ) {
- return $this->dieWithError( [
+ $this->dieWithError( [
'apierror-translate-rename-state-invalid',
wfEscapeWikiText( $msgState ), wfEscapeWikiText( $renameMsgState )
] );
@@ -250,7 +252,9 @@ class ApiManageMessageGroups extends ApiBase {
// Add as rename
$stringComparator = new SimpleStringComparator();
$similarity = $stringComparator->getSimilarity(
+ // @phan-suppress-next-line PhanTypeArraySuspiciousNullable T240141
$msg['content'],
+ // @phan-suppress-next-line PhanTypeArraySuspiciousNullable T240141
$renameMsg['content']
);
$sourceChanges->addRename( $code, $msg, $renameMsg, $similarity );
diff --git a/MLEB/Translate/api/ApiQueryLanguageStats.php b/MLEB/Translate/api/ApiQueryLanguageStats.php
index 04d61d7a..89f25f8a 100644
--- a/MLEB/Translate/api/ApiQueryLanguageStats.php
+++ b/MLEB/Translate/api/ApiQueryLanguageStats.php
@@ -18,23 +18,24 @@ class ApiQueryLanguageStats extends ApiStatsQuery {
parent::__construct( $query, $moduleName, 'ls' );
}
- /// Overwritten from ApiStatsQuery
+ // ApiStatsQuery methods
+
+ /** @inheritDoc */
protected function validateTargetParamater( array $params ) {
- $all = TranslateUtils::getLanguageNames( null );
$requested = $params[ 'language' ];
-
- if ( !isset( $all[ $requested ] ) ) {
- $this->dieWithError( [ 'apierror-translate-invalidlanguage' ] );
+ if ( !TranslateUtils::isSupportedLanguageCode( $requested ) ) {
+ $this->dieWithError( [ 'apierror-translate-invalidlanguage', $requested ] );
}
return $requested;
}
- /// Overwritten from ApiStatsQuery
+ /** @inheritDoc */
protected function loadStatistics( $target, $flags = 0 ) {
return MessageGroupStats::forLanguage( $target, $flags );
}
+ /** @inheritDoc */
protected function makeItem( $item, $stats ) {
$data = parent::makeItem( $item, $stats );
$data['group'] = $item;
@@ -42,6 +43,14 @@ class ApiQueryLanguageStats extends ApiStatsQuery {
return $data;
}
+ /** @inheritDoc */
+ protected function getCacheRebuildJob( string $target ): IJobSpecification {
+ return MessageGroupStatsRebuildJob::newJob( [ 'languagecode' => $target ] );
+ }
+
+ // Api methods
+
+ /** @inheritDoc */
protected function getAllowedParams() {
$params = parent::getAllowedParams();
$params['language'] = [
@@ -52,6 +61,7 @@ class ApiQueryLanguageStats extends ApiStatsQuery {
return $params;
}
+ /** @inheritDoc */
protected function getExamplesMessages() {
return [
'action=query&meta=languagestats&lslanguage=fi'
diff --git a/MLEB/Translate/api/ApiQueryManageMessageGroups.php b/MLEB/Translate/api/ApiQueryManageMessageGroups.php
index 84387b47..0e647de3 100644
--- a/MLEB/Translate/api/ApiQueryManageMessageGroups.php
+++ b/MLEB/Translate/api/ApiQueryManageMessageGroups.php
@@ -107,7 +107,7 @@ class ApiQueryManageMessageGroups extends ApiQueryBase {
}
// sort them based on similarity
- usort( $renameList, function ( $a, $b ) {
+ usort( $renameList, static function ( $a, $b ) {
return -( $a['similarity'] <=> $b['similarity'] );
} );
diff --git a/MLEB/Translate/api/ApiQueryMessageCollection.php b/MLEB/Translate/api/ApiQueryMessageCollection.php
index 85b4a498..62b109f5 100644
--- a/MLEB/Translate/api/ApiQueryMessageCollection.php
+++ b/MLEB/Translate/api/ApiQueryMessageCollection.php
@@ -7,19 +7,24 @@
* @license GPL-2.0-or-later
*/
+use MediaWiki\Extension\Translate\Utilities\ConfigHelper;
+
/**
* Api module for querying MessageCollection.
*
* @ingroup API TranslateAPI
*/
class ApiQueryMessageCollection extends ApiQueryGeneratorBase {
-
- /**
- * @param ApiQuery $query
- * @param string $moduleName
- */
- public function __construct( $query, $moduleName ) {
+ /** @var ConfigHelper */
+ private $configHelper;
+
+ public function __construct(
+ ApiQuery $query,
+ string $moduleName,
+ ConfigHelper $configHelper
+ ) {
parent::__construct( $query, $moduleName, 'mc' );
+ $this->configHelper = $configHelper;
}
public function execute() {
@@ -34,15 +39,13 @@ class ApiQueryMessageCollection extends ApiQueryGeneratorBase {
$this->run( $resultPageSet );
}
- private function validateLanguageCode( $code ) {
- if ( !Language::isValidBuiltInCode( $code ) ) {
- $this->dieWithError( [ 'apierror-translate-invalidlanguage' ] );
+ private function validateLanguageCode( string $code ): void {
+ if ( !TranslateUtils::isSupportedLanguageCode( $code ) ) {
+ $this->dieWithError( [ 'apierror-translate-invalidlanguage', $code ] );
}
}
private function run( ApiPageSet $resultPageSet = null ) {
- global $wgTranslateBlacklist;
-
$params = $this->extractRequestParams();
$group = MessageGroups::getGroup( $params['group'] );
@@ -52,29 +55,33 @@ class ApiQueryMessageCollection extends ApiQueryGeneratorBase {
$languageCode = $params[ 'language' ];
$this->validateLanguageCode( $languageCode );
+
+ // Even though translation to source language maybe disabled, we still want to
+ // fetch the message collections for the source language.
if ( $group->getSourceLanguage() === $languageCode ) {
$name = Language::fetchLanguageName( $languageCode, $this->getLanguage()->getCode() );
$this->addWarning( [ 'apiwarn-translate-language-disabled-source', wfEscapeWikiText( $name ) ] );
- }
- $languages = $group->getTranslatableLanguages();
- if ( $languages !== null ) {
- if ( !isset( $languages[ $languageCode ] ) ) {
- $name = Language::fetchLanguageName( $languageCode, $this->getLanguage()->getCode() );
- $this->dieWithError( [ 'apierror-translate-language-disabled', $name ] );
- }
} else {
- $checks = [
- $group->getId(),
- strtok( $group->getId(), '-' ),
- '*'
- ];
-
- foreach ( $checks as $check ) {
- if ( isset( $wgTranslateBlacklist[ $check ][ $languageCode ] ) ) {
- $name = Language::fetchLanguageName( $languageCode, $this->getLanguage()->getCode() );
- $reason = $wgTranslateBlacklist[ $check ][ $languageCode ];
- $this->dieWithError( [ 'apierror-translate-language-disabled-reason', $name, $reason ] );
+ $languages = $group->getTranslatableLanguages();
+ if ( $languages === null ) {
+ $checks = [
+ $group->getId(),
+ strtok( $group->getId(), '-' ),
+ '*'
+ ];
+
+ $disabledLanguages = $this->configHelper->getDisabledTargetLanguages();
+ foreach ( $checks as $check ) {
+ if ( isset( $disabledLanguages[ $check ][ $languageCode ] ) ) {
+ $name = Language::fetchLanguageName( $languageCode, $this->getLanguage()->getCode() );
+ $reason = $disabledLanguages[ $check ][ $languageCode ];
+ $this->dieWithError( [ 'apierror-translate-language-disabled-reason', $name, $reason ] );
+ }
}
+ } elseif ( !isset( $languages[ $languageCode ] ) ) {
+ // Not a translatable language
+ $name = Language::fetchLanguageName( $languageCode, $this->getLanguage()->getCode() );
+ $this->dieWithError( [ 'apierror-translate-language-disabled', $name ] );
}
}
diff --git a/MLEB/Translate/api/ApiQueryMessageGroupStats.php b/MLEB/Translate/api/ApiQueryMessageGroupStats.php
index 73b53585..30688070 100644
--- a/MLEB/Translate/api/ApiQueryMessageGroupStats.php
+++ b/MLEB/Translate/api/ApiQueryMessageGroupStats.php
@@ -19,7 +19,9 @@ class ApiQueryMessageGroupStats extends ApiStatsQuery {
parent::__construct( $query, $moduleName, 'mgs' );
}
- /// Overwritten from ApiStatsQuery
+ // ApiStatsQuery methods
+
+ /** @inheritDoc */
protected function validateTargetParamater( array $params ) {
$group = MessageGroups::getGroup( $params['group'] );
if ( !$group ) {
@@ -31,11 +33,12 @@ class ApiQueryMessageGroupStats extends ApiStatsQuery {
return $group->getId();
}
- /// Overwritten from ApiStatsQuery
+ /** @inheritDoc */
protected function loadStatistics( $target, $flags = 0 ) {
return MessageGroupStats::forGroup( $target, $flags );
}
+ /** @inheritDoc */
protected function makeItem( $item, $stats ) {
$data = parent::makeItem( $item, $stats );
$data['code'] = $item; // For BC
@@ -44,6 +47,14 @@ class ApiQueryMessageGroupStats extends ApiStatsQuery {
return $data;
}
+ /** @inheritDoc */
+ protected function getCacheRebuildJob( string $target ): IJobSpecification {
+ return MessageGroupStatsRebuildJob::newJob( [ 'groupid' => $target ] );
+ }
+
+ // Api methods
+
+ /** @inheritDoc */
protected function getAllowedParams() {
$params = parent::getAllowedParams();
$params['group'] = [
@@ -54,6 +65,7 @@ class ApiQueryMessageGroupStats extends ApiStatsQuery {
return $params;
}
+ /** @inheritDoc */
protected function getExamplesMessages() {
return [
'action=query&meta=messagegroupstats&mgsgroup=page-Example'
diff --git a/MLEB/Translate/api/ApiQueryMessageGroups.php b/MLEB/Translate/api/ApiQueryMessageGroups.php
index 5751b5c3..a9a63e26 100644
--- a/MLEB/Translate/api/ApiQueryMessageGroups.php
+++ b/MLEB/Translate/api/ApiQueryMessageGroups.php
@@ -24,6 +24,9 @@ class ApiQueryMessageGroups extends ApiQueryBase {
$filter = $params['filter'];
$groups = [];
+ $props = array_flip( $params['prop'] );
+
+ $needsMetadata = isset( $props['prioritylangs'] ) || isset( $props['priorityforce'] );
// Parameter root as all for all pages subgroups
if ( $params['root'] === 'all' ) {
@@ -33,7 +36,6 @@ class ApiQueryMessageGroups extends ApiQueryBase {
$groups[$id] = $group;
}
}
- TranslateMetadata::preloadGroups( array_keys( $groups ) );
} elseif ( $params['format'] === 'flat' ) {
if ( $params['root'] !== '' ) {
$group = MessageGroups::getGroup( $params['root'] );
@@ -44,7 +46,7 @@ class ApiQueryMessageGroups extends ApiQueryBase {
$groups = MessageGroups::getAllGroups();
usort( $groups, [ 'MessageGroups', 'groupLabelSort' ] );
}
- TranslateMetadata::preloadGroups( array_keys( $groups ) );
+ TranslateMetadata::preloadGroups( array_keys( $groups ), __METHOD__ );
} elseif ( $params['root'] !== '' ) {
// format=tree from now on, as it is the only other valid option
$group = MessageGroups::getGroup( $params['root'] );
@@ -53,11 +55,13 @@ class ApiQueryMessageGroups extends ApiQueryBase {
$groups = MessageGroups::subGroups( $group, $childIds );
// The parent group is the first, ignore it
array_shift( $groups );
- TranslateMetadata::preloadGroups( $childIds );
}
} else {
$groups = MessageGroups::getGroupStructure();
- TranslateMetadata::preloadGroups( array_keys( MessageGroups::getAllGroups() ) );
+ }
+
+ if ( $needsMetadata && $groups ) {
+ TranslateMetadata::preloadGroups( array_keys( $groups ), __METHOD__ );
}
if ( $params['root'] === '' ) {
@@ -76,8 +80,6 @@ class ApiQueryMessageGroups extends ApiQueryBase {
unset( $groups['!sandbox'] );
}
- $props = array_flip( $params['prop'] );
-
$result = $this->getResult();
$matcher = new StringMatcher( '', $filter );
/** @var MessageGroup|array $mixed */
@@ -88,6 +90,13 @@ class ApiQueryMessageGroups extends ApiQueryBase {
continue;
}
+ if (
+ $params['languageFilter'] !== '' &&
+ TranslateMetadata::isExcluded( $group->getId(), $params['languageFilter'] )
+ ) {
+ continue;
+ }
+
$a = $this->formatGroup( $mixed, $props );
$result->setIndexedTagName( $a, 'group' );
@@ -272,6 +281,10 @@ class ApiQueryMessageGroups extends ApiQueryBase {
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_DFLT => '',
],
+ 'languageFilter' => [
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_DFLT => '',
+ ]
];
Hooks::run( 'TranslateGetAPIMessageGroupsParameterList', [ &$allowedParams ] );
diff --git a/MLEB/Translate/api/ApiQueryMessageTranslations.php b/MLEB/Translate/api/ApiQueryMessageTranslations.php
index 3a24a720..f5bfb29a 100644
--- a/MLEB/Translate/api/ApiQueryMessageTranslations.php
+++ b/MLEB/Translate/api/ApiQueryMessageTranslations.php
@@ -40,10 +40,7 @@ class ApiQueryMessageTranslations extends ApiQueryBase {
'page_title ' . $dbr->buildLike( "$base/", $dbr->anyString() ),
],
__METHOD__,
- [
- 'ORDER BY' => 'page_title',
- 'USE INDEX' => 'name_title',
- ]
+ [ 'ORDER BY' => 'page_title', ]
);
$titles = [];
diff --git a/MLEB/Translate/api/ApiStatsQuery.php b/MLEB/Translate/api/ApiStatsQuery.php
index d2ee762c..b14d34eb 100644
--- a/MLEB/Translate/api/ApiStatsQuery.php
+++ b/MLEB/Translate/api/ApiStatsQuery.php
@@ -61,8 +61,9 @@ abstract class ApiStatsQuery extends ApiQueryBase {
$result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'stats' );
if ( $incomplete ) {
- DeferredUpdates::addCallableUpdate( function () use ( $target ) {
- $this->loadStatistics( $target );
+ DeferredUpdates::addCallableUpdate( function () use ( $target ): void {
+ $jobQueue = JobQueueGroup::singleton();
+ $jobQueue->push( $this->getCacheRebuildJob( $target ) );
} );
}
}
@@ -76,6 +77,8 @@ abstract class ApiStatsQuery extends ApiQueryBase {
];
}
+ abstract protected function getCacheRebuildJob( string $target ): IJobSpecification;
+
protected function getAllowedParams() {
return [
'offset' => [
diff --git a/MLEB/Translate/api/ApiTranslateSandbox.php b/MLEB/Translate/api/ApiTranslateSandbox.php
index da7fb30d..286ebedd 100644
--- a/MLEB/Translate/api/ApiTranslateSandbox.php
+++ b/MLEB/Translate/api/ApiTranslateSandbox.php
@@ -51,14 +51,10 @@ class ApiTranslateSandbox extends ApiBase {
}
$username = $params['username'];
+ $services = MediaWikiServices::getInstance();
- if ( is_callable( [ UserNameUtils::class, 'getCanonical' ] ) ) {
- // MW 1.35+
- $userNameUtils = MediaWikiServices::getInstance()->getUserNameUtils();
- $canonicalName = $userNameUtils->getCanonical( $username, UserNameUtils::RIGOR_CREATABLE );
- } else {
- $canonicalName = User::getCanonicalName( $username, 'creatable' );
- }
+ $userNameUtils = $services->getUserNameUtils();
+ $canonicalName = $userNameUtils->getCanonical( $username, UserNameUtils::RIGOR_CREATABLE );
if ( $canonicalName === false ) {
$this->dieWithError( 'noname', 'invalidusername' );
@@ -85,16 +81,9 @@ class ApiTranslateSandbox extends ApiBase {
'id' => $user->getId(),
] ];
- $services = MediaWikiServices::getInstance();
- if ( method_exists( $services, 'getUserOptionsManager' ) ) {
- // MW 1.35+
- $userOptionsManager = $services->getUserOptionsManager();
- $userOptionsManager->setOption( $user, 'language', $this->getContext()->getLanguage()->getCode() );
- $userOptionsManager->saveOptions( $user );
- } else {
- $user->setOption( 'language', $this->getContext()->getLanguage()->getCode() );
- $user->saveSettings();
- }
+ $userOptionsManager = $services->getUserOptionsManager();
+ $userOptionsManager->setOption( $user, 'language', $this->getContext()->getLanguage()->getCode() );
+ $userOptionsManager->saveOptions( $user );
$this->getResult()->addValue( null, $this->getModuleName(), $output );
}
@@ -197,7 +186,7 @@ class ApiTranslateSandbox extends ApiBase {
$page = WikiPage::factory( $userpage );
$content = ContentHandler::makeContent( $babeltext, $userpage );
- $page->doEditContent( $content, $summary, EDIT_NEW, false, $user );
+ TranslateUtils::doPageEdit( $page, $content, $user, $summary, EDIT_NEW );
}
public function isWriteMode() {
diff --git a/MLEB/Translate/api/ApiTranslationAids.php b/MLEB/Translate/api/ApiTranslationAids.php
deleted file mode 100644
index db70d335..00000000
--- a/MLEB/Translate/api/ApiTranslationAids.php
+++ /dev/null
@@ -1,133 +0,0 @@
-<?php
-/**
- * Api module for querying message aids.
- *
- * @file
- * @author Niklas Laxström
- * @license GPL-2.0-or-later
- */
-
-/**
- * Api module for querying message aids.
- *
- * @ingroup API TranslateAPI
- */
-class ApiTranslationAids extends ApiBase {
- public function execute() {
- $params = $this->extractRequestParams();
-
- $title = Title::newFromText( $params['title'] );
- if ( !$title ) {
- $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ] );
- }
-
- $handle = new MessageHandle( $title );
- if ( !$handle->isValid() ) {
- $this->dieWithError( 'apierror-translate-nomessagefortitle', 'nomessagefortitle' );
- }
-
- if ( (string)$params['group'] !== '' ) {
- $group = MessageGroups::getGroup( $params['group'] );
- } else {
- $group = $handle->getGroup();
- }
-
- if ( !$group ) {
- $this->dieWithError( 'apierror-translate-invalidgroup', 'invalidgroup' );
- }
-
- $data = [];
- $times = [];
-
- $props = $params['prop'];
- $aggregator = new QueryAggregator();
-
- // Figure out the intersection of supported and requested aids
- $types = $group->getTranslationAids();
- $props = array_intersect( $props, array_keys( $types ) );
-
- $result = $this->getResult();
-
- // Create list of aids, populate web services queries
- /** @var TranslationAid[] $aids */
- $aids = [];
-
- $dataProvider = new TranslationAidDataProvider( $handle );
- foreach ( $props as $type ) {
- // Do not proceed if translation aid is not supported for this message group
- if ( !isset( $types[$type] ) ) {
- $types[$type] = 'UnsupportedTranslationAid';
- }
-
- $class = $types[$type];
- $obj = new $class( $group, $handle, $this, $dataProvider );
-
- if ( $obj instanceof QueryAggregatorAware ) {
- $obj->setQueryAggregator( $aggregator );
- try {
- $obj->populateQueries();
- } catch ( TranslationHelperException $e ) {
- $data[$type] = [ 'error' => $e->getMessage() ];
- // Prevent processing this aids and thus overwriting our error
- continue;
- }
- }
-
- $aids[$type] = $obj;
- }
-
- // Execute all web service queries asynchronously to save time
- $start = microtime( true );
- $aggregator->run();
- $times['query_aggregator'] = round( microtime( true ) - $start, 3 );
-
- // Construct the result data structure
- foreach ( $aids as $type => $obj ) {
- $start = microtime( true );
-
- try {
- $aid = $obj->getData();
- } catch ( TranslationHelperException $e ) {
- $aid = [ 'error' => $e->getMessage() ];
- }
-
- if ( isset( $aid['**'] ) ) {
- $result->setIndexedTagName( $aid, $aid['**'] );
- unset( $aid['**'] );
- }
-
- $data[$type] = $aid;
- $times[$type] = round( microtime( true ) - $start, 3 );
- }
-
- $result->addValue( null, 'helpers', $data );
- $result->addValue( null, 'times', $times );
- }
-
- protected function getAllowedParams() {
- $props = array_keys( TranslationAid::getTypes() );
- Hooks::run( 'TranslateTranslationAids', [ &$props ] );
-
- return [
- 'title' => [
- ApiBase::PARAM_TYPE => 'string',
- ApiBase::PARAM_REQUIRED => true,
- ],
- 'group' => [
- ApiBase::PARAM_TYPE => 'string',
- ],
- 'prop' => [
- ApiBase::PARAM_DFLT => implode( '|', $props ),
- ApiBase::PARAM_TYPE => $props,
- ApiBase::PARAM_ISMULTI => true,
- ],
- ];
- }
-
- protected function getExamplesMessages() {
- return [
- 'action=translationaids&title=MediaWiki:January/fi'
- => 'apihelp-translationaids-example-1',
- ];
- }
-}
diff --git a/MLEB/Translate/api/ApiTranslationReview.php b/MLEB/Translate/api/ApiTranslationReview.php
index fcdd7ffb..3ed2a4da 100644
--- a/MLEB/Translate/api/ApiTranslationReview.php
+++ b/MLEB/Translate/api/ApiTranslationReview.php
@@ -36,19 +36,19 @@ class ApiTranslationReview extends ApiBase {
break;
case 'permissiondenied':
$this->dieWithError( 'apierror-permissiondenied-generic', 'permissiondenied' );
- break; // Unreachable, but throws off code analyzer.
+ // dieWithError prevents continuation
case 'blocked':
$this->dieBlocked( $this->getUser()->getBlock() );
- break; // Unreachable, but throws off code analyzer.
+ // dieBlocked prevents continuation
case 'unknownmessage':
$this->dieWithError( 'apierror-translate-unknownmessage', $error );
- break; // Unreachable, but throws off code analyzer.
+ // dieWithError prevents continuation
case 'owntranslation':
$this->dieWithError( 'apierror-translate-owntranslation', $error );
- break; // Unreachable, but throws off code analyzer.
+ // dieWithError prevents continuation
case 'fuzzymessage':
$this->dieWithError( 'apierror-translate-fuzzymessage', $error );
- break; // Unreachable, but throws off code analyzer.
+ // dieWithError prevents continuation
default:
$this->dieWithError( [ 'apierror-unknownerror', $error ], $error );
}
@@ -78,7 +78,7 @@ class ApiTranslationReview extends ApiBase {
* @return bool whether the action was recorded.
*/
public static function doReview( User $user, RevisionRecord $revRecord, $comment = null ) {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = wfGetDB( DB_PRIMARY );
$table = 'translate_reviews';
$row = [
'trr_user' => $user->getId(),
diff --git a/MLEB/Translate/api/ApiTranslationStash.php b/MLEB/Translate/api/ApiTranslationStash.php
index 29bd0996..b7f60e2e 100644
--- a/MLEB/Translate/api/ApiTranslationStash.php
+++ b/MLEB/Translate/api/ApiTranslationStash.php
@@ -33,7 +33,7 @@ class ApiTranslationStash extends ApiBase {
}
}
- $stash = new TranslationStashStorage( wfGetDB( DB_MASTER ) );
+ $stash = new TranslationStashStorage( wfGetDB( DB_PRIMARY ) );
$action = $params['subaction'];
if ( $action === 'add' ) {