| Index: trunk/phase3/includes/Article.php |
| — | — | @@ -4262,23 +4262,30 @@ |
| 4263 | 4263 | |
| 4264 | 4264 | /** |
| 4265 | 4265 | * Get parser options suitable for rendering the primary article wikitext |
| 4266 | | - * @return mixed ParserOptions object or boolean false |
| | 4266 | + * @return ParserOptions object |
| 4267 | 4267 | */ |
| 4268 | 4268 | public function getParserOptions() { |
| 4269 | 4269 | global $wgUser; |
| 4270 | | - |
| 4271 | 4270 | if ( !$this->mParserOptions ) { |
| 4272 | | - $this->mParserOptions = new ParserOptions( $wgUser ); |
| 4273 | | - $this->mParserOptions->setTidy( true ); |
| 4274 | | - $this->mParserOptions->enableLimitReport(); |
| | 4271 | + $this->mParserOptions = $this->makeParserOptions( $wgUser ); |
| 4275 | 4272 | } |
| 4276 | | - |
| 4277 | | - // Clone to allow modifications of the return value without affecting |
| 4278 | | - // the cache |
| | 4273 | + // Clone to allow modifications of the return value without affecting cache |
| 4279 | 4274 | return clone $this->mParserOptions; |
| 4280 | 4275 | } |
| 4281 | 4276 | |
| 4282 | 4277 | /** |
| | 4278 | + * Get parser options suitable for rendering the primary article wikitext |
| | 4279 | + * @param User $user |
| | 4280 | + * @return ParserOptions |
| | 4281 | + */ |
| | 4282 | + public function makeParserOptions( User $user ) { |
| | 4283 | + $options = ParserOptions::newFromUser( $user ); |
| | 4284 | + $options->enableLimitReport(); // show inclusion/loop reports |
| | 4285 | + $options->setTidy( true ); // fix bad HTML |
| | 4286 | + return $options; |
| | 4287 | + } |
| | 4288 | + |
| | 4289 | + /** |
| 4283 | 4290 | * Updates cascading protections |
| 4284 | 4291 | * |
| 4285 | 4292 | * @param $parserOutput mixed ParserOptions object, or boolean false |
| Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php |
| — | — | @@ -513,9 +513,10 @@ |
| 514 | 514 | * @param Title $title |
| 515 | 515 | * @param string $text wikitext |
| 516 | 516 | * @param int $id Source revision Id |
| | 517 | + * @param ParserOptions $pOpts |
| 517 | 518 | * @return array( string wikitext, array of template versions ) |
| 518 | 519 | */ |
| 519 | | - public static function expandText( Title $title, $text, $id ) { |
| | 520 | + public static function expandText( Title $title, $text, $id, ParserOptions $pOpts ) { |
| 520 | 521 | global $wgParser; |
| 521 | 522 | # Notify Parser if includes should be stabilized |
| 522 | 523 | $resetManager = false; |
| — | — | @@ -531,8 +532,7 @@ |
| 532 | 533 | } |
| 533 | 534 | } |
| 534 | 535 | } |
| 535 | | - $options = self::makeParserOptions(); // default options |
| 536 | | - $outputText = $wgParser->preprocess( $text, $title, $options, $id ); |
| | 536 | + $outputText = $wgParser->preprocess( $text, $title, $pOpts, $id ); |
| 537 | 537 | $pOutput = $wgParser->getOutput(); |
| 538 | 538 | # Stable parse done! |
| 539 | 539 | if ( $resetManager ) { |
| — | — | @@ -547,9 +547,10 @@ |
| 548 | 548 | * @param Title $title |
| 549 | 549 | * @param string $text |
| 550 | 550 | * @param int $id Source revision Id |
| | 551 | + * @param ParserOptions $pOpts |
| 551 | 552 | * @return ParserOutput |
| 552 | 553 | */ |
| 553 | | - public static function parseStableText( Title $title, $text, $id, $parserOptions ) { |
| | 554 | + public static function parseStableText( Title $title, $text, $id, ParserOptions $pOpts ) { |
| 554 | 555 | global $wgParser; |
| 555 | 556 | # Notify Parser if includes should be stabilized |
| 556 | 557 | $resetManager = false; |
| — | — | @@ -566,7 +567,7 @@ |
| 567 | 568 | } |
| 568 | 569 | } |
| 569 | 570 | # Parse the new body, wikitext -> html |
| 570 | | - $parserOut = $wgParser->parse( $text, $title, $parserOptions, true, true, $id ); |
| | 571 | + $parserOut = $wgParser->parse( $text, $title, $pOpts, true, true, $id ); |
| 571 | 572 | # Stable parse done! |
| 572 | 573 | if ( $resetManager ) { |
| 573 | 574 | $incManager->clear(); // reset the FRInclusionManager as needed |
| — | — | @@ -575,28 +576,21 @@ |
| 576 | 577 | } |
| 577 | 578 | |
| 578 | 579 | /** |
| 579 | | - * Get standard parser options |
| 580 | | - * @param User $user (optional) |
| 581 | | - * @return ParserOptions |
| 582 | | - */ |
| 583 | | - public static function makeParserOptions( $user = null ) { |
| 584 | | - global $wgUser; |
| 585 | | - $user = $user ? $user : $wgUser; // assume current |
| 586 | | - $options = ParserOptions::newFromUser( $user ); |
| 587 | | - # Show inclusion/loop reports |
| 588 | | - $options->enableLimitReport(); |
| 589 | | - # Fix bad HTML |
| 590 | | - $options->setTidy( true ); |
| 591 | | - return $options; |
| | 580 | + * Like ParserCache::getKey() with stable-pcache instead of pcache |
| | 581 | + */ |
| | 582 | + protected static function getCacheKey( ParserCache $parserCache, Article $article, $popts ) { |
| | 583 | + $key = $parserCache->getKey( $article, $popts ); |
| | 584 | + $key = str_replace( ':pcache:', ':stable-pcache:', $key ); |
| | 585 | + return $key; |
| 592 | 586 | } |
| 593 | 587 | |
| 594 | 588 | /** |
| 595 | 589 | * Get the page cache for the stable version of an article |
| 596 | 590 | * @param Article $article |
| 597 | | - * @param User $user |
| | 591 | + * @param ParserOptions $opts |
| 598 | 592 | * @return mixed (ParserOutput/false) |
| 599 | 593 | */ |
| 600 | | - public static function getPageCache( Article $article, $user ) { |
| | 594 | + public static function getPageCache( Article $article, ParserOptions $popts ) { |
| 601 | 595 | global $parserMemc, $wgCacheEpoch; |
| 602 | 596 | wfProfileIn( __METHOD__ ); |
| 603 | 597 | # Make sure it is valid |
| — | — | @@ -605,7 +599,7 @@ |
| 606 | 600 | return null; |
| 607 | 601 | } |
| 608 | 602 | $parserCache = ParserCache::singleton(); |
| 609 | | - $key = self::getCacheKey( $parserCache, $article, $user ); |
| | 603 | + $key = self::getCacheKey( $parserCache, $article, $popts ); |
| 610 | 604 | # Get the cached HTML |
| 611 | 605 | wfDebug( "Trying parser cache $key\n" ); |
| 612 | 606 | $value = $parserMemc->get( $key ); |
| — | — | @@ -638,25 +632,13 @@ |
| 639 | 633 | } |
| 640 | 634 | |
| 641 | 635 | /** |
| 642 | | - * Like ParserCache::getKey() with stable-pcache instead of pcache |
| 643 | | - */ |
| 644 | | - protected static function getCacheKey( $parserCache, Article $article, $popts ) { |
| 645 | | - if( $popts instanceof User ) { |
| 646 | | - $popts = ParserOptions::newFromUser( $popts ); |
| 647 | | - } |
| 648 | | - $key = $parserCache->getKey( $article, $popts ); |
| 649 | | - $key = str_replace( ':pcache:', ':stable-pcache:', $key ); |
| 650 | | - return $key; |
| 651 | | - } |
| 652 | | - |
| 653 | | - /** |
| 654 | 636 | * @param Article $article |
| 655 | 637 | * @param ParserOptions $popts |
| 656 | 638 | * @param parserOutput $parserOut |
| 657 | 639 | * Updates the stable cache of a page with the given $parserOut |
| 658 | 640 | */ |
| 659 | | - public static function updatePageCache( |
| 660 | | - Article $article, $popts, ParserOutput $parserOut = null |
| | 641 | + public static function setPageCache( |
| | 642 | + Article $article, ParserOptions $popts, ParserOutput $parserOut = null |
| 661 | 643 | ) { |
| 662 | 644 | global $parserMemc, $wgParserCacheExpireTime, $wgEnableParserCache; |
| 663 | 645 | wfProfileIn( __METHOD__ ); |
| Index: trunk/extensions/FlaggedRevs/api/actions/ApiReview.php |
| — | — | @@ -69,7 +69,7 @@ |
| 70 | 70 | $article = new FlaggedPage( $title ); |
| 71 | 71 | // Now get the template and image parameters needed |
| 72 | 72 | list( $templateIds, $fileTimeKeys ) = |
| 73 | | - RevisionReviewForm::currentIncludeVersions( $article, $rev ); |
| | 73 | + RevisionReviewForm::getRevIncludes( $article, $rev, $wgUser ); |
| 74 | 74 | // Get version parameters for review submission (flat strings) |
| 75 | 75 | list( $templateParams, $imageParams, $fileVersion ) = |
| 76 | 76 | RevisionReviewForm::getIncludeParams( $article, $templateIds, $fileTimeKeys ); |
| Index: trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php |
| — | — | @@ -575,29 +575,29 @@ |
| 576 | 576 | * Get template and image versions from parsing a revision. |
| 577 | 577 | * @param Article $article |
| 578 | 578 | * @param Revision $rev |
| | 579 | + * @param User $user |
| 579 | 580 | * @return array( templateIds, fileSHA1Keys ) |
| 580 | 581 | * templateIds like ParserOutput->mTemplateIds |
| 581 | 582 | * fileSHA1Keys like ParserOutput->mImageTimeKeys |
| 582 | 583 | */ |
| 583 | | - public static function currentIncludeVersions( Article $article, Revision $rev ) { |
| | 584 | + public static function getRevIncludes( Article $article, Revision $rev, User $user ) { |
| 584 | 585 | global $wgParser, $wgOut, $wgEnableParserCache; |
| 585 | 586 | wfProfileIn( __METHOD__ ); |
| 586 | 587 | $pOutput = false; |
| | 588 | + $pOpts = $article->makeParserOptions( $user ); |
| | 589 | + $parserCache = ParserCache::singleton(); |
| 587 | 590 | # Current version: try parser cache |
| 588 | 591 | if ( $rev->isCurrent() ) { |
| 589 | | - $parserCache = ParserCache::singleton(); |
| 590 | | - $pOutput = $parserCache->get( $article, $wgOut->parserOptions() ); |
| | 592 | + $pOutput = $parserCache->get( $article, $pOpts ); |
| 591 | 593 | } |
| 592 | 594 | # Otherwise (or on cache miss), parse the rev text... |
| 593 | 595 | if ( !$pOutput ) { |
| 594 | 596 | $text = $rev->getText(); |
| 595 | 597 | $title = $article->getTitle(); |
| 596 | | - $options = FlaggedRevs::makeParserOptions(); |
| 597 | | - $pOutput = $wgParser->parse( |
| 598 | | - $text, $title, $options, true, true, $rev->getId() ); |
| | 598 | + $pOutput = $wgParser->parse( $text, $title, $pOpts, true, true, $rev->getId() ); |
| 599 | 599 | # Might as well save the cache while we're at it |
| 600 | 600 | if ( $rev->isCurrent() && $wgEnableParserCache ) { |
| 601 | | - $parserCache->save( $pOutput, $article, $options ); |
| | 601 | + $parserCache->save( $pOutput, $article, $pOpts ); |
| 602 | 602 | } |
| 603 | 603 | } |
| 604 | 604 | wfProfileOut( __METHOD__ ); |
| Index: trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php |
| — | — | @@ -598,7 +598,7 @@ |
| 599 | 599 | |
| 600 | 600 | # Parse and output HTML |
| 601 | 601 | if ( $redirHtml == '' ) { |
| 602 | | - $parserOptions = FlaggedRevs::makeParserOptions(); |
| | 602 | + $parserOptions = $this->article->makeParserOptions( $wgUser ); |
| 603 | 603 | $parserOut = FlaggedRevs::parseStableText( |
| 604 | 604 | $this->article->getTitle(), $text, $frev->getRevId(), $parserOptions ); |
| 605 | 605 | $this->addParserOutput( $parserOut ); |
| — | — | @@ -671,7 +671,8 @@ |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | # Get parsed stable version and output HTML |
| 675 | | - $parserOut = FlaggedRevs::getPageCache( $this->article, $wgUser ); |
| | 675 | + $parserOptions = $this->article->makeParserOptions( $wgUser ); |
| | 676 | + $parserOut = FlaggedRevs::getPageCache( $this->article, $parserOptions ); |
| 676 | 677 | if ( $parserOut ) { |
| 677 | 678 | $this->addParserOutput( $parserOut ); |
| 678 | 679 | } else { |
| — | — | @@ -681,11 +682,10 @@ |
| 682 | 683 | # Don't parse redirects, use separate handling... |
| 683 | 684 | if ( $redirHtml == '' ) { |
| 684 | 685 | # Get the new stable output |
| 685 | | - $parserOptions = FlaggedRevs::makeParserOptions(); |
| 686 | 686 | $parserOut = FlaggedRevs::parseStableText( |
| 687 | 687 | $this->article->getTitle(), $text, $srev->getRevId(), $parserOptions ); |
| 688 | 688 | # Update the stable version cache |
| 689 | | - FlaggedRevs::updatePageCache( $this->article, $parserOptions, $parserOut ); |
| | 689 | + FlaggedRevs::setPageCache( $this->article, $parserOptions, $parserOut ); |
| 690 | 690 | # Add the stable output to the page view |
| 691 | 691 | $this->addParserOutput( $parserOut ); |
| 692 | 692 | |
| Index: trunk/extensions/FlaggedRevs/presentation/RevisionReviewFormUI.php |
| — | — | @@ -385,7 +385,7 @@ |
| 386 | 386 | # Do we need to get inclusion IDs from parser output? |
| 387 | 387 | if ( $this->templateIDs === null || $this->imageSHA1Keys === null ) { |
| 388 | 388 | list( $this->templateIDs, $this->imageSHA1Keys ) = |
| 389 | | - RevisionReviewForm::currentIncludeVersions( $this->article, $this->rev ); |
| | 389 | + RevisionReviewForm::getRevIncludes( $this->article, $this->rev, $this->user ); |
| 390 | 390 | } |
| 391 | 391 | return array( $this->templateIDs, $this->imageSHA1Keys ); |
| 392 | 392 | } |