From: Gergő Tisza Date: Wed, 12 Jun 2019 11:41:15 +0000 (+0200) Subject: Do move options checks before the move X-Git-Tag: 1.34.0-rc.0~1436^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=commitdiff_plain;h=5b0fd153dfc3732a320355bd9b8ab7fd737f0434;p=lhc%2Fweb%2Fwiklou.git Do move options checks before the move 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 --- diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index 15b7c632ae..252df5be09 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -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. *