aboutsummaryrefslogtreecommitdiffstats
path: root/includes/parser/DateFormatter.php
Commit message (Collapse)AuthorAgeFilesLines
* Use explicit nullable type on parameter argumentsUmherirrender2024-10-161-1/+1
| | | | | | | | | | | Implicitly marking parameter $... as nullable is deprecated in php8.4, the explicit nullable type must be used instead Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a Break one long line in SpecialPage.php Bug: T376276 Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
* Namespace all remaining classes in includes/parserJames D. Forrester2024-10-151-0/+6
| | | | | Bug: T353458 Change-Id: If02cc9b1ff78e26c1cf8c91ee4695845eb133829
* parser: Fix formatdate parser function for ISO year 0 = 1 BCthiemowmde2024-02-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm not sure how this ever happened, but I'm sure it's a mistake. The following test scenario should make it very obvious: * {{#formatdate:-0002-12-31|mdy}} * {{#formatdate:-0001-12-31|mdy}} * {{#formatdate:0000-12-31|mdy}} * {{#formatdate:0001-12-31|mdy}} * {{#formatdate:0002-12-31|mdy}} Expected output: 3 BC, 2 BC, 1 BC, 1, 2, … Current output: 3 BC, 2 BC, 0 (?), 1, 2, … Note how "1 BC" is skipped and shown as "0" instead. Everything else is correct, e.g. the ISO year -1 is already displayed as "2 BC". It's really only this single outlier. In case you don't know: There is no year 0 when the BC specifier is used. There is either year 1 after or year 1 before Christ. This is different in ISO, mostly to make calculations easier. That's why the DateFormater already does an extra `- 1` and `+ 1` in the two makeIsoYear and makeNormalYear methods. The problematic line of code was originally written in 2003, see https://phabricator.wikimedia.org/rMW98fc03e6 The core parser function exists since 2009, see https://phabricator.wikimedia.org/rMWb9ffb5a7 Change-Id: Iaeb7a954579a409fefd87dab4e2a15778ab39fb4
* Reorg: Move HTML-related classes out of includes/ to Html/Amir Sarabadani2023-02-161-0/+1
| | | | | Bug: T321882 Change-Id: I5dc1f7e9c303cd3f5b9dd7010d6bb470d8400a18
* parser: Minor code style improvements in DateFormatterthiemowmde2023-01-111-29/+13
| | | | | | | | | | | | | Why? * I found the LAST constant somewhat fragile and redundant. A complete array of target formats already exists. We can just use that. * We can use the convenient ?? operator now. Parts of this patch are split from I6e113d1. I believe this here is uncontroversial, that's why I re-submitted it as a separate patch. Change-Id: Id5c480d4e0183aa64fa4f19a5c03bbb537f9f971
* Use the null coalescing assignment operatorTim Starling2022-10-211-1/+1
| | | | | | | | Available since PHP 7.4. Automated search, manual replacement. Change-Id: Ibb163141526e799bff08cfeb4037b52144bb39fa
* DateFormatter: Move non-changing code out of anonymous functionThiemo Kreuz2022-08-101-4/+3
| | | | Change-Id: I85a5ec6ed354000a0f50e80f1e1201113c1cad3e
* DateFormatter: Turn private immutable properties into constantsThiemo Kreuz2022-08-081-37/+41
| | | | | | | | | | These are created once in the constructor and never touched again. Modern PHP allows us to be much more expressive in constants. Intentionally not doing anything else in this patch. More cleanup will be done in a later patch. Change-Id: Icae484dd7e2dd2a05247c111d9f2261c214c5d4e
* DateFormatter: Rename reused variable nameThiemo Kreuz2022-08-081-6/+6
| | | | Change-Id: Ibe5f921c6378c24137f503f1625262bb5842bfe2
* phan: Remove PhanTypePossiblyInvalidDimOffset suppressionUmherirrender2022-03-281-0/+2
| | | | | | | | | | | Make phan stricter about array keys Remaining false positive issues are suppressed. The suppression and the setting change can only be done together Bug: T304887 Depends-On: I3105a5fd4826f8667b5232834defc5ec93be32a1 Depends-On: Ie9610a6e83731468311edb3ed17f80fc509de385 Change-Id: I701f12ab94478c3b8e7fd82110ade74a8e6b04ef
* Remove some more comments that literally repeat the codeThiemo Kreuz2021-12-091-1/+1
| | | | | | | | Nothing to learn from these. You can find a longer explanation in the comments in I93751e6. Change-Id: I195aae70fc282b58be5b18160783f27d38605d15
* Remove dead variables and functions and unneeded parenthesisUmherirrender2021-08-131-3/+0
| | | | | | Found by sonarqube Change-Id: I3464d25e94d98aaca55d9209d5175542b335f994
* Use more neutral or alternative languageReedy2021-03-201-4/+2
| | | | | Bug: T277987 Change-Id: Iafc4b3e3137936046487119b7e17635f4e560277
* Fix even more PSR12.Properties.ConstantVisibility.NotFoundReedy2020-05-161-11/+11
| | | | Change-Id: I6d98efcfac1f1c0ab6a442e0af6d5daa6ef7801a
* Rehabilitate DateFormatterTim Starling2019-04-101-249/+192
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix notices emitted from DateFormatterTim Starling2019-04-101-7/+10
| | | | | | | | | | | | | Some languages have date abbreviations that contain ".", which allows the non-ISO regexes to match an input string containing an invalid month name. Use preg_quote() to avoid this. Also fix the error handling case of makeIsoMonth(). If the input date is invalid, don't try to wrap it in a date span, since that's semantically incorrect and may also access unset members of $bits, causing a notice. Bug: T220563 Change-Id: Ib2b3fb315dc93b60de595d3c445637f6bcc78a1a
* Use PHP 7 '??' operator instead of if-then-elseFomafix2018-10-211-4/+1
| | | | Change-Id: If9d4be5d88c8927f63cbb84dfc8181baf62ea3eb
* Add type hint Language where possibleFomafix2018-08-121-1/+1
| | | | | | Also use ?? instead of ?: to check for null. Change-Id: I058b61d7e06cdefecdafa82f60109cc386e2a809
* Mass conversion of $wgContLang to serviceAryeh Gregor2018-08-111-2/+4
| | | | | | | Brought to you by vim macros. Bug: T200246 Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
* Remove language as string for DateFormatter::getInstanceFomafix2018-04-191-5/+2
| | | | Change-Id: I677ab561d67b63f0c86f65fadf9319e41444a22a
* parser: Deprecate string type for $lang arg in DateFormatter::getInstanceFomafix2018-02-201-1/+4
| | | | | | | | | | | | | The parameter $lang is not used with type string in the Git repository: https://codesearch.wmflabs.org/search/?q=DateFormatter%3A%3AgetInstance This function is only used with type Language and without parameter. The support for the language as string will be removed with Change-ID I677ab561d67b63f0c86f65fadf9319e41444a22a. The removal of the support for the type string simplifies the code. Change-Id: I0c0ab46ffc0fab6b68672940e979ad7e5754a7d1
* Miscellaneous indentation tweaksBartosz Dziewoński2017-02-271-2/+2
| | | | | | | | | | I was bored. What? Don't look at me that way. I mostly targetted mixed tabs and spaces, but others were not spared. Note that some of the whitespace changes are inside HTML output, extended regexps or SQL snippets. Change-Id: Ie206cc946459f6befcfc2d520e35ad3ea3c0f1e0
* Replace use of &$thisBrad Jorsch2017-01-311-1/+1
| | | | | | | | | Use of &$this doesn't work in PHP 7.1. For callbacks to methods like array_map() it's completely unnecessary, while for hooks we still need to pass a reference and so we need to copy $this into a local variable. Bug: T153505 Change-Id: I8bbb26e248cd6f213fd0e7460d6d6935a3f9e468
* Make most of DateFormatter privateMax Semenik2017-01-191-10/+18
| | | | | | | | As discussed in https://gerrit.wikimedia.org/r/#/c/332702/ , these methods and fields shouldn't have been marked public in the first place. No outside users. Also, declare a couple of fields and remove unused ones. Change-Id: I7775978c87d983784a484ee2ad901d25c42499b3
* Un-blacklist PhanUndeclaredVariableErik Bernhardson2017-01-181-4/+7
| | | | | | | | | | Undeclared variables are a very common error type that we want to catch as often as possible. To avoid needing to refactor a variety of global level code (mostly in old-style maintenance scripts) this ignores undeclared variables in global scope. This is still a good improvement over what was happening previously. Change-Id: I50b41d571724244552074b9408abbdf6160aca59
* Convert all array() syntax to []Kunal Mehta2016-02-171-10/+10
| | | | | | | | | | Per wikitech-l consensus: https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html Notes: * Disabled CallTimePassByReference due to false positives (T127163) Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
* Replace newAccelerator() with getLocalServerInstance()Aaron Schulz2015-11-021-1/+1
| | | | | | The name is clearer and more consistent, with simpler arguments. Change-Id: I7205a99ce033e8b086a52cd02c8a721e99c84b1e
* objectcache: Introduce IExpiringStore for convenient TTL constantsTimo Tijhof2015-10-281-1/+1
| | | | | | | Also consistently use self:: instead of BagOStuff:: for constants referenced within the BagOStuff class. Change-Id: I20fde9fa5cddcc9e92fa6a02b05dc7effa846742
* Make DateFormatter::getInstance use APCAaron Schulz2015-10-261-9/+14
| | | | Change-Id: Idfff805903bffcdd6ff8f2a3c1331ca63476933e
* Minor cleanupsMax Semenik2015-04-021-1/+1
| | | | | | | | * Declare undeclared variables * Kill unused variables * Fix comments including PHPDoc Change-Id: I60015f6b6740aa9088bda3745f4dc4e65e29fcb1
* Add missing documentation in DateFormatter.phpm4tx2015-01-261-6/+7
| | | | Change-Id: Ic5c04bdb88bc57a7c44159d7858ef791c24354c4
* Fix phpcs issues in parseraddshore2014-08-121-12/+12
| | | | | | | | This fixes all issues except for: - class names - line length Change-Id: Ie91b010d5b3eec49d3b80b6e93b125a901ef43c6
* Cleanup some docs (includes/[m-r])umherirrender2014-07-241-1/+1
| | | | | | | | | | - Swap "$variable type" to "type $variable" - Added missing types - Fixed spacing inside docs - Makes beginning of @param/@return/@var/@throws in capital - Changed some types to match the more common spelling Change-Id: I8ebfbcea0e2ae2670553822acedde49c1aa7e98d
* Revert "Declare visibility on class properties of includes/parser/"Ori.livneh2014-05-161-33/+4
| | | | | | | | | See https://bugzilla.wikimedia.org/65375#c4 This reverts commit f359cdf61462782743a87943938ef4cce78b2647. Bug: 65375 Change-Id: I12a60b5cc52a07a6deabcbf47c7c99cd2faac3c3
* Various documentation updates for includes/parser/Siebrand Mazeland2014-05-111-0/+2
| | | | Change-Id: I16dd3a792cc83f8c80b3652d42c055730f6d177a
* Fix most CodeSniffer issues in includes/parser/Siebrand Mazeland2014-05-111-2/+4
| | | | | | | Remaining are the classes containing underscores and possibly a few other issues that will be addressed soonish. Change-Id: Icf56374c71afc134420ebbcfecf12dcb29dc9564
* Declare visibility on class properties of includes/parser/Siebrand Mazeland2014-05-111-4/+33
| | | | Change-Id: If03a9bd5eb83be4d15f54e73f49f42540fb7d5fc
* Fixed some @params documentation (includes/parser)umherirrender2014-04-221-7/+7
| | | | | | | | | Swapped some "$var type" to "type $var" or added missing types before the $var. Changed some other types to match the more common spelling. Makes beginning of some text in captial. Also added some missing @param. Change-Id: I49f8f48b521878de7abd9cc40efdeff6cf9a37e0
* Fix "@param null $param" documentationsThiemo Mättig2014-04-091-1/+2
| | | | | | | ... and very few other documentation details that are closely connected to these mistakes. Change-Id: I5b2691948e196124c77f0cc04d0ed5a7167cac25
* Removed space after issetumherirrender2013-04-261-3/+3
| | | | | | While at it, added/removed some other spaces in the same files Change-Id: Iabb23a448f6f53eb6020155f9c744f74f8b11786
* Fixed spacing in logging/parser/profiler/rl/revdel/search folderumherirrender2013-04-201-5/+9
| | | | | | | Added spaces before if, foreach Added some braces for one line statements Change-Id: I11bbcfa351e945b7bde10c2105d61a3cf5622205
* Added/Removed spaces around string concatenationumherirrender2013-04-131-1/+1
| | | | | | | | | And added/removed spaces around some other tokens, like +, -, *, /, <, >, =, ! Fixed windows newline style Change-Id: I0b9c8c408f3f6bfc0d685a074d7ec468fb848fc8
* fix some spacingumherirrender2013-03-251-1/+1
| | | | | | | | | | | * Removed spaces around array index * Removed double spaces or added spaces to begin or end of function calls, method signature, conditions or foreachs * Added braces to one-line ifs * Changed multi line conditions to one line conditions * Realigned some arrays Change-Id: Ia04d2a99d663b07101013c2d53b3b2e872fd9cc3
* Spellchecked /includes directoryYuri Astrakhan2013-03-131-1/+1
| | | | | | | | | * Ran spell-checker over code comments in /includes/ * A few spellchecking fixes for wfDebug() calls Found one very strange (NOOP?) line in Linker.php - see "TODO: BUG?" Change-Id: Ibb86b51073b980eda9ecce2cf0b8dd33f058adbf
* Fixed @param tags to conform with Doxygen format.Tyler Anthony Romeo2013-03-111-5/+5
| | | | | | | | | | | Doxygen expects parameter types to come before the parameter name in @param tags. Used a quick regex to switch everything around where possible. This only fixes cases where a primitve variable (or a primitive followed by other types) is the variable type. Other cases will need to be fixed manually. Change-Id: Ic59fd20856eb0489d70f3469a56ebce0efb3db13
* fix some spacingumherirrender2013-03-071-4/+4
| | | | | | | | Added/removed spaces around logical/arithmetic operator Reduced multiple empty lines to one empty line Removed wrong tabs before comments at end of line Removed too many spaces in assigments Change-Id: I2bba4e72f9b5f88c53324d7b70e6042f1aad8f6b
* fix some spacingumherirrender2013-02-041-16/+16
| | | | Change-Id: I88e73d47a552918880514d88a876296a6cb80d88
* Remove a bunch of trailing spaces and unneeded newlinesumherirrender2012-10-101-2/+2
| | | | Change-Id: I00f369641320acd7f087427ef031f3ee7efa0997
* Make DateFormatter work in any language, by default in the page content languagerobin2012-07-211-33/+38
| | | | | | | | | | | Add a lang parameter to DateFormatter so it can work in any language instead of only the site content language. (The memcached key is now per language code.) Use by default parser->getTargetLanguage() so it is parsed in the page content language by default. Also add some documentation and remove unneeded whitespace. If needed, a parameter to {{#dateformatter}} can now be easily added, to specify the language to format in. Change-Id: If61854920065f7c3b4170ab89e9aa66b299f9dd8
* Added missing GPLv2 headers in some places.Alexandre Emsenhuber2012-05-011-0/+16
| | | | | | Also made file/class documentation more consistent. Change-Id: I10c077f27a2077a266a64048fa137f7b1f8e226c