Merge "Add getStatsdDataFactory to MediawikiServices"
[lhc/web/wiklou.git] / includes / api / ApiEditPage.php
index 59264e8..08aba94 100644 (file)
@@ -67,7 +67,7 @@ class ApiEditPage extends ApiBase {
                                        ->getRedirectChain();
                                // array_shift( $titles );
 
-                               $redirValues = array();
+                               $redirValues = [];
 
                                /** @var $newTitle Title */
                                foreach ( $titles as $id => $newTitle ) {
@@ -76,10 +76,10 @@ class ApiEditPage extends ApiBase {
                                                $titles[$id - 1] = $oldTitle;
                                        }
 
-                                       $redirValues[] = array(
+                                       $redirValues[] = [
                                                'from' => $titles[$id - 1]->getPrefixedText(),
                                                'to' => $newTitle->getPrefixedText()
-                                       );
+                                       ];
 
                                        $titleObj = $newTitle;
                                }
@@ -142,7 +142,7 @@ class ApiEditPage extends ApiBase {
                                                        'You have been blocked from editing',
                                                        'blocked',
                                                        0,
-                                                       array( 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) )
+                                                       [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
                                                );
                                                break;
                                        case 'autoblockedtext':
@@ -150,7 +150,7 @@ class ApiEditPage extends ApiBase {
                                                        'Your IP address has been blocked automatically, because it was used by a blocked user',
                                                        'autoblocked',
                                                        0,
-                                                       array( 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) )
+                                                       [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
                                                );
                                                break;
                                        default:
@@ -231,29 +231,29 @@ class ApiEditPage extends ApiBase {
                        if ( $params['undoafter'] > 0 ) {
                                if ( $params['undo'] < $params['undoafter'] ) {
                                        list( $params['undo'], $params['undoafter'] ) =
-                                               array( $params['undoafter'], $params['undo'] );
+                                               [ $params['undoafter'], $params['undo'] ];
                                }
                                $undoafterRev = Revision::newFromId( $params['undoafter'] );
                        }
                        $undoRev = Revision::newFromId( $params['undo'] );
                        if ( is_null( $undoRev ) || $undoRev->isDeleted( Revision::DELETED_TEXT ) ) {
-                               $this->dieUsageMsg( array( 'nosuchrevid', $params['undo'] ) );
+                               $this->dieUsageMsg( [ 'nosuchrevid', $params['undo'] ] );
                        }
 
                        if ( $params['undoafter'] == 0 ) {
                                $undoafterRev = $undoRev->getPrevious();
                        }
                        if ( is_null( $undoafterRev ) || $undoafterRev->isDeleted( Revision::DELETED_TEXT ) ) {
-                               $this->dieUsageMsg( array( 'nosuchrevid', $params['undoafter'] ) );
+                               $this->dieUsageMsg( [ 'nosuchrevid', $params['undoafter'] ] );
                        }
 
                        if ( $undoRev->getPage() != $pageObj->getId() ) {
-                               $this->dieUsageMsg( array( 'revwrongpage', $undoRev->getId(),
-                                       $titleObj->getPrefixedText() ) );
+                               $this->dieUsageMsg( [ 'revwrongpage', $undoRev->getId(),
+                                       $titleObj->getPrefixedText() ] );
                        }
                        if ( $undoafterRev->getPage() != $pageObj->getId() ) {
-                               $this->dieUsageMsg( array( 'revwrongpage', $undoafterRev->getId(),
-                                       $titleObj->getPrefixedText() ) );
+                               $this->dieUsageMsg( [ 'revwrongpage', $undoafterRev->getId(),
+                                       $titleObj->getPrefixedText() ] );
                        }
 
                        $newContent = $contentHandler->getUndoContent(
@@ -285,7 +285,7 @@ class ApiEditPage extends ApiBase {
 
                // EditPage wants to parse its stuff from a WebRequest
                // That interface kind of sucks, but it's workable
-               $requestArray = array(
+               $requestArray = [
                        'wpTextbox1' => $params['text'],
                        'format' => $contentFormat,
                        'model' => $contentHandler->getModelID(),
@@ -294,7 +294,7 @@ class ApiEditPage extends ApiBase {
                        'wpIgnoreBlankArticle' => true,
                        'wpIgnoreSelfRedirect' => true,
                        'bot' => $params['bot'],
-               );
+               ];
 
                if ( !is_null( $params['summary'] ) ) {
                        $requestArray['wpSummary'] = $params['summary'];
@@ -335,7 +335,7 @@ class ApiEditPage extends ApiBase {
                        $section = $params['section'];
                        if ( !preg_match( '/^((T-)?\d+|new)$/', $section ) ) {
                                $this->dieUsage( "The section parameter must be a valid section id or 'new'",
-                                       "invalidsection" );
+                                       'invalidsection' );
                        }
                        $content = $pageObj->getContent();
                        if ( $section !== '0' && $section != 'new'
@@ -363,10 +363,11 @@ class ApiEditPage extends ApiBase {
 
                // Apply change tags
                if ( count( $params['tags'] ) ) {
-                       if ( $user->isAllowed( 'applychangetags' ) ) {
+                       $tagStatus = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user );
+                       if ( $tagStatus->isOK() ) {
                                $requestArray['wpChangeTags'] = implode( ',', $params['tags'] );
                        } else {
-                               $this->dieUsage( 'You don\'t have permission to set change tags.', 'taggingnotallowed' );
+                               $this->dieStatus( $tagStatus );
                        }
                }
 
@@ -428,8 +429,8 @@ class ApiEditPage extends ApiBase {
 
                // Run hooks
                // Handle APIEditBeforeSave parameters
-               $r = array();
-               if ( !Hooks::run( 'APIEditBeforeSave', array( $ep, $content, &$r ) ) ) {
+               $r = [];
+               if ( !Hooks::run( 'APIEditBeforeSave', [ $ep, $content, &$r ] ) ) {
                        if ( count( $r ) ) {
                                $r['result'] = 'Failure';
                                $apiResult->addValue( null, $this->getModuleName(), $r );
@@ -473,19 +474,19 @@ class ApiEditPage extends ApiBase {
                                $this->dieUsageMsg( 'noimageredirect-logged' );
 
                        case EditPage::AS_SPAM_ERROR:
-                               $this->dieUsageMsg( array( 'spamdetected', $result['spam'] ) );
+                               $this->dieUsageMsg( [ 'spamdetected', $result['spam'] ] );
 
                        case EditPage::AS_BLOCKED_PAGE_FOR_USER:
                                $this->dieUsage(
                                        'You have been blocked from editing',
                                        'blocked',
                                        0,
-                                       array( 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) )
+                                       [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
                                );
 
                        case EditPage::AS_MAX_ARTICLE_SIZE_EXCEEDED:
                        case EditPage::AS_CONTENT_TOO_BIG:
-                               $this->dieUsageMsg( array( 'contenttoobig', $this->getConfig()->get( 'MaxArticleSize' ) ) );
+                               $this->dieUsageMsg( [ 'contenttoobig', $this->getConfig()->get( 'MaxArticleSize' ) ] );
 
                        case EditPage::AS_READ_ONLY_PAGE_ANON:
                                $this->dieUsageMsg( 'noedit-anon' );
@@ -563,82 +564,82 @@ class ApiEditPage extends ApiBase {
        }
 
        public function getAllowedParams() {
-               return array(
-                       'title' => array(
+               return [
+                       'title' => [
                                ApiBase::PARAM_TYPE => 'string',
-                       ),
-                       'pageid' => array(
+                       ],
+                       'pageid' => [
                                ApiBase::PARAM_TYPE => 'integer',
-                       ),
+                       ],
                        'section' => null,
-                       'sectiontitle' => array(
+                       'sectiontitle' => [
                                ApiBase::PARAM_TYPE => 'string',
-                       ),
-                       'text' => array(
+                       ],
+                       'text' => [
                                ApiBase::PARAM_TYPE => 'text',
-                       ),
+                       ],
                        'summary' => null,
-                       'tags' => array(
-                               ApiBase::PARAM_TYPE => ChangeTags::listExplicitlyDefinedTags(),
+                       'tags' => [
+                               ApiBase::PARAM_TYPE => 'tags',
                                ApiBase::PARAM_ISMULTI => true,
-                       ),
+                       ],
                        'minor' => false,
                        'notminor' => false,
                        'bot' => false,
-                       'basetimestamp' => array(
+                       'basetimestamp' => [
                                ApiBase::PARAM_TYPE => 'timestamp',
-                       ),
-                       'starttimestamp' => array(
+                       ],
+                       'starttimestamp' => [
                                ApiBase::PARAM_TYPE => 'timestamp',
-                       ),
+                       ],
                        'recreate' => false,
                        'createonly' => false,
                        'nocreate' => false,
-                       'watch' => array(
+                       'watch' => [
                                ApiBase::PARAM_DFLT => false,
                                ApiBase::PARAM_DEPRECATED => true,
-                       ),
-                       'unwatch' => array(
+                       ],
+                       'unwatch' => [
                                ApiBase::PARAM_DFLT => false,
                                ApiBase::PARAM_DEPRECATED => true,
-                       ),
-                       'watchlist' => array(
+                       ],
+                       'watchlist' => [
                                ApiBase::PARAM_DFLT => 'preferences',
-                               ApiBase::PARAM_TYPE => array(
+                               ApiBase::PARAM_TYPE => [
                                        'watch',
                                        'unwatch',
                                        'preferences',
                                        'nochange'
-                               ),
-                       ),
+                               ],
+                       ],
                        'md5' => null,
-                       'prependtext' => array(
+                       'prependtext' => [
                                ApiBase::PARAM_TYPE => 'text',
-                       ),
-                       'appendtext' => array(
+                       ],
+                       'appendtext' => [
                                ApiBase::PARAM_TYPE => 'text',
-                       ),
-                       'undo' => array(
+                       ],
+                       'undo' => [
                                ApiBase::PARAM_TYPE => 'integer'
-                       ),
-                       'undoafter' => array(
+                       ],
+                       'undoafter' => [
                                ApiBase::PARAM_TYPE => 'integer'
-                       ),
-                       'redirect' => array(
+                       ],
+                       'redirect' => [
                                ApiBase::PARAM_TYPE => 'boolean',
                                ApiBase::PARAM_DFLT => false,
-                       ),
-                       'contentformat' => array(
+                       ],
+                       'contentformat' => [
                                ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
-                       ),
-                       'contentmodel' => array(
+                       ],
+                       'contentmodel' => [
                                ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
-                       ),
-                       'token' => array(
+                       ],
+                       'token' => [
                                // Standard definition automatically inserted
-                               ApiBase::PARAM_HELP_MSG_APPEND => array( 'apihelp-edit-param-token' ),
-                       ),
-               );
+                               ApiBase::PARAM_HELP_MSG_APPEND => [ 'apihelp-edit-param-token' ],
+                       ],
+               ];
        }
 
        public function needsToken() {
@@ -646,7 +647,7 @@ class ApiEditPage extends ApiBase {
        }
 
        protected function getExamplesMessages() {
-               return array(
+               return [
                        'action=edit&title=Test&summary=test%20summary&' .
                                'text=article%20content&basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
                                => 'apihelp-edit-example-edit',
@@ -656,7 +657,7 @@ class ApiEditPage extends ApiBase {
                        'action=edit&title=Test&undo=13585&undoafter=13579&' .
                                'basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
                                => 'apihelp-edit-example-undo',
-               );
+               ];
        }
 
        public function getHelpUrls() {