Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / includes / api / ApiMove.php
index f6b6b35..540860b 100644 (file)
@@ -20,6 +20,8 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * API Module to move pages
  * @ingroup API
@@ -59,7 +61,7 @@ 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' ) ) {
                                $this->dieWithError( 'apierror-fileexists-sharedrepo-perm' );
@@ -86,6 +88,7 @@ class ApiMove extends ApiBase {
                $status = $this->movePage( $fromTitle, $toTitle, $params['reason'], !$params['noredirect'],
                        $params['tags'] ?: [] );
                if ( !$status->isOK() ) {
+                       $user->spreadAnyEditBlock();
                        $this->dieStatus( $status );
                }
 
@@ -200,22 +203,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;
                }