Commit graph

1650 commits

Author SHA1 Message Date
Daimona Eaytoy
fbf5f8178f language: mark sprintfDate as unsafe
It uses several msg()->text(), and is thus unsafe. taint-check 3.0.0 will
see it on its own, but let's mark it now.

Change-Id: I7b02e110bbf9dbd5317f717b3a421d21cb3b2ab0
2019-10-20 13:05:08 +00:00
Aaron Schulz
0dec11bc1e language: optimize uc(), lc(), and (uc|lc)first() and enforce return type
In some cases these would previously not return strings if passed things like
integers or floats which should be harmless. Note that ord() on an integer or
float internally casts the value to a string to get the first octet code.

Bug: T229266
Change-Id: I0dca34dde39bc1d3ace9b4a3196af334357b0653
2019-10-16 17:46:15 +00:00
Aryeh Gregor
f23c4570e4 Make grammar transform cache an instance member
Normally there shouldn't be more than one Language object in existence
at a time because of $mLangObjCache, so there's no need for a
MapCacheLRU for grammar transformations. Just make it an instance member
of Language.

If someone directly called the Language constructor instead of
factory(), or meddled with $mLangObjCache, with one of the three
languages that have transforms defined, and called
getGrammarTransformations() on both distinct objects, this change could
result in duplication of an array of about 50 elements. I think the risk
is acceptable.

The change should be covered acceptably by existing tests for LanguageHe
and LanguageRu.  (There's not much to test.)

Bug: T201405
Change-Id: I483bafbbb7d109b670596f16381def9e3bd26d89
2019-10-08 22:24:22 +00:00
Aryeh Gregor
8c4f59db64 New LanguageFallback service
This replaces the static Language methods getFallbackFor(),
getFallbacksFor(), and getFallbacksIncludingSiteLanguage(). There is
100% unit and integration test coverage for the new class.

One deliberate functional change: I changed one place where we threw
MWException to InvalidArgumentException.

Bug: T201405
Depends-On: Ie7a89f6ed7d52a0bc01672019ff92e7ee105a1f3
Change-Id: I49222eb55f1feec5b1dcd40f364cffe0c8801855
2019-10-08 15:11:39 -07:00
Aryeh Gregor
6d80b6c082 Split some Language methods to LanguageNameUtils
These are static methods that have to do with processing language names
and codes. I didn't include fallback behavior, because that would mean a
circular dependency with LocalisationCache.

In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class
constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I
also renamed fetchLanguageName(s) to getLanguageName(s).

There is 100% test coverage for the code in the new class.

This was previously committed as 2e52f48c2e and reverted because it
depended on e4468a1d6b, which had to be reverted for performance
issues. There should be no changes other than rebasing.

Bug: T201405
Change-Id: Ifa346c8a92bf1eb57dc5e79458b32b7b26f1ee8a
2019-10-07 15:20:52 -07:00
Aryeh Gregor
043d88f680 Make LocalisationCache a service
This removes Language::$dataCache without deprecation, because 1) I
don't know of a way to properly simulate it in the new paradigm, and 2)
I found no direct access to the member outside of the Language and
LanguageTest classes.

An earlier version of this patch (e4468a1d6b) had to be reverted
because of a massive slowdown on test runs. Based on some local testing,
this should fix the problem. Running all tests in languages is slowed
down by only around 20% instead of a factor of five, and memory usage is
actually reduced greatly (~350 MB -> ~200 MB). The slowdown is still not
great, but I assume it's par for the course for converting things to
services and is acceptable. If not, I can try to optimize further.

Bug: T231220
Bug: T231198
Bug: T231200
Bug: T201405
Change-Id: Ieadbd820379a006d8ad2d2e4a1e96241e172ec5a
2019-10-07 13:18:47 -07:00
Daimona Eaytoy
b5cbb5ab3f Upgrade phan config to 0.7.1
This allows us to remove many suppressions for phan false positives.

