diff options
Diffstat (limited to 'MLEB/Translate/api/ApiTranslationStash.php')
-rw-r--r-- | MLEB/Translate/api/ApiTranslationStash.php | 108 |
1 files changed, 28 insertions, 80 deletions
diff --git a/MLEB/Translate/api/ApiTranslationStash.php b/MLEB/Translate/api/ApiTranslationStash.php index 72c0e299..dad11719 100644 --- a/MLEB/Translate/api/ApiTranslationStash.php +++ b/MLEB/Translate/api/ApiTranslationStash.php @@ -4,7 +4,7 @@ * * @file * @author Niklas Laxström - * @license GPL-2.0+ + * @license GPL-2.0-or-later */ /** @@ -19,14 +19,14 @@ class ApiTranslationStash extends ApiBase { // The user we are operating on, not necessarly the user making the request $user = $this->getUser(); - if ( isset( $params['username'] ) ){ + if ( isset( $params['username'] ) ) { if ( $this->getUser()->isAllowed( 'translate-sandboxmanage' ) ) { $user = User::newFromName( $params['username'] ); if ( !$user ) { - $this->dieUsageMsg( array( 'invalidparam', 'username' ) ); + $this->dieWithError( [ 'apierror-badparameter', 'username' ], 'invalidparam' ); } } else { - $this->dieUsageMsg( array( 'invalidparam', 'username' ) ); + $this->dieWithError( [ 'apierror-badparameter', 'username' ], 'invalidparam' ); } } @@ -35,10 +35,10 @@ class ApiTranslationStash extends ApiBase { if ( $action === 'add' ) { if ( !isset( $params['title'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'title' ) ); + $this->dieWithError( [ 'apierror-missingparam', 'title' ] ); } if ( !isset( $params['translation'] ) ) { - $this->dieUsageMsg( array( 'missingparam', 'translation' ) ); + $this->dieWithError( [ 'apierror-missingparam', 'translation' ] ); } // @todo: Return value of Title::newFromText not checked @@ -52,7 +52,7 @@ class ApiTranslationStash extends ApiBase { } if ( $action === 'query' ) { - $output['translations'] = array(); + $output['translations'] = []; $translations = $stash->getTranslations( $user ); foreach ( $translations as $translation ) { @@ -82,106 +82,54 @@ class ApiTranslationStash extends ApiBase { $comparison = $group->getMessage( $key, $handle->getCode() ); } - return array( + return [ 'title' => $title->getPrefixedText(), 'definition' => $definition, 'translation' => $translation->getValue(), 'comparison' => $comparison, 'metadata' => $translation->getMetadata(), - ); + ]; } - public function isWriteMode() { return true; } - public function getTokenSalt() { - return 'translationstash'; - } - - public static function getToken() { - $user = RequestContext::getMain()->getUser(); - - return $user->getEditToken( 'translationstash' ); - } - - public static function injectTokenFunction( &$list ) { - $list['translationstash'] = array( __CLASS__, 'getToken' ); - - return true; + public function needsToken() { + return 'csrf'; } public function getAllowedParams() { - return array( - 'subaction' => array( - ApiBase::PARAM_TYPE => array( 'add', 'query' ), + return [ + 'subaction' => [ + ApiBase::PARAM_TYPE => [ 'add', 'query' ], ApiBase::PARAM_REQUIRED => true, - ), - 'title' => array( + ], + 'title' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'translation' => array( + ], + 'translation' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'metadata' => array( + ], + 'metadata' => [ ApiBase::PARAM_TYPE => 'string', - ApiBase::PARAM_DFLT => null, - ), - 'token' => array( + ], + 'token' => [ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true, - ), - 'username' => array( + ], + 'username' => [ ApiBase::PARAM_TYPE => 'string', - ), - ); - } - - /** - * @deprecated since MediaWiki core 1.25 - */ - public function getParamDescription() { - $action = TranslateUtils::getTokenAction( 'translationstash' ); - - return array( - 'subaction' => 'Action', - 'title' => 'Title of the translation unit page', - 'translation' => 'Translation made by the user', - 'metadata' => 'Json object', - 'token' => "A token previously acquired with $action", - 'username' => 'Optionally the user whose stash to get. ' - . 'Only privileged users can do this', - ); - } - - /** - * @deprecated since MediaWiki core 1.25 - */ - public function getDescription() { - return 'Add translations to stash'; - } - - /** - * @deprecated since MediaWiki core 1.25 - */ - public function getExamples() { - return array( - "api.php?action=translationstash&subaction=add&title=MediaWiki:Jan/fi&" . - "translation=tammikuu&metadata={}", - "api.php?action=translationstash&subaction=query", - ); + ], + ]; } - /** - * @see ApiBase::getExamplesMessages() - */ protected function getExamplesMessages() { - return array( + return [ 'action=translationstash&subaction=add&title=MediaWiki:Jan/fi&translation=tammikuu&metadata={}' => 'apihelp-translationstash-example-1', 'action=translationstash&subaction=query' => 'apihelp-translationstash-example-2', - ); + ]; } } |