From 8b85aafbf2ae97d658e8a68a6f0cf569531f7017 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 20 Nov 2003 13:40:30 +0000 Subject: [PATCH] Date formatter into temp branch --- includes/OutputPage.php | 3 +- includes/Setup.php | 7 ++++ languages/Language.php | 83 +---------------------------------------- 3 files changed, 11 insertions(+), 82 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 37379c83a8..6ff2cc2fd2 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -713,7 +713,8 @@ $t[] = "" ; $text = $this->doBlockLevels( $text, $linestart ); if($wgUseDynamicDates) { - $text = $wgLang->replaceDates( $text ); + global $wgDateFormatter; + $text = $wgDateFormatter->reformat( $wgUser->getOption("date"), $text ); } $text = $this->replaceExternalLinks( $text ); diff --git a/includes/Setup.php b/includes/Setup.php index 944c758b33..3d33b47eb6 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -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 diff --git a/languages/Language.php b/languages/Language.php index b27421f808..54d8d3a0f7 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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; } -- 2.20.1