Commit graph

117 commits

Author SHA1 Message Date
Bartosz Dziewoński
c9f73efd5a Namespace MessageSpecifier under Wikimedia\Message\
In change I625a48a6ecd3fad5c2ed76b23343a0fef91e1b83 I am planning to
make Wikimedia\Message\MessageValue use it, and we try to pretend that
it is a library separate from MediaWiki, so it makes sense to move
MessageSpecifier to the same namespace under Wikimedia\.

Bug: T353458
Change-Id: I9ff4ff7beb098b60c92f564591937c7d789c6684
2024-07-28 14:21:32 +02:00
jenkins-bot
1a4278e1e8 Merge "Drop duplicate test cases and @dataProviders from tests" 2024-07-21 04:06:33 +00:00
Umherirrender
e6d8ccb15c tests: Use LanguageFactory in ConverterRuleTest
Bug: T343771
Change-Id: Ie0f08b29f3daff33f23c7107ccf98e2c3aa78cf9
2024-07-20 21:46:39 +02:00
thiemowmde
32d214dd6d Drop duplicate test cases and @dataProviders from tests
A single test function can have multiple @dataProviders. No problem.

A @dataProvider can also be used by multiple test functions. No
problem. No need to duplicate such large pieces of code when it's
identical anyway.

Change-Id: I5aea36304ec2d1666ff2334ba883df07a70c15c5
2024-07-19 10:18:31 +00:00
jenkins-bot
1ad99a04a4 Merge "language: Widen @covers for some MessageTest cases" 2024-07-17 18:09:33 +00:00
jenkins-bot
cb2f659f5b Merge "language: Improve behavior of RawMessage used as MessageSpecifier" 2024-07-16 14:34:21 +00:00
Timo Tijhof
95045051c8 language: Widen @covers for some MessageTest cases
Per rationale in https://gerrit.wikimedia.org/r/1036673 and other changes
at https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen

Change-Id: I468ec8688e657ea24890e4fa21b4378d53e48a75
2024-07-16 15:09:52 +01:00
Bartosz Dziewoński
159dad8abb language: Improve behavior of RawMessage used as MessageSpecifier
We have some code that expects that if you disassemble a
MessageSpecifier using its getKey() and getParams() methods,
then assemble a new MessageSpecifier using the return values,
you will get (at least approximately) the same message.

This was not the case with RawMessage, even though it implements
the MessageSpecifier interface, because its "keys" are not real
message keys, and this operation would mess it up.

Override the MessageSpecifier methods on RawMessage so that they're
compatible with how everyone expects a MessageSpecifier to work.

Add some tests for OutputPage, Message\Converter and Status
to verify some scenarios that would previously have failed.

Depends-On: I41991989515b4791bc1746f26bd404bf4f17dbdb
Depends-On: I612361dd20ff8aad4c0069f1c5af78e3e13b9692
Change-Id: Iddd14efa8b9536277c372257d5a7be135f26a540
2024-07-16 15:06:26 +01:00
Fomafix
3bfbd004ca LanguageConverter: Replace global $wgRequest
Replace $wgRequest by RequestContext::getMain()->getRequest().

Change-Id: I8f30a7b8c6d0e6e97850860164165e5bc3e9dfc0
2024-07-14 09:20:27 +00:00
nokibsarkar
6895bc84d5 LanguageConverter: Added support for mni-Beng in mniwiki
This is the Language Converter from Meitei Script to Bengali Script in mniwiki.
I don't know the language. I got help from a native speaker User:Haoreima.
The original prototype was in a Python Library written by myself.
It only converts the words that have Meitei characters (U+ABC0..U+ABFF).
The original prototype is already being used in mniwiki via Gadget and a Bot.

