From f69bee7798f1ac80325be362a3510a4d06aba7b0 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 11 Oct 2008 08:26:01 +0000 Subject: [PATCH] * Reintroduce user page move permission as per r41465, generally useful regardless of whether the Renameuser extension is in use. Do the check in Title::getUserPermissionsErrorsInternal(), so that the move page tab won't be displayed on user pages for users who can't move them. * Use error message text suitable for humans. Be specific about whether the source or the destination is the problem, say what the namespace is for those people who don't get namespaces, don't introduce unnecessary jargon words like "root" for a page that isn't a subpage. * Fixed incorrect display of movenotallowed for immobile namespaces, use the new specific error messages. --- includes/DefaultSettings.php | 2 ++ includes/Title.php | 52 ++++++++++++++++++++++++++----- languages/messages/MessagesEn.php | 10 ++++-- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index afa45483d4..0a2b817cc5 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1128,6 +1128,7 @@ $wgGroupPermissions['*' ]['writeapi'] = true; // Implicit group for all logged-in accounts $wgGroupPermissions['user' ]['move'] = true; $wgGroupPermissions['user' ]['move-subpages'] = true; +$wgGroupPermissions['user' ]['move-rootuserpages'] = true; // can move root userpages $wgGroupPermissions['user' ]['read'] = true; $wgGroupPermissions['user' ]['edit'] = true; $wgGroupPermissions['user' ]['createpage'] = true; @@ -1166,6 +1167,7 @@ $wgGroupPermissions['sysop']['import'] = true; $wgGroupPermissions['sysop']['importupload'] = true; $wgGroupPermissions['sysop']['move'] = true; $wgGroupPermissions['sysop']['move-subpages'] = true; +$wgGroupPermissions['sysop']['move-rootuserpages'] = true; $wgGroupPermissions['sysop']['patrol'] = true; $wgGroupPermissions['sysop']['autopatrol'] = true; $wgGroupPermissions['sysop']['protect'] = true; diff --git a/includes/Title.php b/includes/Title.php index 7f1179e5c2..36d0f2ce9c 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1221,8 +1221,43 @@ class Title { ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) ) ) { $errors[] = $user->isAnon() ? array ('nocreatetext') : array ('nocreate-loggedin'); } - } elseif( $action == 'move' && !( $this->isMovable() && $user->isAllowed( 'move' ) ) ) { - $errors[] = $user->isAnon() ? array ( 'movenologintext' ) : array ('movenotallowed'); + + } elseif ( $action == 'move' ) { + if ( !$user->isAllowed( 'move' ) ) { + // User can't move anything + $errors[] = $user->isAnon() ? array ( 'movenologintext' ) : array ('movenotallowed'); + } elseif ( !$user->isAllowed( 'move-rootuserpages' ) + && $this->getNamespace() == NS_USER && !$this->isSubpage() ) + { + // Show user page-specific message only if the user can move other pages + $errors[] = array( 'cant-move-user-page' ); + } + + // Check for immobile pages + if ( !MWNamespace::isMovable( $this->getNamespace() ) ) { + // Specific message for this case + $errors[] = array( 'immobile-source-namespace', $this->getNsText() ); + } elseif ( !$this->isMovable() ) { + // Less specific message for rarer cases + $errors[] = array( 'immobile-page' ); + } + + } elseif ( $action == 'move-target' ) { + if ( !$user->isAllowed( 'move' ) ) { + // User can't move anything + $errors[] = $user->isAnon() ? array ( 'movenologintext' ) : array ('movenotallowed'); + } elseif ( !$user->isAllowed( 'move-rootuserpages' ) + && $this->getNamespace() == NS_USER && !$this->isSubpage() ) + { + // Show user page-specific message only if the user can move other pages + $errors[] = array( 'cant-move-to-user-page' ); + } + if ( !MWNamespace::isMovable( $this->getNamespace() ) ) { + $errors[] = array( 'immobile-target-namespace', $this->getNsText() ); + } elseif ( !$this->isMovable() ) { + $errors[] = array( 'immobile-target-page' ); + } + } elseif ( !$user->isAllowed( $action ) ) { $return = null; $groups = array_map( array( 'User', 'makeGroupLinkWiki' ), @@ -2380,6 +2415,8 @@ class Title { * @return \type{\mixed} True on success, getUserPermissionsErrors()-like array on failure */ public function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) { + global $wgUser; + $errors = array(); if( !$nt ) { // Normally we'd add this to $errors, but we'll get @@ -2389,8 +2426,11 @@ class Title { if( $this->equals( $nt ) ) { $errors[] = array('selfmove'); } - if( !$this->isMovable() || !$nt->isMovable() ) { - $errors[] = array('immobile_namespace'); + if( !$this->isMovable() ) { + $errors[] = array( 'immobile-source-namespace', $this->getNsText() ); + } + if ( !$nt->isMovable() ) { + $errors[] = array('immobile-target-namespace', $nt->getNsText() ); } $oldid = $this->getArticleID(); @@ -2422,11 +2462,10 @@ class Title { } if ( $auth ) { - global $wgUser; $errors = wfArrayMerge($errors, $this->getUserPermissionsErrors('move', $wgUser), $this->getUserPermissionsErrors('edit', $wgUser), - $nt->getUserPermissionsErrors('move', $wgUser), + $nt->getUserPermissionsErrors('move-target', $wgUser), $nt->getUserPermissionsErrors('edit', $wgUser)); } @@ -2436,7 +2475,6 @@ class Title { $errors[] = array('spamprotectiontext'); } - global $wgUser; $err = null; if( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err, $reason ) ) ) { $errors[] = array('hookaborted', $err); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index e94c2ba583..0b1b11d8b4 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2660,7 +2660,11 @@ please be sure you understand the consequences of this before proceeding.", In those cases, you will have to move or merge the page manually if desired.", 'movearticle' => 'Move page:', +'movenologin' => 'Not logged in', +'movenologintext' => 'You must be a registered user and [[Special:Userlogin|logged in]] to move a page.', 'movenotallowed' => 'You do not have permission to move pages.', +'cant-move-user-page' => 'You do not have permission to move user pages (apart from subpages).', +'cant-move-to-user-page' => 'You do not have permission to move a page to a user page (except to a user subpage).', 'newtitle' => 'To new title:', 'move-watch' => 'Watch this page', 'movepagebtn' => 'Move page', @@ -2693,8 +2697,10 @@ Do you want to delete it to make way for the move?', 'delete_and_move_reason' => 'Deleted to make way for move', 'selfmove' => 'Source and destination titles are the same; cannot move a page over itself.', -'immobile_namespace' => 'Source or destination title is of a special type; -cannot move pages from and into that namespace.', +'immobile-source-namespace' => 'Cannot move pages in namespace "$1"', +'immobile-target-namespace' => 'Cannot move pages into namespace "$1"', +'immobile-source-page' => 'This page is not movable.', +'immobile-target-page' => 'Cannot move to that destination title.', 'imagenocrossnamespace' => 'Cannot move file to non-file namespace', 'imagetypemismatch' => 'The new file extension does not match its type', 'imageinvalidfilename' => 'The target file name is invalid', -- 2.20.1