From: Brion Vibber Date: Wed, 27 Oct 2004 07:37:35 +0000 (+0000) Subject: Some legibility cleanup; remove some debug code; make the Special:Userlogin special... X-Git-Tag: 1.5.0alpha1~1442 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=ce9e97429b5ec7bc0d9b66077253afc07a1a3b9d;p=lhc%2Fweb%2Fwiklou.git Some legibility cleanup; remove some debug code; make the Special:Userlogin special case work in non-English non-French wikis --- diff --git a/includes/Title.php b/includes/Title.php index 4b29f113f2..ef00872cea 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -754,28 +754,37 @@ class Title { */ function userCanEdit() { global $wgUser; - if ( -1 == $this->mNamespace ) { return false; } - if ( NS_MEDIAWIKI == $this->mNamespace && !$wgUser->isAllowed('editinterface') ) { return false; } - # if ( 0 == $this->getArticleID() ) { return false; } - if ( $this->mDbkeyform == '_' ) { return false; } + if( NS_SPECIAL == $this->mNamespace ) { + return false; + } + if( NS_MEDIAWIKI == $this->mNamespace && + !$wgUser->isAllowed('editinterface') ) { + return false; + } + if( $this->mDbkeyform == '_' ) { + # FIXME: Is this necessary? Shouldn't be allowed anyway... + return false; + } + # protect global styles and js if ( NS_MEDIAWIKI == $this->mNamespace - && preg_match("/\\.(css|js)$/", $this->mTextform ) - && !$wgUser->isAllowed('editinterface') ) - { return false; } - //if ( $this->isCssJsSubpage() and !$this->userCanEditCssJsSubpage() ) { return false; } + && preg_match("/\\.(css|js)$/", $this->mTextform ) + && !$wgUser->isAllowed('editinterface') ) { + return false; + } + # protect css/js subpages of user pages # XXX: this might be better using restrictions # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working - if( Namespace::getUser() == $this->mNamespace - and preg_match("/\\.(css|js)$/", $this->mTextform ) - and !$wgUser->isAllowed('editinterface') - and !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) ) - { return false; } - $ur = $wgUser->getRights(); - - foreach ( $this->getRestrictions() as $r ) { - if ( '' != $r && ( ! in_array( $r, $ur ) ) ) { + if( NS_USER == $this->mNamespace + && preg_match("/\\.(css|js)$/", $this->mTextform ) + && !$wgUser->isAllowed('editinterface') + && !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) ) { + return false; + } + + foreach( $this->getRestrictions() as $right ) { + if( '' != $right && !$wgUser->isAllowed( $right ) ) { return false; } } @@ -789,26 +798,31 @@ class Title { */ function userCanRead() { global $wgUser; - global $wgWhitelistRead; - if($wgUser->isAllowed('read')) { + if( $wgUser->isAllowed('read') ) { return true; } else { - $name = $this->getPrefixedText(); - - /** user can create an account */ - if($wgUser->isAllowed('createaccount') - && $name == 'Special:Userlogin') { return true; } - else { - echo $name; - print_r($wgUser->getRights()); - } + global $wgWhitelistRead; + + /** If anon users can create an account, + they need to reach the login page first! */ + if( $wgUser->isAllowed( 'createaccount' ) + && $this->mId == NS_SPECIAL + && $this->getText() == 'Userlogin' ) { + return true; + } /** some pages are explicitly allowed */ - if( in_array( $name, $wgWhitelistRead ) ) return true; + $name = $this->getPrefixedText(); + if( in_array( $name, $wgWhitelistRead ) ) { + return true; + } + # Compatibility with old settings if( $this->getNamespace() == NS_MAIN ) { - if( in_array( ':' . $name, $wgWhitelistRead ) ) return true; + if( in_array( ':' . $name, $wgWhitelistRead ) ) { + return true; + } } } return false;