Commit graph

128 commits

Author SHA1 Message Date
Umherirrender
93ce9ff0a5 Hard-deprecate manual construction of Language objects
Bug: T343771
Depends-On: Ie0f08b29f3daff33f23c7107ccf98e2c3aa78cf9
Depends-On: I2d46db4be6e967ee5e7764c6df62d2214fe08683
Depends-On: Id2423c87c17a2f357d5e1cfeef3aeb83b6ad9a0d
Depends-On: I65ad7a46114d1ba812fc47bf623c0a5753acac97
Depends-On: Ib7ec113a21fd36a82c0345ffb98ed8692d82155d
Depends-On: Ib390ffe80ffd62b7f22efe86f6a08108959a970c
Change-Id: I0c8d136ef22e43749a171f08e19b9b9b507edba9
2024-07-20 21:11:33 +00:00
Ollie Shotton
e82ec6265c Improve human-readable duration in Language
by using the new `Language::formatDurationBetweenTimestamps()` method

Change-Id: I119f3916d4e3003e3d09817eb0eb3e61499292f6
2024-06-25 17:25:03 +00:00
Umherirrender
9879723ef3 Use namespaced classes (1)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Ic4d4dd61de5ab896fb6173eb579c81f164a1e4a3
2024-06-16 20:18:23 +02:00
Ebrahim Byagowi
a717db8e60 Add namespace and deprecation alias to FormatJson
This patch introduces a namespace declaration for the
MediaWiki\Json to FormatJson and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I5e1311e4eb7a878a7db319b725ae262f40671c32
2024-05-16 16:28:01 +03:30
Ebrahim Byagowi
14b4269d83 Add namespace and deprecation alias to Xml and XmlSelect
This patch introduces a new namespace declaration,
MediaWiki\Xml and adds Xml and XmlSelect to it
and establishes class aliases marked as deprecated
since version 1.43.

