r23821 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23820‎ | r23821 | r23822 >
Date:04:18, 7 July 2007
Author:amidaniel
Status:old
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -979,6 +979,15 @@
980980 $notice = wfMsgExt( 'cascadeprotected', array('parsemag'), count($cascadeSources) ) . "\n$titles";
981981
982982 $this->addWikiText( $notice );
 983+ } else if ( $wgTitle->isNamespaceProtected() ) {
 984+ global $wgNamespaceProtection;
 985+
 986+ $ns = ($wgTitle->getNamespace() == NS_MAIN)
 987+ ?wfMsg('nstab-main')
 988+ :$wgTitle->getNsText();
 989+
 990+ $this->addWikiText( wfMsg( 'namespaceprotectedtext', $ns,
 991+ implode( ',', $wgNamespaceProtection[$wgTitle->getNamespace()] ) ) );
983992 } else {
984993 $this->addWikiText( wfMsg( 'protectedpagetext' ) );
985994 }
Index: trunk/phase3/includes/Title.php
@@ -995,6 +995,31 @@
996996 return $this->userCan( $action, false );
997997 }
998998
 999+ /**
 1000+ * Determines if $wgUser is unable to edit this page because it has been protected
 1001+ * by $wgNamespaceProtection.
 1002+ *
 1003+ * @return boolean
 1004+ */
 1005+ public function isNamespaceProtected( ) {
 1006+ global $wgNamespaceProtection, $wgUser;
 1007+
 1008+ $fname = 'Title::isNamespaceProtected';
 1009+
 1010+ if ( array_key_exists( $this->mNamespace, $wgNamespaceProtection ) ) {
 1011+ $nsProt = $wgNamespaceProtection[ $this->mNamespace ];
 1012+ if ( !is_array($nsProt) ) $nsProt = array($nsProt);
 1013+ foreach( $nsProt as $right ) {
 1014+ if( '' != $right && !$wgUser->isAllowed( $right ) ) {
 1015+ wfProfileOut( $fname );
 1016+ return true;
 1017+ }
 1018+ }
 1019+ }
 1020+
 1021+ return false;
 1022+ }
 1023+
9991024 /**
10001025 * Can $wgUser perform $action on this page?
10011026 * @param string $action action that permission needs to be checked for
@@ -1005,7 +1030,7 @@
10061031 $fname = 'Title::userCan';
10071032 wfProfileIn( $fname );
10081033
1009 - global $wgUser, $wgNamespaceProtection;
 1034+ global $wgUser;
10101035
10111036 $result = null;
10121037 wfRunHooks( 'userCan', array( &$this, &$wgUser, $action, &$result ) );
@@ -1019,15 +1044,8 @@
10201045 return false;
10211046 }
10221047
1023 - if ( array_key_exists( $this->mNamespace, $wgNamespaceProtection ) ) {
1024 - $nsProt = $wgNamespaceProtection[ $this->mNamespace ];
1025 - if ( !is_array($nsProt) ) $nsProt = array($nsProt);
1026 - foreach( $nsProt as $right ) {
1027 - if( '' != $right && !$wgUser->isAllowed( $right ) ) {
1028 - wfProfileOut( $fname );
1029 - return false;
1030 - }
1031 - }
 1048+ if ( $this->isNamespaceProtected() ) {
 1049+ return false;
10321050 }
10331051
10341052 if( $this->mDbkeyform == '_' ) {
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -785,6 +785,7 @@
786786 '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.",
787787 'sqlhidden' => '(SQL query hidden)',
788788 '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:',
 789+'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.',
789790
790791 # Login and logout pages
791792 'logouttitle' => 'User logout',
@@ -2913,4 +2914,4 @@
29142915 'watchlistedit-raw-added' => '{{PLURAL:$1|1 title was|$1 titles were}} added:',
29152916 'watchlistedit-raw-removed' => '{{PLURAL:$1|1 title was|$1 titles were}} removed:',
29162917
2917 -);
\ No newline at end of file
 2918+);

Follow-up revisions

RevisionCommit summaryAuthorDate
r23912Merged revisions 23662-23909 via svnmerge from...david18:11, 9 July 2007

Status & tagging log