From: Alexandre Emsenhuber Date: Tue, 29 Jul 2008 17:28:26 +0000 (+0000) Subject: * (bugs 6089, 13079) Show edit section links for transcluded template if, and only... X-Git-Tag: 1.31.0-rc.0~46299 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=9b44e8f749a9dfdaca579790f9d56aefdc936d99;p=lhc%2Fweb%2Fwiklou.git * (bugs 6089, 13079) Show edit section links for transcluded template if, and only if the user can edit it, made Title::getUserPermissionsErrorsInternal() public so that it can be used in Parser and it can pass the User object from ParserOptions. * Get the stubthreshold option from ParserOptions and not from $wgUser --- diff --git a/includes/Title.php b/includes/Title.php index 448db9b499..82d480b6be 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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(); diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index c074717b0f..8d2b690301 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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 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'] ); diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php index 330ec446cb..5b6e8ed469 100644 --- a/includes/parser/ParserOptions.php +++ b/includes/parser/ParserOptions.php @@ -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 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 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__ ); } }