Revert r24105, r24106, r24107 'security fix' forbidden text/css and text/javascript...
[lhc/web/wiklou.git] / includes / MagicWord.php
index e616639..2ad02e4 100644 (file)
@@ -1,8 +1,7 @@
 <?php
 /**
  * File for magic words
- * @package MediaWiki
- * @subpackage Parser
+ * @addtogroup Parser
  */
 
 /**
@@ -21,7 +20,6 @@
  * magic words which are also Parser variables, add a MagicWordwgVariableIDs
  * hook. Use string keys.
  *
- * @package MediaWiki
  */
 class MagicWord {
        /**#@+
@@ -43,8 +41,19 @@ class MagicWord {
                'currentyear',
                'currenttime',
                'currenthour',
+               'localmonth',
+               'localmonthname',
+               'localmonthnamegen',
+               'localmonthabbrev',
+               'localday',
+               'localday2',
+               'localdayname',
+               'localyear',
+               'localtime',
+               'localhour',
                'numberofarticles',
                'numberoffiles',
+               'numberofedits',
                'sitename',
                'server',
                'servername',
@@ -57,7 +66,14 @@ class MagicWord {
                'namespacee',
                'currentweek',
                'currentdow',
+               'localweek',
+               'localdow',
                'revisionid',
+               'revisionday',
+               'revisionday2',
+               'revisionmonth',
+               'revisionyear',
+               'revisiontimestamp',
                'subpagename',
                'subpagenamee',
                'displaytitle',
@@ -70,7 +86,6 @@ class MagicWord {
                'subjectpagename',
                'subjectpagenamee',
                'numberofusers',
-               'rawsuffix',
                'newsectionlink',
                'numberofpages',
                'currentversion',
@@ -78,18 +93,20 @@ class MagicWord {
                '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;
@@ -137,6 +154,11 @@ class MagicWord {
                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" );
+               }
        }
 
        /**
@@ -155,7 +177,7 @@ class MagicWord {
                        $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 );
@@ -182,7 +204,7 @@ class MagicWord {
                if ( $this->mRegex === '' )
                        $this->initRegex();
 
-               return $this->mCaseSensitive ? '' : 'i';
+               return $this->mCaseSensitive ? '' : 'iu';
        }
 
        /**
@@ -266,7 +288,7 @@ class MagicWord {
         * Used in matchAndRemove()
         * @private
         **/
-       function pregRemoveAndRecord( $match ) {
+       function pregRemoveAndRecord( ) {
                $this->mFound = true;
                return '';
        }
@@ -275,7 +297,7 @@ class MagicWord {
         * 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;
        }
@@ -355,8 +377,9 @@ class MagicWord {
         * 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;
                }
        }
 
@@ -365,4 +388,4 @@ class MagicWord {
        }
 }
 
-?>
+