r59872 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59871‎ | r59872 | r59873 >
Date:08:42, 9 December 2009
Author:thomasv
Status:resolved (Comments)
Tags:
Comment:
follow up to r59787 : preprocess, cache parser instance
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -287,14 +287,15 @@
288288 */
289289 function pr_parse_index_links( $index_title ){
290290
 291+ # Instanciate a new parser object to avoid side effects of $parser->replaceVariables
 292+ global $pr_index_parser;
 293+ if( is_null($pr_index_parser) ) {
 294+ $pr_index_parser = new Parser;
 295+ }
291296 $rev = Revision::newFromTitle( $index_title );
292297 $text = $rev->getText();
293 - # Instanciate a new parser object to avoid side effects of $parser->replaceVariables
294 - $parser = new Parser;
295 - $parser->clearState();
296 - $parser->mOptions = new ParserOptions();
297 - $parser->setTitle( $index_title );
298 - $rtext = $parser->replaceVariables( $text );
 298+ $options = new ParserOptions();
 299+ $rtext = $pr_index_parser->preprocess( $text, $index_title, $options );
299300 $text_links_pattern = "/\[\[([^:\|]*?)(\|(.*?)|)\]\]/i";
300301 preg_match_all( $text_links_pattern, $rtext, $text_links, PREG_PATTERN_ORDER );
301302 return $text_links;

Follow-up revisions

RevisionCommit summaryAuthorDate
r60035follow-up to r59872thomasv12:03, 14 December 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r59787create a fresh parser object, as suggested by brion in r56878thomasv14:14, 7 December 2009

Comments

#Comment by Tim Starling (talk | contribs)   07:21, 14 December 2009

Missing default value for $pr_index_parser. Can generate fatal errors if register_globals is enabled and the user passes a string for pr_index_parser. Please add "$pr_index_parser = null" to the top of the file.

#Comment by ThomasV (talk | contribs)   12:12, 14 December 2009

Done in r60035. On further thought, it seems to me that it would be more efficient to store the list of links, currently returned by pr_parse_index_links(), in a new column, that would be added to the 'pr_index' table. That column would be updated whenever an index page is parsed. That way, we would not need to parse the index page everytime we parse a page that uses the tag.

Status & tagging log