r78338 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78337‎ | r78338 | r78339 >
Date:22:33, 13 December 2010
Author:ialex
Status:ok
Tags:
Comment:
Checking namespace restriction with $wgUser while calling Title::getUserPermissionsErrors() with anoter User object is really not a good idea
Modified paths:
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -1142,16 +1142,23 @@
11431143 }
11441144
11451145 /**
1146 - * Determines if $wgUser is unable to edit this page because it has been protected
 1146+ * Determines if $user is unable to edit this page because it has been protected
11471147 * by $wgNamespaceProtection.
11481148 *
 1149+ * @param $user User object, $wgUser will be used if not passed
11491150 * @return \type{\bool}
11501151 */
1151 - public function isNamespaceProtected() {
1152 - global $wgNamespaceProtection, $wgUser;
 1152+ public function isNamespaceProtected( User $user = null ) {
 1153+ global $wgNamespaceProtection;
 1154+
 1155+ if ( $user === null ) {
 1156+ global $wgUser;
 1157+ $user = $wgUser;
 1158+ }
 1159+
11531160 if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
11541161 foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
1155 - if ( $right != '' && !$wgUser->isAllowed( $right ) ) {
 1162+ if ( $right != '' && !$user->isAllowed( $right ) ) {
11561163 return true;
11571164 }
11581165 }
@@ -1352,7 +1359,7 @@
13531360 }
13541361
13551362 # Check $wgNamespaceProtection for restricted namespaces
1356 - if ( $this->isNamespaceProtected() ) {
 1363+ if ( $this->isNamespaceProtected( $user ) ) {
13571364 $ns = $this->mNamespace == NS_MAIN ?
13581365 wfMsg( 'nstab-main' ) : $this->getNsText();
13591366 $errors[] = $this->mNamespace == NS_MEDIAWIKI ?

Status & tagging log