r48254 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48253‎ | r48254 | r48255 >
Date:05:19, 10 March 2009
Author:werdna
Status:ok
Tags:
Comment:
Tweak r48249 -- allow specification of the default format, and require the date to take up the entire argument.
Modified paths:
  • /trunk/phase3/includes/parser/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/includes/parser/DateFormatter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -89,11 +89,17 @@
9090 }
9191 }
9292
93 - static function formatDate( $parser, $date ) {
 93+ static function formatDate( $parser, $date, $defaultPref = null ) {
9494 $df = DateFormatter::getInstance();
9595
 96+ $date = trim($date);
 97+
9698 $pref = $parser->mOptions->getDateFormat();
97 - $date = $df->reformat( $pref, $date, false );
 99+
 100+ if ($pref == 'default' && $defaultPref)
 101+ $pref = $defaultPref;
 102+
 103+ $date = $df->reformat( $pref, $date, array('match-whole') );
98104 return $date;
99105 }
100106
Index: trunk/phase3/includes/parser/DateFormatter.php
@@ -117,7 +117,11 @@
118118 * @param $preference String: User preference
119119 * @param $text String: Text to reformat
120120 */
121 - function reformat( $preference, $text, $linked = true ) {
 121+ function reformat( $preference, $text, $options = array('linked') ) {
 122+
 123+ $linked = in_array( 'linked', $options );
 124+ $match_whole = in_array( 'match-whole', $options );
 125+
122126 if ( isset( $this->preferences[$preference] ) ) {
123127 $preference = $this->preferences[$preference];
124128 } else {
@@ -145,6 +149,13 @@
146150 $regex = str_replace( array( '\[\[', '\]\]' ), '', $regex );
147151 }
148152
 153+ if ($match_whole) {
 154+ // Let's hope this works
 155+ $regex = preg_replace( '!^/!', '/^', $regex );
 156+ $regex = str_replace( $this->regexTrail,
 157+ '$'.$this->regexTrail, $regex );
 158+ }
 159+
149160 // Another horrible hack
150161 $this->mLinked = $linked;
151162 $text = preg_replace_callback( $regex, array( &$this, 'replace' ), $text );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r48249* (bug 4582) Provide preference-based autoformatting of unlinked dates with t...werdna01:07, 10 March 2009

Status & tagging log