<?php
/**
* File for magic words
- * @package MediaWiki
- * @subpackage Parser
+ * @addtogroup Parser
*/
/**
* magic words which are also Parser variables, add a MagicWordwgVariableIDs
* hook. Use string keys.
*
- * @package MediaWiki
*/
class MagicWord {
/**#@+
'currentyear',
'currenttime',
'currenthour',
+ 'localmonth',
+ 'localmonthname',
+ 'localmonthnamegen',
+ 'localmonthabbrev',
+ 'localday',
+ 'localday2',
+ 'localdayname',
+ 'localyear',
+ 'localtime',
+ 'localhour',
'numberofarticles',
'numberoffiles',
+ 'numberofedits',
'sitename',
'server',
'servername',
'namespacee',
'currentweek',
'currentdow',
+ 'localweek',
+ 'localdow',
'revisionid',
+ 'revisionday',
+ 'revisionday2',
+ 'revisionmonth',
+ 'revisionyear',
+ 'revisiontimestamp',
'subpagename',
'subpagenamee',
'displaytitle',
'subjectpagename',
'subjectpagenamee',
'numberofusers',
- 'rawsuffix',
'newsectionlink',
'numberofpages',
'currentversion',
'basepagenamee',
'urlencode',
'currenttimestamp',
+ 'localtimestamp',
'directionmark',
'language',
'contentlanguage',
'pagesinnamespace',
'numberofadmins',
+ 'defaultsort',
);
static public $mObjects = array();
/**#@-*/
- function MagicWord($id = 0, $syn = '', $cs = false) {
+ function __construct($id = 0, $syn = '', $cs = false) {
$this->mId = $id;
$this->mSynonyms = (array)$syn;
$this->mCaseSensitive = $cs;
global $wgContLang;
$this->mId = $id;
$wgContLang->getMagic( $this );
+ if ( !$this->mSynonyms ) {
+ $this->mSynonyms = array( 'dkjsagfjsgashfajsh' );
+ #throw new MWException( "Error: invalid magic word '$id'" );
+ wfDebugLog( 'exception', "Error: invalid magic word '$id'\n" );
+ }
}
/**
$escSyn[] = preg_quote( $synonym, '/' );
$this->mBaseRegex = implode( '|', $escSyn );
- $case = $this->mCaseSensitive ? '' : 'i';
+ $case = $this->mCaseSensitive ? '' : 'iu';
$this->mRegex = "/{$this->mBaseRegex}/{$case}";
$this->mRegexStart = "/^(?:{$this->mBaseRegex})/{$case}";
$this->mVariableRegex = str_replace( "\\$1", "(.*?)", $this->mRegex );
if ( $this->mRegex === '' )
$this->initRegex();
- return $this->mCaseSensitive ? '' : 'i';
+ return $this->mCaseSensitive ? '' : 'iu';
}
/**
* Used in matchAndRemove()
* @private
**/
- function pregRemoveAndRecord( $match ) {
+ function pregRemoveAndRecord( ) {
$this->mFound = true;
return '';
}
* Replaces the word with something else
*/
function replace( $replacement, $subject, $limit=-1 ) {
- $res = preg_replace( $this->getRegex(), wfRegexReplacement( $replacement ), $subject, $limit );
+ $res = preg_replace( $this->getRegex(), StringUtils::escapeRegexReplacement( $replacement ), $subject, $limit );
$this->mModified = !($res === $subject);
return $res;
}
* lookup in a list of magic words
*/
function addToArray( &$array, $value ) {
+ global $wgContLang;
foreach ( $this->mSynonyms as $syn ) {
- $array[$syn] = $value;
+ $array[$wgContLang->lc($syn)] = $value;
}
}
}
}
-?>
+