From: Brad Jorsch Date: Thu, 16 Apr 2015 14:37:13 +0000 (-0400) Subject: API: Update ApiTag, fix error handling X-Git-Tag: 1.31.0-rc.0~11678^2 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;ds=inline;h=5adee6924bcc385577cadd8e93d5717fb5fb976c;p=lhc%2Fweb%2Fwiklou.git API: Update ApiTag, fix error handling Change I7b37295e didn't get rebased to take into account the new ApiTag module added the same day. So update it now. Also fix some errors in error handling noticed while testing this update. Bug: T96251 Bug: T96252 Change-Id: If8b63af91547e117b9d7d88e2ec9739131ee09b7 --- diff --git a/includes/api/ApiTag.php b/includes/api/ApiTag.php index fcf0ac1b41..527c6cb106 100644 --- a/includes/api/ApiTag.php +++ b/includes/api/ApiTag.php @@ -40,26 +40,25 @@ class ApiTag extends ApiBase { // validate and process each revid, rcid and logid $this->requireAtLeastOneParameter( $params, 'revid', 'rcid', 'logid' ); - $result = $this->getResult(); $ret = array(); if ( $params['revid'] ) { foreach ( $params['revid'] as $id ) { - $ret[] = $this->processIndividual( 'revid', $params, $id, $result ); + $ret[] = $this->processIndividual( 'revid', $params, $id ); } } if ( $params['rcid'] ) { foreach ( $params['rcid'] as $id ) { - $ret[] = $this->processIndividual( 'rcid', $params, $id, $result ); + $ret[] = $this->processIndividual( 'rcid', $params, $id ); } } if ( $params['logid'] ) { foreach ( $params['logid'] as $id ) { - $ret[] = $this->processIndividual( 'logid', $params, $id, $result ); + $ret[] = $this->processIndividual( 'logid', $params, $id ); } } - $result->setIndexedTagName( $ret, 'result' ); - $result->addValue( null, $this->getModuleName(), $ret ); + ApiResult::setIndexedTagName( $ret, 'result' ); + $this->getResult()->addValue( null, $this->getModuleName(), $ret ); } protected static function validateLogId( $logid ) { @@ -69,7 +68,7 @@ class ApiTag extends ApiBase { return (bool)$result; } - protected function processIndividual( $type, $params, $id, &$result ) { + protected function processIndividual( $type, $params, $id ) { $idResult = array( $type => $id ); // validate the ID @@ -102,11 +101,11 @@ class ApiTag extends ApiBase { $this->getUser() ); if ( !$status->isOK() ) { - if ( $status->hasWarning( 'actionthrottledtext' ) ) { + if ( $status->hasMessage( 'actionthrottledtext' ) ) { $idResult['status'] = 'skipped'; } else { $idResult['status'] = 'failure'; - $ret['errors'] = $result->convertStatusToArray( $status, 'error' ); + $idResult['errors'] = $this->getErrorFormatter()->arrayFromStatus( $status, 'error' ); } } else { $idResult['status'] = 'success'; @@ -115,9 +114,9 @@ class ApiTag extends ApiBase { } else { $idResult['actionlogid'] = $status->value->logId; $idResult['added'] = $status->value->addedTags; - $result->setIndexedTagName( $idResult['added'], 't' ); + ApiResult::setIndexedTagName( $idResult['added'], 't' ); $idResult['removed'] = $status->value->removedTags; - $result->setIndexedTagName( $idResult['removed'], 't' ); + ApiResult::setIndexedTagName( $idResult['removed'], 't' ); } } return $idResult;