From d81f562b712f2387fa02290bf2ca86392ab356f2 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 11 Oct 2006 20:21:25 +0000 Subject: Aktualisierung auf Version 1.8.1 --- includes/DateFormatter.php | 131 +++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 64 deletions(-) (limited to 'includes/DateFormatter.php') diff --git a/includes/DateFormatter.php b/includes/DateFormatter.php index 02acac73..dc077fdc 100644 --- a/includes/DateFormatter.php +++ b/includes/DateFormatter.php @@ -1,25 +1,11 @@ prxISO2 = '\[\[(-?\d{4})-(\d{2})-(\d{2})]]'; # Real regular expressions - $this->regexes[DF_DMY] = "/{$this->prxDM} *,? *{$this->prxY}{$this->regexTrail}"; - $this->regexes[DF_YDM] = "/{$this->prxY} *,? *{$this->prxDM}{$this->regexTrail}"; - $this->regexes[DF_MDY] = "/{$this->prxMD} *,? *{$this->prxY}{$this->regexTrail}"; - $this->regexes[DF_YMD] = "/{$this->prxY} *,? *{$this->prxMD}{$this->regexTrail}"; - $this->regexes[DF_DM] = "/{$this->prxDM}{$this->regexTrail}"; - $this->regexes[DF_MD] = "/{$this->prxMD}{$this->regexTrail}"; - $this->regexes[DF_ISO1] = "/{$this->prxISO1}{$this->regexTrail}"; - $this->regexes[DF_ISO2] = "/{$this->prxISO2}{$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}"; + $this->regexes[self::ISO2] = "/{$this->prxISO2}{$this->regexTrail}"; # Extraction keys # See the comments in replace() for the meaning of the letters - $this->keys[DF_DMY] = 'jFY'; - $this->keys[DF_YDM] = 'Y jF'; - $this->keys[DF_MDY] = 'FjY'; - $this->keys[DF_YMD] = 'Y Fj'; - $this->keys[DF_DM] = 'jF'; - $this->keys[DF_MD] = 'Fj'; - $this->keys[DF_ISO1] = 'ymd'; # y means ISO year - $this->keys[DF_ISO2] = 'ymd'; + $this->keys[self::DMY] = 'jFY'; + $this->keys[self::YDM] = 'Y jF'; + $this->keys[self::MDY] = 'FjY'; + $this->keys[self::YMD] = 'Y Fj'; + $this->keys[self::DM] = 'jF'; + $this->keys[self::MD] = 'Fj'; + $this->keys[self::ISO1] = 'ymd'; # y means ISO year + $this->keys[self::ISO2] = 'ymd'; # Target date formats - $this->targets[DF_DMY] = '[[F j|j F]] [[Y]]'; - $this->targets[DF_YDM] = '[[Y]], [[F j|j F]]'; - $this->targets[DF_MDY] = '[[F j]], [[Y]]'; - $this->targets[DF_YMD] = '[[Y]] [[F j]]'; - $this->targets[DF_DM] = '[[F j|j F]]'; - $this->targets[DF_MD] = '[[F j]]'; - $this->targets[DF_ISO1] = '[[Y|y]]-[[F j|m-d]]'; - $this->targets[DF_ISO2] = '[[y-m-d]]'; + $this->targets[self::DMY] = '[[F j|j F]] [[Y]]'; + $this->targets[self::YDM] = '[[Y]], [[F j|j F]]'; + $this->targets[self::MDY] = '[[F j]], [[Y]]'; + $this->targets[self::YMD] = '[[Y]] [[F j]]'; + $this->targets[self::DM] = '[[F j|j F]]'; + $this->targets[self::MD] = '[[F j]]'; + $this->targets[self::ISO1] = '[[Y|y]]-[[F j|m-d]]'; + $this->targets[self::ISO2] = '[[y-m-d]]'; # Rules # pref source target - $this->rules[DF_DMY][DF_MD] = DF_DM; - $this->rules[DF_ALL][DF_MD] = DF_MD; - $this->rules[DF_MDY][DF_DM] = DF_MD; - $this->rules[DF_ALL][DF_DM] = DF_DM; - $this->rules[DF_NONE][DF_ISO2] = DF_ISO1; + $this->rules[self::DMY][self::MD] = self::DM; + $this->rules[self::ALL][self::MD] = self::MD; + $this->rules[self::MDY][self::DM] = self::MD; + $this->rules[self::ALL][self::DM] = self::DM; + $this->rules[self::NONE][self::ISO2] = self::ISO1; + + $this->preferences = array( + 'default' => self::NONE, + 'dmy' => self::DMY, + 'mdy' => self::MDY, + 'ymd' => self::YMD, + 'ISO 8601' => self::ISO1, + ); } /** * @static */ function &getInstance() { - global $wgDBname, $wgMemc; + global $wgMemc; static $dateFormatter = false; if ( !$dateFormatter ) { - $dateFormatter = $wgMemc->get( "$wgDBname:dateformatter" ); + $dateFormatter = $wgMemc->get( wfMemcKey( 'dateformatter' ) ); if ( !$dateFormatter ) { $dateFormatter = new DateFormatter; - $wgMemc->set( "$wgDBname:dateformatter", $dateFormatter, 3600 ); + $wgMemc->set( wfMemcKey( 'dateformatter' ), $dateFormatter, 3600 ); } } return $dateFormatter; } /** - * @param $preference - * @param $text + * @param string $preference User preference + * @param string $text Text to reformat */ function reformat( $preference, $text ) { - if ($preference == 'ISO 8601') $preference = 4; # The ISO 8601 option used to be 4 - for ( $i=1; $i<=DF_LAST; $i++ ) { + if ( isset( $this->preferences[$preference] ) ) { + $preference = $this->preferences[$preference]; + } else { + $preference = self::NONE; + } + for ( $i=1; $i<=self::LAST; $i++ ) { $this->mSource = $i; if ( @$this->rules[$preference][$i] ) { # Specific rules $this->mTarget = $this->rules[$preference][$i]; - } elseif ( @$this->rules[DF_ALL][$i] ) { + } elseif ( @$this->rules[self::ALL][$i] ) { # General rules - $this->mTarget = $this->rules[DF_ALL][$i]; + $this->mTarget = $this->rules[self::ALL][$i]; } elseif ( $preference ) { # User preference $this->mTarget = $preference; @@ -131,7 +142,7 @@ class DateFormatter # Default $this->mTarget = $i; } - $text = preg_replace_callback( $this->regexes[$i], 'wfMainDateReplace', $text ); + $text = preg_replace_callback( $this->regexes[$i], array( &$this, 'replace' ), $text ); } return $text; } @@ -277,12 +288,4 @@ class DateFormatter } } -/** - * @todo document - */ -function wfMainDateReplace( $matches ) { - $df =& DateFormatter::getInstance(); - return $df->replace( $matches ); -} - ?> -- cgit v1.2.3-54-g00ecf