From: Brion Vibber Date: Sat, 13 Jan 2007 03:22:20 +0000 (+0000) Subject: * fix last commit so quickUserCan() actually skips the cascading query X-Git-Tag: 1.31.0-rc.0~54435 X-Git-Url: http://git.cyclocoop.org/%22.%28%24lien.?a=commitdiff_plain;h=cf506938b5267375b4e16e546f2d21ea6f271846;p=lhc%2Fweb%2Fwiklou.git * fix last commit so quickUserCan() actually skips the cascading query * use quick check for move tab privilege check * drop quickUserCan(Edit|Move|*); just provide one quickUserCan and use the permission keys explicitly. the other (non-quick) funcs are i think deprecated, so marking them so * adjusted some whitespace --- diff --git a/includes/Parser.php b/includes/Parser.php index 3a9db6d933..d6f0570586 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -3395,7 +3395,7 @@ class Parser global $wgMaxTocLevel, $wgContLang; $doNumberHeadings = $this->mOptions->getNumberHeadings(); - if( !$this->mTitle->quickUserCanEdit() ) { + if( !$this->mTitle->quickUserCan( 'edit' ) ) { $showEditLink = 0; } else { $showEditLink = $this->mOptions->getEditSection(); diff --git a/includes/ParserCache.php b/includes/ParserCache.php index b8e43e90d7..3d7bdb4240 100644 --- a/includes/ParserCache.php +++ b/includes/ParserCache.php @@ -35,7 +35,7 @@ class ParserCache { function getKey( &$article, &$user ) { global $action; $hash = $user->getPageRenderingHash(); - if( !$article->mTitle->quickUserCanEdit() ) { + if( !$article->mTitle->quickUserCan( 'edit' ) ) { // section edit links are suppressed even if the user has them on $edit = '!edit=0'; } else { diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 1308868e3d..f2c7d6151c 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -664,7 +664,7 @@ class SkinTemplate extends Skin { true); wfProfileIn( "$fname-edit" ); - if ( $this->mTitle->quickUserCanEdit() && ( $this->mTitle->exists() || $this->mTitle->userCanCreate( false ) ) ) { + if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->userCanCreate( false ) ) ) { $istalk = $this->mTitle->isTalkPage(); $istalkclass = $istalk?' istalk':''; $content_actions['edit'] = array( @@ -721,7 +721,7 @@ class SkinTemplate extends Skin { 'href' => $this->mTitle->getLocalUrl( 'action=delete' ) ); } - if ( $this->mTitle->userCanMove()) { + if ( $this->mTitle->quickUserCan( 'move' ) ) { $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage ); $content_actions['move'] = array( 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false, diff --git a/includes/Title.php b/includes/Title.php index c2d2262f6d..2fafcb7bd7 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1077,18 +1077,29 @@ class Title { return $this->mWatched; } - function quickUserCan( $action ) { + /** + * Can $wgUser perform $action on this page? + * This skips potentially expensive cascading permission checks. + * + * Suitable for use for nonessential UI controls in common cases, but + * _not_ for functional access control. + * + * May provide false positives, but should never provide a false negative. + * + * @param string $action action that permission needs to be checked for + * @return boolean + */ + public function quickUserCan( $action ) { return $this->userCan( $action, false ); } /** - * Can $wgUser perform $action this page? + * Can $wgUser perform $action on this page? * @param string $action action that permission needs to be checked for * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries. * @return boolean - * @private */ - function userCan( $action, $doExpensiveQueries = true ) { + public function userCan( $action, $doExpensiveQueries = true ) { $fname = 'Title::userCan'; wfProfileIn( $fname ); @@ -1105,8 +1116,9 @@ class Title { wfProfileOut( $fname ); return false; } - if ( array_key_exists( $this->mNamespace, $wgNamespaceProtection ) ) { - $nsProt = $wgNamespaceProtection[ $this->mNamespace ]; + + 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 ) ) { @@ -1131,8 +1143,8 @@ class Title { wfProfileOut( $fname ); return false; } - - if ( $this->isCascadeProtected() ) { + + if ( $doExpensiveQueries && $this->isCascadeProtected() ) { # We /could/ use the protection level on the source page, but it's fairly ugly # as we have to establish a precedence hierarchy for pages included by multiple # cascade-protected pages. So just restrict it to people with 'protect' permission, @@ -1175,31 +1187,27 @@ class Title { /** * Can $wgUser edit this page? * @return boolean - * @access public + * @deprecated use userCan('edit') */ - function userCanEdit( $doExpensiveQueries = true ) { + public function userCanEdit( $doExpensiveQueries = true ) { return $this->userCan( 'edit', $doExpensiveQueries ); } - function quickUserCanEdit( ) { - return $this->userCanEdit( false ); - } - /** * Can $wgUser create this page? * @return boolean - * @access public + * @deprecated use userCan('create') */ - function userCanCreate( $doExpensiveQueries = true ) { + public function userCanCreate( $doExpensiveQueries = true ) { return $this->userCan( 'create', $doExpensiveQueries ); } /** * Can $wgUser move this page? * @return boolean - * @access public + * @deprecated use userCan('move') */ - function userCanMove( $doExpensiveQueries = true ) { + public function userCanMove( $doExpensiveQueries = true ) { return $this->userCan( 'move', $doExpensiveQueries ); } @@ -1218,9 +1226,9 @@ class Title { /** * Can $wgUser read this page? * @return boolean - * @access public + * @fixme fold these checks into userCan() */ - function userCanRead() { + public function userCanRead() { global $wgUser; $result = null;