r38196 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38195‎ | r38196 | r38197 >
Date:17:28, 29 July 2008
Author:ialex
Status:old
Tags:
Comment:
* (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
Modified paths:
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserOptions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -3411,11 +3411,7 @@
34123412 global $wgMaxTocLevel, $wgContLang;
34133413
34143414 $doNumberHeadings = $this->mOptions->getNumberHeadings();
3415 - if( !$this->mTitle->quickUserCan( 'edit' ) ) {
3416 - $showEditLink = 0;
3417 - } else {
3418 - $showEditLink = $this->mOptions->getEditSection();
3419 - }
 3415+ $showEditLink = $this->mOptions->getEditSection();
34203416
34213417 # Inhibit editsection links if requested in the page
34223418 if ( isset( $this->mDoubleUnderscores['noeditsection'] ) ) {
@@ -3609,10 +3605,20 @@
36103606 if( $isTemplate ) {
36113607 # Put a T flag in the section identifier, to indicate to extractSections()
36123608 # that sections inside <includeonly> should be counted.
3613 - $editlink = $sk->doEditSectionLink(Title::newFromText( $titleText ), "T-$sectionIndex");
 3609+ $titleObj = Title::newFromText( $titleText );
 3610+ $section = "T-$sectionIndex";
 3611+ $tooltip = $headlineHint;
36143612 } else {
3615 - $editlink = $sk->doEditSectionLink($this->mTitle, $sectionIndex, $headlineHint);
 3613+ $titleObj = $this->mTitle;
 3614+ $section = $sectionIndex;
 3615+ $tooltip = '';
36163616 }
 3617+ // Use Title::getUserPermissionsErrorsInternal() so that we can pass our User object
 3618+ if( $titleObj->getUserPermissionsErrorsInternal( 'edit', $this->mOptions->getUser(), false ) === array() ){
 3619+ $editlink = $sk->doEditSectionLink( $titleObj, $section, $tooltip );
 3620+ } else {
 3621+ $editlink = '';
 3622+ }
36173623 } else {
36183624 $editlink = '';
36193625 }
@@ -4042,7 +4048,6 @@
40434049 * $options is a bit field, RLH_FOR_UPDATE to select for update
40444050 */
40454051 function replaceLinkHolders( &$text, $options = 0 ) {
4046 - global $wgUser;
40474052 global $wgContLang;
40484053
40494054 $fname = 'Parser::replaceLinkHolders';
@@ -4058,7 +4063,7 @@
40594064 wfProfileIn( $fname.'-check' );
40604065 $dbr = wfGetDB( DB_SLAVE );
40614066 $page = $dbr->tableName( 'page' );
4062 - $threshold = $wgUser->getOption('stubthreshold');
 4067+ $threshold = $this->mOptions->getStubThreshold();
40634068
40644069 # Sort by namespace
40654070 asort( $this->mLinkHolders['namespaces'] );
Index: trunk/phase3/includes/parser/ParserOptions.php
@@ -5,32 +5,32 @@
66 * @todo document
77 * @ingroup Parser
88 */
9 -class ParserOptions
10 -{
 9+class ParserOptions {
1110 # All variables are supposed to be private in theory, although in practise this is not the case.
12 - var $mUseTeX; # Use texvc to expand <math> tags
13 - var $mUseDynamicDates; # Use DateFormatter to format dates
14 - var $mInterwikiMagic; # Interlanguage links are removed and returned in an array
15 - var $mAllowExternalImages; # Allow external images inline
16 - var $mAllowExternalImagesFrom; # If not, any exception?
17 - var $mSkin; # Reference to the preferred skin
18 - var $mDateFormat; # Date format index
19 - var $mEditSection; # Create "edit section" links
20 - var $mNumberHeadings; # Automatically number headings
21 - var $mAllowSpecialInclusion; # Allow inclusion of special pages
22 - var $mTidy; # Ask for tidy cleanup
23 - var $mInterfaceMessage; # Which lang to call for PLURAL and GRAMMAR
24 - var $mTargetLanguage; # Overrides above setting with arbitrary language
25 - var $mMaxIncludeSize; # Maximum size of template expansions, in bytes
26 - var $mMaxPPNodeCount; # Maximum number of nodes touched by PPFrame::expand()
27 - var $mMaxPPExpandDepth; # Maximum recursion depth in PPFrame::expand()
28 - var $mMaxTemplateDepth; # Maximum recursion depth for templates within templates
29 - var $mRemoveComments; # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
30 - var $mTemplateCallback; # Callback for template fetching
31 - var $mEnableLimitReport; # Enable limit report in an HTML comment on output
32 - var $mTimestamp; # Timestamp used for {{CURRENTDAY}} etc.
 11+ var $mUseTeX; //!< Use texvc to expand <math> tags
 12+ var $mUseDynamicDates; //!< Use DateFormatter to format dates
 13+ var $mInterwikiMagic; //!< Interlanguage links are removed and returned in an array
 14+ var $mAllowExternalImages; //!< Allow external images inline
 15+ var $mAllowExternalImagesFrom; //!< If not, any exception?
 16+ var $mSkin; //!< Reference to the preferred skin
 17+ var $mDateFormat; //!< Date format index
 18+ var $mEditSection; //!< Create "edit section" links
 19+ var $mNumberHeadings; //!< Automatically number headings
 20+ var $mStubThreshold; //!< Treshold for marking pages as "stub"
 21+ var $mAllowSpecialInclusion; //!< Allow inclusion of special pages
 22+ var $mTidy; //!< Ask for tidy cleanup
 23+ var $mInterfaceMessage; //!< Which lang to call for PLURAL and GRAMMAR
 24+ var $mTargetLanguage; //!< Overrides above setting with arbitrary language
 25+ var $mMaxIncludeSize; //!< Maximum size of template expansions, in bytes
 26+ var $mMaxPPNodeCount; //!< Maximum number of nodes touched by PPFrame::expand()
 27+ var $mMaxPPExpandDepth; //!< Maximum recursion depth in PPFrame::expand()
 28+ var $mMaxTemplateDepth; //!< Maximum recursion depth for templates within templates
 29+ var $mRemoveComments; //!< Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
 30+ var $mTemplateCallback; //!< Callback for template fetching
 31+ var $mEnableLimitReport; //!< Enable limit report in an HTML comment on output
 32+ var $mTimestamp; //!< Timestamp used for {{CURRENTDAY}} etc.
3333
34 - var $mUser; # Stored user object, just used to initialise the skin
 34+ var $mUser; //!< Stored user object
3535
3636 function getUseTeX() { return $this->mUseTeX; }
3737 function getUseDynamicDates() { return $this->mUseDynamicDates; }
@@ -39,6 +39,7 @@
4040 function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom; }
4141 function getEditSection() { return $this->mEditSection; }
4242 function getNumberHeadings() { return $this->mNumberHeadings; }
 43+ function getStubThreshold() { return $this->mStubThreshold; }
4344 function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; }
4445 function getTidy() { return $this->mTidy; }
4546 function getInterfaceMessage() { return $this->mInterfaceMessage; }
@@ -50,6 +51,10 @@
5152 function getTemplateCallback() { return $this->mTemplateCallback; }
5253 function getEnableLimitReport() { return $this->mEnableLimitReport; }
5354
 55+ function getUser() {
 56+ return $this->mUser;
 57+ }
 58+
5459 function getSkin() {
5560 if ( !isset( $this->mSkin ) ) {
5661 $this->mSkin = $this->mUser->getSkin();
@@ -79,6 +84,7 @@
8085 function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat, $x ); }
8186 function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); }
8287 function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); }
 88+ function setStubThreshold( $x ) { return wfSetVar( $this->mStubThreshold, $x ); }
