X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fapi%2FApiMove.php;h=d8f48b85a1378f180df1992e6af576ef8de5221b;hb=529fc12d2ad2032337594389448fdb5b55802830;hp=f6b6b35df2913210388d8cf023c9d2394ad55904;hpb=c2f9376c19335219d403e602496fa44f4a3e7b55;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index f6b6b35df2..d8f48b85a1 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -20,6 +20,8 @@ * @file */ +use MediaWiki\MediaWikiServices; + /** * API Module to move pages * @ingroup API @@ -59,11 +61,12 @@ class ApiMove extends ApiBase { if ( $toTitle->getNamespace() == NS_FILE && !RepoGroup::singleton()->getLocalRepo()->findFile( $toTitle ) - && wfFindFile( $toTitle ) + && MediaWikiServices::getInstance()->getRepoGroup()->findFile( $toTitle ) ) { - if ( !$params['ignorewarnings'] && $user->isAllowed( 'reupload-shared' ) ) { + if ( !$params['ignorewarnings'] && + $this->getPermissionManager()->userHasRight( $user, 'reupload-shared' ) ) { $this->dieWithError( 'apierror-fileexists-sharedrepo-perm' ); - } elseif ( !$user->isAllowed( 'reupload-shared' ) ) { + } elseif ( !$this->getPermissionManager()->userHasRight( $user, 'reupload-shared' ) ) { $this->dieWithError( 'apierror-cantoverwrite-sharedfile' ); } } @@ -86,6 +89,7 @@ class ApiMove extends ApiBase { $status = $this->movePage( $fromTitle, $toTitle, $params['reason'], !$params['noredirect'], $params['tags'] ?: [] ); if ( !$status->isOK() ) { + $user->spreadAnyEditBlock(); $this->dieStatus( $status ); } @@ -169,7 +173,7 @@ class ApiMove extends ApiBase { * @return Status */ protected function movePage( Title $from, Title $to, $reason, $createRedirect, $changeTags ) { - $mp = new MovePage( $from, $to ); + $mp = MediaWikiServices::getInstance()->getMovePageFactory()->newMovePage( $from, $to ); $valid = $mp->isValidMove(); if ( !$valid->isOK() ) { return $valid; @@ -182,7 +186,7 @@ class ApiMove extends ApiBase { } // Check suppressredirect permission - if ( !$user->isAllowed( 'suppressredirect' ) ) { + if ( !$this->getPermissionManager()->userHasRight( $user, 'suppressredirect' ) ) { $createRedirect = true; } @@ -200,22 +204,22 @@ class ApiMove extends ApiBase { public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect, $changeTags = [] ) { $retval = []; - $success = $fromTitle->moveSubpages( $toTitle, true, $reason, !$noredirect, $changeTags ); - if ( isset( $success[0] ) ) { - $status = $this->errorArrayToStatus( $success ); - return [ 'errors' => $this->getErrorFormatter()->arrayFromStatus( $status ) ]; + $mp = new MovePage( $fromTitle, $toTitle ); + $result = + $mp->moveSubpagesIfAllowed( $this->getUser(), $reason, !$noredirect, $changeTags ); + if ( !$result->isOk() ) { + // This means the whole thing failed + return [ 'errors' => $this->getErrorFormatter()->arrayFromStatus( $result ) ]; } // At least some pages could be moved // Report each of them separately - foreach ( $success as $oldTitle => $newTitle ) { + foreach ( $result->getValue() as $oldTitle => $status ) { $r = [ 'from' => $oldTitle ]; - if ( is_array( $newTitle ) ) { - $status = $this->errorArrayToStatus( $newTitle ); - $r['errors'] = $this->getErrorFormatter()->arrayFromStatus( $status ); + if ( $status->isOK() ) { + $r['to'] = $status->getValue(); } else { - // Success - $r['to'] = $newTitle; + $r['errors'] = $this->getErrorFormatter()->arrayFromStatus( $status ); } $retval[] = $r; }