From: Andrew Garrett Date: Tue, 10 Mar 2009 05:19:05 +0000 (+0000) Subject: Tweak r48249 -- allow specification of the default format, and require the date to... X-Git-Tag: 1.31.0-rc.0~42535 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=commitdiff_plain;h=72acc9b179d5aa865b07695566c2d8c6ea9e64b3;p=lhc%2Fweb%2Fwiklou.git Tweak r48249 -- allow specification of the default format, and require the date to take up the entire argument. --- diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 83714517ba..f5bb76ef1f 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -89,11 +89,17 @@ class CoreParserFunctions { } } - static function formatDate( $parser, $date ) { + static function formatDate( $parser, $date, $defaultPref = null ) { $df = DateFormatter::getInstance(); + $date = trim($date); + $pref = $parser->mOptions->getDateFormat(); - $date = $df->reformat( $pref, $date, false ); + + if ($pref == 'default' && $defaultPref) + $pref = $defaultPref; + + $date = $df->reformat( $pref, $date, array('match-whole') ); return $date; } diff --git a/includes/parser/DateFormatter.php b/includes/parser/DateFormatter.php index d2153f0163..aa6415e47a 100644 --- a/includes/parser/DateFormatter.php +++ b/includes/parser/DateFormatter.php @@ -117,7 +117,11 @@ class DateFormatter * @param $preference String: User preference * @param $text String: Text to reformat */ - function reformat( $preference, $text, $linked = true ) { + function reformat( $preference, $text, $options = array('linked') ) { + + $linked = in_array( 'linked', $options ); + $match_whole = in_array( 'match-whole', $options ); + if ( isset( $this->preferences[$preference] ) ) { $preference = $this->preferences[$preference]; } else { @@ -145,6 +149,13 @@ class DateFormatter $regex = str_replace( array( '\[\[', '\]\]' ), '', $regex ); } + if ($match_whole) { + // Let's hope this works + $regex = preg_replace( '!^/!', '/^', $regex ); + $regex = str_replace( $this->regexTrail, + '$'.$this->regexTrail, $regex ); + } + // Another horrible hack $this->mLinked = $linked; $text = preg_replace_callback( $regex, array( &$this, 'replace' ), $text );