X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiMove.php;h=1fb034f85fb5370ce92a65340a0f3d6335bdbd7e;hb=69fabec0f10aa4c74682f52e943c8717c86ba85a;hp=18e582d6375790fab74c3f408bb1c76d68eac530;hpb=b9100546942cc018b00e3e6cf6f9de8f3ecdcf1e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index 18e582d637..1fb034f85f 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -77,9 +77,18 @@ class ApiMove extends ApiBase { $this->dieWithError( 'apierror-ratelimited' ); } + // Check if the user is allowed to add the specified changetags + if ( $params['tags'] ) { + $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user ); + if ( !$ableToTag->isOK() ) { + $this->dieStatus( $ableToTag ); + } + } + // Move the page $toTitleExists = $toTitle->exists(); - $status = $this->movePage( $fromTitle, $toTitle, $params['reason'], !$params['noredirect'] ); + $status = $this->movePage( $fromTitle, $toTitle, $params['reason'], !$params['noredirect'], + $params['tags'] ?: [] ); if ( !$status->isOK() ) { $this->dieStatus( $status ); } @@ -94,7 +103,7 @@ class ApiMove extends ApiBase { // a redirect to the new title. This is not safe, but what we did before was // even worse: we just determined whether a redirect should have been created, // and reported that it was created if it should have, without any checks. - // Also note that isRedirect() is unreliable because of bug 37209. + // Also note that isRedirect() is unreliable because of T39209. $r['redirectcreated'] = $fromTitle->exists(); $r['moveoverredirect'] = $toTitleExists; @@ -102,7 +111,13 @@ class ApiMove extends ApiBase { // Move the talk page if ( $params['movetalk'] && $toTalk && $fromTalk->exists() && !$fromTitle->isTalkPage() ) { $toTalkExists = $toTalk->exists(); - $status = $this->movePage( $fromTalk, $toTalk, $params['reason'], !$params['noredirect'] ); + $status = $this->movePage( + $fromTalk, + $toTalk, + $params['reason'], + !$params['noredirect'], + $params['tags'] ?: [] + ); if ( $status->isOK() ) { $r['talkfrom'] = $fromTalk->getPrefixedText(); $r['talkto'] = $toTalk->getPrefixedText(); @@ -117,13 +132,23 @@ class ApiMove extends ApiBase { // Move subpages if ( $params['movesubpages'] ) { - $r['subpages'] = $this->moveSubpages( $fromTitle, $toTitle, - $params['reason'], $params['noredirect'] ); + $r['subpages'] = $this->moveSubpages( + $fromTitle, + $toTitle, + $params['reason'], + $params['noredirect'], + $params['tags'] ?: [] + ); ApiResult::setIndexedTagName( $r['subpages'], 'subpage' ); if ( $params['movetalk'] ) { - $r['subpages-talk'] = $this->moveSubpages( $fromTalk, $toTalk, - $params['reason'], $params['noredirect'] ); + $r['subpages-talk'] = $this->moveSubpages( + $fromTalk, + $toTalk, + $params['reason'], + $params['noredirect'], + $params['tags'] ?: [] + ); ApiResult::setIndexedTagName( $r['subpages-talk'], 'subpage' ); } } @@ -149,26 +174,28 @@ class ApiMove extends ApiBase { * @param Title $to * @param string $reason * @param bool $createRedirect + * @param array $changeTags Applied to the entry in the move log and redirect page revision * @return Status */ - protected function movePage( Title $from, Title $to, $reason, $createRedirect ) { + protected function movePage( Title $from, Title $to, $reason, $createRedirect, $changeTags ) { $mp = new MovePage( $from, $to ); $valid = $mp->isValidMove(); if ( !$valid->isOK() ) { return $valid; } - $permStatus = $mp->checkPermissions( $this->getUser(), $reason ); + $user = $this->getUser(); + $permStatus = $mp->checkPermissions( $user, $reason ); if ( !$permStatus->isOK() ) { return $permStatus; } // Check suppressredirect permission - if ( !$this->getUser()->isAllowed( 'suppressredirect' ) ) { + if ( !$user->isAllowed( 'suppressredirect' ) ) { $createRedirect = true; } - return $mp->move( $this->getUser(), $reason, $createRedirect ); + return $mp->move( $user, $reason, $createRedirect, $changeTags ); } /** @@ -176,11 +203,13 @@ class ApiMove extends ApiBase { * @param Title $toTitle * @param string $reason * @param bool $noredirect + * @param array $changeTags Applied to the entry in the move log and redirect page revisions * @return array */ - public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect ) { + public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect, $changeTags = [] ) { $retval = []; - $success = $fromTitle->moveSubpages( $toTitle, true, $reason, !$noredirect ); + + $success = $fromTitle->moveSubpages( $toTitle, true, $reason, !$noredirect, $changeTags ); if ( isset( $success[0] ) ) { $status = $this->errorArrayToStatus( $success ); return [ 'errors' => $this->getErrorFormatter()->arrayFromStatus( $status ) ]; @@ -242,7 +271,11 @@ class ApiMove extends ApiBase { 'nochange' ], ], - 'ignorewarnings' => false + 'ignorewarnings' => false, + 'tags' => [ + ApiBase::PARAM_TYPE => 'tags', + ApiBase::PARAM_ISMULTI => true, + ], ]; } @@ -259,6 +292,6 @@ class ApiMove extends ApiBase { } public function getHelpUrls() { - return 'https://www.mediawiki.org/wiki/API:Move'; + return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Move'; } }