r62625 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62624‎ | r62625 | r62626 >
Date:00:05, 17 February 2010
Author:juliano
Status:deferred
Tags:
Comment:
Some improvements to WikilogUtils::parsedArticle().
Cache parsed comment texts whenever possible.
Modified paths:
  • /trunk/extensions/Wikilog/WikilogComment.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogUtils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikilog/WikilogUtils.php
@@ -41,6 +41,23 @@
4242 * @param $title Article title object.
4343 * @param $feed Whether the result should be part of a feed.
4444 * @return Two-element array containing the article and its parser output.
 45+ *
 46+ * @note Mw1.16+ provides Article::getParserOptions() and
 47+ * Article::getParserOutput(), that could be used here in the future.
 48+ * The problem is that getParserOutput() uses ParserCache exclusively,
 49+ * which means that only ParserOptions control the key used to store
 50+ * the output in the cache and there is no hook yet in
 51+ * ParserCache::getKey() to set these extra bits (and the
 52+ * 'PageRenderingCache' hook is not useful here, it is in the wrong
 53+ * place without access to the parser options). This is certainly
 54+ * something that should be fixed in the future. FIXME
 55+ *
 56+ * @note This function makes a clone of the parser if
 57+ * $wgWikilogCloneParser is set, but cloning the parser is not
 58+ * officially supported. The problem here is that we need a different
 59+ * parser that we could mess up without interfering with normal page
 60+ * rendering, and we can't create a new instance because of too many
 61+ * broken extensions around. Check self::parserSanityCheck().
4562 */
4663 public static function parsedArticle( Title $title, $feed = false ) {
4764 global $wgWikilogCloneParser;
@@ -52,14 +69,27 @@
5370 $article = new Article( $title );
5471
5572 # First try the parser cache.
56 - if ( $wgEnableParserCache ) {
 73+ $useParserCache = $wgEnableParserCache &&
 74+ intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
 75+ $article->exists();
 76+
 77+ # Parser options.
 78+ $parserOpt = ParserOptions::newFromUser( $wgUser );
 79+ $parserOpt->setTidy( true );
 80+ if ( $feed ) {
 81+ $parserOpt->setEditSection( false );
 82+ } else {
 83+ $parserOpt->enableLimitReport();
 84+ }
 85+
 86+ if ( $useParserCache ) {
5787 # Select parser cache according to the $feed flag.
5888 $parserCache = $feed
5989 ? WikilogParserCache::singleton()
6090 : ParserCache::singleton();
6191
6292 # Look for the parsed article output in the parser cache.
63 - $parserOutput = $parserCache->get( $article, $wgUser );
 93+ $parserOutput = $parserCache->get( $article, $parserOpt );
6494
6595 # On success, return the object retrieved from the cache.
6696 if ( $parserOutput ) {
@@ -67,17 +97,10 @@
6898 }
6999 }
70100
71 - # Parser options.
72 - $parserOpt = ParserOptions::newFromUser( $wgUser );
73 - $parserOpt->setTidy( true );
74 -
75101 # Enable some feed-specific behavior.
76102 if ( $feed ) {
77103 $saveFeedParse = WikilogParser::enableFeedParsing();
78104 $saveExpUrls = WikilogParser::expandLocalUrls();
79 - $parserOpt->setEditSection( false );
80 - } else {
81 - $parserOpt->enableLimitReport();
82105 }
83106
84107 # Get a parser instance, if not already cached.
@@ -99,8 +122,8 @@
100123 $parserOutput = $parser->parse( $arttext, $title, $parserOpt );
101124
102125 # Save in parser cache.
103 - if ( $wgEnableParserCache && $parserOutput->getCacheTime() != -1 ) {
104 - $parserCache->save( $parserOutput, $article, $wgUser );
 126+ if ( $useParserCache && $parserOutput->getCacheTime() != -1 ) {
 127+ $parserCache->save( $parserOutput, $article, $parserOpt );
105128 }
106129
107130 # Restore default behavior.
Index: trunk/extensions/Wikilog/WikilogComment.php
@@ -608,8 +608,13 @@
609609 $params = $this->getCommentMsgParams( $comment );
610610 $html = $this->formatCommentHeader( $comment, $params );
611611
612 - $text = $wgOut->parse( $comment->getText() ); // TODO: Optimize this.
613 - $html .= WikilogUtils::wrapDiv( 'wl-comment-text', $text );
 612+ if ( $comment->mCommentRev ) {
 613+ list( $article, $parserOutput ) = WikilogUtils::parsedArticle( $comment->mCommentTitle );
 614+ $text = $parserOutput->getText();
 615+ if ( $text ) {
 616+ $html .= WikilogUtils::wrapDiv( 'wl-comment-text', $text );
 617+ }
 618+ }
614619
615620 $html .= $this->formatCommentFooter( $comment, $params );
616621 $html .= $this->getCommentToolLinks( $comment );

Status & tagging log