Bug: T357853
Change-Id: I810f18050f29efa38b2a646d96644e298af47c50
2024-07-06 17:05:19 +06:00
jenkins-bot
d18d0c2283 Merge "language: Widen @covers tags in phpunit tests" 2024-06-25 22:50:53 +00:00
jenkins-bot
776aa14633 Merge "Replace db with getDb for Tests" 2024-06-25 20:31:50 +00:00
Timo Tijhof
4160c223f2 language: Widen @covers tags in phpunit tests
Add a few missing `@group Language` tags as well.
Remove stray `@group Cache` from two classes since "Cache" is not a
MediaWiki core component (per T248519 and related tasks, we did long
ago in Bugzilla have a "MediaWiki-Cache" category, but that's since
been re-orged into BagOStuff, HTTP-Cache, and Parser/ParserCache,
and Internationalization/LocalisationCache, per the description at
<https://phabricator.wikimedia.org/project/profile/1329/>.)

Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen

> Given all called methods are de-facto and liberally claimed, and
> that we keep the coverage limited to the subject class, it maintains
> the spirit and intent by listing the class explicitly instead.
>
> PHPUnit offers a more precise tool when you need it (i.e. when testing
> legacy monster/god classes), but for well-written code, the
> class-wide tag is exactly what you want.
>
> We lose useful coverage and waste valuable time on keeping tags
> accurate through refactors (or worse, forget to do so).
> Tracking tiny per-method details wastes time in realizing (and
> fixing) when people inevitably don't keep them in sync, and time
> lost in finding uncovered code to write tests to realize it was
> already covered but "not yet claimed".

Bug: T364652
Change-Id: I9cfc4c210b90bfed6fd988a2525f80f5f5ee4870
2024-06-25 18:51:54 +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
Wandji69
c257e2276c Replace db with getDb for Tests
Bug: T316841
Change-Id: I29e535e8ee9b5641a4546d53b98cd5060d39681d
2024-06-23 23:47:56 +01:00
jenkins-bot
547b5e2b11 Merge "tests: Use namespaced classes (1)" 2024-06-14 17:48:06 +00:00
Umherirrender
6c41df61e9 tests: Use namespaced classes (1)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Iae45fa269363be8ee05c598ea6926514ce817762
2024-06-14 17:19:36 +00:00
Umherirrender
b4e0d31644 tests: Use namespaced classes (@covers)
Some fixes done via codesniffer fix (Ibd0f48e14e)

Change-Id: I0404ceca7c5abe8d32ef9a8fce404c7b89ffbaae
2024-06-14 00:15:40 +02:00
jenkins-bot
780df68f9d Merge "Use upstream markTestSkippedIfExtensionNotLoaded in test" 2024-06-04 18:48:06 +00:00
jenkins-bot
51b2c4a1cd Merge "MessageCacheTest: Get LanguageCode from MainConfig instead of global variable" 2024-06-01 00:44:09 +00:00
Bartosz Dziewoński
f18362ccce Deprecate Message::objectParams() and related code
This functionality was introduced in 2021 (commit 349819dc5a)
to support the addition of UserGroupMembershipParam, which was
never used, and no other use case appeared.

Its existence is now preventing us from allowing serializing
of MessageValue objects as JSON (since the parameters can't be
guaranteed to be serializable).

Deprecate:
* method: MessageValue::objectParams()
* method: Message::objectParams()
* method: Message::objectParam()
* class: UserGroupMembershipParam
* constant: ParamType::OBJECT
* Passing Stringable objects to ScalarParam

Change-Id: I492edabb7ea1d75774b45eb9fd18261b39963f9f
2024-05-28 22:03:46 +00:00
Fomafix
36e6f15e65 MessageCacheTest: Get LanguageCode from MainConfig instead of global variable
Change-Id: I4bce4042283f9062e1b84662f5b21aed6007c667
2024-05-24 10:22:20 +00:00
Fomafix
418b032846 Tests: Use $this->overrideConfigValue instead of global variable
Change-Id: Ia3b22032df55002da72428619adf7c783c185b4e
2024-05-24 09:06:22 +00:00
Fomafix
b0b0066682 language: Deprecate MessageCache::get without Language object
Trigger a deprecation warning if MessageCache::get gets called without
a Language object. On omitted parameter still the content language is
used.

Also change from $langcode = true to $language = null. This allows to
introduce a PHP type check in I8d0de2c7c2e6d087228844874d8251933b4acea4.

Change-Id: Ib27cfc0af090790daca3995fb1c3d78712d53ae6
2024-05-19 14:55:47 +00:00
jenkins-bot
735ce693f4 Merge "Add Language::formatDurationBetweenTimestamps method" 2024-05-05 01:12:10 +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
Timo Tijhof
c02513c97e phpunit: Fix tests relying on implicit wgScript/wgArticlePath
A number of tests have hardcoded expections that pass only in WMF CI
where Quibble has LocalSettings.php with $wgScript and $wgArticlePath
set a certain way.

We could fix these by adding setMwGlobals() in their tests, as we
often do, but these are so often forgotten that I'd rather we just
add them to TestSetup.php so that it is simply impossible to write a
test that that passes locally for you (if you have the same config)
but not for someone else.

There is a larger project in there somewhere about expanding this
slowly such that we basically only pluck DB-settings and extension
enablement from LocalSettings and otherwise run the tests with the
default settings in PHPUnit. Pretty much by definition, any (other)
setting you have in LocalSettings is irrelevant because it either:
1. has no effect on the test (majority, harmless either way),
2. has a custom default via TestSetup.php (which has precedence over
   LocalSettings.php),
3. is relevant to the code being tested and the test case correctly
   calls setMwGlobals() to ensure a consistent value during test.
4. is relevant to the tested code but has no override, thus only
   passes if you happen to have the "right" value set for it
   (undesirable).

Case 4 is already categorically impossible for the most common config
settings that influence random code because we give them a value
in TestSetup.php. This patch expands that to include $wgScript
and $wgArticlePath. Perhaps in the future we can think about a way
to do this automatically by either re-applying MainConfigSchema
(sans db settings) or by only selectively applying LocalSettings.php
in the first place.

This patch follows-up I072ddf89562fe, which added a test case in
WikitextContentHandlerIntegrationTest.php that assumed "/index.php"
as the value of $wgScript. This passes in WMF CI since Quibble uses
that value, but the tests failed in most local development installs
since those tend to use "/w" instead.

Rather than one-off fixing that one test with overrideConfigValues(),
switch to a more general fixture, since the precise values don't
matter for this test.

Bug: T349087
Bug: T277470
Change-Id: If4304b7ca4a838bd892d4516a0b5c6dfbc30986e
2024-05-05 00:00:01 +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
523372df32 Migrate to IDatabase::newDeleteQueryBuilder
Change-Id: Idf42d67c1b0b311f81a1d60a7a8a6f875f99e864
2024-04-12 20:12:05 +02:00
jenkins-bot
00349f5e14 Merge "Message::inLanguage(): accept Bcp47Code as well as string and Language" 2024-04-12 15:40:02 +00:00
Jon Harald Søby
1df54ce20e Implement language converter for Standard Moroccan Amazigh (zgh)
Requested by the zgh community in the Wikimedia Incubator at [1];
the converter is the same as for Shilha (`shi`); the main difference
between the two languages is that the main script for `zgh` is
Tifinagh, which can't be losslessly converted to the Latin script
(the former is unicameral, the latter is bicameral), so the
converter and configuration added here is essentially one-directional.

[1] https://incubator.wikimedia.org/wiki/Special:PermaLink/6060805

Change-Id: I483a1594f001226439497f0870176e9a1e447458
2024-04-11 16:40:50 +02:00
C. Scott Ananian
c23cf3b0b1 Message::inLanguage(): accept Bcp47Code as well as string and Language
Bug: T327379
Followup-To: I982e0df706a633b05dcc02b5220b737c19adc401
Followup-To: I24932449b8c40e3a5072748d87667184f4befa67
Change-Id: Id99e5695bcfd347170cb4f2f80a557d189df6d44
2024-04-10 14:24:05 -04:00
thiemowmde
9d57dc8434 Use upstream markTestSkippedIfExtensionNotLoaded in test
Change-Id: Ifab541f7323163e98f23393eb2227240cebc0daf
2024-04-10 14:15:16 +02:00
Winston Sung
a9058148ba
Follow-up "ZhConverter: Fix language variant fallback chain"
* Removed 'zh' from all variants to prevent unexpected conversion
  (e.g., Hant in zh-cn converted to Hani with
  -{H|zh:Hani; zh-hant:Hant;}- ,
  which was referring to
  -{H|Hani=>zh-hant:Hant; Hani=>zh-tw:Hant; Hani=>zh-hk:Hant;
  Hani=>zh-mo:Hant;}-
  instead of
  -{H|zh-hans:Hani; zh-hant:Hant;}- )

Bug: T352554
Change-Id: I58db0f92e911dcce38beb2d9835681a8158328db
2024-03-08 11:37:41 +08:00
Abijeet
8ddc4ee2ef Add TranslationAliasesDirs to specify special page aliases in JSON
The TranslationAliasesDirs configuration allows defining translatable
aliases in JSON files. The value should be a name or names of folders
that contains files that have localized aliases. Each language should
have a separate file.

Currently, it supports defining special page aliases but in the
future can be extended to support magic words and namespace aliases.

The patch adds a script: ConvertExtensionsMessagesToTranslationAlias
that can be used to convert existing ExtensionMessagesFiles to the new
format.

Bug: T89947
Change-Id: Ief16a48a8dc8742854f67301791aa2a0b0531116
2024-03-06 18:13:28 +05:30
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
rxy
9604fd122a Fix and split Japanese era related logic
Bug: T356419
Change-Id: I764dff7f0d2bcddb5668d8497d0fe66e3ef3bf21
2024-02-15 21:19:19 +00:00
jenkins-bot
fc685448e1 Merge "Namespace Message, move to appropriate directory" 2024-02-15 15:51:23 +00:00
Winston Sung
aac0c8007a ZhConverter: Fix language variant fallback chain
Fix the fallback chain for the language converter for zh by:

* Changed fallback order into
  * zh-hk' <=> 'zh-mo' first, 'zh-hant' second
  * 'zh-sg' <=> 'zh-my' first, 'zh-hans' second
* Added 'zh' to all variants (except 'zh') to reduce
  "converter-manual-rule-error" messages
  ('Error detected in manual language conversion rule').

Bug: T352554
Change-Id: Ia006c0cb00bcc809f32267b1c1feca773daadb3b
2024-02-15 04:20:40 +00:00
James D. Forrester
eeb5a740b3 Namespace Message, move to appropriate directory
Bug: T353458
Change-Id: I088cbc53fbcdb974e5b05b45a62e91709dacc024
2024-02-14 15:10:36 -05: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
Daimona Eaytoy
175c0c4abf Replace more instances of deprecated MWException
Bug: T328220
Change-Id: Iba90f7f9b5766bccc05380d040138d74d5e9558a
2024-01-19 23:11:59 +00:00
Ariel T. Glenn
325ec96492 update a few tests to use PHP 7.4 syntax
Bug: T261872
Change-Id: Ia573136f0ab90025a1588e9dfd5add081d9ffdae
2024-01-09 10:19:00 +02:00
jenkins-bot
132a7955ae Merge "Make two messages not raw HTML" 2023-12-18 18:59:57 +00:00
jenkins-bot
317895e99e Merge "Improve layering: remove reference to SpecialBlock from Language" 2023-12-15 14:53:01 +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
Jon Harald Søby
0e8a92d9ff Make two messages not raw HTML
Two messages were added to wgRawHtmlMessages instead of just
fixing the way they were parsed so they can't contain raw
HTML. This fixes that.

In order to avoid breakage on-wiki for old customized messages
that took advantage of them being parsed as raw HTML, rename
the messages too. Also rename a few other messages from the
same set to stay consistent.

Note: These messages are suppressed in favour of Echo's messages
when Echo is enabled, and Echo is enabled on all Wikimedia wikis,
so the existing customized messages on Wikimedia wikis are basically
no-ops.

Bug: T353316
Change-Id: Ib0d1c79247fe091f2806b7c23ffb2fe22cc4df4a
2023-12-15 11:10:37 +01:00
Bartosz Dziewoński
316915f753 LanguageConverterFactory: Use ServiceOptions
Change-Id: I8d374b51511a2873dce646aa453c5e0e2c076a14
2023-12-11 22:03:50 +01:00
Umherirrender
388b0374fa tests: Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: Ib326ae1e5c8409a98398c721e8b8ce42c73bd012
2023-12-11 15:59:55 +01:00