* fix last commit so quickUserCan() actually skips the cascading query
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 13 Jan 2007 03:22:20 +0000 (03:22 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 13 Jan 2007 03:22:20 +0000 (03:22 +0000)
* 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

includes/Parser.php
includes/ParserCache.php
includes/SkinTemplate.php
includes/Title.php

index 3a9db6d..d6f0570 100644 (file)
@@ -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();
index b8e43e9..3d7bdb4 100644 (file)
@@ -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 {
index 1308868..f2c7d61 100644 (file)
@@ -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,
index c2d2262..2fafcb7 100644 (file)
@@ -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;