From bfe73169d95640973e703e89d311cc20593cedb9 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Mon, 13 Dec 2010 22:33:08 +0000 Subject: [PATCH] Checking namespace restriction with $wgUser while calling Title::getUserPermissionsErrors() with anoter User object is really not a good idea --- includes/Title.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index 2a1f412e37..5924b1d474 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1142,16 +1142,23 @@ class Title { } /** - * Determines if $wgUser is unable to edit this page because it has been protected + * Determines if $user is unable to edit this page because it has been protected * by $wgNamespaceProtection. * + * @param $user User object, $wgUser will be used if not passed * @return \type{\bool} */ - public function isNamespaceProtected() { - global $wgNamespaceProtection, $wgUser; + public function isNamespaceProtected( User $user = null ) { + global $wgNamespaceProtection; + + if ( $user === null ) { + global $wgUser; + $user = $wgUser; + } + if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) { foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) { - if ( $right != '' && !$wgUser->isAllowed( $right ) ) { + if ( $right != '' && !$user->isAllowed( $right ) ) { return true; } } @@ -1352,7 +1359,7 @@ class Title { } # Check $wgNamespaceProtection for restricted namespaces - if ( $this->isNamespaceProtected() ) { + if ( $this->isNamespaceProtected( $user ) ) { $ns = $this->mNamespace == NS_MAIN ? wfMsg( 'nstab-main' ) : $this->getNsText(); $errors[] = $this->mNamespace == NS_MEDIAWIKI ? -- 2.20.1