Bug: T353458
Change-Id: I45cccd540b6e15f267d3ab588a064fbeb719d921
2024-05-16 15:23:14 +03:30
jenkins-bot
ca8335d859 Merge "Introduce {{#FORMAL:}} magic word to simplify translations" 2024-05-09 10:16:41 +00:00
Niklas Laxström
390246c8ca Introduce {{#FORMAL:}} magic word to simplify translations
Bug: T238433
Change-Id: I33732900318af96fef106d18e1aae6c143474e3e
2024-05-08 06:25:52 +00:00
Ollie Shotton
63d1ab6808 Add Language::formatDurationBetweenTimestamps method
which takes two timestamps in order to calculate a more accurate text representation of the duration between the timestamps

Bug: T219397
Co-authored-by: addshore <addshorewiki@gmail.com>
Co-authored-by: Silvan <silvan.heintze@wikimedia.de>
Change-Id: I290f8da815f9571dae75fddde2da2010cc9a7fec
2024-05-05 01:22:53 +01:00
jenkins-bot
513b57cbf4 Merge "docs: Fix 'Calender' typo in Language::tsToYear() docs" 2024-05-04 08:42:44 +00:00
Lewis Cawte
c1c15a307d docs: Fix 'Calender' typo in Language::tsToYear() docs
Change-Id: Iebdaf9e3d6d6cd4b0a9a87482650a3dd2dbdd5a9
2024-05-04 08:20:08 +00:00
addshore
3ab0eff2a6 Add months as duration to Language:formatDuration
I think there is further room for improvement
here, such as a method that takes 2 points in time
and gives you a more precise summarization of the duration
in terms of actual dates.
(And we will do this in a followup)

To avoid changing behaviour where this method is called
the default interval of `month` is not specified, so
existing calls return as they did before.
For callers that want `month` granularity, they can
specify month.

Bug: T219397
Change-Id: I5a07e14629fd9f67b1f17df3db75b68f98295dfb
2024-05-04 08:19:20 +03:00
Umherirrender
723134eade Add explicit parentheses around mixed boolean operator
Mixing different binary boolean operators within an expression
without using parentheses to clarify precedence is not allowed (T358966)

Change-Id: I24ca752d5dac7c948fdbcabf721f6f0aef8a466f
2024-03-23 01:58:59 +01:00
Reedy
2295da3004 Fix more incorrect casing of MediaWiki
Change-Id: I331e5636823a0beae8d804148f648cfaffd6a1f8
2024-02-19 14:35:34 +00:00
rxy
9604fd122a Fix and split Japanese era related logic
Bug: T356419
Change-Id: I764dff7f0d2bcddb5668d8497d0fe66e3ef3bf21
2024-02-15 21:19:19 +00:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Máté Szabó
939a1576e0 Language: Don't generate local dates in the year 10000
MediaWiki only supports 14 character timestamps, and most date input
fields accordingly limit the accepted input range to fit within that
constraint, so the largest acceptable date is 9999-12-31 23:59:59.
However, if an user's own timezone preference is set to a timezone with
a higher offset than the server timezone, such dates may overflow into
the year 10000 and cause an error ("The timestamp XYZ should have 14
characters"). This very commonly happens when an admin decides to block
an user until 9999-12-31 instead of using the infinite expiry for some
reason, effectively breaking the block log for every user with a
timezone offset higher than the server offset.

Making MediaWiki support dates beyond the year 10000 would be a larger
undertaking, so for now, limit the impact of this problem by ensuring
that userAdjust() does not generate a local date that sprintfDate()
would not be able to handle.

Bug: T32148
Bug: T277809
Change-Id: I17ceee6c80dcc1559c6d66f1956ba1f0a4b519a3
2024-02-03 14:53:31 +01:00
Bartosz Dziewoński
e4c7272976 Change uses of getDBLoadBalancerFactory() to getConnectionProvider()
Update cases where one of the IConnectionProvider methods is called
immediately.

This doesn't really change anything, but I hope it helps promote
getConnectionProvider() as the common way to do this.

Follow-up to 8604c384f6.

Change-Id: Id0e7d02bab0c570343c2b1f03c70b44ee39db112
2024-01-22 22:27:45 +01:00
Daimona Eaytoy
175c0c4abf Replace more instances of deprecated MWException
Bug: T328220
Change-Id: Iba90f7f9b5766bccc05380d040138d74d5e9558a
2024-01-19 23:11:59 +00:00
Daimona Eaytoy
2520f3d1c4 Replace more usages of deprecated MWException
Bug: T328220
Change-Id: Ie9b56bcf5e962e275d80570cad98d676da505894
2024-01-19 22:01:12 +00:00
Timo Tijhof
937847b26a Replace various magic numbers with easy-to-verify expressions
Follows-up I8518e0488 (9c02258a04).

Instead of documenting how to compute the number to manually verify
it, use the expression directly. This should make it significantly
easier to understand, verify, and modify.

Noteworthy:

* Language.php, I kept 31_556_952 as-is because the
  calculation would otherwise involve a float. It also has the benefit
  of allowing the long durations to build upon that as a given number.

* SqlBlobStore.php, remove this irrelevant default value as it is
  unreachable. The only call to new SqlBlobStore is BlobStoreFactory,
  which always calls setCacheExpiry. For back-compat and to keep
  tests as-is, move to re-used constant between class and config.

Change-Id: I86b034883bd7efdf93b8365b43178af826f1c703
2024-01-11 15:12:24 +11:00
jenkins-bot
3e07889c70 Merge "Inline once-called short private methods to its caller, part 1" 2023-12-19 00:05:45 +00:00
Amir Sarabadani
a778d3fea7 Inline once-called short private methods to its caller, part 1
This makes the code easier to read to avoid jumps and improves
encapsulation by not allowing the rest of the class having access to the
logic. Of course, if needed then some code can be refactored out again
but for now let's not do YAGNI.

Change-Id: Ic37524e386fc04fd67e33768417ff8425f85b0ca
2023-12-18 23:43:32 +00:00
daniel
be754ece78 Improve layering: remove reference to SpecialBlock from Language
Special pages belong to the interaction layer, lower level code should
not access them. That is especially true for something used everywhere
in the code base, like Language.

Change-Id: I46a2a7d60ff73dac3ce72e657c6232b6168a98e8
2023-12-15 14:10:42 +00:00
Tim Starling
9c02258a04 Use thousands separators in selected integer literals
For readability. Allowed since PHP 7.4.

I searched for integer literals of 6 or more digits, and also changed
some nearby smaller numbers for consistency.

Bug: T353205
Change-Id: I8518e04889ba8fd52e0f9476a74f8e3e1454b678
2023-12-12 09:22:45 +11:00
Umherirrender
a073bbc468 language: Avoid multiple signs in Language::userAdjust
In php8.2 the use of multiple signs makes further signs ignored
strtotime( "+-120 minutes" ) is processed as strtotime( "+120 minutes" )
Remove the + from the call as positive numbers are added also without +

Bug: T351848
Change-Id: I469c0e1b60eb17f051fc6a826265a3fd978f8de8
2023-11-23 16:13:45 +00:00
Fomafix
23901c0541 Language: Use $this->msg() instead of wfMessage()->inLanguage( $this )
Also use localized message text for message 'just-now'.

Change-Id: Id2a40d0810dff6f0df71507f02777b14c39f8cba
2023-11-11 19:12:28 +00:00
Dreamy Jazz
43863eeaa8 Fix spelling in documentation of Language::truncateForVisual
Fix the spelling of 'string' in the documentation of Language::
truncateForVisual.

Change-Id: I12b897dc32b1036ed4303ece75a30b167d07d2e1
2023-10-31 14:39:11 +00:00
C. Scott Ananian
e01e41bdea Implement Language::isSameCodeAs()
This implements the additional Bcp47Code interface method required by
wikimedia/bcp-47-code 2.0.0.

Bug: T331887
Change-Id: If3abc8a55eda8879ca904b25e9e3e5d40c1b0bab
2023-10-04 12:29:57 -04:00
thiemowmde
e705900a81 Improve/fix documentation of Language::getMagicWords()
It's not (only) an array of strings (aliases). It also contains the
case-sensitive flag as an integer (no, not as a bool).

Change-Id: Iba3cc6fd14360c0d972beb809940139c5b9e63bb
2023-10-03 15:50:55 +02:00
jenkins-bot
ac546dd4f7 Merge "Use word-separator message for Language::formatTimePeriod()" 2023-10-02 15:31:02 +00:00
Reedy
40f7d7632a Language: minor cleanup
* Remove unnecessary duplicate documentation
* Code tweaks

Change-Id: I9c8c190bee58195eace08cba18a51e4572896ef7
2023-10-02 13:34:11 +00:00
Reedy
b0b17ce751 Languages: minor cleanup
* Remove unnecessary duplicate documentation
* Code tweaks
* Rename Language::getSerchIndexVariant() to Language::getSearchIndexVariant()

Change-Id: I10d8b9b82e5f781b8c5d9b349827e3b219745083
2023-10-02 13:34:05 +00:00
Dringsim
ecb4f0be4e
Use word-separator message for Language::formatTimePeriod()
Bug: T347802
Change-Id: Ie7f7b267bbd079af9f4e5aab896c52b823c2afe7
2023-10-01 18:22:11 +08:00
jenkins-bot
89ff1030ff Merge "Language: Avoid string cast in getFormattedNsText()" 2023-09-25 10:02:55 +00:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
James D. Forrester
a8a6cfd966 Namespace NamespaceInfo under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: Ibe103cd362535d3cb94cb8931e95fc74099d1497
2023-09-19 05:17:04 +00:00
Timo Tijhof
15260fb0c7 Language: Avoid string cast in getFormattedNsText()
Follows-up 553f40f973 (Ie8733237a6).

Change-Id: I18200bf7dd7591f3053691427dadd0b921c76839
2023-09-15 01:51:51 +00:00
Daimona Eaytoy
3f35734ac0 Remove redundant empty() constructs
empty() only makes sense when the expression it checks is possibly
undefined, otherwise it's equivalent to a truthiness check with the
additional downside of suppressing errors when it's not wanted.

Replace it with simple truthiness checks, using strict comparison when
that seems to help with polymorphic variables.

These were caught by a bespoke phan plugin.

Change-Id: I52999e5286a0d9ad70b0da40b41b9f998ecb990e
2023-09-08 23:18:11 +02:00
Fomafix
3ca361e487 Language: Remove deprecated parameter $noSeparators to formatNum()
The parameter $noSeparators is hard deprecated since 1c9bbfc14e
included in MediaWiki 1.36.

Also remove comment to commafy removed in 7f4e9bfa39.

Change-Id: Ice69e3593eddbe771a626533f5db1a75ae5c366f
2023-09-07 20:13:39 +00:00
Amir Sarabadani
15a278189f Reorg: Move MWTimestamp to MediaWiki\Utils
Bug: T321882
Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
2023-08-19 05:53:40 +02:00
Fomafix
0f935809fd Language: Remove deprecated functions and constants
The functions are hard deprecated since MediaWiki 1.40.

Bug: T343185
Bug: T325974
Bug: T325982
Bug: T325962
Bug: T325986
Bug: T325979
Bug: T325981
Bug: T252095
Change-Id: I016b1c173126ac8ff264918279d0c7912c428699
2023-08-06 00:53:30 +02:00
jenkins-bot
56f58b4c21 Merge "LogFormatterTestCase: avoid database access" 2023-08-01 15:06:01 +00:00
Daimona Eaytoy
db8897dbe7 LogFormatterTestCase: avoid database access
LogFormatter is another place that uses the global state a lot, with
Title, Linker, etc. Some of its dependencies were accessing the
database, but most LogFormatter methods are not in the database group.

This patch tries to work around the DB dependencies by providing
(complex) mocks that do not access the DB. There's a lot of mocking
involved, but that's just because of the current state of LogFormatter,
and hopefully it'll get better some day.

Rights- and ProtectLogFormatter also need a mock DB connection because
they use the database to format expiry.

Bug: T155147
Change-Id: I4fa9ee4fb246e08cb2b4577454029b5af3276b79
2023-08-01 16:35:20 +02:00
Tim Starling
772662378a Make minimumGroupingDigits an integer and add documentation
All Messages*.php variables are supposed to be documented in
MessagesEn.php.

I don't see the point in having Language::minimumGroupingDigits() return
null, and then expecting every caller to cast null to zero.

The default for English is properly 1, not 0, since 3-digit numbers do
not need grouping. We don't write 999 as ",999". Setting it to 1
instead of null should improve the performance of the JS commafyNumber()
by avoiding the unnecessary loop body. Change the QUnit test data to
confirm that this works.

In the PHP implementation, adjust the comparison to avoid the
preg_match() when minimumGroupingDigits is 1.

Change-Id: I6679d69e7094502303389039550e17a47189e2dc
2023-07-31 13:18:49 +10:00
thiemowmde
d46de9b632 language: Add specific type hints to all LocalisationCache properties
Change-Id: I40456cd7deedfb9238d5bca4ab6856a5867152b5
2023-07-26 23:52:46 +00:00
jenkins-bot
7d94e330b4 Merge "Language: Prefer mb_str_split and strtr function" 2023-07-05 13:54:10 +00:00
Func
bfd4001c6c LocalisationCache: Preserve fallback source language info
Prefix messages with their source language code when saving to the cache.

Bug: T229992
Change-Id: I06ae6432c80ffeb924b2a3ac29ad2e876b715b33
2023-06-14 22:06:36 +08:00
Func
10bf1c7a2a Language: Prefer mb_str_split and strtr function
The `mb_str_split` function is better than `str_split` since we
don't need to hard-code the length of multi-bytes char.
The `strtr` function only travels the string one time, which is
very suitable for replacing a mapping of chars.

Change-Id: I25186250624f7c1403567957faf7d5ab414e1884
2023-05-30 22:01:34 +08:00
Daimona Eaytoy
43fb8de838 language: Annotate list() methods as preserving taintedness
The $list parameter to the various *list() methods is not escaped by
these methods, so any taintedness in the argument is preserved by the
method and kept in the return value. taint-check has troubles figuring
this out on its own due to T274780, so annotate the parameters.

Note: once this is merged, taint-check could start failing on some
repos. Any errors would have a decent chance of being true positives.

Bug: T253879
Change-Id: I6cf56aca9760370cbeae19879e6b170b1cbd273f
2023-05-20 11:39:55 +02:00