Do move options checks before the move
authorGergő Tisza <tgr.huwiki@gmail.com>
Wed, 12 Jun 2019 11:41:15 +0000 (13:41 +0200)
committerGergő Tisza <tgr.huwiki@gmail.com>
Wed, 12 Jun 2019 12:13:17 +0000 (14:13 +0200)
This is both more correct conceptually (if the move-subpages
permission check depends on the page content, we want that to be
the content that is getting moved) and hopefully more robust
(whereas doing permission checks on a title just after having
moved it might run into issues with replication lag).

Also, permission checks can be expensive so skip the move-subpage
check when the user did not request moving subpages anyway. And
replace the deprecated method.

Bug: T225366
Change-Id: I9809b2a5bbae4006d5c5389dfd7c04f20f7da8fd

includes/specials/SpecialMovepage.php

index 15b7c63..252df5b 100644 (file)
@@ -597,7 +597,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() ) {
@@ -646,19 +654,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.
                 *