Merge "Add CollationFa"
[lhc/web/wiklou.git] / includes / api / ApiTag.php
index c1a6810..f6c0584 100644 (file)
@@ -30,10 +30,7 @@ class ApiTag extends ApiBase {
                $user = $this->getUser();
 
                // make sure the user is allowed
-               if ( !$user->isAllowed( 'changetags' ) ) {
-                       $this->dieUsage( "You don't have permission to add or remove change tags from individual edits",
-                               'permissiondenied' );
-               }
+               $this->checkUserRightsAny( 'changetags' );
 
                if ( $user->isBlocked() ) {
                        $this->dieBlocked( $user->getBlock() );
@@ -41,7 +38,7 @@ class ApiTag extends ApiBase {
 
                // validate and process each revid, rcid and logid
                $this->requireAtLeastOneParameter( $params, 'revid', 'rcid', 'logid' );
-               $ret = array();
+               $ret = [];
                if ( $params['revid'] ) {
                        foreach ( $params['revid'] as $id ) {
                                $ret[] = $this->processIndividual( 'revid', $params, $id );
@@ -63,14 +60,14 @@ class ApiTag extends ApiBase {
        }
 
        protected static function validateLogId( $logid ) {
-               $dbr = wfGetDB( DB_SLAVE );
-               $result = $dbr->selectField( 'logging', 'log_id', array( 'log_id' => $logid ),
+               $dbr = wfGetDB( DB_REPLICA );
+               $result = $dbr->selectField( 'logging', 'log_id', [ 'log_id' => $logid ],
                        __METHOD__ );
                return (bool)$result;
        }
 
        protected function processIndividual( $type, $params, $id ) {
-               $idResult = array( $type => $id );
+               $idResult = [ $type => $id ];
 
                // validate the ID
                $valid = false;
@@ -88,7 +85,8 @@ class ApiTag extends ApiBase {
 
                if ( !$valid ) {
                        $idResult['status'] = 'error';
-                       $idResult += $this->parseMsg( array( "nosuch$type", $id ) );
+                       // Messages: apierror-nosuchrcid apierror-nosuchrevid apierror-nosuchlogid
+                       $idResult += $this->getErrorFormatter()->formatMessage( [ "apierror-nosuch$type", $id ] );
                        return $idResult;
                }
 
@@ -132,31 +130,31 @@ class ApiTag extends ApiBase {
        }
 
        public function getAllowedParams() {
-               return array(
-                       'rcid' => array(
+               return [
+                       'rcid' => [
                                ApiBase::PARAM_TYPE => 'integer',
                                ApiBase::PARAM_ISMULTI => true,
-                       ),
-                       'revid' => array(
+                       ],
+                       'revid' => [
                                ApiBase::PARAM_TYPE => 'integer',
                                ApiBase::PARAM_ISMULTI => true,
-                       ),
-                       'logid' => array(
+                       ],
+                       'logid' => [
                                ApiBase::PARAM_TYPE => 'integer',
                                ApiBase::PARAM_ISMULTI => true,
-                       ),
-                       'add' => array(
+                       ],
+                       'add' => [
                                ApiBase::PARAM_TYPE => 'tags',
                                ApiBase::PARAM_ISMULTI => true,
-                       ),
-                       'remove' => array(
+                       ],
+                       'remove' => [
                                ApiBase::PARAM_TYPE => 'string',
                                ApiBase::PARAM_ISMULTI => true,
-                       ),
-                       'reason' => array(
+                       ],
+                       'reason' => [
                                ApiBase::PARAM_DFLT => '',
-                       ),
-               );
+                       ],
+               ];
        }
 
        public function needsToken() {
@@ -164,12 +162,12 @@ class ApiTag extends ApiBase {
        }
 
        protected function getExamplesMessages() {
-               return array(
+               return [
                        'action=tag&revid=123&add=vandalism&token=123ABC'
                                => 'apihelp-tag-example-rev',
                        'action=tag&logid=123&remove=spam&reason=Wrongly+applied&token=123ABC'
                                => 'apihelp-tag-example-log',
-               );
+               ];
        }
 
        public function getHelpUrls() {