r19060 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r19059‎ | r19060 | r19061 >
Date:12:36, 10 January 2007
Author:werdna
Status:old
Tags:
Comment:
Precautionary measure against murder of author by domas and mark: Instead of making a templatelinks request for *every* *single* *template* on a page, make one big one, and store the result.
Modified paths:
  • /branches/werdna/restrictions-separation/includes/Parser.php (modified) (history)

Diff [purge]

Index: branches/werdna/restrictions-separation/includes/Parser.php
@@ -105,6 +105,7 @@
106106 // multiple SQL queries for the same string
107107 $mTemplatePath; // stores an unsorted hash of all the templates already loaded
108108 // in this path. Used for loop detection.
 109+ var $mTlTemplates;
109110
110111 # Temporary
111112 # These are variables reset at least once per parse regardless of $clearState
@@ -234,6 +235,8 @@
235236 );
236237 $this->mDefaultSort = false;
237238
 239+ $this->mTlTemplates = array ();
 240+
238241 wfRunHooks( 'ParserClearState', array( &$this ) );
239242 wfProfileOut( __METHOD__ );
240243 }
@@ -288,6 +291,18 @@
289292
290293 $this->mOptions = $options;
291294 $this->mTitle =& $title;
 295+
 296+ if ($this->mTitle->areRestrictionsCascading()) {
 297+ $article = new Article($this->mTitle);
 298+ $template_titles = $article->getUsedTemplates();
 299+
 300+ $this->mTlTemplates = array ();
 301+
 302+ foreach ($this->mTlTemplates as $template) {
 303+ $this->mTlTemplates[] = $template->getPrefixedText();
 304+ }
 305+ }
 306+
292307 $oldRevisionId = $this->mRevisionId;
293308 $oldRevisionTimestamp = $this->mRevisionTimestamp;
294309 if( $revid !== null ) {
@@ -3051,22 +3066,19 @@
30523067 # If this page is subject to cascading restrictions, check that the template is included in templatelinks
30533068 if ($this->mTitle->areRestrictionsCascading()) {
30543069 # Subject to cascading restrictions. Check for templatelinks entry
3055 - $cc_article = new Article( $this->mTitle );
30563070
3057 - $cc_dbr =& wfGetDB( DB_SLAVE );
3058 -
3059 - $cc_res = $cc_dbr->selectField( 'templatelinks', 'tl_from',
3060 - array( 'tl_from' => $cc_article->getID(), 'tl_namespace' => $ns, 'tl_title' => $part1 ),
3061 - __METHOD__ );
3062 -
30633071 # Use mTlUpdatePages to avoid recursion.
30643072 if (!$this->mTlUpdatePages) {
30653073 $this->mTlUpdatePages = array ();
30663074 }
30673075
 3076+ $res = in_array($part1, $this->mTlTemplates);
 3077+
30683078 if (!$res && !in_array($this->mTitle->getPrefixedText(), $this->mTlUpdatePages)) {
 3079+ $cc_article = new Article( $this->mTitle );
 3080+
30693081 # This title needs a templatelinks refresh. Do it now.
3070 - wfDebug("Needs templatelinks refresh.");
 3082+ wfDebug("Needs templatelinks refresh.\n");
30713083
30723084 $this->mTlUpdatePages[] = $this->mTitle->getPrefixedText();
30733085
@@ -3079,6 +3091,7 @@
30803092 # Parse the text
30813093 $cc_options = new ParserOptions;
30823094 $cc_options->setTidy(true);
 3095+
30833096 # The below is what I'm worried about recursion in.
30843097 $cc_poutput = $wgParser->parse( $cc_text, $this->mTitle, $cc_options, true, true, $cc_newid );
30853098