Per talk with Simetrical, add a param to Title::quickUserCan and Title::userCan inste...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Tue, 29 Jul 2008 20:35:11 +0000 (20:35 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Tue, 29 Jul 2008 20:35:11 +0000 (20:35 +0000)
includes/Title.php
includes/parser/Parser.php
includes/parser/ParserCache.php

index 82d480b..825c9ae 100644 (file)
@@ -999,11 +999,12 @@ class Title {
         *
         * May provide false positives, but should never provide a false negative.
         *
-        * @param string $action action that permission needs to be checked for
+        * @param $action String: action that permission needs to be checked for
+        * @param $user User object, optional
         * @return boolean
         */
-       public function quickUserCan( $action ) {
-               return $this->userCan( $action, false );
+       public function quickUserCan( $action, $user = null ) {
+               return $this->userCan( $action, false, $user );
        }
 
        /**
@@ -1025,13 +1026,17 @@ class Title {
 
        /**
         * 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.
+        * @param $action String: action that permission needs to be checked for
+        * @param $doExpensiveQueries Bool: set this to false to avoid doing unnecessary queries.
+        * @param $user User object, optional 
         * @return boolean
         */
-       public function userCan( $action, $doExpensiveQueries = true ) {
-               global $wgUser;
-               return ( $this->getUserPermissionsErrorsInternal( $action, $wgUser, $doExpensiveQueries ) === array());
+       public function userCan( $action, $doExpensiveQueries = true, $user = null ) {
+               if( $user === null ){
+                       global $wgUser;
+                       $user = $wgUser;
+               }
+               return ( $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries ) === array());
        }
 
        /**
@@ -1134,7 +1139,7 @@ class Title {
         * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries.
         * @return array Array of arrays of the arguments to wfMsg to explain permissions problems.
         */
-       public function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true ) {
+       private function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true ) {
                wfProfileIn( __METHOD__ );
 
                $errors = array();
index 8d2b690..52a61e4 100644 (file)
@@ -3613,8 +3613,7 @@ class Parser
                                        $section = $sectionIndex;
                                        $tooltip = '';
                                }
-                               // Use Title::getUserPermissionsErrorsInternal() so that we can pass our User object
-                               if( $titleObj->getUserPermissionsErrorsInternal( 'edit', $this->mOptions->getUser(), false ) === array() ){
+                               if( $titleObj->quickUserCan( 'edit', $this->mOptions->getUser() ) ){
                                        $editlink = $sk->doEditSectionLink( $titleObj, $section, $tooltip );
                                } else {
                                        $editlink = '';
index bf11da2..b2bd2ba 100644 (file)
@@ -29,7 +29,7 @@ class ParserCache {
        function getKey( &$article, &$user ) {
                global $action;
                $hash = $user->getPageRenderingHash();
-               if( !$article->mTitle->quickUserCan( 'edit' ) ) {
+               if( !$article->mTitle->quickUserCan( 'edit', $user ) ) {
                        // section edit links are suppressed even if the user has them on
                        $edit = '!edit=0';
                } else {