jenkins-bot has submitted this change and it was merged.
Change subject: Update for API error i18n
......................................................................
Update for API error i18n
See Iae0e2ce3. Since Thanks master requires core master, this just
depends on the master patch instead of trying to maintain BC.
Depends-On: Iae0e2ce3bd42dd4776a9779664086119ac188412
Change-Id: Ib6e66f7e94c41b7a27fe867f079626ac0ade4f1b
---
M ApiFlowThank.php
M ApiRevThank.php
M ApiThank.php
M SpecialThanks.php
M i18n/en.json
M i18n/qqq.json
M tests/phpunit/ApiFlowThankIntegrationTest.php
M tests/phpunit/ApiRevThankIntegrationTest.php
M tests/phpunit/ApiRevThankUnitTest.php
9 files changed, 38 insertions(+), 64 deletions(-)
Approvals:
Catrope: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ApiFlowThank.php b/ApiFlowThank.php
index ec8c3d1..31acb2c 100644
--- a/ApiFlowThank.php
+++ b/ApiFlowThank.php
@@ -28,7 +28,7 @@
try {
$postId = UUID::create( $params['postid'] );
} catch ( FlowException $e ) {
- $this->dieUsage( 'Post ID is invalid', 'invalidpostid'
);
+ $this->dieWithError( 'thanks-error-invalidpostid',
'invalidpostid' );
}
$data = $this->getFlowData( $postId );
@@ -83,11 +83,11 @@
try {
$data = $rootPostLoader->getWithRoot( $postId );
} catch ( FlowException $e ) {
- $this->dieUsage( 'Post ID is invalid', 'invalidpostid'
);
+ $this->dieWithError( 'thanks-error-invalidpostid',
'invalidpostid' );
}
if ( $data['post'] === null ) {
- $this->dieUsage( 'Post ID is invalid', 'invalidpostid'
);
+ $this->dieWithError( 'thanks-error-invalidpostid',
'invalidpostid' );
}
return $data;
}
@@ -99,7 +99,7 @@
private function getRecipientFromPost( PostRevision $post ) {
$recipient = User::newFromId( $post->getCreatorId() );
if ( !$recipient->loadFromId() ) {
- $this->dieUsage( 'Recipient is invalid',
'invalidrecipient' );
+ $this->dieWithError( 'thanks-error-invalidrecipient',
'invalidrecipient' );
}
return $recipient;
}
diff --git a/ApiRevThank.php b/ApiRevThank.php
index febe356..102da35 100644
--- a/ApiRevThank.php
+++ b/ApiRevThank.php
@@ -38,9 +38,9 @@
// Revision ID 1 means an invalid argument was passed in.
if ( !$revision || $revision->getId() === 1 ) {
- $this->dieUsage( 'Revision ID is not valid',
'invalidrevision' );
+ $this->dieWithError( 'thanks-error-invalidrevision',
'invalidrevision' );
} elseif ( $revision->isDeleted( Revision::DELETED_TEXT ) ) {
- $this->dieUsage( 'Revision has been deleted',
'revdeleted' );
+ $this->dieWithError( 'thanks-error-revdeleted',
'revdeleted' );
}
return $revision;
}
@@ -48,7 +48,7 @@
private function getTitleFromRevision( Revision $revision ) {
$title = Title::newFromID( $revision->getPage() );
if ( !$title instanceof Title ) {
- $this->dieUsage( 'Page title could not be retrieved',
'notitle' );
+ $this->dieWithError( 'thanks-error-notitle', 'notitle'
);
}
return $title;
}
@@ -67,7 +67,7 @@
private function getUserFromRevision( Revision $revision ) {
$recipient = $revision->getUser();
if ( !$recipient ) {
- $this->dieUsage( 'No valid recipient found',
'invalidrecipient' );
+ $this->dieWithError( 'thanks-error-invalidrecipient',
'invalidrecipient' );
}
return User::newFromId( $recipient );
}
diff --git a/ApiThank.php b/ApiThank.php
index 23ec8f4..fac762e 100644
--- a/ApiThank.php
+++ b/ApiThank.php
@@ -8,17 +8,17 @@
abstract class ApiThank extends ApiBase {
protected function dieIfEchoNotInstalled() {
if ( !class_exists( 'EchoNotifier' ) ) {
- $this->dieUsage( 'Echo is not installed on this wiki',
'echonotinstalled' );
+ $this->dieWithError( 'thanks-error-echonotinstalled',
'echonotinstalled' );
}
}
protected function dieOnBadUser( User $user ) {
if ( $user->isAnon() ) {
- $this->dieUsage( 'Anonymous users cannot send thanks',
'notloggedin' );
+ $this->dieWithError( 'thanks-error-notloggedin',
'notloggedin' );
} elseif ( $user->pingLimiter( 'thanks-notification' ) ) {
- $this->dieUsageMsg( [ 'actionthrottledtext' ] );
+ $this->dieWithError( [ 'thanks-error-ratelimited',
$user->getName() ], 'ratelimited' );
} elseif ( $user->isBlocked() ) {
- $this->dieUsageMsg( [ 'blockedtext' ] );
+ $this->dieBlocked( $user->getBlock() );
}
}
@@ -26,9 +26,9 @@
global $wgThanksSendToBots;
if ( $user->getId() === $recipient->getId() ) {
- $this->dieUsage( 'You cannot thank yourself',
'invalidrecipient' );
+ $this->dieWithError(
'thanks-error-invalidrecipient-self', 'invalidrecipient' );
} elseif ( !$wgThanksSendToBots && in_array( 'bot',
$recipient->getGroups() ) ) {
- $this->dieUsage( 'Bots cannot be thanked',
'invalidrecipient' );
+ $this->dieWithError(
'thanks-error-invalidrecipient-bot', 'invalidrecipient' );
}
}
diff --git a/SpecialThanks.php b/SpecialThanks.php
index 36aed90..7870f3b 100644
--- a/SpecialThanks.php
+++ b/SpecialThanks.php
@@ -146,40 +146,12 @@
try {
$api->execute();
- } catch ( UsageException $e ) {
- return $this->handleErrorCodes( $e->getCodeString() );
+ } catch ( ApiUsageException $e ) {
+ return Status::wrap( $e->getStatusValue() );
}
$this->result = $api->getResult()->getResultData( [ 'result' ]
);
return Status::newGood();
- }
-
- /**
- * Handle error codes returned by the API.
- *
- * @param $code
- * @return Status
- */
- protected function handleErrorCodes( $code ) {
- $status = new Status;
- switch ( $code ) {
- case 'invalidrevision':
- case 'invalidpostid':
- case 'ratelimited':
- // Message keys used here:
- // * thanks-error-invalidrevision
- // * thanks-error-invalidpostid
- // * thanks-error-ratelimited
- $status->fatal( 'thanks-error-' . $code );
- break;
- case 'notloggedin':
- case 'blockedtext':
- $status->fatal( $code );
- break;
- default:
- $status->fatal( 'thanks-error-undefined' );
- }
- return $status;
}
/**
diff --git a/i18n/en.json b/i18n/en.json
index 88fac07..6b6c327 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -11,6 +11,13 @@
"thanks-button-thanked": "{{GENDER:$1|{{GENDER:$2|Thanked}}}}",
"thanks-error-undefined": "Thank action failed (error code: $1). Please
try again.",
"thanks-error-invalidrevision": "Revision ID is not valid.",
+ "thanks-error-revdeleted": "Revision has been deleted",
+ "thanks-error-notitle": "Page title could not be retrieved",
+ "thanks-error-invalidrecipient": "No valid recipient found",
+ "thanks-error-invalidrecipient-bot": "Bots cannot be thanked",
+ "thanks-error-invalidrecipient-self": "You cannot thank yourself",
+ "thanks-error-echonotinstalled": "Echo is not installed on this wiki",
+ "thanks-error-notloggedin": "Anonymous users cannot send thanks",
"thanks-error-ratelimited": "{{GENDER:$1|You}}'ve exceeded your rate
limit. Please wait some time and try again.",
"thanks-thank-tooltip": "{{GENDER:$1|Send}} a thank you notification to
this {{GENDER:$2|user}}",
"thanks-thank-tooltip-no": "{{GENDER:$1|Cancel}} the thank you
notification",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index efdd616..87da1b9 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -21,6 +21,13 @@
"thanks-button-thanked": "This message immediately replaces the message
{{msg-mw|Thanks-button-thank}} after it's pressed. It means that the thanking
operation has been completed.\n\nSame as {{msg-mw|Thanks-thanked}}, but the
context is in a button.\n\nParameters:\n* $1 - The user that is thanking, for
gender\n* $2 - The user that is being thanked, for
gender\n{{Identical|Thanked}}",
"thanks-error-undefined": "Error message that is displayed when the
thank action fails. $1 is the error code returned by the API (an English
string)",
"thanks-error-invalidrevision": "Error message that is displayed when
the revision ID is not valid",
+ "thanks-error-echonotinstalled": "Error message that is displayed when
Echo is not installed",
+ "thanks-error-invalidrecipient": "Error message that is displayed when
no recipient is found",
+ "thanks-error-invalidrecipient-bot": "Error message that is displayed
when the recipient is a bot",
+ "thanks-error-invalidrecipient-self": "Error message that is displayed
when the recipient is the user doing the thanking",
+ "thanks-error-notitle": "Error message that is displayed when the title
of the page cannot be determined",
+ "thanks-error-notloggedin": "Error message that is displayed when the
user is not logged in",
+ "thanks-error-revdeleted": "Error message that is displayed when the
revision has been deleted (RevDel)",
"thanks-error-ratelimited": "Error message that is displayed when user
exceeds rate limit. Parameters:\n* $1 - gender",
"thanks-thank-tooltip": "Tooltip that appears when a user hovers over
the \"thank\" link. Parameters:\n* $1 - The user sending the thanks. Can be
used for GENDER support.\n* $2 - The user receiving the thanks. Can be used
for GENDER support",
"thanks-thank-tooltip-no": "Tooltip that appears when a user hovers
over the \"No\" confirmation link (which cancels the thank action).
Parameters:\n* $1 - The user sending the thanks. Can be used for GENDER
support.",
diff --git a/tests/phpunit/ApiFlowThankIntegrationTest.php
b/tests/phpunit/ApiFlowThankIntegrationTest.php
index a14b189..f4c1fff 100644
--- a/tests/phpunit/ApiFlowThankIntegrationTest.php
+++ b/tests/phpunit/ApiFlowThankIntegrationTest.php
@@ -117,11 +117,7 @@
}
public function testRequestWithoutToken() {
- if ( class_exists( 'ApiUsageException' ) ) {
- $this->setExpectedException( 'ApiUsageException', 'The
"token" parameter must be set.' );
- } else {
- $this->setExpectedException( 'UsageException', 'The
token parameter must be set' );
- }
+ $this->setExpectedException( 'ApiUsageException', 'The "token"
parameter must be set.' );
$this->doApiRequest( [
'action' => 'flowthank',
'postid' => UUID::create( '42' )->getAlphadecimal(),
@@ -129,11 +125,7 @@
}
public function testInvalidRequest() {
- if ( class_exists( 'ApiUsageException' ) ) {
- $this->setExpectedException( 'ApiUsageException', 'The
"postid" parameter must be set.' );
- } else {
- $this->setExpectedException( 'UsageException', 'The
postid parameter must be set' );
- }
+ $this->setExpectedException( 'ApiUsageException', 'The "postid"
parameter must be set.' );
$this->doApiRequestWithToken( [ 'action' => 'flowthank' ] );
}
@@ -146,7 +138,7 @@
}
public function testRequestWithInvalidId() {
- $this->setExpectedException( 'UsageException', 'Post ID is
invalid' );
+ $this->setExpectedException( 'ApiUsageException', 'Post ID is
not valid' );
list( $result,, ) = $this->doApiRequestWithToken( [
'action' => 'flowthank',
'postid' => UUID::create( '42' )->getAlphadecimal(),
@@ -154,7 +146,7 @@
}
public function testRequestWithOwnId() {
- $this->setExpectedException( 'UsageException', 'You cannot
thank yourself' );
+ $this->setExpectedException( 'ApiUsageException', 'You cannot
thank yourself' );
list( $result,, ) = $this->doApiRequestWithToken( [
'action' => 'flowthank',
'postid' =>
$this->postByMe->getPostId()->getAlphadecimal(),
diff --git a/tests/phpunit/ApiRevThankIntegrationTest.php
b/tests/phpunit/ApiRevThankIntegrationTest.php
index 395daa4..a19eba2 100644
--- a/tests/phpunit/ApiRevThankIntegrationTest.php
+++ b/tests/phpunit/ApiRevThankIntegrationTest.php
@@ -36,11 +36,7 @@
}
public function testRequestWithoutToken() {
- if ( class_exists( 'ApiUsageException' ) ) {
- $this->setExpectedException( 'ApiUsageException', 'The
"token" parameter must be set.' );
- } else {
- $this->setExpectedException( 'UsageException', 'The
token parameter must be set' );
- }
+ $this->setExpectedException( 'ApiUsageException', 'The "token"
parameter must be set.' );
$this->doApiRequest( [
'action' => 'thank',
'source' => 'someSource',
@@ -75,7 +71,7 @@
}
public function testInvalidRequest() {
- $this->setExpectedException( 'UsageException' );
+ $this->setExpectedException( 'ApiUsageException' );
$this->doApiRequestWithToken( [ 'action' => 'thank' ] );
}
diff --git a/tests/phpunit/ApiRevThankUnitTest.php
b/tests/phpunit/ApiRevThankUnitTest.php
index 70a377b..69a39a5 100644
--- a/tests/phpunit/ApiRevThankUnitTest.php
+++ b/tests/phpunit/ApiRevThankUnitTest.php
@@ -26,7 +26,7 @@
$method->setAccessible( true );
if ( $expectedError ) {
- $this->setExpectedException( 'UsageException',
$expectedError );
+ $this->setExpectedException( 'ApiUsageException',
$expectedError );
}
$method->invoke( $module, $user );
@@ -67,7 +67,7 @@
$mockUser->expects( $this->once() )
->method( 'isBlocked' )
->will( $this->returnValue( true ) );
- $mockUser->expects( $this->any() )
+ $mockUser->expects( $this->once() )
->method( 'getBlock' )
->will( $this->returnValue( new Block( [
'address' => 'Test user',
--
To view, visit https://gerrit.wikimedia.org/r/321455
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib6e66f7e94c41b7a27fe867f079626ac0ade4f1b
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Thanks
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits