r41961 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r41960 | r41961 (on ViewVC) | r41962 >
Date:08:26, 11 October 2008
Author:tstarling
Status:ok (Comments)
Tags:
Comment:* 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.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/Title.php
===================================================================
--- trunk/phase3/includes/Title.php	(revision 41960)
+++ trunk/phase3/includes/Title.php	(revision 41961)
@@ -1221,8 +1221,43 @@
 				( !$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 @@
 	 * @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,9 +2426,12 @@
 		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();
 		$newid = $nt->getArticleID();
@@ -2422,11 +2462,10 @@
 		}
 
 		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 @@
 			$errors[] = array('spamprotectiontext');
 		}
 		
-		global $wgUser;
 		$err = null;
 		if( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err, $reason ) ) ) {
 			$errors[] = array('hookaborted', $err);
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 41960)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 41961)
@@ -1128,6 +1128,7 @@
 // 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']['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;
Index: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php	(revision 41960)
+++ trunk/phase3/languages/messages/MessagesEn.php	(revision 41961)
@@ -2660,7 +2660,11 @@
 
 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 @@
 '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',

Follow-up revisions

RevisionCommit summaryAuthorDate
r41963Continuation of r41961: remove this move page hook since I just readded the feat...tstarling08:33, 11 October 2008

Comments

#Comment by Voice of All (Talk | contribs)   18:25, 11 October 2008

Where does move-target come from?

#Comment by Brion VIBBER (Talk | contribs)   02:47, 13 October 2008

Title::isValidMoveOperation() uses separate actions for the move source and move target when building up the permission/error checks:

			$errors = wfArrayMerge($errors, 
					$this->getUserPermissionsErrors('move', $wgUser),
					$this->getUserPermissionsErrors('edit', $wgUser),
					$nt->getUserPermissionsErrors('move-target', $wgUser),
					$nt->getUserPermissionsErrors('edit', $wgUser));
Views
Toolbox