Anomie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/321418
Change subject: Update for API error i18n
......................................................................
Update for API error i18n
See Iae0e2ce3.
Change-Id: If3bb09c0f32e600fa33ec79260ed46e16832876d
---
M api/ApiCodeDiff.php
M api/ApiCodeUpdate.php
M api/ApiQueryCodeComments.php
M api/ApiQueryCodePaths.php
M api/ApiQueryCodeRevisions.php
M api/ApiQueryCodeTags.php
M api/ApiRevisionUpdate.php
M i18n/en.json
M i18n/qqq.json
9 files changed, 118 insertions(+), 35 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CodeReview
refs/changes/18/321418/1
diff --git a/api/ApiCodeDiff.php b/api/ApiCodeDiff.php
index dbe9ee7..d3df508 100644
--- a/api/ApiCodeDiff.php
+++ b/api/ApiCodeDiff.php
@@ -22,20 +22,32 @@
public function execute() {
global $wgCodeReviewMaxDiffSize;
// Before doing anything at all, let's check permissions
- if ( !$this->getUser()->isAllowed( 'codereview-use' ) ) {
- $this->dieUsage( 'You don\'t have permission to view
code diffs', 'permissiondenied' );
+ if ( is_callable( array( $this, 'checkUserRightsAny' ) ) ) {
+ $this->checkUserRightsAny( 'codereview-use' );
+ } else {
+ if ( !$this->getUser()->isAllowed( 'codereview-use' ) )
{
+ $this->dieUsage( 'You don\'t have permission to
view code diffs', 'permissiondenied' );
+ }
}
$params = $this->extractRequestParams();
$repo = CodeRepository::newFromName( $params['repo'] );
if ( !$repo ) {
- $this->dieUsage( "Invalid repo ``{$params['repo']}''",
'invalidrepo' );
+ if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+ $this->dieWithError( array(
'apierror-invalidrepo', wfEscapeWikiText( $params['repo'] ) ) );
+ } else {
+ $this->dieUsage( "Invalid repo
``{$params['repo']}''", 'invalidrepo' );
+ }
}
$lastStoredRev = $repo->getLastStoredRev();
if ( $params['rev'] > $lastStoredRev ) {
- $this->dieUsage( "There is no revision with ID
{$params['rev']}", 'nosuchrev' );
+ if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+ $this->dieWithError( array(
'apierror-nosuchrevid', $params['rev'] ) );
+ } else {
+ $this->dieUsage( "There is no revision with ID
{$params['rev']}", 'nosuchrev' );
+ }
}
$diff = $repo->getDiff( $params['rev'] );
diff --git a/api/ApiCodeUpdate.php b/api/ApiCodeUpdate.php
index 9a6042a..51500ed 100644
--- a/api/ApiCodeUpdate.php
+++ b/api/ApiCodeUpdate.php
@@ -22,14 +22,22 @@
public function execute() {
// Before doing anything at all, let's check permissions
- if ( !$this->getUser()->isAllowed( 'codereview-use' ) ) {
- $this->dieUsage( 'You don\'t have permission to update
code', 'permissiondenied' );
+ if ( is_callable( array( $this, 'checkUserRightsAny' ) ) ) {
+ $this->checkUserRightsAny( 'codereview-use' );
+ } else {
+ if ( !$this->getUser()->isAllowed( 'codereview-use' ) )
{
+ $this->dieUsage( 'You don\'t have permission to
update code', 'permissiondenied' );
+ }
}
$params = $this->extractRequestParams();
$repo = CodeRepository::newFromName( $params['repo'] );
if ( !$repo ) {
- $this->dieUsage( "Invalid repo ``{$params['repo']}''",
'invalidrepo' );
+ if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+ $this->dieWithError( array(
'apierror-invalidrepo', wfEscapeWikiText( $params['repo'] ) ) );
+ } else {
+ $this->dieUsage( "Invalid repo
``{$params['repo']}''", 'invalidrepo' );
+ }
}
$svn = SubversionAdaptor::newFromRepo( $repo->getPath() );
diff --git a/api/ApiQueryCodeComments.php b/api/ApiQueryCodeComments.php
index 8ffc445..38d287d 100644
--- a/api/ApiQueryCodeComments.php
+++ b/api/ApiQueryCodeComments.php
@@ -29,21 +29,34 @@
}
public function execute() {
- global $wgUser;
// Before doing anything at all, let's check permissions
- if ( !$wgUser->isAllowed( 'codereview-use' ) ) {
- $this->dieUsage( 'You don\'t have permission to view
code comments', 'permissiondenied' );
+ if ( is_callable( array( $this, 'checkUserRightsAny' ) ) ) {
+ $this->checkUserRightsAny( 'codereview-use' );
+ } else {
+ if ( !$this->getUser()->isAllowed( 'codereview-use' ) )
{
+ $this->dieUsage( 'You don\'t have permission to
view code comments', 'permissiondenied' );
+ }
}
$params = $this->extractRequestParams();
$this->props = array_flip( $params['prop'] );
if ( isset( $this->props['revision'] ) ) {
- $this->setWarning( 'ccprop=revision has been deprecated
in favor of ccprop=status' );
+ if ( is_callable( [ $this, 'addDeprecation' ] ) ) {
+ $this->addDeprecation(
+ [
'apiwarn-deprecation-withreplacement', 'ccprop=revision', 'ccprop=status' ]
+ );
+ } else {
+ $this->setWarning( 'ccprop=revision has been
deprecated in favor of ccprop=status' );
+ }
}
$listview = new CodeCommentsListView( $params['repo'] );
if ( is_null( $listview->getRepo() ) ) {
- $this->dieUsage( "Invalid repo ``{$params['repo']}''",
'invalidrepo' );
+ if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+ $this->dieWithError( array(
'apierror-invalidrepo', wfEscapeWikiText( $params['repo'] ) ) );
+ } else {
+ $this->dieUsage( "Invalid repo
``{$params['repo']}''", 'invalidrepo' );
+ }
}
$pager = $listview->getPager();
diff --git a/api/ApiQueryCodePaths.php b/api/ApiQueryCodePaths.php
index e26e358..ed924d1 100644
--- a/api/ApiQueryCodePaths.php
+++ b/api/ApiQueryCodePaths.php
@@ -26,14 +26,22 @@
public function execute() {
// Before doing anything at all, let's check permissions
- if ( !$this->getUser()->isAllowed( 'codereview-use' ) ) {
- $this->dieUsage( 'You don\'t have permission to view
code paths', 'permissiondenied' );
+ if ( is_callable( array( $this, 'checkUserRightsAny' ) ) ) {
+ $this->checkUserRightsAny( 'codereview-use' );
+ } else {
+ if ( !$this->getUser()->isAllowed( 'codereview-use' ) )
{
+ $this->dieUsage( 'You don\'t have permission to
view code paths', 'permissiondenied' );
+ }
}
$params = $this->extractRequestParams();
$repo = CodeRepository::newFromName( $params['repo'] );
if ( !$repo instanceof CodeRepository ) {
- $this->dieUsage( "Invalid repo ``{$params['repo']}''",
'invalidrepo' );
+ if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+ $this->dieWithError( array(
'apierror-invalidrepo', wfEscapeWikiText( $params['repo'] ) ) );
+ } else {
+ $this->dieUsage( "Invalid repo
``{$params['repo']}''", 'invalidrepo' );
+ }
}
$this->addTables( 'code_paths' );
diff --git a/api/ApiQueryCodeRevisions.php b/api/ApiQueryCodeRevisions.php
index 66cfed3..022c44a 100644
--- a/api/ApiQueryCodeRevisions.php
+++ b/api/ApiQueryCodeRevisions.php
@@ -31,8 +31,12 @@
public function execute() {
$this->getMain()->setCacheMode( 'anon-public-user-private' );
// Before doing anything at all, let's check permissions
- if ( !$this->getUser()->isAllowed( 'codereview-use' ) ) {
- $this->dieUsage( 'You don\'t have permission to view
code revisions', 'permissiondenied' );
+ if ( is_callable( array( $this, 'checkUserRightsAny' ) ) ) {
+ $this->checkUserRightsAny( 'codereview-use' );
+ } else {
+ if ( !$this->getUser()->isAllowed( 'codereview-use' ) )
{
+ $this->dieUsage( 'You don\'t have permission to
view code revisions', 'permissiondenied' );
+ }
}
$params = $this->extractRequestParams();
@@ -41,7 +45,11 @@
$repo = CodeRepository::newFromName( $params['repo'] );
if ( !$repo ) {
- $this->dieUsage( "Invalid repo ``{$params['repo']}''",
'invalidrepo' );
+ if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+ $this->dieWithError( array(
'apierror-invalidrepo', wfEscapeWikiText( $params['repo'] ) ) );
+ } else {
+ $this->dieUsage( "Invalid repo
``{$params['repo']}''", 'invalidrepo' );
+ }
}
$data = array();
diff --git a/api/ApiQueryCodeTags.php b/api/ApiQueryCodeTags.php
index cf9cb1d..54fe6d9 100644
--- a/api/ApiQueryCodeTags.php
+++ b/api/ApiQueryCodeTags.php
@@ -26,14 +26,22 @@
public function execute() {
// Before doing anything at all, let's check permissions
- if ( !$this->getUser()->isAllowed( 'codereview-use' ) ) {
- $this->dieUsage( 'You don\'t have permission to view
code tags', 'permissiondenied' );
+ if ( is_callable( array( $this, 'checkUserRightsAny' ) ) ) {
+ $this->checkUserRightsAny( 'codereview-use' );
+ } else {
+ if ( !$this->getUser()->isAllowed( 'codereview-use' ) )
{
+ $this->dieUsage( 'You don\'t have permission to
view code tags', 'permissiondenied' );
+ }
}
$params = $this->extractRequestParams();
$repo = CodeRepository::newFromName( $params['repo'] );
if ( !$repo instanceof CodeRepository ) {
- $this->dieUsage( "Invalid repo ``{$params['repo']}''",
'invalidrepo' );
+ if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+ $this->dieWithError( array(
'apierror-invalidrepo', wfEscapeWikiText( $params['repo'] ) ) );
+ } else {
+ $this->dieUsage( "Invalid repo
``{$params['repo']}''", 'invalidrepo' );
+ }
}
$data = array();
diff --git a/api/ApiRevisionUpdate.php b/api/ApiRevisionUpdate.php
index fe5c4d3..938e425 100644
--- a/api/ApiRevisionUpdate.php
+++ b/api/ApiRevisionUpdate.php
@@ -26,18 +26,24 @@
public function execute() {
$user = $this->getUser();
// Before doing anything at all, let's check permissions
- if ( !$user->isAllowed( 'codereview-use' ) ) {
- $this->dieUsage( 'You don\'t have permission to update
code', 'permissiondenied' );
+ if ( is_callable( array( $this, 'checkUserRightsAny' ) ) ) {
+ $this->checkUserRightsAny( 'codereview-use' );
+ } else {
+ if ( !$user->isAllowed( 'codereview-use' ) ) {
+ $this->dieUsage( 'You don\'t have permission
to update code', 'permissiondenied' );
+ }
}
$params = $this->extractRequestParams();
- if (
- $params['comment'] &&
- !$user->isAllowed( 'codereview-post-comment' )
- )
- {
- $this->dieUsage( 'You do not have permission to post
comment', 'permissiondenied' );
+ if ( $params['comment'] ) {
+ if ( is_callable( array( $this, 'checkUserRightsAny' )
) ) {
+ $this->checkUserRightsAny(
'codereview-post-comment' );
+ } else {
+ if ( !$user->isAllowed(
'codereview-post-comment' ) ) {
+ $this->dieUsage( 'You do not have
permission to post comment', 'permissiondenied' );
+ }
+ }
}
global $wgCodeReviewInlineComments;
@@ -46,18 +52,34 @@
&& isset( $params['patchline'] )
)
{
- $this->dieUsageMsg( "Can not attach a comment to a diff
when inline commenting is disabled (\$wgCodeReviewInlineComments is false)." );
+ if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+ $this->dieWithError(
'apierror-codereview-inlinecommentingdisabled', 'inlinecommentingdisabled' );
+ } else {
+ $this->dieUsage(
+ 'Can not attach a comment to a diff
when inline commenting is disabled '
+ . '($wgCodeReviewInlineComments
is false).',
+ 'inlinecommentingdisabled'
+ );
+ }
}
$repo = CodeRepository::newFromName( $params['repo'] );
if ( !$repo ) {
- $this->dieUsage( "Invalid repo ``{$params['repo']}''",
'invalidrepo' );
+ if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+ $this->dieWithError( array(
'apierror-invalidrepo', wfEscapeWikiText( $params['repo'] ) ) );
+ } else {
+ $this->dieUsage( "Invalid repo
``{$params['repo']}''", 'invalidrepo' );
+ }
}
$rev = $repo->getRevision( $params['rev'] );
if ( !$rev ) {
- $this->dieUsage( "There is no revision with ID
{$params['rev']}", 'nosuchrev' );
+ if ( is_callable( array( $this, 'dieWithError' ) ) ) {
+ $this->dieWithError( array(
'apierror-nosuchrevid', $params['rev'] ) );
+ } else {
+ $this->dieUsage( "There is no revision with ID
{$params['rev']}", 'nosuchrev' );
+ }
}
$revisionCommitter = new CodeRevisionCommitterApi( $repo, $rev
);
diff --git a/i18n/en.json b/i18n/en.json
index 6f259ef..29299da 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -180,7 +180,7 @@
"right-codereview-associate": "Manage revision associations",
"right-codereview-review-own": "Mark your own revisions as
\"{{int:code-status-ok}}\" or \"{{int:code-status-resolved}}\"",
"action-repoadmin": "manage code repositories",
- "action-codereview-use": "use Special:Code",
+ "action-codereview-use": "use CodeReview",
"action-codereview-add-tag": "add new tags to revisions",
"action-codereview-remove-tag": "remove tags from revisions",
"action-codereview-post-comment": "add comments on revisions",
@@ -233,5 +233,7 @@
"apihelp-query+coderevisions-example-2": "Fetch info for revisions in
MediaWiki",
"apihelp-query+codetags-description": "Get a list of tags applied to
revisions in a given repository.",
"apihelp-query+codetags-param-repo": "Name of the repository.",
- "apihelp-query+codetags-example-1": "List tags in MediaWiki"
+ "apihelp-query+codetags-example-1": "List tags in MediaWiki",
+ "apierror-invalidrepo": "Invalid repo \"$1\".",
+ "apierror-codereview-inlinecommentingdisabled": "Can not attach a
comment to a diff when inline commenting is disabled
(<var>$wgCodeReviewInlineComments</var> is false)."
}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index f9b9571..e47777c 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -259,5 +259,7 @@
"apihelp-query+coderevisions-example-2":
"{{doc-apihelp-example|query+coderevisions}}",
"apihelp-query+codetags-description":
"{{doc-apihelp-description|query+codetags}}",
"apihelp-query+codetags-param-repo":
"{{doc-apihelp-param|query+codetags|repo}}",
- "apihelp-query+codetags-example-1":
"{{doc-apihelp-example|query+codetags}}"
+ "apihelp-query+codetags-example-1":
"{{doc-apihelp-example|query+codetags}}",
+ "apierror-codereview-inlinecommentingdisabled": "{{doc-apierror}}",
+ "apierror-invalidrepo": "{{doc-apierror}}\n\nParameters:\n* $1 -
Supplied repository name."
}
--
To view, visit https://gerrit.wikimedia.org/r/321418
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If3bb09c0f32e600fa33ec79260ed46e16832876d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CodeReview
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits