Update for API error i18n

See Iae0e2ce3.

Change-Id: I09c564413f91e410bf9ba8336f65cb14d7105a07
This commit is contained in:
Brad Jorsch 2016-11-03 15:16:55 -04:00
parent 3d26056f7e
commit 4cbea0bcf7
7 changed files with 120 additions and 43 deletions

View file

@ -7,7 +7,11 @@ class ApiAbuseFilterCheckMatch extends ApiBase {
// "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 @@ class ApiAbuseFilterCheckMatch extends ApiBase {
);
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 @@ class ApiAbuseFilterCheckMatch extends ApiBase {
);
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(

View file

@ -5,10 +5,14 @@ class ApiAbuseFilterCheckSyntax extends ApiBase {
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();

View file

@ -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 @@ class ApiAbuseFilterUnblockAutopromote extends ApiBase {
public function getAllowedParams() {
return array(
'user' => array(
ApiBase::PARAM_TYPE => 'user',
ApiBase::PARAM_REQUIRED => true
),
'token' => null,

View file

@ -36,8 +36,12 @@ class ApiQueryAbuseFilters extends ApiQueryBase {
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 @@ class ApiQueryAbuseFilters extends ApiQueryBase {
/* 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'] ) );

View file

@ -39,7 +39,11 @@ class ApiQueryAbuseLog extends ApiQueryBase {
$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( $this->errorArrayToStatus( $errors ) );
} else {
$this->dieUsageMsg( $errors[0] );
}
return;
}
@ -58,14 +62,23 @@ class ApiQueryAbuseLog extends ApiQueryBase {
$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 @@ class ApiQueryAbuseLog extends ApiQueryBase {
}
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 @@ class ApiQueryAbuseLog extends ApiQueryBase {
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() );

View file

@ -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."
}

View file

@ -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."
}