From e18deb56526d5fef47bda009de611ea35cf06f24 Mon Sep 17 00:00:00 2001 From: Daniel Cannon Date: Sat, 7 Jul 2007 04:18:44 +0000 Subject: [PATCH] If the user is unable to edit a page because the namespace is protected, rather than the page itself, show a different message--namely, namespaceprotectedtext. --- includes/OutputPage.php | 9 ++++++++ includes/Title.php | 38 +++++++++++++++++++++++-------- languages/messages/MessagesEn.php | 3 ++- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 3ea6e3378b..0ca713b69b 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -979,6 +979,15 @@ class OutputPage { $notice = wfMsgExt( 'cascadeprotected', array('parsemag'), count($cascadeSources) ) . "\n$titles"; $this->addWikiText( $notice ); + } else if ( $wgTitle->isNamespaceProtected() ) { + global $wgNamespaceProtection; + + $ns = ($wgTitle->getNamespace() == NS_MAIN) + ?wfMsg('nstab-main') + :$wgTitle->getNsText(); + + $this->addWikiText( wfMsg( 'namespaceprotectedtext', $ns, + implode( ',', $wgNamespaceProtection[$wgTitle->getNamespace()] ) ) ); } else { $this->addWikiText( wfMsg( 'protectedpagetext' ) ); } diff --git a/includes/Title.php b/includes/Title.php index d089d8ac7f..37815eb678 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -995,6 +995,31 @@ class Title { return $this->userCan( $action, false ); } + /** + * Determines if $wgUser is unable to edit this page because it has been protected + * by $wgNamespaceProtection. + * + * @return boolean + */ + public function isNamespaceProtected( ) { + global $wgNamespaceProtection, $wgUser; + + $fname = 'Title::isNamespaceProtected'; + + if ( array_key_exists( $this->mNamespace, $wgNamespaceProtection ) ) { + $nsProt = $wgNamespaceProtection[ $this->mNamespace ]; + if ( !is_array($nsProt) ) $nsProt = array($nsProt); + foreach( $nsProt as $right ) { + if( '' != $right && !$wgUser->isAllowed( $right ) ) { + wfProfileOut( $fname ); + return true; + } + } + } + + return false; + } + /** * Can $wgUser perform $action on this page? * @param string $action action that permission needs to be checked for @@ -1005,7 +1030,7 @@ class Title { $fname = 'Title::userCan'; wfProfileIn( $fname ); - global $wgUser, $wgNamespaceProtection; + global $wgUser; $result = null; wfRunHooks( 'userCan', array( &$this, &$wgUser, $action, &$result ) ); @@ -1019,15 +1044,8 @@ class Title { return false; } - if ( array_key_exists( $this->mNamespace, $wgNamespaceProtection ) ) { - $nsProt = $wgNamespaceProtection[ $this->mNamespace ]; - if ( !is_array($nsProt) ) $nsProt = array($nsProt); - foreach( $nsProt as $right ) { - if( '' != $right && !$wgUser->isAllowed( $right ) ) { - wfProfileOut( $fname ); - return false; - } - } + if ( $this->isNamespaceProtected() ) { + return false; } if( $this->mDbkeyform == '_' ) { diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 89f70faf42..18b4d5e8e4 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -785,6 +785,7 @@ Query: $2', 'editinginterface' => "'''Warning:''' You are editing a page which is used to provide interface text for the software. Changes to this page will affect the appearance of the user interface for other users.", 'sqlhidden' => '(SQL query hidden)', 'cascadeprotected' => 'This page has been protected from editing, because it is included in the following {{PLURAL:$1|page|pages}}, which are protected with the "cascading" option turned on:', +'namespaceprotectedtext'=>'Because this page resides in the $1 namespace, editing of it has been restricted to users with the rights "$2". Please [[Special:Userlogin|log-in]] or contact an administrator to request permission to edit it.', # Login and logout pages 'logouttitle' => 'User logout', @@ -2913,4 +2914,4 @@ $1', 'watchlistedit-raw-added' => '{{PLURAL:$1|1 title was|$1 titles were}} added:', 'watchlistedit-raw-removed' => '{{PLURAL:$1|1 title was|$1 titles were}} removed:', -); \ No newline at end of file +); -- 2.20.1