[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: ApiQueryContentTranslation: Refactor anonymous access case

2017-11-07 Thread jenkins-bot (Code Review)
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 
Gerrit-Reviewer: Nikerabbit 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: ApiQueryContentTranslation: Refactor anonymous access case

2017-11-06 Thread Santhosh (Code Review)
Santhosh has uploaded a new change for review. ( 
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, 30 insertions(+), 15 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation 
refs/changes/51/389451/1

diff --git a/api/ApiQueryContentTranslation.php 
b/api/ApiQueryContentTranslation.php
index 5b91733..636f209 100644
--- a/api/ApiQueryContentTranslation.php
+++ b/api/ApiQueryContentTranslation.php
@@ -38,9 +38,33 @@
$params = $this->extractRequestParams();
$result = $this->getResult();
$user = $this->getUser();
-   $translator = new Translator( $user );
+   $translator = null;
 
-   // Case A: Find a translation for given work
+   if ( !$user->isAnon() ) {
+   $translator = new Translator( $user );
+   }
+
+   // Case A: Find a translation for given work from anonymous 
context
+   if ( $translator === null ) {
+   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;
+   }
+
+   // 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 +72,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 +94,7 @@
return;
}
 
-   // Case C: Find list of translations
+   // Case D: Find list of translations
$translations = $translator->getAllTranslations(
$params['limit'],
$params['offset'],
@@ -118,9 +134,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: newchange
Gerrit-Change-Id: I9bddd8c5497037d34172cdcbdf8e1acf6262dac8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits