* (bugs 6089, 13079) Show edit section links for transcluded template if, and only...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Tue, 29 Jul 2008 17:28:26 +0000 (17:28 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Tue, 29 Jul 2008 17:28:26 +0000 (17:28 +0000)
* Get the stubthreshold option from ParserOptions and not from $wgUser

includes/Title.php
includes/parser/Parser.php
includes/parser/ParserOptions.php

index 448db9b..82d480b 100644 (file)
@@ -1134,7 +1134,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.
         */
-       private function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true ) {
+       public function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true ) {
                wfProfileIn( __METHOD__ );
 
                $errors = array();
index c074717..8d2b690 100644 (file)
@@ -3411,11 +3411,7 @@ class Parser
                global $wgMaxTocLevel, $wgContLang;
 
                $doNumberHeadings = $this->mOptions->getNumberHeadings();
-               if( !$this->mTitle->quickUserCan( 'edit' ) ) {
-                       $showEditLink = 0;
-               } else {
-                       $showEditLink = $this->mOptions->getEditSection();
-               }
+               $showEditLink = $this->mOptions->getEditSection();
 
                # Inhibit editsection links if requested in the page
                if ( isset( $this->mDoubleUnderscores['noeditsection'] ) ) {
@@ -3609,9 +3605,19 @@ class Parser
                                if( $isTemplate ) {
                                        # Put a T flag in the section identifier, to indicate to extractSections()
                                        # that sections inside <includeonly> should be counted.
-                                       $editlink = $sk->doEditSectionLink(Title::newFromText( $titleText ), "T-$sectionIndex");
+                                       $titleObj = Title::newFromText( $titleText );
+                                       $section = "T-$sectionIndex";
+                                       $tooltip = $headlineHint;
                                } else {
-                                       $editlink = $sk->doEditSectionLink($this->mTitle, $sectionIndex, $headlineHint);
+                                       $titleObj = $this->mTitle;
+                                       $section = $sectionIndex;
+                                       $tooltip = '';
+                               }
+                               // Use Title::getUserPermissionsErrorsInternal() so that we can pass our User object
+                               if( $titleObj->getUserPermissionsErrorsInternal( 'edit', $this->mOptions->getUser(), false ) === array() ){
+                                       $editlink = $sk->doEditSectionLink( $titleObj, $section, $tooltip );
+                               } else {
+                                       $editlink = '';
                                }
                        } else {
                                $editlink = '';
@@ -4042,7 +4048,6 @@ class Parser
         * $options is a bit field, RLH_FOR_UPDATE to select for update
         */
        function replaceLinkHolders( &$text, $options = 0 ) {
-               global $wgUser;
                global $wgContLang;
 
                $fname = 'Parser::replaceLinkHolders';
@@ -4058,7 +4063,7 @@ class Parser
                        wfProfileIn( $fname.'-check' );
                        $dbr = wfGetDB( DB_SLAVE );
                        $page = $dbr->tableName( 'page' );
-                       $threshold = $wgUser->getOption('stubthreshold');
+                       $threshold = $this->mOptions->getStubThreshold();
 
                        # Sort by namespace
                        asort( $this->mLinkHolders['namespaces'] );
index 330ec44..5b6e8ed 100644 (file)
@@ -5,32 +5,32 @@
  * @todo document
  * @ingroup Parser
  */
-class ParserOptions
-{
+class ParserOptions {
        # All variables are supposed to be private in theory, although in practise this is not the case.
-       var $mUseTeX;                    # Use texvc to expand <math> tags
-       var $mUseDynamicDates;           # Use DateFormatter to format dates
-       var $mInterwikiMagic;            # Interlanguage links are removed and returned in an array
-       var $mAllowExternalImages;       # Allow external images inline
-       var $mAllowExternalImagesFrom;   # If not, any exception?
-       var $mSkin;                      # Reference to the preferred skin
-       var $mDateFormat;                # Date format index
-       var $mEditSection;               # Create "edit section" links
-       var $mNumberHeadings;            # Automatically number headings
-       var $mAllowSpecialInclusion;     # Allow inclusion of special pages
-       var $mTidy;                      # Ask for tidy cleanup
-       var $mInterfaceMessage;          # Which lang to call for PLURAL and GRAMMAR
-       var $mTargetLanguage;            # Overrides above setting with arbitrary language
-       var $mMaxIncludeSize;            # Maximum size of template expansions, in bytes
-       var $mMaxPPNodeCount;            # Maximum number of nodes touched by PPFrame::expand()
-       var $mMaxPPExpandDepth;          # Maximum recursion depth in PPFrame::expand()
-       var $mMaxTemplateDepth;          # Maximum recursion depth for templates within templates
-       var $mRemoveComments;            # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
-       var $mTemplateCallback;          # Callback for template fetching
-       var $mEnableLimitReport;         # Enable limit report in an HTML comment on output
-       var $mTimestamp;                 # Timestamp used for {{CURRENTDAY}} etc.
-
-       var $mUser;                      # Stored user object, just used to initialise the skin
+       var $mUseTeX;                    //!< Use texvc to expand <math> tags
+       var $mUseDynamicDates;           //!< Use DateFormatter to format dates
+       var $mInterwikiMagic;            //!< Interlanguage links are removed and returned in an array
+       var $mAllowExternalImages;       //!< Allow external images inline
+       var $mAllowExternalImagesFrom;   //!< If not, any exception?
+       var $mSkin;                      //!< Reference to the preferred skin
+       var $mDateFormat;                //!< Date format index
+       var $mEditSection;               //!< Create "edit section" links
+       var $mNumberHeadings;            //!< Automatically number headings
+       var $mStubThreshold;             //!< Treshold for marking pages as "stub"
+       var $mAllowSpecialInclusion;     //!< Allow inclusion of special pages
+       var $mTidy;                      //!< Ask for tidy cleanup
+       var $mInterfaceMessage;          //!< Which lang to call for PLURAL and GRAMMAR
+       var $mTargetLanguage;            //!< Overrides above setting with arbitrary language
+       var $mMaxIncludeSize;            //!< Maximum size of template expansions, in bytes
+       var $mMaxPPNodeCount;            //!< Maximum number of nodes touched by PPFrame::expand()
+       var $mMaxPPExpandDepth;          //!< Maximum recursion depth in PPFrame::expand()
+       var $mMaxTemplateDepth;          //!< Maximum recursion depth for templates within templates
+       var $mRemoveComments;            //!< Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
+       var $mTemplateCallback;          //!< Callback for template fetching
+       var $mEnableLimitReport;         //!< Enable limit report in an HTML comment on output
+       var $mTimestamp;                 //!< Timestamp used for {{CURRENTDAY}} etc.
+
+       var $mUser;                      //!< Stored user object
 
        function getUseTeX()                        { return $this->mUseTeX; }
        function getUseDynamicDates()               { return $this->mUseDynamicDates; }
@@ -39,6 +39,7 @@ class ParserOptions
        function getAllowExternalImagesFrom()       { return $this->mAllowExternalImagesFrom; }
        function getEditSection()                   { return $this->mEditSection; }
        function getNumberHeadings()                { return $this->mNumberHeadings; }
+       function getStubThreshold()                 { return $this->mStubThreshold; }
        function getAllowSpecialInclusion()         { return $this->mAllowSpecialInclusion; }
        function getTidy()                          { return $this->mTidy; }
        function getInterfaceMessage()              { return $this->mInterfaceMessage; }
@@ -50,6 +51,10 @@ class ParserOptions
        function getTemplateCallback()              { return $this->mTemplateCallback; }
        function getEnableLimitReport()             { return $this->mEnableLimitReport; }
 
+       function getUser() {
+               return $this->mUser;    
+       }
+
        function getSkin() {
                if ( !isset( $this->mSkin ) ) {
                        $this->mSkin = $this->mUser->getSkin();
@@ -79,6 +84,7 @@ class ParserOptions
        function setDateFormat( $x )                { return wfSetVar( $this->mDateFormat, $x ); }
        function setEditSection( $x )               { return wfSetVar( $this->mEditSection, $x ); }
        function setNumberHeadings( $x )            { return wfSetVar( $this->mNumberHeadings, $x ); }
+       function setStubThreshold( $x )             { return wfSetVar( $this->mStubThreshold, $x ); }
        function setAllowSpecialInclusion( $x )     { return wfSetVar( $this->mAllowSpecialInclusion, $x ); }
        function setTidy( $x )                      { return wfSetVar( $this->mTidy, $x); }
        function setSkin( $x )                      { $this->mSkin = $x; }
@@ -98,7 +104,7 @@ class ParserOptions
 
        /**
         * Get parser options
-        * @static
+        * @param $user User
         */
        static function newFromUser( $user ) {
                return new ParserOptions( $user );
@@ -109,8 +115,9 @@ class ParserOptions
                global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
                global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgMaxArticleSize;
                global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth;
-               $fname = 'ParserOptions::initialiseFromUser';
-               wfProfileIn( $fname );
+
+               wfProfileIn( __METHOD__ );
+
                if ( !$userInput ) {
                        global $wgUser;
                        if ( isset( $wgUser ) ) {
@@ -133,6 +140,7 @@ class ParserOptions
                $this->mDateFormat = null; # Deferred
                $this->mEditSection = true;
                $this->mNumberHeadings = $user->getOption( 'numberheadings' );
+               $this->mStubThreshold = $user->getOption( 'stubthreshold' );
                $this->mAllowSpecialInclusion = $wgAllowSpecialInclusion;
                $this->mTidy = false;
                $this->mInterfaceMessage = false;
@@ -144,6 +152,7 @@ class ParserOptions
                $this->mRemoveComments = true;
                $this->mTemplateCallback = array( 'Parser', 'statelessFetchTemplate' );
                $this->mEnableLimitReport = false;
-               wfProfileOut( $fname );
+
+               wfProfileOut( __METHOD__ );
        }
 }