Rehabilitate DateFormatter
authorTim Starling <tstarling@wikimedia.org>
Wed, 10 Apr 2019 05:33:57 +0000 (15:33 +1000)
committerTim Starling <tstarling@wikimedia.org>
Wed, 10 Apr 2019 11:00:04 +0000 (21:00 +1000)
commit76ca6c9b184da0c9a5f9c9e701e6257dbbdb077d
tree46b6aba01eb929127f3532bef6c73a32440fe520
parent421b4258b5c02375448c9a7d958ede71bf473929
Rehabilitate DateFormatter

This code is surprisingly little changed since I added the class in
November 2003, and needs some modernisation.

* Remove the "linked" option, unused since 1.21. Similarly, make the
  "match-whole" option implied. This allows the regexes to be
  simplified. Nothing will be broken, according to CodeSearch.
* Instead of ucfirst(), use the canonical month name from the language.
  This will work with e.g. French which does not capitalise month names.
* Stop caching DateFormatter instances in APC. Caching was added
  in 2005 when initialisation was being done on every request, but now
  it is only needed when parsing a page with {{#formatdate}}, which is
  rarely, and the constructor overhead is only 200µs after Language
  object data initialisation. Instead, use an in-process cache via a
  factory service.
* Add docs and extra tests.
* Remove todo note obsolete since 38 minutes after the original commit.
* Rename many variables.
* Use double-slash comments
* Don't store the Language object, just get arrays.
* Use mb_strtolower() instead of Language::lc() -- any customisation of
  Language::lc() would break PCRE case-insensitive matching.
* Use named subpatterns instead of "keys"
* Remove the ISO1/ISO2 distinction, the only difference was linking.
* Use closure variables instead of temporary object members

Change-Id: I25fb1203dba2930724d7bc28ad0d51f59f88e1ea
autoload.php
includes/MediaWikiServices.php
includes/ServiceWiring.php
includes/parser/CoreParserFunctions.php
includes/parser/DateFormatter.php
includes/parser/DateFormatterFactory.php [new file with mode: 0644]
tests/parser/parserTests.txt