Bug: T231636
Depends-On: I82a279e1f7b0fdefd3bb712e46c7d0665429d065
Change-Id: I5c251e9584a1ae9fb1577afcafb5001e0dcd41c7
2019-09-04 08:20:53 +00:00
Daimona Eaytoy
c659bc6308 Unsuppress another phan issue (part 7)
Bug: T231636
Depends-On: I2cd24e73726394e3200a570c45d5e86b6849bfa9
Depends-On: I4fa3e6aad872434ca397325ed7a83f94973661d0
Change-Id: Ie6233561de78457cae5e4e44e220feec2d1272d8
2019-09-03 17:19:21 +00:00
Daimona Eaytoy
e70b5b3309 Unsuppress other phan issues (part 4)
Bug: T231636
Depends-On: I58e67c2b38389df874438deada4239510d21654f
Change-Id: I6e5fba7bd273219b1206559420b5bdb78734aa84
2019-08-31 17:13:39 +00:00
Daimona Eaytoy
5eac6d131c Unsuppress more phan issues (part 3)
Bug: T231636
Depends-On: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
Change-Id: I58e67c2b38389df874438deada4239510d21654f
2019-08-31 16:38:55 +00:00
Daimona Eaytoy
fb3428eb8f Unsuppress other phan issues with low count
And also update approximated counts, which for the most part are lower
than reported (hooray!)

Bug: T231636
Depends-On: Ica50297ec7c71a81ba2204f9763499da925067bd
Change-Id: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
2019-08-30 09:42:15 +00:00
Daimona Eaytoy
7f7efbe026 Globally unsuppress phan issues with low count
All of these suppression prevent the detection of many common mistakes,
and could easily prevent things like T231488. Especially if there are
few issues of a given type, it's way better to suppress them inline,
instead of disabling them for the whole core.
This patch only touches the one with a lower count (although those
counts may be out of date).

Bug: T231636
Change-Id: Ica50297ec7c71a81ba2204f9763499da925067bd
2019-08-30 09:40:47 +00:00
Amir Sarabadani
308e6427ae Revert "Make LocalisationCache a service"
This reverts commits:
 - 76a940350d
 - b78b8804d0
 - 2e52f48c2e
 - e4468a1d6b

Bug: T231200
Bug: T231198
Change-Id: I1a7e46a979ae5c9c8130dd3927f6663a216ba753
2019-08-26 18:28:26 +02:00
Aryeh Gregor
2e52f48c2e Split some Language methods to LanguageNameUtils
These are static methods that have to do with processing language names
and codes. I didn't include fallback behavior, because that would mean a
circular dependency with LocalisationCache.

In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class
constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I
also renamed fetchLanguageName(s) to getLanguageName(s).

There is 100% test coverage for the code in the new class.

Change-Id: I245ae94bfc1f62b6af75ea57525139adf2539fe6
2019-08-23 12:52:35 +03:00
Aryeh Gregor
e4468a1d6b Make LocalisationCache a service
This removes Language::$dataCache without deprecation, because 1) I
don't know of a way to properly simulate it in the new paradigm, and 2)
I found no direct access to the member outside of the Language and
LanguageTest classes.

Change-Id: Iaa86c48e7434f081a53f5bae8723c37c5a34f503
2019-08-22 14:25:18 +03:00
Clara Andrew-Wani
2836292794 Hard deprecrate Language::viewPrevNext()
Bug: T207977
Change-Id: I800689b04868d144f086913df9cd6b27dd74aa81
2019-06-29 11:12:20 -04:00
Fomafix
110a5877e9 Use [...] instead of array(...) in PHP comments and documentation
Change-Id: I0c83783051bf35fe785bc01644eeb2946902b6b2
2019-06-17 21:15:09 +02:00
Umherirrender
9421f6f52f Fix param type of search terms in search related classes
Change-Id: I036434268f1e7992f7f9f23d2c1c0fcd399823c8
2019-06-14 19:50:12 +02:00
clarakosi
4ca72763ec Refactor buildPrevNextNavigation
Refactored buildPrevNextNavigation() into standalone helper class,
PrevNextNavigationRenderer, to be used by both SpecialPages and Pagers.

Bug:T207977
Change-Id: Ic49837a451f795ec203e867961ec1c69075cc91a
2019-06-05 19:32:27 -04:00
Derick Alangi
166d09893b languages: Hard deprecate Language::getExtraUserToggles() method
This seems to be still used internally in core but in no extension. Also,
this function really doesn't do anything so hard deprecating in preparation
for removal.

