Jump to: navigation, search

Obsolete

These patches have been functionally replaced by the EditSubPages extension. Their original function is described in an old revision of the parent article. Both need to be applied for the described behaviour to take effect. A version of the patch for earlier versions of MediaWiki (1.6.5) is also available.

EditPage.php

This patch was prepared against MediaWiki 1.9.2.

--- EditPage.php.orig	2007-02-05 10:14:58.000000000 +1100
+++ EditPage.php	2007-02-10 19:26:14.000000000 +1100
@@ -280,7 +280,7 @@
 	 */
 	function edit() {
 		global $wgOut, $wgUser, $wgRequest, $wgTitle;
-		global $wgEmailConfirmToEdit;
+		global $wgEmailConfirmToEdit, $wgGroupPermissions;
 
 		if ( ! wfRunHooks( 'AlternateEdit', array( &$this  ) ) )
 			return;
@@ -303,21 +303,10 @@
 
 		if ( ! $this->mTitle->userCanEdit() ) {
 			wfDebug( "$fname: user can't edit\n" );
-			$wgOut->readOnlyPage( $this->getContent(), true );
-			wfProfileOut( $fname );
-			return;
-		}
-		wfDebug( "$fname: Checking blocks\n" );
-		if ( !$this->preview && !$this->diff && $wgUser->isBlockedFrom( $this->mTitle, !$this->save ) ) {
-			# When previewing, don't check blocked state - will get caught at save time.
-			# Also, check when starting edition is done against slave to improve performance.
-			wfDebug( "$fname: user is blocked\n" );
-			$this->blockedPage();
-			wfProfileOut( $fname );
-			return;
-		}
-		if ( !$wgUser->isAllowed('edit') ) {
-			if ( $wgUser->isAnon() ) {
+			if ( !$wgUser->isAllowed('edit') && $wgUser->isAnon() &&
+			  $wgGroupPermissions['user' ]['edit'] &&
+			  !array_diff($this->mTitle->getRestrictions('edit'),
+			     array('*', 'user')) ) {
 				wfDebug( "$fname: user must log in\n" );
 				$this->userNotLoggedInPage();
 				wfProfileOut( $fname );
@@ -329,6 +318,16 @@
 				return;
 			}
 		}
+		wfDebug( "$fname: Checking blocks\n" );
+		if ( !$this->preview && !$this->diff && $wgUser->isBlockedFrom( $this->mTitle, !$this->save ) ) {
+			# When previewing, don't check blocked state - will get caught at save time.
+			# Also, check when starting edition is done against slave to improve performance.
+			wfDebug( "$fname: user is blocked\n" );
+			$this->blockedPage();
+			wfProfileOut( $fname );
+			return;
+		}
+
 		if ($wgEmailConfirmToEdit && !$wgUser->isEmailConfirmed()) {
 			wfDebug("$fname: user must confirm e-mail address\n");
 			$this->userNotConfirmedPage();
@@ -653,14 +652,16 @@
 			return true;
 		}
 
-		if ( !$wgUser->isAllowed('edit') ) {
-			if ( $wgUser->isAnon() ) {
+		if ( ! $this->mTitle->userCanEdit() ) {
+			if ( !$wgUser->isAllowed('edit') && $wgUser->isAnon() &&
+			  $wgGroupPermissions['user' ]['edit'] &&
+			  !array_diff($this->mTitle->getRestrictions('edit'),
+			    array('*', 'user')) ) {
 				$this->userNotLoggedInPage();
 				wfProfileOut( "$fname-checks" );
 				wfProfileOut( $fname );
 				return false;
-			}
-			else {
+			} else {
 				$wgOut->readOnlyPage();
 				wfProfileOut( "$fname-checks" );
 				wfProfileOut( $fname );
 

Title.php

This patch was also prepared against MediaWiki 1.9.2.

--- Title.php.orig	2007-02-05 10:14:59.000000000 +1100
+++ Title.php	2007-02-10 19:13:10.000000000 +1100
@@ -1033,7 +1033,8 @@
 
 		if( $action == 'edit' || $action == '' ) {
 			$r = $this->getRestrictions( 'edit' );
-			foreach( $wgRestrictionLevels as $level ) {
+			if (in_array('*', $r)) {
+			} else foreach( $wgRestrictionLevels as $level ) {
 				if( in_array( $level, $r ) && $level != '' ) {
 					return( true );
 				}
@@ -1042,7 +1043,8 @@
 
 		if( $action == 'move' || $action == '' ) {
 			$r = $this->getRestrictions( 'move' );
-			foreach( $wgRestrictionLevels as $level ) {
+			if (in_array('*', $r)) {
+			} else foreach( $wgRestrictionLevels as $level ) {
 				if( in_array( $level, $r ) && $level != '' ) {
 					return( true );
 				}
@@ -1117,17 +1119,6 @@
 			return false;
 		}
 
-		foreach( $this->getRestrictions($action) as $right ) {
-			// Backwards compatibility, rewrite sysop -> protect
-			if ( $right == 'sysop' ) {
-				$right = 'protect';
-			}
-			if( '' != $right && !$wgUser->isAllowed( $right ) ) {
-				wfProfileOut( $fname );
-				return false;
-			}
-		}
-
 		if( $action == 'move' &&
 			!( $this->isMovable() && $wgUser->isAllowed( 'move' ) ) ) {
 			wfProfileOut( $fname );
@@ -1135,11 +1126,16 @@
 		}
 
 		if( $action == 'create' ) {
-			if( (  $this->isTalkPage() && !$wgUser->isAllowed( 'createtalk' ) ) ||
-				( !$this->isTalkPage() && !$wgUser->isAllowed( 'createpage' ) ) ) {
-				wfProfileOut( $fname );
-				return false;
-			}
+			$action .= $this->isTalkPage() ? 'talk' : 'page';
+		}
+
+		# Must come after the 'create' mapping
+		$rGroups = $this->getRestrictions($action);
+		$eGroups = $wgUser->getEffectiveGroups();
+		if ( (($rGroups && !array_intersect($rGroups, $eGroups)) ||
+		  !$wgUser->isAllowed($action)) && !in_array('*', $rGroups) ) {
+			wfProfileOut( $fname );
+			return false;
 		}
 
 		wfProfileOut( $fname );
@@ -1328,8 +1324,10 @@
 			$temp = explode( '=', trim( $restrict ) );
 			if(count($temp) == 1) {
 				// old format should be treated as edit/move restriction
-				$this->mRestrictions["edit"] = explode( ',', trim( $temp[0] ) );
-				$this->mRestrictions["move"] = explode( ',', trim( $temp[0] ) );
+				if ($temp[0] != '') {
+					$this->mRestrictions["edit"] = explode( ',', trim( $temp[0] ) );
+					$this->mRestrictions["move"] = explode( ',', trim( $temp[0] ) );
+				}
 			} else {
 				$this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) );
 			}
 
Personal tools