Possibly partial patch to make userCanEdit avoid running cascade-protection queries...
authorAndrew Garrett <werdna@users.mediawiki.org>
Sat, 13 Jan 2007 02:37:02 +0000 (02:37 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Sat, 13 Jan 2007 02:37:02 +0000 (02:37 +0000)
includes/Parser.php
includes/ParserCache.php
includes/SkinTemplate.php
includes/Title.php

index ff1b757..3a9db6d 100644 (file)
@@ -3395,7 +3395,7 @@ class Parser
                global $wgMaxTocLevel, $wgContLang;
 
                $doNumberHeadings = $this->mOptions->getNumberHeadings();
-               if( !$this->mTitle->userCanEdit() ) {
+               if( !$this->mTitle->quickUserCanEdit() ) {
                        $showEditLink = 0;
                } else {
                        $showEditLink = $this->mOptions->getEditSection();
index 37a42b7..b8e43e9 100644 (file)
@@ -35,7 +35,7 @@ class ParserCache {
        function getKey( &$article, &$user ) {
                global $action;
                $hash = $user->getPageRenderingHash();
-               if( !$article->mTitle->userCanEdit() ) {
+               if( !$article->mTitle->quickUserCanEdit() ) {
                        // section edit links are suppressed even if the user has them on
                        $edit = '!edit=0';
                } else {
index 015b8ca..1308868 100644 (file)
@@ -664,7 +664,7 @@ class SkinTemplate extends Skin {
                                true);
 
                        wfProfileIn( "$fname-edit" );
-                       if ( $this->mTitle->userCanEdit() && ( $this->mTitle->exists() || $this->mTitle->userCanCreate() ) ) {
+                       if ( $this->mTitle->quickUserCanEdit() && ( $this->mTitle->exists() || $this->mTitle->userCanCreate( false ) ) ) {
                                $istalk = $this->mTitle->isTalkPage();
                                $istalkclass = $istalk?' istalk':'';
                                $content_actions['edit'] = array(
index 5a3aec0..10fd9a3 100644 (file)
@@ -1077,16 +1077,23 @@ class Title {
                return $this->mWatched;
        }
 
+       function quickUserCan( $action ) {
+               return $this->userCan( $action, false );
+       }
+
        /**
         * Can $wgUser perform $action 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) {
+       function userCan( $action, $doExpensiveQueries = true ) {
                $fname = 'Title::userCan';
                wfProfileIn( $fname );
 
+               !$doExpensiveQueries or die(wfBacktrace() );
+
                global $wgUser, $wgNamespaceProtection;
 
                $result = null;
@@ -1172,8 +1179,12 @@ class Title {
         * @return boolean
         * @access public
         */
-       function userCanEdit() {
-               return $this->userCan('edit');
+       function userCanEdit( $doExpensiveQueries = true ) {
+               return $this->userCan( 'edit', $doExpensiveQueries );
+       }
+
+       function quickUserCanEdit( ) {
+               return $this->userCanEdit( false );
        }
 
        /**
@@ -1181,8 +1192,8 @@ class Title {
         * @return boolean
         * @access public
         */
-       function userCanCreate() {
-               return $this->userCan('create');
+       function userCanCreate( $doExpensiveQueries = true ) {
+               return $this->userCan( 'create', $doExpensiveQueries );
        }
 
        /**
@@ -1190,8 +1201,8 @@ class Title {
         * @return boolean
         * @access public
         */
-       function userCanMove() {
-               return $this->userCan('move');
+       function userCanMove( $doExpensiveQueries = true ) {
+               return $this->userCan( 'move', $doExpensiveQueries );
        }
 
        /**