Merge "Make Special:ChangeContentModel field labels consistently use colons"
[lhc/web/wiklou.git] / includes / api / ApiMove.php
index cc4490e..d8f48b8 100644 (file)
@@ -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' );
                        }
                }
@@ -170,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;
@@ -183,7 +186,7 @@ class ApiMove extends ApiBase {
                }
 
                // Check suppressredirect permission
-               if ( !$user->isAllowed( 'suppressredirect' ) ) {
+               if ( !$this->getPermissionManager()->userHasRight( $user, 'suppressredirect' ) ) {
                        $createRedirect = true;
                }
 
@@ -201,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;
                }