X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiRevisionDelete.php;h=763aef5f03a11ff5a9500f8a15c45baad6d9111b;hb=9ac29c74edda2f457814a1ed634a19f9a44fd0a5;hp=4db3ca1d89b4827bb8b07223b76248618c3e2c01;hpb=a45caa8469bc6091d2161fde212c454cc0f0b970;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiRevisionDelete.php b/includes/api/ApiRevisionDelete.php index 4db3ca1d89..763aef5f03 100644 --- a/includes/api/ApiRevisionDelete.php +++ b/includes/api/ApiRevisionDelete.php @@ -36,31 +36,29 @@ class ApiRevisionDelete extends ApiBase { $params = $this->extractRequestParams(); $user = $this->getUser(); - if ( !$user->isAllowed( RevisionDeleter::getRestriction( $params['type'] ) ) ) { - $this->dieUsageMsg( 'badaccess-group0' ); - } + $this->checkUserRightsAny( RevisionDeleter::getRestriction( $params['type'] ) ); if ( $user->isBlocked() ) { $this->dieBlocked( $user->getBlock() ); } if ( !$params['ids'] ) { - $this->dieUsage( "At least one value is required for 'ids'", 'badparams' ); + $this->dieWithError( [ 'apierror-paramempty', 'ids' ], 'paramempty_ids' ); } - $hide = $params['hide'] ?: array(); - $show = $params['show'] ?: array(); + $hide = $params['hide'] ?: []; + $show = $params['show'] ?: []; if ( array_intersect( $hide, $show ) ) { - $this->dieUsage( "Mutually exclusive values for 'hide' and 'show'", 'badparams' ); + $this->dieWithError( 'apierror-revdel-mutuallyexclusive', 'badparams' ); } elseif ( !$hide && !$show ) { - $this->dieUsage( "At least one value is required for 'hide' or 'show'", 'badparams' ); + $this->dieWithError( 'apierror-revdel-paramneeded', 'badparams' ); } - $bits = array( + $bits = [ 'content' => RevisionDeleter::getRevdelConstant( $params['type'] ), 'comment' => Revision::DELETED_COMMENT, 'user' => Revision::DELETED_USER, - ); - $bitfield = array(); + ]; + $bitfield = []; foreach ( $bits as $key => $bit ) { if ( in_array( $key, $hide ) ) { $bitfield[$bit] = 1; @@ -72,9 +70,7 @@ class ApiRevisionDelete extends ApiBase { } if ( $params['suppress'] === 'yes' ) { - if ( !$user->isAllowed( 'suppressrevision' ) ) { - $this->dieUsageMsg( 'badaccess-group0' ); - } + $this->checkUserRightsAny( 'suppressrevision' ); $bitfield[Revision::DELETED_RESTRICTED] = 1; } elseif ( $params['suppress'] === 'no' ) { $bitfield[Revision::DELETED_RESTRICTED] = 0; @@ -88,20 +84,20 @@ class ApiRevisionDelete extends ApiBase { } $targetObj = RevisionDeleter::suggestTarget( $params['type'], $targetObj, $params['ids'] ); if ( $targetObj === null ) { - $this->dieUsage( 'A target title is required for this RevDel type', 'needtarget' ); + $this->dieWithError( [ 'apierror-revdel-needtarget' ], 'needtarget' ); } $list = RevisionDeleter::createList( $params['type'], $this->getContext(), $targetObj, $params['ids'] ); $status = $list->setVisibility( - array( 'value' => $bitfield, 'comment' => $params['reason'], 'perItemStatus' => true ) + [ 'value' => $bitfield, 'comment' => $params['reason'], 'perItemStatus' => true ] ); $result = $this->getResult(); $data = $this->extractStatusInfo( $status ); $data['target'] = $targetObj->getFullText(); - $data['items'] = array(); + $data['items'] = []; foreach ( $status->itemStatuses as $id => $s ) { $data['items'][$id] = $this->extractStatusInfo( $s ); @@ -121,52 +117,22 @@ class ApiRevisionDelete extends ApiBase { } private function extractStatusInfo( $status ) { - $ret = array( + $ret = [ 'status' => $status->isOK() ? 'Success' : 'Fail', - ); - $errors = $this->formatStatusMessages( $status->getErrorsByType( 'error' ) ); + ]; + + $errors = $this->getErrorFormatter()->arrayFromStatus( $status, 'error' ); if ( $errors ) { - ApiResult::setIndexedTagName( $errors, 'e' ); $ret['errors'] = $errors; } - $warnings = $this->formatStatusMessages( $status->getErrorsByType( 'warning' ) ); + $warnings = $this->getErrorFormatter()->arrayFromStatus( $status, 'warning' ); if ( $warnings ) { - ApiResult::setIndexedTagName( $warnings, 'w' ); $ret['warnings'] = $warnings; } return $ret; } - private function formatStatusMessages( $messages ) { - if ( !$messages ) { - return array(); - } - $ret = array(); - foreach ( $messages as $m ) { - if ( $m['message'] instanceof Message ) { - $msg = $m['message']; - $message = array( 'message' => $msg->getKey() ); - if ( $msg->getParams() ) { - $message['params'] = $msg->getParams(); - ApiResult::setIndexedTagName( $message['params'], 'p' ); - } - } else { - $message = array( 'message' => $m['message'] ); - $msg = wfMessage( $m['message'] ); - if ( isset( $m['params'] ) ) { - $message['params'] = $m['params']; - ApiResult::setIndexedTagName( $message['params'], 'p' ); - $msg->params( $m['params'] ); - } - } - $message['rendered'] = $msg->useDatabase( false )->inLanguage( 'en' )->plain(); - $ret[] = $message; - } - - return $ret; - } - public function mustBePosted() { return true; } @@ -176,30 +142,30 @@ class ApiRevisionDelete extends ApiBase { } public function getAllowedParams() { - return array( - 'type' => array( + return [ + 'type' => [ ApiBase::PARAM_TYPE => RevisionDeleter::getTypes(), ApiBase::PARAM_REQUIRED => true - ), + ], 'target' => null, - 'ids' => array( + 'ids' => [ ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_REQUIRED => true - ), - 'hide' => array( - ApiBase::PARAM_TYPE => array( 'content', 'comment', 'user' ), + ], + 'hide' => [ + ApiBase::PARAM_TYPE => [ 'content', 'comment', 'user' ], ApiBase::PARAM_ISMULTI => true, - ), - 'show' => array( - ApiBase::PARAM_TYPE => array( 'content', 'comment', 'user' ), + ], + 'show' => [ + ApiBase::PARAM_TYPE => [ 'content', 'comment', 'user' ], ApiBase::PARAM_ISMULTI => true, - ), - 'suppress' => array( - ApiBase::PARAM_TYPE => array( 'yes', 'no', 'nochange' ), + ], + 'suppress' => [ + ApiBase::PARAM_TYPE => [ 'yes', 'no', 'nochange' ], ApiBase::PARAM_DFLT => 'nochange', - ), + ], 'reason' => null, - ); + ]; } public function needsToken() { @@ -207,14 +173,14 @@ class ApiRevisionDelete extends ApiBase { } protected function getExamplesMessages() { - return array( + return [ 'action=revisiondelete&target=Main%20Page&type=revision&ids=12345&' . 'hide=content&token=123ABC' => 'apihelp-revisiondelete-example-revision', 'action=revisiondelete&type=logging&ids=67890&hide=content|comment|user&' . 'reason=BLP%20violation&token=123ABC' => 'apihelp-revisiondelete-example-log', - ); + ]; } public function getHelpUrls() {