r32272 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r32271‎ | r32272 | r32273 >
Date:00:16, 21 March 2008
Author:brion
Status:old
Tags:
Comment:
Don't toss in empty lines on pages that don't need a see templtae...
Modified paths:
  • /trunk/extensions/DidYouMean/DidYouMean.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DidYouMean/DidYouMean.php
@@ -90,16 +90,18 @@
9191
9292 if (preg_match( "/{{[sS]ee\|([^}]*)}}/", $text, $see )) {
9393 wfDebug( "HIPP: see Hit\n" );
 94+ $hasTemplate = true;
9495 $sees = explode("|", $see[1]);
9596 } elseif (preg_match( "/{{[xX]see(\|[^}]*)}}/", $text, $see )) {
9697 wfDebug( "HIPP: xsee Hit\n" );
 98+ $hasTemplate = true;
9799 preg_match_all( "/\|\[\[([^]|]*)(?:\|([^|]*))?\]\](?: \(([^)]*)\))?/", $see[1], $ma );
98100 $sees = $ma[1];
99101 } else {
100102 wfDebug( "HIPP: (x)see Miss\n" );
101103 # there's no {{see}} in this chunk of wikitext
102104 # if this is the 1st chunk of the article itself we can put an empty {{see}} there.
103 - $text = "{{see|}}\n" . $text;
 105+ $hasTemplate = false;
104106 $sees = array();
105107 }
106108
@@ -118,10 +120,15 @@
119121
120122 # TODO is it better to use $parser->insertStripItem() ?
121123
122 - if (count($sees))
 124+ if (count($sees)) {
 125+ if( !$hasTemplate ) {
 126+ // We need to squish in a fresh copy of the template...
 127+ $text = "{{see|}}\n" . $text;
 128+ }
123129 $built_sees = build_sees($sees);
124 - else
 130+ } else {
125131 $built_sees = '';
 132+ }
126133
127134 $text = preg_replace(
128135 '/{{[xX]?[sS]ee\|[^}]*}}/',
@@ -297,10 +304,10 @@
298305 return true;
299306
300307 if ($article->isRedirect($text)) {
301 - if (!$wgParser->mDymRedirBeforeEdit && !($flags & EDIT_NEW))
 308+ if (empty( $wgParser->mDymRedirBeforeEdit ) && !($flags & EDIT_NEW))
302309 wfDymDoDelete( $article->getID() );
303310 } else {
304 - if ($wgParser->mDymRedirBeforeEdit || $flags & EDIT_NEW)
 311+ if (!empty( $wgParser->mDymRedirBeforeEdit ) || $flags & EDIT_NEW)
305312 wfDymDoInsert( $article->getID(), $article->getTitle()->getText() );
306313 }
307314

Status & tagging log