jenkins-bot has submitted this change and it was merged. Change subject: Update for API error i18n ......................................................................
Update for API error i18n See Iae0e2ce3. Change-Id: Ibb54647bde62af4d73a125371d392f699d0f13ee --- M api/ApiQueryCheckUser.php M api/ApiQueryCheckUserLog.php M i18n/en.json M i18n/qqq.json 4 files changed, 58 insertions(+), 17 deletions(-) Approvals: Gergő Tisza: Looks good to me, approved jenkins-bot: Verified diff --git a/api/ApiQueryCheckUser.php b/api/ApiQueryCheckUser.php index e315adb..7f98eb6 100644 --- a/api/ApiQueryCheckUser.php +++ b/api/ApiQueryCheckUser.php @@ -18,18 +18,30 @@ $params['request'], $params['target'], $params['reason'], $params['timecond'], $params['limit'], $params['xff'] ); - if ( !$this->getUser()->isAllowed( 'checkuser' ) ) { - $this->dieUsage( 'You need the checkuser right', 'permissionerror' ); + if ( is_callable( [ $this, 'checkUserRightsAny' ] ) ) { + $this->checkUserRightsAny( 'checkuser' ); + } else { + if ( !$this->getUser()->isAllowed( 'checkuser' ) ) { + $this->dieUsage( 'You need the checkuser right', 'permissionerror' ); + } } if ( $wgCheckUserForceSummary && is_null( $reason ) ) { - $this->dieUsage( 'You must define reason for check', 'missingdata' ); + if ( is_callable( [ $this, 'dieWithError' ] ) ) { + $this->dieWithError( 'apierror-checkuser-missingsummary', 'missingdata' ); + } else { + $this->dieUsage( 'You must define reason for check', 'missingdata' ); + } } $reason = $this->msg( 'checkuser-reason-api', $reason )->inContentLanguage()->text(); $timeCutoff = strtotime( $timecond ); // absolute time if ( !$timeCutoff ) { - $this->dieUsage( 'You need use correct time limit (like "-2 weeks" or "2 weeks ago")', 'invalidtime' ); + if ( is_callable( [ $this, 'dieWithError' ] ) ) { + $this->dieWithError( 'apierror-checkuser-timelimit', 'invalidtime' ); + } else { + $this->dieUsage( 'You need use correct time limit (like "-2 weeks" or "2 weeks ago")', 'invalidtime' ); + } } $this->addTables( 'cu_changes' ); @@ -41,7 +53,11 @@ case 'userips': $user_id = User::idFromName( $target ); if ( !$user_id ) { - $this->dieUsage( 'Target user does not exist', 'nosuchuser' ); + if ( is_callable( [ $this, 'dieWithError' ] ) ) { + $this->dieWithError( [ 'nosuchusershort', wfEscapeWikiText( $target ) ], 'nosuchuser' ); + } else { + $this->dieUsage( 'Target user does not exist', 'nosuchuser' ); + } } $this->addFields( array( 'cuc_timestamp', 'cuc_ip', 'cuc_xff' ) ); @@ -80,7 +96,11 @@ if ( IP::isIPAddress( $target ) ) { $cond = CheckUser::getIpConds( $db, $target, isset( $xff ) ); if ( !$cond ) { - $this->dieUsage( 'IP or range is invalid', 'invalidip' ); + if ( is_callable( [ $this, 'dieWithError' ] ) ) { + $this->dieWithError( 'apierror-badip', 'invalidip' ); + } else { + $this->dieUsage( 'IP or range is invalid', 'invalidip' ); + } } $this->addWhere( $cond ); $log_type = array(); @@ -93,7 +113,11 @@ } else { $user_id = User::idFromName( $target ); if ( !$user_id ) { - $this->dieUsage( 'Target user does not exist', 'nosuchuser' ); + if ( is_callable( [ $this, 'dieWithError' ] ) ) { + $this->dieWithError( [ 'nosuchusershort', wfEscapeWikiText( $target ) ], 'nosuchuser' ); + } else { + $this->dieUsage( 'Target user does not exist', 'nosuchuser' ); + } } $this->addWhereFld( 'cuc_user_text', $target ); $log_type = array( 'useredits', 'user' ); @@ -148,7 +172,11 @@ $log_type .= '-xff'; } } else { - $this->dieUsage( 'IP or range is invalid', 'invalidip' ); + if ( is_callable( [ $this, 'dieWithError' ] ) ) { + $this->dieWithError( 'apierror-badip', 'invalidip' ); + } else { + $this->dieUsage( 'IP or range is invalid', 'invalidip' ); + } } $this->addFields( array( @@ -197,7 +225,11 @@ break; default: - $this->dieUsage( 'Invalid request mode', 'invalidmode' ); + if ( is_callable( [ $this, 'dieWithError' ] ) ) { + $this->dieWithError( 'apierror-checkuser-invalidmode', 'invalidmode' ); + } else { + $this->dieUsage( 'Invalid request mode', 'invalidmode' ); + } } } diff --git a/api/ApiQueryCheckUserLog.php b/api/ApiQueryCheckUserLog.php index ae9c383..34add77 100644 --- a/api/ApiQueryCheckUserLog.php +++ b/api/ApiQueryCheckUserLog.php @@ -11,8 +11,12 @@ public function execute() { $params = $this->extractRequestParams(); - if ( !$this->getUser()->isAllowed( 'checkuser-log' ) ) { - $this->dieUsage( 'You need the checkuser-log right', 'permissionerror' ); + if ( is_callable( [ $this, 'checkUserRightsAny' ] ) ) { + $this->checkUserRightsAny( 'checkuser-log' ); + } else { + if ( !$this->getUser()->isAllowed( 'checkuser-log' ) ) { + $this->dieUsage( 'You need the checkuser-log right', 'permissionerror' ); + } } $limit = $params['limit']; @@ -39,14 +43,13 @@ if ( $continue !== null ) { $cont = explode( '|', $continue ); $op = $dir === 'older' ? '<' : '>'; - if ( count( $cont ) !== 2 || wfTimestamp( TS_UNIX, $cont[0] ) === false ) { - $this->dieUsage( 'Invalid continue param. You should pass the ' . - 'original value returned by the previous query', '_badcontinue' ); - } + $this->dieContinueUsageIf( count( $cont ) !== 2 ); + $this->dieContinueUsageIf( wfTimestamp( TS_UNIX, $cont[0] ) === false ); $db = $this->getDB(); $timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) ); $id = intval( $cont[1] ); + $this->dieContinueUsageIf( $cont[1] !== (string)$id ); $this->addWhere( "cul_timestamp $op $timestamp OR " . diff --git a/i18n/en.json b/i18n/en.json index 2dcc128..a60e5d0 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -103,5 +103,8 @@ "apihelp-query+checkuserlog-param-from": "The timestamp to start enumerating from.", "apihelp-query+checkuserlog-param-to": "The timestamp to end enumerating.", "apihelp-query+checkuserlog-example-1": "Show checks of [[User:Example]]", - "apihelp-query+checkuserlog-example-2": "Show checks of 192.0.2.0/24 after 2011-10-15T23:00:00Z" + "apihelp-query+checkuserlog-example-2": "Show checks of 192.0.2.0/24 after 2011-10-15T23:00:00Z", + "apierror-checkuser-missingsummary": "You must define reason for check.", + "apierror-checkuser-timelimit": "You need use correct time limit (like \"-2 weeks\" or \"2 weeks ago\").", + "apierror-checkuser-invalidmode": "Invalid request mode" } diff --git a/i18n/qqq.json b/i18n/qqq.json index 6de8e71..7ea3d53 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -123,5 +123,8 @@ "apihelp-query+checkuserlog-param-from": "{{doc-apihelp-param|query+checkuserlog|from}}", "apihelp-query+checkuserlog-param-to": "{{doc-apihelp-param|query+checkuserlog|to}}", "apihelp-query+checkuserlog-example-1": "Do not translate \"User:Example\".\n----\n{{doc-apihelp-example|query+checkuserlog}}", - "apihelp-query+checkuserlog-example-2": "{{doc-apihelp-example|query+checkuserlog}}" + "apihelp-query+checkuserlog-example-2": "{{doc-apihelp-example|query+checkuserlog}}", + "apierror-checkuser-invalidmode": "{{doc-apierror}}", + "apierror-checkuser-missingsummary": "{{doc-apierror}}", + "apierror-checkuser-timelimit": "{{doc-apierror}}" } -- To view, visit https://gerrit.wikimedia.org/r/321415 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ibb54647bde62af4d73a125371d392f699d0f13ee Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CheckUser Gerrit-Branch: master Gerrit-Owner: Anomie <bjor...@wikimedia.org> Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits