Anomie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/321408

Change subject: Update for API error i18n
......................................................................

Update for API error i18n

See Iae0e2ce3.

Change-Id: I09c564413f91e410bf9ba8336f65cb14d7105a07
---
M api/ApiAbuseFilterCheckMatch.php
M api/ApiAbuseFilterCheckSyntax.php
M api/ApiAbuseFilterUnblockAutopromote.php
M api/ApiQueryAbuseFilters.php
M api/ApiQueryAbuseLog.php
M i18n/en.json
M i18n/qqq.json
7 files changed, 120 insertions(+), 43 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AbuseFilter 
refs/changes/08/321408/1

diff --git a/api/ApiAbuseFilterCheckMatch.php b/api/ApiAbuseFilterCheckMatch.php
index d13e48c..8f704fe 100644
--- a/api/ApiAbuseFilterCheckMatch.php
+++ b/api/ApiAbuseFilterCheckMatch.php
@@ -7,7 +7,11 @@
 
                // "Anti-DoS"
                if ( !$this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
-                       $this->dieUsage( 'You don\'t have permission to test 
abuse filters', 'permissiondenied' );
+                       if ( is_callable( [ $this, 'dieWithError' ] ) ) {
+                               $this->dieWithError( 
'apierror-abusefilter-canttest', 'permissiondenied' );
+                       } else {
+                               $this->dieUsage( 'You don\'t have permission to 
test abuse filters', 'permissiondenied' );
+                       }
                }
 
                $vars = null;
@@ -27,7 +31,11 @@
                        );
 
                        if ( !$row ) {
-                               $this->dieUsageMsg( array( 'nosuchrcid', 
$params['rcid'] ) );
+                               if ( is_callable( [ $this, 'dieWithError' ] ) ) 
{
+                                       $this->dieWithError( [ 
'apierror-nosuchrcid', $params['rcid'] ] );
+                               } else {
+                                       $this->dieUsageMsg( [ 'nosuchrcid', 
$params['rcid'] ] );
+                               }
                        }
 
                        $vars = AbuseFilter::getVarsFromRCRow( $row );
@@ -41,17 +49,25 @@
                        );
 
                        if ( !$row ) {
-                               $this->dieUsage(
-                                       "There is no abuselog entry with the id 
``{$params['logid']}''",
-                                       'nosuchlogid'
-                               );
+                               if ( is_callable( [ $this, 'dieWithError' ] ) ) 
{
+                                       $this->dieWithError( [ 
'apierror-abusefilter-nosuchlogid', $params['logid'] ], 'nosuchlogid' );
+                               } else {
+                                       $this->dieUsage(
+                                               "There is no abuselog entry 
with the id ``{$params['logid']}''",
+                                               'nosuchlogid'
+                                       );
+                               }
                        }
 
                        $vars = AbuseFilter::loadVarDump( $row->afl_var_dump );
                }
 
                if ( AbuseFilter::checkSyntax( $params[ 'filter' ] ) !== true ) 
{
-                       $this->dieUsage( 'The filter has invalid syntax', 
'badsyntax' );
+                       if ( is_callable( [ $this, 'dieWithError' ] ) ) {
+                               $this->dieWithError( 
'apierror-abusefilter-badsyntax', 'badsyntax' );
+                       } else {
+                               $this->dieUsage( 'The filter has invalid 
syntax', 'badsyntax' );
+                       }
                }
 
                $result = array(
diff --git a/api/ApiAbuseFilterCheckSyntax.php 
b/api/ApiAbuseFilterCheckSyntax.php
index dfb8274..4f04a58 100644
--- a/api/ApiAbuseFilterCheckSyntax.php
+++ b/api/ApiAbuseFilterCheckSyntax.php
@@ -5,10 +5,14 @@
        public function execute() {
                // "Anti-DoS"
                if ( !$this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
-                       $this->dieUsage(
-                               'You don\'t have permission to check syntax of 
abuse filters',
-                               'permissiondenied'
-                       );
+                       if ( is_callable( [ $this, 'dieWithError' ] ) ) {
+                               $this->dieWithError( 
'apierror-abusefilter-cantcheck', 'permissiondenied' );
+                       } else {
+                               $this->dieUsage(
+                                       'You don\'t have permission to check 
syntax of abuse filters',
+                                       'permissiondenied'
+                               );
+                       }
                }
 
                $params = $this->extractRequestParams();
diff --git a/api/ApiAbuseFilterUnblockAutopromote.php 
b/api/ApiAbuseFilterUnblockAutopromote.php
index 8155747..04cc945 100644
--- a/api/ApiAbuseFilterUnblockAutopromote.php
+++ b/api/ApiAbuseFilterUnblockAutopromote.php
@@ -2,25 +2,42 @@
 
 class ApiAbuseFilterUnblockAutopromote extends ApiBase {
        public function execute() {
-               if ( !$this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
-                       $this->dieUsage( 'You do not have permissions to 
unblock autopromotion', 'permissiondenied' );
+               if ( is_callable( [ $this, 'checkUserRightsAny' ] ) ) {
+                       $this->checkUserRightsAny( 'abusefilter-modify' );
+               } else {
+                       if ( !$this->getUser()->isAllowed( 'abusefilter-modify' 
) ) {
+                               $this->dieUsage( 'You do not have permissions 
to unblock autopromotion', 'permissiondenied' );
+                       }
                }
 
                $params = $this->extractRequestParams();
                $user = User::newFromName( $params['user'] );
 
                if ( $user === false ) {
-                       // Oh god this is so bad but this message uses GENDER
-                       $msg = wfMessage( 'abusefilter-reautoconfirm-none', 
$params['user'] )->text();
-                       $this->dieUsage( $msg, 'notsuspended' );
+                       $encParamName = $this->encodeParamName( 'user' );
+                       if ( is_callable( [ $this, 'dieWithError' ] ) ) {
+                               $this->dieWithError(
+                                       [ 'apierror-baduser', $encParamName, 
wfEscapeWikiText( $param['user'] ) ],
+                                       "baduser_{$encParamName}"
+                               );
+                       } else {
+                               $this->dieUsage(
+                                       "Invalid value '{$param['user']}' for 
user parameter $encParamName",
+                                       "baduser_{$encParamName}"
+                               );
+                       }
                }
 
                $key = AbuseFilter::autoPromoteBlockKey( $user );
                $stash = ObjectCache::getMainStashInstance();
                if ( !$stash->get( $key ) ) {
-                       // Same as above :(
-                       $msg = wfMessage( 'abusefilter-reautoconfirm-none', 
$params['user'] )->text();
-                       $this->dieUsage( $msg, 'notsuspended' );
+                       if ( is_callable( [ $this, 'dieWithError' ] ) ) {
+                               $this->dieWithError( [ 
'abusefilter-reautoconfirm-none', $user->getName() ], 'notsuspended' );
+                       } else {
+                               $msg = wfMessage( 
'abusefilter-reautoconfirm-none', $user->getName() )
+                                       ->inLanguage( 'en' )->useDatabase( 
false )->text();
+                               $this->dieUsage( $msg, 'notsuspended' );
+                       }
                }
 
                $stash->delete( $key );
@@ -40,6 +57,7 @@
        public function getAllowedParams() {
                return array(
                        'user' => array(
+                               ApiBase::PARAM_TYPE => 'user',
                                ApiBase::PARAM_REQUIRED => true
                        ),
                        'token' => null,
diff --git a/api/ApiQueryAbuseFilters.php b/api/ApiQueryAbuseFilters.php
index 239ea41..d8e390b 100644
--- a/api/ApiQueryAbuseFilters.php
+++ b/api/ApiQueryAbuseFilters.php
@@ -36,8 +36,12 @@
 
        public function execute() {
                $user = $this->getUser();
-               if ( !$user->isAllowed( 'abusefilter-view' ) ) {
-                       $this->dieUsage( 'You don\'t have permission to view 
abuse filters', 'permissiondenied' );
+               if ( is_callable( [ $this, 'checkUserRightsAny' ] ) ) {
+                       $this->checkUserRightsAny( 'abusefilter-view' );
+               } else {
+                       if ( !$user->isAllowed( 'abusefilter-view' ) ) {
+                               $this->dieUsage( 'You don\'t have permission to 
view abuse filters', 'permissiondenied' );
+                       }
                }
 
                $params = $this->extractRequestParams();
@@ -79,12 +83,14 @@
 
                        /* Check for conflicting parameters. */
                        if ( ( isset( $show['enabled'] ) && isset( 
$show['!enabled'] ) )
-                                       || ( isset( $show['deleted'] ) && 
isset( $show['!deleted'] ) )
-                                       || ( isset( $show['private'] ) && 
isset( $show['!private'] ) ) ) {
-                                       $this->dieUsage(
-                                               'Incorrect parameter - mutually 
exclusive values may not be supplied',
-                                               'show'
-                                       );
+                               || ( isset( $show['deleted'] ) && isset( 
$show['!deleted'] ) )
+                               || ( isset( $show['private'] ) && isset( 
$show['!private'] ) )
+                       ) {
+                               if ( is_callable( [ $this, 'dieWithError' ] ) ) 
{
+                                       $this->dieWithError( 'apierror-show' );
+                               } else {
+                                       $this->dieUsageMsg( 'show' );
+                               }
                        }
 
                        $this->addWhereIf( 'af_enabled = 0', isset( 
$show['!enabled'] ) );
diff --git a/api/ApiQueryAbuseLog.php b/api/ApiQueryAbuseLog.php
index c7fb112..126fc3f 100644
--- a/api/ApiQueryAbuseLog.php
+++ b/api/ApiQueryAbuseLog.php
@@ -39,7 +39,11 @@
                $errors = $this->getTitle()->getUserPermissionsErrors(
                        'abusefilter-log', $user, true, array( 
'ns-specialprotected' ) );
                if ( count( $errors ) ) {
-                       $this->dieUsageMsg( $errors[0] );
+                       if ( is_callable( [ $this, 'errorArrayToStatus' ] ) ) {
+                               $this->dieStatus( self::errorArrayToStatus( 
$errors ) );
+                       } else {
+                               $this->dieUsageMsg( $errors[0] );
+                       }
                        return;
                }
 
@@ -58,14 +62,23 @@
                $fld_hidden = isset( $prop['hidden'] );
                $fld_revid = isset( $prop['revid'] );
 
-               if ( $fld_ip && !$user->isAllowed( 'abusefilter-private' ) ) {
-                       $this->dieUsage( 'You don\'t have permission to view IP 
addresses', 'permissiondenied' );
-               }
-               if ( $fld_details && !$user->isAllowed( 
'abusefilter-log-detail' ) ) {
-                       $this->dieUsage(
-                               'You don\'t have permission to view detailed 
abuse log entries',
-                               'permissiondenied'
-                       );
+               if ( is_callable( [ $this, 'checkUserRightsAny' ] ) ) {
+                       if ( $fld_ip ) {
+                               $this->checkUserRightsAny( 
'abusefilter-private' );
+                       }
+                       if ( $fld_details ) {
+                               $this->checkUserRightsAny( 
'abusefilter-log-detail' );
+                       }
+               } else {
+                       if ( $fld_ip && !$user->isAllowed( 
'abusefilter-private' ) ) {
+                               $this->dieUsage( 'You don\'t have permission to 
view IP addresses', 'permissiondenied' );
+                       }
+                       if ( $fld_details && !$user->isAllowed( 
'abusefilter-log-detail' ) ) {
+                               $this->dieUsage(
+                                       'You don\'t have permission to view 
detailed abuse log entries',
+                                       'permissiondenied'
+                               );
+                       }
                }
                // Match permissions for viewing events on private filters to 
SpecialAbuseLog (bug 42814)
                if ( $params['filter'] &&
@@ -77,10 +90,16 @@
                        }
                        foreach ( $params['filter'] as $filter ) {
                                if ( AbuseFilter::filterHidden( $filter ) ) {
-                                       $this->dieUsage(
-                                               'You don\'t have permission to 
view log entries for private filters',
-                                               'permissiondenied'
-                                       );
+                                       if ( is_callable( [ $this, 
'dieWithError' ] ) ) {
+                                               $this->dieWithError(
+                                                       [ 
'apierror-permissiondenied', $this->msg( 'action-abusefilter-log-private' ) ]
+                                               );
+                                       } else {
+                                               $this->dieUsage(
+                                                       'You don\'t have 
permission to view log entries for private filters',
+                                                       'permissiondenied'
+                                               );
+                                       }
                                }
                        }
                }
@@ -145,7 +164,11 @@
                if ( !is_null( $title ) ) {
                        $titleObj = Title::newFromText( $title );
                        if ( is_null( $titleObj ) ) {
-                               $this->dieUsageMsg( array( 'invalidtitle', 
$title ) );
+                               if ( is_callable( [ $this, 'dieWithError' ] ) ) 
{
+                                       $this->dieWithError( array( 
'apierror-invalidtitle', wfEscapeWikiText( $title ) ) );
+                               } else {
+                                       $this->dieUsageMsg( array( 
'invalidtitle', $title ) );
+                               }
                        }
                        $this->addWhereFld( 'afl_namespace', 
$titleObj->getNamespace() );
                        $this->addWhereFld( 'afl_title', $titleObj->getDBkey() 
);
diff --git a/i18n/en.json b/i18n/en.json
index 9657998..0804663 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -39,6 +39,7 @@
        "action-abusefilter-modify-restricted": "modify abuse filters with 
restricted actions",
        "action-abusefilter-revert": "revert all changes by a given abuse 
filter",
        "action-abusefilter-view-private": "view abuse filters marked as 
private",
+       "action-abusefilter-log-private": "view logs of abuse filters marked as 
private",
        "abusefilter-log": "Abuse filter log",
        "abusefilter-log-summary": "This log shows a list of all actions caught 
by the filters.",
        "abusefilter-log-search": "Search the abuse log",
@@ -438,5 +439,9 @@
        "apihelp-query+abuselog-param-limit": "The maximum amount of entries to 
list.",
        "apihelp-query+abuselog-param-prop": "Which properties to get.",
        "apihelp-query+abuselog-example-1": "Show recent log entries",
-       "apihelp-query+abuselog-example-2": "Show recent log entries for 
[[API]]"
+       "apihelp-query+abuselog-example-2": "Show recent log entries for 
[[API]]",
+       "apierror-abusefilter-canttest": "You don't have permission to test 
abuse filters.",
+       "apierror-abusefilter-cantcheck": "You don't have permission to check 
syntax of abuse filters.",
+       "apierror-abusefilter-nosuchlogid": "There is no abuselog entry with 
the id $1.",
+       "apierror-abusefilter-badsyntax": "The filter has invalid syntax."
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 0b60ff1..1a72108 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -70,6 +70,7 @@
        "action-abusefilter-modify-restricted": 
"{{doc-action|abusefilter-modify-restricted}}",
        "action-abusefilter-revert": "{{doc-action|abusefilter-revert}}",
        "action-abusefilter-view-private": 
"{{doc-action|abusefilter-view-private}}",
+       "action-abusefilter-log-private": 
"{{doc-action|abusefilter-log-private}}",
        "abusefilter-log": "Caption of [[Special:AbuseLog]]",
        "abusefilter-log-summary": "This message is displayed at the top of the 
log overview page for extension AbuseFilter.",
        "abusefilter-log-search": "Caption of a fieldset for filter definition 
on [[Special:AbuseLog]]",
@@ -417,5 +418,9 @@
        "apihelp-query+abuselog-param-limit": 
"{{doc-apihelp-param|query+abuselog|limit}}",
        "apihelp-query+abuselog-param-prop": 
"{{doc-apihelp-param|query+abuselog|prop}}",
        "apihelp-query+abuselog-example-1": 
"{{doc-apihelp-example|query+abuselog}}",
-       "apihelp-query+abuselog-example-2": 
"{{doc-apihelp-example|query+abuselog}}"
+       "apihelp-query+abuselog-example-2": 
"{{doc-apihelp-example|query+abuselog}}",
+       "apierror-abusefilter-badsyntax": "{{doc-apierror}}",
+       "apierror-abusefilter-cantcheck": "{{doc-apierror}}",
+       "apierror-abusefilter-canttest": "{{doc-apierror}}",
+       "apierror-abusefilter-nosuchlogid": "{{doc-apierror}}\n\nParameters:\n* 
$1 - AbuseFilter log ID number."
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/321408
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I09c564413f91e410bf9ba8336f65cb14d7105a07
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to