8389 function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion, $x ); }
8490 function setTidy( $x ) { return wfSetVar( $this->mTidy, $x); }
8591 function setSkin( $x ) { $this->mSkin = $x; }
@@ -98,7 +104,7 @@
99105
100106 /**
101107 * Get parser options
102 - * @static
 108+ * @param $user User
103109 */
104110 static function newFromUser( $user ) {
105111 return new ParserOptions( $user );
@@ -109,8 +115,9 @@
110116 global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
111117 global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgMaxArticleSize;
112118 global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth;
113 - $fname = 'ParserOptions::initialiseFromUser';
114 - wfProfileIn( $fname );
 119+
 120+ wfProfileIn( __METHOD__ );
 121+
115122 if ( !$userInput ) {
116123 global $wgUser;
117124 if ( isset( $wgUser ) ) {
@@ -133,6 +140,7 @@
134141 $this->mDateFormat = null; # Deferred
135142 $this->mEditSection = true;
136143 $this->mNumberHeadings = $user->getOption( 'numberheadings' );
 144+ $this->mStubThreshold = $user->getOption( 'stubthreshold' );
137145 $this->mAllowSpecialInclusion = $wgAllowSpecialInclusion;
138146 $this->mTidy = false;
139147 $this->mInterfaceMessage = false;
@@ -144,6 +152,7 @@
145153 $this->mRemoveComments = true;
146154 $this->mTemplateCallback = array( 'Parser', 'statelessFetchTemplate' );
147155 $this->mEnableLimitReport = false;
148 - wfProfileOut( $fname );
 156+
 157+ wfProfileOut( __METHOD__ );
149158 }
150159 }
Index: trunk/phase3/includes/Title.php
@@ -1134,7 +1134,7 @@
11351135 * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries.
11361136 * @return array Array of arrays of the arguments to wfMsg to explain permissions problems.
11371137 */
1138 - private function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true ) {
 1138+ public function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true ) {
11391139 wfProfileIn( __METHOD__ );
11401140
11411141 $errors = array();

Follow-up revisions

RevisionCommit summaryAuthorDate
r38201Oops, forgot RELEASE-NOTES for r38196ialex18:18, 29 July 2008
r38208Revert r38196, r38204 -- "(bugs 6089, 13079) Show edit section links for tran...brion23:56, 29 July 2008

Status & tagging log