jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/389451 )
Change subject: ApiQueryContentTranslation: Refactor anonymous access case ...................................................................... ApiQueryContentTranslation: Refactor anonymous access case Refactor the API handling for anonymous contexts Follow up: Ia7ec94c23ae and If3871eb0d5 Change-Id: I9bddd8c5497037d34172cdcbdf8e1acf6262dac8 --- M api/ApiQueryContentTranslation.php 1 file changed, 26 insertions(+), 14 deletions(-) Approvals: jenkins-bot: Verified Nikerabbit: Looks good to me, approved diff --git a/api/ApiQueryContentTranslation.php b/api/ApiQueryContentTranslation.php index 5b91733..277c710 100644 --- a/api/ApiQueryContentTranslation.php +++ b/api/ApiQueryContentTranslation.php @@ -38,9 +38,30 @@ $params = $this->extractRequestParams(); $result = $this->getResult(); $user = $this->getUser(); + + // Case A: Find a translation for given work from anonymous context + if ( $user->isAnon() ) { + if ( $params['translationid'] ) { + $this->dieWithError( 'apierror-cx-mustbeloggedin-viewtranslations', 'notloggedin' ); + } + if ( $params['sourcetitle'] && $params['from'] && $params['to'] ) { + $translation = Translation::find( + $params['from'], $params['to'], $params[ 'sourcetitle' ] + ); + + $result->addValue( + [ 'query', 'contenttranslation' ], + 'translation', + $translation->translation + ); + } + + return; + } + $translator = new Translator( $user ); - // Case A: Find a translation for given work + // Case B: Find a translation for given work for the current user. if ( $params['sourcetitle'] && $params['from'] && $params['to'] ) { $work = new TranslationWork( $params['sourcetitle'], $params['from'], $params['to'] ); $this->find( $work, $translator ); @@ -48,15 +69,7 @@ return; } - // Case B: Find a translation for given id - if ( $user->isAnon() ) { - if ( is_callable( [ $this, 'dieWithError' ] ) ) { - $this->dieWithError( 'apierror-cx-mustbeloggedin-viewtranslations', 'notloggedin' ); - } else { - $this->dieUsage( 'To view your translations, you must log in', 'notloggedin' ); - } - } - + // Case C: Find a translation for given id if ( $params['translationid'] ) { $translation = $translator->getTranslation( $params['translationid'] ); if ( $translation !== null ) { @@ -78,7 +91,7 @@ return; } - // Case C: Find list of translations + // Case D: Find list of translations $translations = $translator->getAllTranslations( $params['limit'], $params['offset'], @@ -118,9 +131,8 @@ public function find( TranslationWork $work, Translator $translator ) { $translation = null; $result = $this->getResult(); - if ( isset( $this->user ) ) { - $translation = Translation::findForTranslator( $work, $translator ); - } + $translation = Translation::findForTranslator( $work, $translator ); + // Check for other drafts. If one exists, return that to the UI which will then // know to display an error to the user because we disallow two users to start // drafts on the same translation work. -- To view, visit https://gerrit.wikimedia.org/r/389451 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I9bddd8c5497037d34172cdcbdf8e1acf6262dac8 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits