MediaWiki r11973 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r11972‎ | r11973 (on ViewVC)‎ | r11974 >
Date:05:37, 5 December 2005
Author:vibber
Status:old
Tags:
Comment:
* Add createpage and createtalk permission keys, allowing a quick
switch to disable page creation for anonymous users.
Jimmy requested we have this ability available.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
===================================================================
--- trunk/phase3/includes/EditPage.php	(revision 11972)
+++ trunk/phase3/includes/EditPage.php	(revision 11973)
@@ -202,6 +202,12 @@
 				return;
 			}
 		}
+		if ( !$this->mTitle->userCan( 'create' ) && !$this->mTitle->exists() ) {
+			wfDebug( "$fname: no create permission\n" );
+			$this->noCreatePermission();
+			wfProfileOut( $fname );
+			return;
+		}
 		if ( wfReadOnly() ) {
 			wfDebug( "$fname: read-only mode is engaged\n" );
 			if( $this->save || $this->preview ) {
@@ -513,6 +519,14 @@
 		# If article is new, insert it.
 		$aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
 		if ( 0 == $aid ) {
+			// Late check for create permission, just in case *PARANOIA*
+			if ( !$this->mTitle->userCan( 'create' ) ) {
+				wfDebug( "$fname: no create permission\n" );
+				$this->noCreatePermission();
+				wfProfileOut( $fname );
+				return;
+			}
+			
 			# Don't save a new article if it's blank.
 			if ( ( '' == $this->textbox1 ) ) {
 					$wgOut->redirect( $this->mTitle->getFullURL() );
@@ -1527,6 +1541,11 @@
 		return strtr( $result, array( "&#x0" => "&#x" ) );
 	}
 	
+	function noCreatePermission() {
+		global $wgOut;
+		$wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
+		$wgOut->addWikiText( wfMsg( 'nocreatetext' ) );
+	}
 
 }
 
Index: trunk/phase3/includes/Title.php
===================================================================
--- trunk/phase3/includes/Title.php	(revision 11972)
+++ trunk/phase3/includes/Title.php	(revision 11973)
@@ -906,6 +906,13 @@
 			wfProfileOut( $fname );
 			return false;
 		}
+		
+		if( $action == 'create' ) {
+			if( (  $this->isTalkPage() && !$wgUser->isAllowed( 'createtalk' ) ) ||
+				( !$this->isTalkPage() && !$wgUser->isAllowed( 'createpage' ) ) ) {
+				return false;
+			}
+		}
 
 		wfProfileOut( $fname );
 		return true;
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 11972)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 11973)
@@ -771,10 +771,14 @@
 $wgGroupPermissions['*'    ]['createaccount']   = true;
 $wgGroupPermissions['*'    ]['read']            = true;
 $wgGroupPermissions['*'    ]['edit']            = true;
+$wgGroupPermissions['*'    ]['createpage']      = true;
+$wgGroupPermissions['*'    ]['createtalk']      = true;
 
 $wgGroupPermissions['user' ]['move']            = true;
 $wgGroupPermissions['user' ]['read']            = true;
 $wgGroupPermissions['user' ]['edit']            = true;
+$wgGroupPermissions['user' ]['createpage']      = true;
+$wgGroupPermissions['user' ]['createtalk']      = true;
 $wgGroupPermissions['user' ]['upload']          = true;
 $wgGroupPermissions['user' ]['reupload']        = true;
 $wgGroupPermissions['user' ]['reupload-shared'] = true;
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 11972)
+++ trunk/phase3/RELEASE-NOTES	(revision 11973)
@@ -292,6 +292,8 @@
 * (bug 4162) Add $wgThumbnailEpoch timestamp to force old thumbs to
   be rerendered on demand, sitewide
 * (bug 4165) Correct validation for user language selection (data taint)
+* Add createpage and createtalk permission keys, allowing a quick
+  switch to disable page creation for anonymous users.
 
 
 === Caveats ===
Index: trunk/phase3/languages/Language.php
===================================================================
--- trunk/phase3/languages/Language.php	(revision 11972)
+++ trunk/phase3/languages/Language.php	(revision 11973)
@@ -785,6 +785,9 @@
 'protectedpagewarning' => "<strong>WARNING:  This page has been locked so that only users with sysop privileges can edit it. Be sure you are following the [[Project:Protected_page_guidelines|protected page guidelines]].</strong>",
 'templatesused'	=> 'Templates used on this page:',
 'edittools' => '<!-- Text here will be shown below edit and upload forms. -->',
+'nocreatetitle' => 'Page creation limited',
+'nocreatetext' => 'This site has restricted the ability to create new pages.
+You can go back and edit an existing page, or [[Special:Userlogin|log in or create an account]].',
 
 # History pages
 #

Status & tagging log

  • 01:58, 13 October 2010 ^demon (Talk | contribs) changed the status of r11973 [removed: new added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox