From 5a30eadb0eff3bdc90229d13909af8d84a65c1ed Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 5 Dec 2005 05:37:10 +0000 Subject: [PATCH] * Add createpage and createtalk permission keys, allowing a quick switch to disable page creation for anonymous users. Jimmy requested we have this ability available. --- RELEASE-NOTES | 2 ++ includes/DefaultSettings.php | 4 ++++ includes/EditPage.php | 19 +++++++++++++++++++ includes/Title.php | 7 +++++++ languages/Language.php | 3 +++ 5 files changed, 35 insertions(+) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index b13845e0a2..843c5eb9be 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -292,6 +292,8 @@ fully support the editing toolbar, but was found to be too confusing. * (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 === diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index f4e602770c..35483d47a5 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -771,10 +771,14 @@ $wgGroupPermissions = array(); $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; diff --git a/includes/EditPage.php b/includes/EditPage.php index 8c73af6ea9..d6d714d794 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -202,6 +202,12 @@ class EditPage { 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 @@ class EditPage { # 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 @@ END return strtr( $result, array( "�" => "&#x" ) ); } + function noCreatePermission() { + global $wgOut; + $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) ); + $wgOut->addWikiText( wfMsg( 'nocreatetext' ) ); + } } diff --git a/includes/Title.php b/includes/Title.php index 433187e1d4..0d5d1c7414 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -906,6 +906,13 @@ class Title { wfProfileOut( $fname ); return false; } + + if( $action == 'create' ) { + if( ( $this->isTalkPage() && !$wgUser->isAllowed( 'createtalk' ) ) || + ( !$this->isTalkPage() && !$wgUser->isAllowed( 'createpage' ) ) ) { + return false; + } + } wfProfileOut( $fname ); return true; diff --git a/languages/Language.php b/languages/Language.php index 743b744ae0..e5ab125c6b 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -785,6 +785,9 @@ the text into a text file and save it for later.', 'protectedpagewarning' => "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]].", 'templatesused' => 'Templates used on this page:', 'edittools' => '', +'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 # -- 2.20.1