function getWasModified(){
return $this->mModified;
}
+
+ # $magicarr is an associative array of (magic word ID => replacement)
+ # This method uses the php feature to do several replacements at the same time,
+ # thereby gaining some efficiency. The result is placed in the out variable
+ # $result. The return value is true if something was replaced.
+
+ /* static */ function replaceMultiple( $magicarr, $subject, &$result ){
+ $search = array();
+ $replace = array();
+ foreach( $magicarr as $id => $replacement ){
+ $mw = MagicWord::get( $id );
+ $search[] = $mw->getRegex();
+ $replace[] = $replacement;
+ }
+
+ $result = preg_replace( $search, $replace, $subject );
+ return !($result === $subject);
+ }
}
# Used in matchAndRemove()
$fname = "OutputPage::replaceVariables";
wfProfileIn( $fname );
-
+ $magic = array();
+
# Basic variables
# See Language.php for the definition of each magic word
-
# As with sigs, this uses the server's local time -- ensure
# this is appropriate for your audience!
- $v = date( "m" );
- $mw =& MagicWord::get( MAG_CURRENTMONTH );
- $text = $mw->replace( $v, $text );
- if( $mw->getWasModified() ) { $this->mContainsOldMagic++; }
-
- $v = $wgLang->getMonthName( date( "n" ) );
- $mw =& MagicWord::get( MAG_CURRENTMONTHNAME );
- $text = $mw->replace( $v, $text );
- if( $mw->getWasModified() ) { $this->mContainsOldMagic++; }
-
- $v = $wgLang->getMonthNameGen( date( "n" ) );
- $mw =& MagicWord::get( MAG_CURRENTMONTHNAMEGEN );
- $text = $mw->replace( $v, $text );
- if( $mw->getWasModified() ) { $this->mContainsOldMagic++; }
-
- $v = date( "j" );
- $mw = MagicWord::get( MAG_CURRENTDAY );
- $text = $mw->replace( $v, $text );
- if( $mw->getWasModified() ) { $this->mContainsOldMagic++; }
-
- $v = $wgLang->getWeekdayName( date( "w" )+1 );
- $mw =& MagicWord::get( MAG_CURRENTDAYNAME );
- $text = $mw->replace( $v, $text );
- if( $mw->getWasModified() ) { $this->mContainsOldMagic++; }
+
+ $magic[MAG_CURRENTMONTH] = date( "m" );
+ $magic[MAG_CURRENTMONTHNAME] = $wgLang->getMonthName( date("n") );
+ $magic[MAG_CURRENTMONTHNAMEGEN] = $wgLang->getMonthNameGen( date("n") );
+ $magic[MAG_CURRENTDAY] = date("j");
+ $magic[MAG_CURRENTDAYNAME] = $wgLang->getWeekdayName( date("w")+1 );
+ $magic[MAG_CURRENTYEAR] = date( "Y" );
+ $magic[MAG_CURRENTTIME] = $wgLang->time( wfTimestampNow(), false );
- $v = date( "Y" );
- $mw =& MagicWord::get( MAG_CURRENTYEAR );
- $text = $mw->replace( $v, $text );
- if( $mw->getWasModified() ) { $this->mContainsOldMagic++; }
-
- $v = $wgLang->time( wfTimestampNow(), false );
- $mw =& MagicWord::get( MAG_CURRENTTIME );
- $text = $mw->replace( $v, $text );
- if( $mw->getWasModified() ) { $this->mContainsOldMagic++; }
+ $this->mContainsOldMagic += MagicWord::replaceMultiple($magic, $text, $text);
$mw =& MagicWord::get( MAG_NUMBEROFARTICLES );
if ( $mw->match( $text ) ) {