Bug: T62260
Change-Id: I568789483084a97e5b3b462235f3d00c3cb87cf9
2019-05-24 10:59:38 -07:00
jenkins-bot
9f5c319b09 Merge "Add 'avoidhours' option to Language#formatTimePeriod" 2019-05-10 16:59:58 +00:00
Jack Phoenix
b704c9f4de Add 'avoidhours' option to Language#formatTimePeriod
Example use case: in some skins we want to show how many *days* ago a page was edited, but we don't really care about the precise _hours_.
Thus we'll set [ 'avoid' => 'avoidhours' ] when calling Language#formatTimePeriod to output something like "Page last edited 60 days ago" instead of "Page last edited 60 days 9 hours ago".

Change-Id: I0a737aab14ccb2b8d4eccdc41e1eb9232eedcb8a
2019-05-10 11:06:00 +03:00
Derick Alangi
b2a1a18008 Language: Remove deprecated initEncoding(), recodeForEdit() & recodeInput()
Language::initEncoding(), ::recodeForEdit(), and ::recodeInput() deprecated in
1.28 are now removed.

Usage
=====

* initEncoding() -
  https://codesearch.wmflabs.org/search/?q=initEncoding&i=nope&files=&repos=

* recodeForEdit() -
  https://codesearch.wmflabs.org/search/?q=recodeForEdit&i=nope&files=&repos=

* recodeInput() -
  https://codesearch.wmflabs.org/search/?q=recodeInput&i=nope&files=&repos=

Bug: T220656
Change-Id: I309ec5eebbdddd3b71541c446b15b15204abf8ca
2019-05-09 12:23:58 -07:00
Aryeh Gregor
2e1ac38485 Mass conversion to NamespaceInfo
Change-Id: I2fef157ceec772f304c0923a1cd8c0eef2e82a0f
2019-05-07 22:44:56 +02:00
rxy
b7d53539f0 Add support for new Japanese era name "Reiwa"
Bug: T219728
Change-Id: I28c26291c38e7e6c167011472236fb81a8adf032
2019-04-20 11:24:26 +00:00
Giuseppe Lavagetto
d46835ef4f Add ability to override mb_strtoupper in Language::ucfirst
Different PHP versions treat unicode differently, and specifically some
wiki resources become unreachable if mb_strtoupper's behavior has changed.
This patch allows to introduce an override table that allows to smooth
the transition period.

It also provides maintenance scripts to generate such an override table.

Bug: T219279
Change-Id: I0503ff4207fded4648c58c7b50e67c55422a4849
2019-04-17 15:18:44 +00:00
Fomafix
22d38b4f80 Remove deprecated Language::setCode
Language::setCode was hard-deprecated in 76f5584377 included in
MediaWiki release 1.33.

