Re-do r96798 ("LanguageConverter now depends on the page content language"), without...
[lhc/web/wiklou.git] / includes / parser / DateFormatter.php
index 9bd6c68..6559e88 100644 (file)
@@ -1,4 +1,9 @@
 <?php
+/**
+ * Date formatter
+ *
+ * @file
+ */
 
 /**
  * Date formatter, recognises dates in plain text and formats them accoding to user preferences.
@@ -29,7 +34,7 @@ class DateFormatter
        /**
         * @todo document
         */
-       function DateFormatter() {
+       function __construct() {
                global $wgContLang;
 
                $this->monthNames = $this->getMonthRegex();
@@ -48,10 +53,10 @@ class DateFormatter
                $this->prxISO2 = '\[\[(-?\d{4})-(\d{2})-(\d{2})\]\]';
 
                # Real regular expressions
-               $this->regexes[self::DMY] = "/{$this->prxDM}( *, *| +){$this->prxY}{$this->regexTrail}";
-               $this->regexes[self::YDM] = "/{$this->prxY}( *, *| +){$this->prxDM}{$this->regexTrail}";
-               $this->regexes[self::MDY] = "/{$this->prxMD}( *, *| +){$this->prxY}{$this->regexTrail}";
-               $this->regexes[self::YMD] = "/{$this->prxY}( *, *| +){$this->prxMD}{$this->regexTrail}";
+               $this->regexes[self::DMY] = "/{$this->prxDM}(?: *, *| +){$this->prxY}{$this->regexTrail}";
+               $this->regexes[self::YDM] = "/{$this->prxY}(?: *, *| +){$this->prxDM}{$this->regexTrail}";
+               $this->regexes[self::MDY] = "/{$this->prxMD}(?: *, *| +){$this->prxY}{$this->regexTrail}";
+               $this->regexes[self::YMD] = "/{$this->prxY}(?: *, *| +){$this->prxMD}{$this->regexTrail}";
                $this->regexes[self::DM] = "/{$this->prxDM}{$this->regexTrail}";
                $this->regexes[self::MD] = "/{$this->prxMD}{$this->regexTrail}";
                $this->regexes[self::ISO1] = "/{$this->prxISO1}{$this->regexTrail}";
@@ -116,6 +121,7 @@ class DateFormatter
        /**
         * @param $preference String: User preference
         * @param $text String: Text to reformat
+        * @param $options Array: can contain 'linked' and/or 'match-whole'
         */
        function reformat( $preference, $text, $options = array('linked') ) {
        
@@ -176,8 +182,8 @@ class DateFormatter
                $bits = array();
                $key = $this->keys[$this->mSource];
                for ( $p=0; $p < strlen($key); $p++ ) {
-                       if ( $key{$p} != ' ' ) {
-                               $bits[$key{$p}] = $matches[$p+1];
+                       if ( $key[$p] != ' ' ) {
+                               $bits[$key[$p]] = $matches[$p+1];
                        }
                }
                
@@ -218,7 +224,7 @@ class DateFormatter
                }
 
                for ( $p=0; $p < strlen( $format ); $p++ ) {
-                       $char = $format{$p};
+                       $char = $format[$p];
                        switch ( $char ) {
                                case 'd': # ISO day of month
                                        $text .= $bits['d'];
@@ -265,10 +271,10 @@ class DateFormatter
                        $isoBits[] = $bits['y'];
                $isoBits[] = $bits['m'];
                $isoBits[] = $bits['d'];
-               $isoDate = implode( '-', $isoBits );;
+               $isoDate = implode( '-', $isoBits );
                
                // Output is not strictly HTML (it's wikitext), but <span> is whitelisted.
-               $text = Xml::tags( 'span',
+               $text = Html::rawElement( 'span',
                                        array( 'class' => 'mw-formatted-date', 'title' => $isoDate ), $text );
                
                return $text;
@@ -321,7 +327,7 @@ class DateFormatter
         * @todo document
         */
        function makeNormalYear( $iso ) {
-               if ( $iso{0} == '-' ) {
+               if ( $iso[0] == '-' ) {
                        $text = (intval( substr( $iso, 1 ) ) + 1) . ' BC';
                } else {
                        $text = intval( $iso );