Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | * produces altered wiki markup. |
24 | 24 | * preprocess() |
25 | 25 | * removes HTML comments and expands templates |
26 | | - * cleanSig() |
| 26 | + * cleanSig() / cleanSigInSig() |
27 | 27 | * Cleans a signature before saving it to preferences |
28 | 28 | * extractSections() |
29 | 29 | * Extracts sections from an article for section editing |
— | — | @@ -192,6 +192,7 @@ |
193 | 193 | $this->firstCallInit(); |
194 | 194 | } |
195 | 195 | $this->mOutput = new ParserOutput; |
| 196 | + $this->mOptions->registerWatcher( array( $this->mOutput, 'recordOption' ) ); |
196 | 197 | $this->mAutonumber = 0; |
197 | 198 | $this->mLastSection = ''; |
198 | 199 | $this->mDTopen = false; |
— | — | @@ -268,12 +269,11 @@ |
269 | 270 | wfProfileIn( __METHOD__ ); |
270 | 271 | wfProfileIn( $fname ); |
271 | 272 | |
| 273 | + $this->mOptions = $options; |
272 | 274 | if ( $clearState ) { |
273 | 275 | $this->clearState(); |
274 | 276 | } |
275 | 277 | |
276 | | - $options->resetUsage(); |
277 | | - $this->mOptions = $options; |
278 | 278 | $this->setTitle( $title ); # Page title has to be set for the pre-processor |
279 | 279 | |
280 | 280 | $oldRevisionId = $this->mRevisionId; |
— | — | @@ -465,10 +465,9 @@ |
466 | 466 | */ |
467 | 467 | function preprocess( $text, $title, $options, $revid = null ) { |
468 | 468 | wfProfileIn( __METHOD__ ); |
| 469 | + $this->mOptions = $options; |
469 | 470 | $this->clearState(); |
470 | 471 | $this->setOutputType( self::OT_PREPROCESS ); |
471 | | - $options->resetUsage(); |
472 | | - $this->mOptions = $options; |
473 | 472 | $this->setTitle( $title ); |
474 | 473 | if ( $revid !== null ) { |
475 | 474 | $this->mRevisionId = $revid; |
— | — | @@ -489,10 +488,9 @@ |
490 | 489 | */ |
491 | 490 | public function getPreloadText( $text, $title, $options ) { |
492 | 491 | # Parser (re)initialisation |
| 492 | + $this->mOptions = $options; |
493 | 493 | $this->clearState(); |
494 | 494 | $this->setOutputType( self::OT_PLAIN ); |
495 | | - $options->resetUsage(); |
496 | | - $this->mOptions = $options; |
497 | 495 | $this->setTitle( $title ); |
498 | 496 | |
499 | 497 | $flags = PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES; |
— | — | @@ -4029,7 +4027,6 @@ |
4030 | 4028 | * @return String: the altered wiki markup |
4031 | 4029 | */ |
4032 | 4030 | public function preSaveTransform( $text, Title $title, $user, $options, $clearState = true ) { |
4033 | | - $options->resetUsage(); |
4034 | 4031 | $this->mOptions = $options; |
4035 | 4032 | $this->setTitle( $title ); |
4036 | 4033 | $this->setUser( $user ); |
— | — | @@ -4211,9 +4208,9 @@ |
4212 | 4209 | function cleanSig( $text, $parsing = false ) { |
4213 | 4210 | if ( !$parsing ) { |
4214 | 4211 | global $wgTitle; |
| 4212 | + $this->mOptions = new ParserOptions; |
4215 | 4213 | $this->clearState(); |
4216 | 4214 | $this->setTitle( $wgTitle ); |
4217 | | - $this->mOptions = new ParserOptions; |
4218 | 4215 | $this->setOutputType = self::OT_PREPROCESS; |
4219 | 4216 | } |
4220 | 4217 | |
— | — | @@ -4861,9 +4858,9 @@ |
4862 | 4859 | */ |
4863 | 4860 | private function extractSections( $text, $section, $mode, $newText='' ) { |
4864 | 4861 | global $wgTitle; |
| 4862 | + $this->mOptions = new ParserOptions; |
4865 | 4863 | $this->clearState(); |
4866 | 4864 | $this->setTitle( $wgTitle ); # not generally used but removes an ugly failure mode |
4867 | | - $this->mOptions = new ParserOptions; |
4868 | 4865 | $this->setOutputType( self::OT_PLAIN ); |
4869 | 4866 | $outText = ''; |
4870 | 4867 | $frame = $this->getPreprocessor()->newFrame(); |
— | — | @@ -5143,13 +5140,13 @@ |
5144 | 5141 | * strip/replaceVariables/unstrip for preprocessor regression testing |
5145 | 5142 | */ |
5146 | 5143 | function testSrvus( $text, $title, $options, $outputType = self::OT_HTML ) { |
| 5144 | + $this->mOptions = $options; |
5147 | 5145 | $this->clearState(); |
5148 | 5146 | if ( !$title instanceof Title ) { |
5149 | 5147 | $title = Title::newFromText( $title ); |
5150 | 5148 | } |
5151 | 5149 | $this->mTitle = $title; |
5152 | 5150 | $options->resetUsage(); |
5153 | | - $this->mOptions = $options; |
5154 | 5151 | $this->setOutputType( $outputType ); |
5155 | 5152 | $text = $this->replaceVariables( $text ); |
5156 | 5153 | $text = $this->mStripState->unstripBoth( $text ); |
Index: trunk/phase3/includes/parser/ParserOutput.php |
— | — | @@ -123,6 +123,7 @@ |
124 | 124 | $mProperties = array(), # Name/value pairs to be cached in the DB |
125 | 125 | $mTOCHTML = ''; # HTML of the TOC |
126 | 126 | private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change. |
| 127 | + private $mAccessedOptions = null; # List of ParserOptions (stored in the keys) |
127 | 128 | |
128 | 129 | function __construct( $text = '', $languageLinks = array(), $categoryLinks = array(), |
129 | 130 | $containsOldMagic = false, $titletext = '' ) |
— | — | @@ -327,4 +328,25 @@ |
328 | 329 | } |
329 | 330 | return $this->mProperties; |
330 | 331 | } |
| 332 | + |
| 333 | + |
| 334 | + /** |
| 335 | + * Returns the options from its ParserOptions which have been taken |
| 336 | + * into account to produce this output or false if not available. |
| 337 | + * @return mixed Array/false |
| 338 | + */ |
| 339 | + public function getUsedOptions() { |
| 340 | + if ( !isset( $this->mAccessedOptions ) ) { |
| 341 | + return false; |
| 342 | + } |
| 343 | + return array_keys( $this->mAccessedOptions ); |
| 344 | + } |
| 345 | + |
| 346 | + /** |
| 347 | + * Callback passed by the Parser to the ParserOptions to keep track of which options are used. |
| 348 | + * @access private |
| 349 | + */ |
| 350 | + function recordOption( $option ) { |
| 351 | + $this->mAccessedOptions[$option] = true; |
| 352 | + } |
331 | 353 | } |
Index: trunk/phase3/includes/parser/ParserCache.php |
— | — | @@ -170,7 +170,7 @@ |
171 | 171 | $now = wfTimestampNow(); |
172 | 172 | |
173 | 173 | $optionsKey = new CacheTime; |
174 | | - $optionsKey->mUsedOptions = $popts->usedOptions(); |
| 174 | + $optionsKey->mUsedOptions = $parserOutput->getUsedOptions(); |
175 | 175 | $optionsKey->updateCacheExpiry( $expire ); |
176 | 176 | |
177 | 177 | $optionsKey->setCacheTime( $now ); |
Index: trunk/phase3/includes/parser/ParserOptions.php |
— | — | @@ -49,16 +49,16 @@ |
50 | 50 | |
51 | 51 | var $mExtraKey = ''; # Extra key that should be present in the caching key. |
52 | 52 | |
53 | | - protected $accessedOptions; |
| 53 | + protected $onAccessCallback = null; |
54 | 54 | |
55 | 55 | function getUseDynamicDates() { return $this->mUseDynamicDates; } |
56 | 56 | function getInterwikiMagic() { return $this->mInterwikiMagic; } |
57 | 57 | function getAllowExternalImages() { return $this->mAllowExternalImages; } |
58 | 58 | function getAllowExternalImagesFrom() { return $this->mAllowExternalImagesFrom; } |
59 | 59 | function getEnableImageWhitelist() { return $this->mEnableImageWhitelist; } |
60 | | - function getEditSection() { $this->accessedOptions['editsection'] = true; |
| 60 | + function getEditSection() { $this->optionUsed('editsection'); |
61 | 61 | return $this->mEditSection; } |
62 | | - function getNumberHeadings() { $this->accessedOptions['numberheadings'] = true; |
| 62 | + function getNumberHeadings() { $this->optionUsed('numberheadings'); |
63 | 63 | return $this->mNumberHeadings; } |
64 | 64 | function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; } |
65 | 65 | function getTidy() { return $this->mTidy; } |
— | — | @@ -73,14 +73,14 @@ |
74 | 74 | function getEnableLimitReport() { return $this->mEnableLimitReport; } |
75 | 75 | function getCleanSignatures() { return $this->mCleanSignatures; } |
76 | 76 | function getExternalLinkTarget() { return $this->mExternalLinkTarget; } |
77 | | - function getMath() { $this->accessedOptions['math'] = true; |
| 77 | + function getMath() { $this->optionUsed('math'); |
78 | 78 | return $this->mMath; } |
79 | | - function getThumbSize() { $this->accessedOptions['thumbsize'] = true; |
| 79 | + function getThumbSize() { $this->optionUsed('thumbsize'); |
80 | 80 | return $this->mThumbSize; } |
81 | 81 | |
82 | 82 | function getIsPreview() { return $this->mIsPreview; } |
83 | 83 | function getIsSectionPreview() { return $this->mIsSectionPreview; } |
84 | | - function getIsPrintable() { $this->accessedOptions['printable'] = true; |
| 84 | + function getIsPrintable() { $this->optionUsed('printable'); |
85 | 85 | return $this->mIsPrintable; } |
86 | 86 | function getUser() { return $this->mUser; } |
87 | 87 | |
— | — | @@ -92,7 +92,7 @@ |
93 | 93 | } |
94 | 94 | |
95 | 95 | function getDateFormat() { |
96 | | - $this->accessedOptions['dateformat'] = true; |
| 96 | + $this->optionUsed('dateformat'); |
97 | 97 | if ( !isset( $this->mDateFormat ) ) { |
98 | 98 | $this->mDateFormat = $this->mUser->getDatePreference(); |
99 | 99 | } |
— | — | @@ -112,7 +112,7 @@ |
113 | 113 | * producing inconsistent tables (Bug 14404). |
114 | 114 | */ |
115 | 115 | function getUserLang() { |
116 | | - $this->accessedOptions['userlang'] = true; |
| 116 | + $this->optionUsed('userlang'); |
117 | 117 | return $this->mUserLang; |
118 | 118 | } |
119 | 119 | |
— | — | @@ -211,17 +211,20 @@ |
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | | - * Returns the options from this ParserOptions which have been used. |
| 215 | + * Registers a callback for tracking which ParserOptions which are used. |
| 216 | + * This is a private API with the parser. |
216 | 217 | */ |
217 | | - public function usedOptions() { |
218 | | - return array_keys( $this->accessedOptions ); |
| 218 | + function registerWatcher( $callback ) { |
| 219 | + $this->onAccessCallback = $callback; |
219 | 220 | } |
220 | 221 | |
221 | 222 | /** |
222 | | - * Resets the memory of options usage. |
| 223 | + * Called when an option is accessed. |
223 | 224 | */ |
224 | | - public function resetUsage() { |
225 | | - $this->accessedOptions = array(); |
| 225 | + protected function optionUsed( $optionName ) { |
| 226 | + if ( $this->onAccessCallback ) { |
| 227 | + call_user_func( $this->onAccessCallback, $optionName ); |
| 228 | + } |
226 | 229 | } |
227 | 230 | |
228 | 231 | /** |