Change-Id: I32f6d1c9b7ad781182945222d40fd209bce23229
2019-04-11 19:38:09 +02:00
Aaron Schulz
deded31820 Fix return type in fallback8bitEncoding() documentation block
Change-Id: Ia50ed305d8f58bdea5d36362e03ad5a1ebbea847
2019-04-09 13:22:52 -07:00
Kunal Mehta
02b18ba4cd Fix/suppress phan errors related to arrays (#11)
Change-Id: Ie5c05fbc88c51d493bc1462005d2f8dde5f72101
2019-04-07 16:27:02 +00:00
Fomafix
6212ab2d3d Language: Use type hint instead of manual type check
Change-Id: I9c68d0838d5865c29bff85b9a6bf50e02e83f556
2019-04-03 18:39:45 +02:00
jenkins-bot
1715b41651 Merge "Sunsetting viewPrevNext" 2019-04-02 17:35:09 +00:00
jenkins-bot
94aa1240f0 Merge "languages: Replace loop with array_pad()" 2019-04-02 01:34:43 +00:00
eranroz
7d129953f6 Sunsetting viewPrevNext
Removing viewPrevNext from Language and moving it to SpecialPage.
Used soley in special pages, and we aim to remove/reduce the dependency
of messages and language

Bug:T207977
Change-Id: I49b41a89ba59cfc24982b321f02c5cca9939decd
2019-04-01 21:36:49 +02:00
Thiemo Kreuz
2218f335e6 languages: Replace loop with array_pad()
Change-Id: Ia5159b44653f033d3db79094e46a0d94e1b1d01e
2019-03-28 13:52:48 +00:00
Lucas Werkmeister
c7668f097d Fix reference to removed truncate() function
truncate() was removed in change I7a3f7a3327 (commit a1b894cc42, task
T197492), so change the documentation to refer to the still existing
truncateForDatabase() instead.

Change-Id: I26cf6521e15eb6f61ad09c92b2d56831590b6663
2019-03-25 17:27:47 +01:00
Derick Alangi
6b4b646d03 languages: Partial revert of I8287118cf8ec01326ead9
Fix bad value for parameter $s: must be a string production error.

Bug: T218883
Change-Id: I550f6cbc7fa9d290001ae0f2454cd1a46e672e0c
2019-03-21 15:32:02 +01:00
Fomafix
197a82eda0 Throw exception on wrong type in Language::isValidCode( $code )
This prevents that Language::isValidCode( null ) returns true.

Depends-On: I38d8358469903afb15331212206635283cedcd46
Change-Id: I5dc5bd45d648a548dfd27aaa1b3c29a2e99f0e8b
2019-03-12 16:40:31 +01:00
Fomafix
79f721948b Language: Use Assert::parameterType for type checks
Depends-On: Ib0cb388958cf720052ca6df73d5145b7ab3f9529
Change-Id: I8287118cf8ec01326ead9c90a38f7b4134c3eba9
2019-03-12 10:28:32 +01:00
jenkins-bot
501ca07005 Merge "Streamline code involving .= string concatenations" 2019-03-11 12:39:04 +00:00
Thiemo Kreuz
cfda5e7efa Streamline code involving .= string concatenations
This was inspired by Idbbdb31. Originally, I did a regex search for
code that did string concatenations like `$str = $str . …` and replaced
them all with the .= operator. A duplicate patch was uploaded by another
author. I rebeased this patch on top of the other, which leaves all
the manual optimizations I did.

Change-Id: Iaeb73d9c63302c9409bd1051b91e0d2bd77788a7
2019-03-11 12:43:45 +01:00
Fomafix
200c722d49 Remove deprecated Language::markNoConversion
Language::markNoConversion was hard-deprecated in 7de2c566d included in
1.32.

Change-Id: I2cc200d7a814e73d9c6138860190f44232a6bd3c
2019-03-08 18:43:53 +01:00
jenkins-bot
ae506d2441 Merge "Hard deprecate Language::setCode" 2019-02-10 06:03:08 +00:00
Kunal Mehta
cc5d9a92a2 build: Updating mediawiki/mediawiki-codesniffer to 24.0.0
Change-Id: I66b1775b7c1d36076d9ca78cbeb42787a743f2aa
2019-02-07 18:39:42 +00:00
Thiemo Kreuz
673dcee058 languages: Fix some soft type hints in the Language class
Change-Id: Ic9ffbc79c6932db97175d0a1da75df45ba3455e0
2019-01-31 19:21:54 +00:00
Fomafix
76f5584377 Hard deprecate Language::setCode
Change-Id: I8f667861ec8e7ae0803179cf1517cb5122e8f545
2019-01-31 11:57:38 +01:00
Thiemo Kreuz
d62f4688e8 Use the ?: shortcut from PHP 5.3 where it makes sense
Change-Id: Ieff70f23b19f0be3670c4ed3e2a5c30ef3792d7f
2019-01-12 21:56:41 +00:00
jenkins-bot
bd78869618 Merge "No yoda conditions" 2018-12-09 01:34:23 +00:00
jenkins-bot
36de1c7c81 Merge "Remove unused parameter" 2018-12-04 06:27:27 +00:00
Jakub Vrana
8625fcec2f Delete always-true condition
Found by PHPStan.

Change-Id: Ibefd9d5d1b374448650a36702db18144f5feddae
2018-12-02 09:59:17 +01:00
Jakub Vrana
758caf7f93 Remove unused parameter
Found by PHPStan.

Change-Id: I8ed0561c18e2af4ee146123b534a864d5ab7f975
2018-12-01 09:47:28 +01:00