Merge "Select "move subpages" by default when moving a page"
[lhc/web/wiklou.git] / includes / specials / SpecialMovepage.php
index d8aa3c7..da34d81 100644 (file)
@@ -147,13 +147,19 @@ class MovePageForm extends UnlistedSpecialPage {
                $out = $this->getOutput();
                $out->setPageTitle( $this->msg( 'move-page', $this->oldTitle->getPrefixedText() ) );
                $out->addModuleStyles( 'mediawiki.special' );
-               $out->addModules( 'mediawiki.special.movePage' );
+               $out->addModules( 'mediawiki.misc-authed-ooui' );
                $this->addHelpLink( 'Help:Moving a page' );
 
-               $out->addWikiMsg( $this->getConfig()->get( 'FixDoubleRedirects' ) ?
-                       'movepagetext' :
-                       'movepagetext-noredirectfixer'
-               );
+               $handlerSupportsRedirects = ContentHandler::getForTitle( $this->oldTitle )
+                       ->supportsRedirects();
+
+               if ( $this->getConfig()->get( 'FixDoubleRedirects' ) ) {
+                       $out->addWikiMsg( 'movepagetext' );
+               } else {
+                       $out->addWikiMsg( $handlerSupportsRedirects ?
+                               'movepagetext-noredirectfixer' :
+                               'movepagetext-noredirectsupport' );
+               }
 
                if ( $this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage() ) {
                        $out->wrapWikiMsg(
@@ -170,6 +176,8 @@ class MovePageForm extends UnlistedSpecialPage {
                $deleteAndMove = false;
                $moveOverShared = false;
 
+               $user = $this->getUser();
+
                $newTitle = $this->newTitle;
 
                if ( !$newTitle ) {
@@ -180,14 +188,14 @@ class MovePageForm extends UnlistedSpecialPage {
                        # If a title was supplied, probably from the move log revert
                        # link, check for validity. We can then show some diagnostic
                        # information and save a click.
-                       $newerr = $this->oldTitle->isValidMoveOperation( $newTitle );
-                       if ( is_array( $newerr ) ) {
-                               $err = $newerr;
+                       $mp = new MovePage( $this->oldTitle, $newTitle );
+                       $status = $mp->isValidMove();
+                       $status->merge( $mp->checkPermissions( $user, null ) );
+                       if ( $status->getErrors() ) {
+                               $err = $status->getErrorsArray();
                        }
                }
 
-               $user = $this->getUser();
-
                if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'articleexists'
                        && $newTitle->quickUserCan( 'delete', $user )
                ) {
@@ -304,8 +312,6 @@ class MovePageForm extends UnlistedSpecialPage {
                        }
                }
 
-               $handler = ContentHandler::getForTitle( $this->oldTitle );
-
                $out->enableOOUI();
                $fields = [];
 
@@ -369,7 +375,7 @@ class MovePageForm extends UnlistedSpecialPage {
                }
 
                if ( $user->isAllowed( 'suppressredirect' ) ) {
-                       if ( $handler->supportsRedirects() ) {
+                       if ( $handlerSupportsRedirects ) {
                                $isChecked = $this->leaveRedirect;
                                $isDisabled = false;
                        } else {
@@ -533,7 +539,7 @@ class MovePageForm extends UnlistedSpecialPage {
                if ( $nt->getNamespace() == NS_FILE
                        && !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) )
                        && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt )
-                       && wfFindFile( $nt )
+                       && MediaWikiServices::getInstance()->getRepoGroup()->findFile( $nt )
                ) {
                        $this->showForm( [ [ 'file-exists-sharedrepo' ] ] );
 
@@ -563,7 +569,8 @@ class MovePageForm extends UnlistedSpecialPage {
 
                        // Delete an associated image if there is
                        if ( $nt->getNamespace() == NS_FILE ) {
-                               $file = wfLocalFile( $nt );
+                               $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+                                       ->newFile( $nt );
                                $file->load( File::READ_LATEST );
                                if ( $file->exists() ) {
                                        $file->delete( $reason, false, $user );
@@ -592,7 +599,15 @@ class MovePageForm extends UnlistedSpecialPage {
                # Do the actual move.
                $mp = new MovePage( $ot, $nt );
 
+               # check whether the requested actions are permitted / possible
                $userPermitted = $mp->checkPermissions( $user, $this->reason )->isOK();
+               if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
+                       $this->moveTalk = false;
+               }
+               if ( $this->moveSubpages ) {
+                       $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+                       $this->moveSubpages = $permissionManager->userCan( 'move-subpages', $user, $ot );
+               }
 
                $status = $mp->moveIfAllowed( $user, $this->reason, $createRedirect );
                if ( !$status->isOK() ) {
@@ -641,19 +656,11 @@ class MovePageForm extends UnlistedSpecialPage {
                $movePage = $this;
                Hooks::run( 'SpecialMovepageAfterMove', [ &$movePage, &$ot, &$nt ] );
 
-               # Now we move extra pages we've been asked to move: subpages and talk
-               # pages.  First, if the old page or the new page is a talk page, we
-               # can't move any talk pages: cancel that.
-               if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
-                       $this->moveTalk = false;
-               }
-
-               if ( count( $ot->getUserPermissionsErrors( 'move-subpages', $user ) ) ) {
-                       $this->moveSubpages = false;
-               }
-
-               /**
-                * Next make a list of id's.  This might be marginally less efficient
+               /*
+                * Now we move extra pages we've been asked to move: subpages and talk
+                * pages.
+                *
+                * First, make a list of id's.  This might be marginally less efficient
                 * than a more direct method, but this is not a highly performance-cri-
                 * tical code path and readable code is more important here.
                 *
@@ -739,14 +746,15 @@ class MovePageForm extends UnlistedSpecialPage {
                                continue;
                        }
 
+                       $mp = new MovePage( $oldSubpage, $newSubpage );
                        # This was copy-pasted from Renameuser, bleh.
-                       if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
+                       if ( $newSubpage->exists() && !$mp->isValidMove()->isOk() ) {
                                $link = $linkRenderer->makeKnownLink( $newSubpage );
                                $extraOutput[] = $this->msg( 'movepage-page-exists' )->rawParams( $link )->escaped();
                        } else {
-                               $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason, $createRedirect );
+                               $status = $mp->moveIfAllowed( $user, $this->reason, $createRedirect );
 
-                               if ( $success === true ) {
+                               if ( $status->isOK() ) {
                                        if ( $this->fixRedirects ) {
                                                DoubleRedirectJob::fixRedirects( 'move', $oldSubpage, $newSubpage );
                                        }