r19064 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r19063‎ | r19064 | r19065 >
Date:16:59, 10 January 2007
Author:werdna
Status:old
Tags:
Comment:
Raft of improvements suggested by Tim Starling. Most significant being a refactor, orphaning ->addPrimaryWikitext; and moving its code, along with that previously in Parser.php (reverted to pre-branch), into Article.php; under Article::outputWikitext. Various other bug-fixes, tweaking, code readability, et cetera. Hopefully there isn't too much work left until we can do a branch merge
Modified paths:
  • /branches/werdna/restrictions-separation/includes/Article.php (modified) (history)
  • /branches/werdna/restrictions-separation/includes/OutputPage.php (modified) (history)
  • /branches/werdna/restrictions-separation/includes/Parser.php (modified) (history)
  • /branches/werdna/restrictions-separation/includes/SpecialUndelete.php (modified) (history)
  • /branches/werdna/restrictions-separation/includes/Title.php (modified) (history)

Diff [purge]

Index: branches/werdna/restrictions-separation/includes/Article.php
@@ -792,7 +792,7 @@
793793 $wgOut->addParserOutputNoText( $parseout );
794794 } else if ( $pcache ) {
795795 # Display content and save to parser cache
796 - $wgOut->addPrimaryWikiText( $text, $this );
 796+ $this->outputWikitext( $text );
797797 } else {
798798 # Display content, don't attempt to save to parser cache
799799 # Don't show section-edit links on old revisions... this way lies madness.
@@ -800,7 +800,7 @@
801801 $oldEditSectionSetting = $wgOut->parserOptions()->setEditSection( false );
802802 }
803803 # Display content and don't save to parser cache
804 - $wgOut->addPrimaryWikiText( $text, $this, false );
 804+ $this->outputWikitext( $text, false );
805805
806806 if( !$this->isCurrent() ) {
807807 $wgOut->parserOptions()->setEditSection( $oldEditSectionSetting );
@@ -2794,6 +2794,64 @@
27952795
27962796 return $summary;
27972797 }
 2798+
 2799+ /**
 2800+ * Add the primary page-view wikitext to the output buffer
 2801+ * Saves the text into the parser cache if possible.
 2802+ *
 2803+ * @param string $text
 2804+ * @param Article $article
 2805+ * @param bool $cache
 2806+ */
 2807+ public function outputWikiText( $text, $cache = true ) {
 2808+ global $wgParser, $wgUser, $wgOut;
 2809+
 2810+ $article = $this;
 2811+
 2812+ $popts = $wgOut->parserOptions();
 2813+ $popts->setTidy(true);
 2814+ $parserOutput = $wgParser->parse( $text, $article->mTitle,
 2815+ $popts, true, true, $this->mRevisionId );
 2816+ $popts->setTidy(false);
 2817+ if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
 2818+ $parserCache =& ParserCache::singleton();
 2819+ $parserCache->save( $parserOutput, $article, $wgUser );
 2820+ }
 2821+
 2822+ # Get templates from templatelinks
 2823+ $tlTemplates_titles = $this->getUsedTemplates();
 2824+
 2825+ $tlTemplates = array ();
 2826+ foreach( $tlTemplates_titles as $template_title) {
 2827+ $tlTemplates[] = $template_title->getDBkey();
 2828+ }
 2829+
 2830+ # Get templates from parser output.
 2831+ $poTemplates_allns = $parserOutput->getTemplates();
 2832+
 2833+ $poTemplates = array ();
 2834+ foreach ( $poTemplates_allns as $ns_templates ) {
 2835+ $poTemplates = array_merge( $poTemplates, $ns_templates );
 2836+ }
 2837+
 2838+ # Get the diff
 2839+ $templates_diff = array_diff( $poTemplates, $tlTemplates );
 2840+
 2841+ if (count( $templates_diff ) > 0) {
 2842+ # Whee, link updates time.
 2843+ $u = new LinksUpdate( $this->mTitle, $parserOutput );
 2844+
 2845+ $dbw =& wfGetDb( DB_MASTER );
 2846+ $dbw->begin();
 2847+
 2848+ $u->doUpdate();
 2849+
 2850+ $dbw->commit();
 2851+ }
 2852+
 2853+ $wgOut->addParserOutput( $parserOutput );
 2854+ }
 2855+
