Date formatter into temp branch
authorTim Starling <tstarling@users.mediawiki.org>
Thu, 20 Nov 2003 13:40:30 +0000 (13:40 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Thu, 20 Nov 2003 13:40:30 +0000 (13:40 +0000)
includes/OutputPage.php
includes/Setup.php
languages/Language.php

index 37379c8..6ff2cc2 100644 (file)
@@ -713,7 +713,8 @@ $t[] = "</table>" ;
                $text = $this->doBlockLevels( $text, $linestart );
                
                if($wgUseDynamicDates) {
-                       $text = $wgLang->replaceDates( $text );
+                       global $wgDateFormatter;
+                       $text = $wgDateFormatter->reformat( $wgUser->getOption("date"), $text );
                }
 
                $text = $this->replaceExternalLinks( $text );
index 944c758..3d33b47 100644 (file)
@@ -19,6 +19,7 @@ if ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) {
 
 $fname = "Setup.php";
 wfProfileIn( $fname );
+global $wgUseDynamicDates;
 wfProfileIn( "$fname-includes" );
 
 # Only files which are used on every invocation should be included here
@@ -53,6 +54,12 @@ $wgMemc = new MemCachedClientforWiki();
 if( $wgUseMemCached ) {
        $wgMemc->set_servers( $wgMemCachedServers );
        $wgMemc->set_debug( $wgMemCachedDebug );
+}
+
+if ( $wgUseDynamicDates ) {
+       include_once( "DateFormatter.php" );
+       global $wgDateFormatter;
+       $wgDateFormatter = new DateFormatter;
 
        # Test it to see if it's working
        # This is necessary because otherwise wfMsg would be extremely inefficient
index b27421f..54d8d3a 100644 (file)
@@ -76,7 +76,8 @@ define("MAG_NOEDITSECTION", 14);
        "No preference",
        "January 15, 2001",
        "15 January 2001",
-       "2001 January 15"
+       "2001 January 15",
+       "2001-01-15"
 );
 
 /* private */ $wgUserTogglesEn = array(
@@ -1359,12 +1360,6 @@ class Language {
                global $wgMonthNamesEn;
                return $wgMonthNamesEn[$key-1];
        }
-       
-       function getMonthRegex()
-       {
-               global $wgMonthNamesEn;
-               return implode( "|", $wgMonthNamesEn );
-       }
 
        function getMonthAbbreviation( $key )
        {
@@ -1554,80 +1549,6 @@ class Language {
                }
        }
 
-       function replaceDates( $text )
-       {
-               global $wgUser, $wgInputEncoding, $wgUseDynamicDates;
-               
-               # Feature can be disabled
-               if ( !$wgUseDynamicDates ) {
-                       return;
-               }
-
-               # Setup
-               
-               $datePreference = $wgUser->getOption( 'date' );
-
-               static $monthNames = "", $rxDM, $rxMD, $rxY, $rxDMY, $rxYDM, $rxMDY, $rxYMD;
-               if ( $monthNames == "" ) {
-                       $monthNames = $this->getMonthRegex();
-                       
-                       # Attempt at UTF-8 support, untested at the moment
-                       if ( $wgInputEncoding == 'UTF-8' ) {
-                               $regexTrail = '(?![a-z])/iu';
-                       } else {
-                               $regexTrail = '(?![a-z])/i';
-                       }
-
-                       # Partial regular expressions
-                       $prxDM = '\[\[(\d{1,2})[ _](' . $monthNames . ')]]';
-                       $prxMD = '\[\[(' . $monthNames . ')[ _](\d{1,2})]]';
-                       $prxY = '\[\[(\d{1,4}([ _]BC|))]]';
-                       
-                       # Real regular expressions
-                       $rxDMY = "/{$prxDM} *,? *{$prxY}{$regexTrail}"; 
-                       $rxYDM = "/{$prxY} *,? *{$prxDM}{$regexTrail}";
-                       $rxMDY = "/{$prxMD} *,? *{$prxY}{$regexTrail}";
-                       $rxYMD = "/{$prxY} *,? *{$prxMD}{$regexTrail}";
-                       $rxDM = "/{$prxDM}{$regexTrail}";
-                       $rxMD = "/{$prxMD}{$regexTrail}";
-                       $rxY = "/{$prxY}{$regexTrail}";
-               }
-               
-               # Do replacements
-               # TODO: month capitalisation?
-               if ( $datePreference == 0 ) { 
-                       # no preference
-                       $text = preg_replace( $rxDMY, '[[$2 $1|$1 $2]] [[$3]]', $text);
-                       $text = preg_replace( $rxYDM, '[[$1]] [[$4 $3]]', $text);
-                       $text = preg_replace( $rxMDY, '[[$1 $2]], [[$3]]', $text);
-                       $text = preg_replace( $rxYMD, '[[$1]] [[$3 $4]]', $text);
-                       $text = preg_replace ( $rxDM, '[[$2 $1|$1 $2]]', $text);
-               } else if ( $datePreference == 1 ) {
-                       # MDY preferred
-                       $text = preg_replace( $rxDMY, '[[$2 $1]], [[$3]]', $text);
-                       $text = preg_replace( $rxYDM, '[[$4 $3]], [[$1]]', $text);
-                       $text = preg_replace( $rxMDY, '[[$1 $2]], [[$3]]', $text);
-                       $text = preg_replace( $rxYMD, '[[$3 $4]], [[$1]]', $text);
-                       $text = preg_replace ( $rxDM, '[[$2 $1]]', $text);
-               } else if ( $datePreference == 2 ) {
-                       # DMY preferred
-                       $text = preg_replace( $rxDMY, '[[$2 $1|$1 $2]] [[$3]]', $text);
-                       $text = preg_replace( $rxYDM, '[[$4 $3|$3 $4]] [[$1]]', $text);
-                       $text = preg_replace( $rxMDY, '[[$1 $2|$2 $1]] [[$3]]', $text);
-                       $text = preg_replace( $rxYMD, '[[$3 $4|$4 $3]] [[$1]]', $text);
-                       $text = preg_replace ( $rxDM, '[[$2 $1|$1 $2]]', $text);
-                       $text = preg_replace ( $rxMD, '[[$1 $2|$2 $1]]', $text);
-               } else if ( $datePreference == 3 ) {
-                       # YMD preferred
-                       $text = preg_replace( $rxDMY, '[[$3]] [[$2 $1]]', $text);
-                       $text = preg_replace( $rxYDM, '[[$1]] [[$4 $3]]', $text);
-                       $text = preg_replace( $rxMDY, '[[$3]] [[$1 $2]]', $text);
-                       $text = preg_replace( $rxYMD, '[[$1]] [[$3 $4]]', $text);
-                       $text = preg_replace ( $rxDM, '[[$2 $1]]', $text);
-               }
-               return $text;
-       }
-
        # For right-to-left language support
        function isRTL() { return false; }