r49794 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49793‎ | r49794 | r49795 >
Date:04:01, 24 April 2009
Author:werdna
Status:resolved (Comments)
Tags:
Comment:
Fix spacing issues with autoformatted dates. Includes a parser test for the specific failure case which was fixed.
Modified paths:
  • /trunk/phase3/includes/parser/DateFormatter.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.txt
@@ -7289,8 +7289,17 @@
72907290 !! result
72917291 <p><a href="https://www.mediawiki.org/index.php?title=2009-03-24&amp;action=edit&amp;redlink=1" class="new" title="2009-03-24 (page does not exist)">2009-03-24</a>
72927292 </p>
7293 -!!end
 7293+!! end
72947294
 7295+!! test
 7296+Spacing of numbers in formatted dates
 7297+!! input
 7298+{{#formatdate:January 15}}
 7299+!! result
 7300+<p><span class="mw-formatted-date" title="01-15">January 15</span>
 7301+</p>
 7302+!! end
 7303+
72957304 #
72967305 #
72977306 #
Index: trunk/phase3/includes/parser/DateFormatter.php
@@ -48,10 +48,10 @@
4949 $this->prxISO2 = '\[\[(-?\d{4})-(\d{2})-(\d{2})\]\]';
5050
5151 # Real regular expressions
52 - $this->regexes[self::DMY] = "/{$this->prxDM} *,? *{$this->prxY}{$this->regexTrail}";
53 - $this->regexes[self::YDM] = "/{$this->prxY} *,? *{$this->prxDM}{$this->regexTrail}";
54 - $this->regexes[self::MDY] = "/{$this->prxMD} *,? *{$this->prxY}{$this->regexTrail}";
55 - $this->regexes[self::YMD] = "/{$this->prxY} *,? *{$this->prxMD}{$this->regexTrail}";
 52+ $this->regexes[self::DMY] = "/{$this->prxDM}( *, *| +){$this->prxY}{$this->regexTrail}";
 53+ $this->regexes[self::YDM] = "/{$this->prxY}( *, *| +){$this->prxDM}{$this->regexTrail}";
 54+ $this->regexes[self::MDY] = "/{$this->prxMD}( *, *| +){$this->prxY}{$this->regexTrail}";
 55+ $this->regexes[self::YMD] = "/{$this->prxY}( *, *| +){$this->prxMD}{$this->regexTrail}";
5656 $this->regexes[self::DM] = "/{$this->prxDM}{$this->regexTrail}";
5757 $this->regexes[self::MD] = "/{$this->prxMD}{$this->regexTrail}";
5858 $this->regexes[self::ISO1] = "/{$this->prxISO1}{$this->regexTrail}";

Follow-up revisions

RevisionCommit summaryAuthorDate
r51339Fix up r49794, make new groups noncapturing, fixing offset problem with linke...werdna12:39, 2 June 2009

Comments

#Comment by Hidemyip (talk | contribs)   05:14, 13 May 2009

This change breaks existing autoformatting for linked dates, because it introduces extra parentheses groupings that throw off the counts. The parser tests missed this because they're only testing the new {{#formatdate}} functionality, and not the older linked date functionality. This patch will fix the problem by introducing new blank ("dummy") match groupings to correspond to the new parentheses groups:

Index: includes/parser/DateFormatter.php
===================================================================
--- includes/parser/DateFormatter.php   (revision 50326)
+++ includes/parser/DateFormatter.php   (working copy)
@@ -59,10 +59,10 @@

        # Extraction keys
        # See the comments in replace() for the meaning of the letters
-       $this->keys[self::DMY] = 'jFY';
+       $this->keys[self::DMY] = 'jF Y';
        $this->keys[self::YDM] = 'Y jF';
-       $this->keys[self::MDY] = 'FjY';
-       $this->keys[self::YMD] = 'Y Fj';
+       $this->keys[self::MDY] = 'Fj Y';
+       $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
#Comment by Tim Starling (talk | contribs)   07:32, 22 May 2009

Presumably it can be dealt with by making the new groups non-capturing.

#Comment by Werdna (talk | contribs)   12:40, 2 June 2009

Fixed up in r51339.

Status & tagging log