27982856 }
27992857
28002858 ?>
Index: branches/werdna/restrictions-separation/includes/Parser.php
@@ -95,7 +95,6 @@
9696 */
9797 # Persistent:
9898 var $mTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables;
99 - var $mTlDoneUpdateFor;
10099
101100 # Cleared with clearState():
102101 var $mOutput, $mAutonumber, $mDTopen, $mStripState;
@@ -106,7 +105,6 @@
107106 // multiple SQL queries for the same string
108107 $mTemplatePath; // stores an unsorted hash of all the templates already loaded
109108 // in this path. Used for loop detection.
110 - var $mTlTemplates;
111109
112110 # Temporary
113111 # These are variables reset at least once per parse regardless of $clearState
@@ -236,8 +234,6 @@
237235 );
238236 $this->mDefaultSort = false;
239237
240 - $this->mTlTemplates = array ();
241 -
242238 wfRunHooks( 'ParserClearState', array( &$this ) );
243239 wfProfileOut( __METHOD__ );
244240 }
@@ -292,18 +288,6 @@
293289
294290 $this->mOptions = $options;
295291 $this->mTitle =& $title;
296 -
297 - if ($this->mTitle->areRestrictionsCascading()) {
298 - $article = new Article($this->mTitle);
299 - $template_titles = $article->getUsedTemplates();
300 -
301 - $this->mTlTemplates = array ();
302 -
303 - foreach ($this->mTlTemplates as $template) {
304 - $this->mTlTemplates[] = $template->getPrefixedText();
305 - }
306 - }
307 -
308292 $oldRevisionId = $this->mRevisionId;
309293 $oldRevisionTimestamp = $this->mRevisionTimestamp;
310294 if( $revid !== null ) {
@@ -3064,45 +3048,7 @@
30653049 }
30663050 $title = Title::newFromText( $part1, $ns );
30673051
3068 - # If this page is subject to cascading restrictions, check that the template is included in templatelinks
3069 - if ( $this->mTitle->areRestrictionsCascading( ) ) {
3070 - # Subject to cascading restrictions. Check for templatelinks entry
30713052
3072 - $res = in_array( $part1, $this->mTlTemplates );
3073 -
3074 - if ( !is_array( $this->mTlDoneUpdateFor ) ) {
3075 - $this->mTlDoneUpdateFor = array ();
3076 - }
3077 -
3078 - if ( !$res && !in_array( $this->mTitle->getPrefixedText(), $this->mTlDoneUpdateFor ) ) {
3079 - $this->mTlDoneUpdateFor[] = $this->mTitle->getPrefixedText();
3080 -
3081 - $cc_article = new Article( $this->mTitle );
3082 -
3083 - # This title needs a templatelinks refresh. Do it now.
3084 - wfDebug("Needs templatelinks refresh.\n");
3085 -
3086 - $this->mTlUpdatePages[] = $this->mTitle->getPrefixedText();
3087 -
3088 - global $wgParser;
3089 -
3090 - # Get content.
3091 - $cc_text = $cc_article->getContent();
3092 - $cc_newid = $cc_article->getRevIdFetched();
3093 -
3094 - # Parse the text
3095 - $cc_options = new ParserOptions;
3096 - $cc_options->setTidy(true);
3097 -
3098 - # The below is what I'm worried about recursion in.
3099 - $cc_poutput = $wgParser->parse( $cc_text, $this->mTitle, $cc_options, true, true, $cc_newid );
3100 -
3101 - # Update the links tables
3102 - $u = new LinksUpdate( $this->mTitle, $cc_poutput );
3103 - $u->doUpdate();
3104 - }
3105 - }
3106 -
31073053 if ( !is_null( $title ) ) {
31083054 $titleText = $title->getPrefixedText();
31093055 # Check for language variants if the template is not found
Index: branches/werdna/restrictions-separation/includes/OutputPage.php
@@ -315,14 +315,26 @@
316316 $this->addWikiTextTitle($text, $title, $linestart);
317317 }
318318
319 - private function addWikiTextTitle($text, &$title, $linestart) {
 319+ function addWikiTextTitleTidy($text, &$title, $linestart = true) {
 320+ addWikiTextTitle( $text, $title, $linestart, true );
 321+ }
 322+
 323+ private function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
320324 global $wgParser;
 325+
321326 $fname = 'OutputPage:addWikiTextTitle';
322327 wfProfileIn($fname);
 328+
323329 wfIncrStats('pcache_not_possible');
324 - $parserOutput = $wgParser->parse( $text, $title, $this->parserOptions(),
 330+
 331+ $popts = $this->parserOptions();
 332+ $popts->setTidy($tidy);
 333+
 334+ $parserOutput = $wgParser->parse( $text, $title, $popts,
325335 $linestart, true, $this->mRevisionId );
 336+
326337 $this->addParserOutput( $parserOutput );
 338+
327339 wfProfileOut($fname);
328340 }
329341
@@ -366,6 +378,7 @@
367379 * @param string $text
368380 * @param Article $article
369381 * @param bool $cache
 382+ * @deprecated Use Article::outputWikitext
370383 */
371384 public function addPrimaryWikiText( $text, $article, $cache = true ) {
372385 global $wgParser, $wgUser;
Index: branches/werdna/restrictions-separation/includes/SpecialUndelete.php
@@ -532,8 +532,7 @@
533533
534534 if( $this->mPreview ) {
535535 $wgOut->addHtml( "<hr />\n" );
536 - $article = new Article ( $archive->title ); # OutputPage wants an Article obj
537 - $wgOut->addPrimaryWikiText( $rev->getText(), $article, false );
 536+ $wgOut->addWikiTextTitle( $rev->getText(), $archive->title, false );
538537 }
539538
540539 $self = SpecialPage::getTitleFor( "Undelete" );
Index: branches/werdna/restrictions-separation/includes/Title.php
@@ -1364,7 +1364,7 @@
13651365 $tables = array ('templatelinks', 'page_restrictions');
13661366 $where_clauses = array( 'tl_namespace' => $this->getNamespace(), 'tl_title' => $this->getDBkey(), 'tl_from=pr_page', 'pr_cascade' => 1 );
13671367
1368 - $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD);
 1368+ $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__);
13691369
13701370 if ($dbr->numRows($res)) {
13711371 wfProfileOut(__METHOD__);