Commit graph

77 commits

Author SHA1 Message Date
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
James D. Forrester
e94c7fa7af Drop LanguageConverterFactory::isTitleConversionDisabled(), deprecated in 1.36
Change-Id: I8949f88866ae6bb343edc5febc34c1f5cae83831
2023-12-08 17:33:01 -05:00
Martin Urbanec
29af4dd074 Move user options related classes into its own namespace
There are a couple of user options related classes already,
and the T321527 work on dynamic defaults is going to add
even more. Let's move them into a separate namespace
to make core a bit more organized.

Old name is kept as an alias for compatibility purposes.

Bug: T321527
Bug: T352284
Change-Id: I9822eb1553870b876d0b8a927e4e86c27d83bd52
2023-11-29 13:27:13 +01:00
James D. Forrester
67217d08df Namespace remaining files under includes/deferred
Bug: T166010
Change-Id: Ibd40734b96fd2900e3ce12239d09becfb4150059
2023-11-22 10:08:53 -05:00
Amir Sarabadani
beb3261b8d Remove language coverter for Kazakh
This has been constantly mentioned as buggy and broken and there is no
official version of latin or Arabic (see the ticket for more details).

This can be turned back as an extension if needed by third party users.

Bug: T350684
Bug: T268143
Depends-On: I6180dca2c49b3119751766268acc56087aaf8414
Change-Id: Ifbf3c8954d885daf891f8d9efc11743d898302f0
2023-11-20 10:31:16 -05:00
Daimona Eaytoy
48a1c0bb2f Autofix spacing around commas
This was done automatically using the
`Universal.WhiteSpace.CommaSpacing` sniff, which will be included in the
next release of the MW PHPCS config.

Some of these have been adjusted manually where the autofix broke
vertical alignment.

Change-Id: I54a4668d8a2759b9d7de47742c943a535a04e211
2023-10-25 01:08:44 +02:00
Fomafix
42b0f55741 Use $this->getServiceContainer() in tests
Use
	$this->getServiceContainer()
instead of
	MediaWikiServices::getInstance()
in tests where possible.

Change-Id: I798b2941f37a43b9073072935b54c3ea0cfe70dd
2023-10-17 18:40:46 +00:00
Fomafix
6d61b366a2 Support message parameters on the uselang=x-xss feature
This allows to check also message parameters for possible JavaScript
injections.

Bug: T340201
Change-Id: I6bef28cd9c6b91713b66b40cba46e9b2dc2a1f05
2023-09-28 15:33:00 +00:00
Lucas Werkmeister
e9991ffb68 Create 'x-xss' language code feature
This creates a new language code, 'x-xss', which is enabled using the
setting $wgUseXssLanguage (similar to how $wgUsePigLatinVariant enables
the 'en-x-piglatin' language code, and likewise defaults to false; will
be enabled in development settings soon).

In this language code, all messages become “malicious”, trying to run
some alert() JavaScript; if any alert() actually fires in the browser,
the message was not escaped properly. ($wgRawHtmlMessages are exempt,
since they’re already known to be “unsafe” and require more rights to
edit on-wiki.) Messages that are not escaped properly are generally a
minor security issue; they effectively let a user with 'editinterface'
right (such as a sysop, on many wikis) run arbitrary JS, without needing
the 'editsitejs' right (normally restricted to interface admins).

Developers can use this language code to more easily check their code
for escaping issues / cross-site scripting vulnerabilities.

Bug: T340201
Change-Id: Ia9a1cf712b139fea5da72046e37035e6de39d8d5
2023-09-28 15:50:11 +02:00
Amir Sarabadani
cd2e19c050 tests: Use $this->getDb() instead of wfGetDB() in integration tests
Deprecated long time ago.

Bug: T330641
Change-Id: Ia57f12d350c3346029aafae25534c9ed262a7e98
2023-09-25 21:08:09 +02: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
Lucas Werkmeister
b47847e4c4 Fix LanguageIntegrationTest::testCldr()
On LanguageNameUtils, the method is called getLanguageName(), not
fetchLanguageName() like on Language.

As far as I can tell, this must have been broken since change
I016b1c1731 (commit 0f935809fd). It might have worked in MediaWiki core
CI because the cldr extension isn’t installed there (and thus the test
is skipped); I have no idea why it seemingly didn’t break cldr’s own CI;
but locally, the test consistently fails.

Bug: T325962
Change-Id: I0a2ff0a41ebe4f3007316e4511926f6b10c71e1d
2023-09-20 16:50:05 +02: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
James D. Forrester
94ece673b2 Namespace TitleValue under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: I4c901d5c32696d8334ec30cede7d9b6f3d8d645e
2023-09-18 18:24:39 +01:00
Umherirrender
790ae736c1 tests: Move test cases from /includes/ into sub folder
Follow move of the tested class
Most moves are part of T321882

Change-Id: I74ab45d6a5331dcb2ff0b65dc2cc7c6315146646
2023-09-13 00:09:05 +02:00
Srishakatux
bd31b57245 Remove ak from core
- Removed ak from `Names.php`, `LanguageConvertorFactoryTest.php` files
- Deleted `MessagesAk.php` file

Bug: T333765
Change-Id: Ic43b4a556158c60a9f429023b0d9b78666642680
2023-08-21 18:46:33 -07:00
Lucas Werkmeister
3bf5cfc347 LocalisationCache: Load only core data if possible (v2)
This reverts change I6490ffba96 (commit e4e613b0d1), restoring
change I7ec2d87c0f (commit cf8e22e1e4). The issues with the last version
should be fixed by the parent change (Icc3324aca7), and we also have
some tests for these issues now (change Iee11cb5c52).

Bug: T342418
Bug: T343343
Bug: T343375
Change-Id: Id9e718f1791c937f53195613a7b76c23d3376a13
2023-08-08 13:10:18 +02:00
Lucas Werkmeister
fee22e61d8 LocalisationCache: Add tests for preload behavior
The new block in testRecacheExtensionMessagesFiles() covers the
underlying issue of T343343 and T343375; see change Icc3324aca7 for an
explanation of the issue.

In order for this test to not crash, we also need to adjust some of the
other tests and data. MessagesEn.php defines $preloadedMessages, and
LocalisationCache assumes (quite rightly so, really) that all of these
messages will be found in the configured MessagesDirs. But in the test,
we override MessagesDirs to point at the test’s JSON files, while still
using the original MessagesEn.php with its $preloadedMessages. Now that
we are triggering the preload mechanism (I think it wasn’t reached by
the tests previously?), it triggers a PHP deprecation (since PHP 8) on
the missing messages, which makes the test fail:

> explode(): Passing null to parameter #2 ($string) of type string is deprecated

I decided to fix this by adding fake entries for all $preloadedMessages
to the test en.json file. This makes the other tests that compare the
entire messages array fail, so instead only compare the three messages
those tests care about ("present-*"). I don’t like this very much, but I
dislike the other two approaches I can think of even more: check
defined( 'MW_PHPUNIT_TEST' ) in the original MessagesEn.php file, or add
a test-specific MessagesEn.php using the Language::getMessagesFileName
hook.

Bug: T342418
Bug: T343343
Bug: T343375
Change-Id: Iee11cb5c52cb9dd777b70a1daa06f41f2c3ca187
2023-08-08 13:09:34 +02:00
Daimona Eaytoy
59b93e9e4f Avoid DB access in non-database tests
Mock the needed dependencies to avoid database access when possible, and
add the test to the Database group otherwise.

Bug: T155147
Change-Id: Ic5c39ab35ab4d993721713285180f072497a5a40
2023-08-06 22:57:48 +00:00
Daimona Eaytoy
d3243571d0 Fix DB usage in non-database tests (part 2)
Mock the relevant services that need the DB instead, when possible. When
not possible, e.g. because DB access is needed for the test to make
sense, add the test to the Database group instead.

Change-Id: Iefbfe00bedc243906c6b860572568343268646cc
2023-08-06 22:57:28 +00: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
13119dc95c Merge "Revert "LocalisationCache: Load only core data if possible"" 2023-08-02 19:52:46 +00:00
Ahmon Dancy
e4e613b0d1 Revert "LocalisationCache: Load only core data if possible"
This reverts commit cf8e22e1e4.

Bug: T342418
Bug: T343375
Change-Id: I6490ffba96b4f2d65d9206a4942f29d24d8bbecb
2023-08-02 19:18:21 +00:00
jenkins-bot
7a9e23c8d9 Merge "LocalisationCache: Load only core data if possible" 2023-08-01 01:05:12 +00:00
Lucas Werkmeister
cf8e22e1e4 LocalisationCache: Load only core data if possible
Extract loadCoreData(), which loads only the core, non-mergeable keys
from the core messages files, not the extension messages files or the
JSON files. Have loadItem() call this method, skipping the full
initLanguage() + recache(), if possible.

Because compiling the plural rules takes up a significant amount of
loading the core-only data (see discussion on Gerrit), extract
readPluralFilesAndRegisterDeps() from readSourceFilesAndRegisterDeps(),
and only call the latter in loadCoreData() (while recache() calls both).
Also remove a comment about readSourceFilesAndRegisterDeps() returning
false if the localisation doesn’t exist, which AFAICT hasn’t been true
since change I35bbb3a7a1 (commit 8e0c0a9fc9) in 2014.

Note that the new “core-only data” path in loadItem() bypasses the
underlying LCStore even if the core data (or indeed all data) happens to
be present in it. Some investigation and benchmarks (see the discussion
on this change on Gerrit) indicate that this is usually a performance
win; in particular, unless manualRecache is set, just checking whether
the LCStore is expired is relatively expensive.

[For further discussion, see also changes I00f2018400 and I64822e050e on
Gerrit, which were later squashed into this change.]

Bug: T342418
Change-Id: I7ec2d87c0f864c7dbfd629f0b47f22dc8a6fa552
2023-07-31 12:33:13 +02:00
jenkins-bot
1f7b8d78a0 Merge "Make minimumGroupingDigits an integer and add documentation" 2023-07-31 09:24:21 +00: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
Lucas Werkmeister
368881a277 LocalisationCache: Add CORE_ONLY_KEYS, ALL_EXCEPT_CORE_ONLY_KEYS
Previously, it was technically possible to set some keys in extension
messages files that didn’t make much sense (e.g. $rtl['en'] = true;).
This prevents optimizing language creation, so going forward, we will no
longer support that; ALL_KEYS is now split into CORE_ONLY_KEYS and
ALL_EXCEPT_CORE_ONLY_KEYS (with a test verifying that no key is missing
or overlapping or anything), and ALL_EXCEPT_CORE_ONLY_KEYS are silently
skipped when loading extension messages files.

To demonstrate that it’s okay to silently skip these keys, patch set 1
of this change on Gerrit instead raised a deprecation warning; CI
indicated that this warning was never hit. Codesearch [1] also suggests
that no known extension was actually using any of these keys. (The
DonationInterface [2] and LandingCheck [3] codesearch results can be
ignored: both of these define es-419 as a new language, using the
Language::getMessagesFileName hook to register their MessagesEs_419.php
as a “core” message file, not an extension message file.)

[1]: https://codesearch.wmcloud.org/search/?q=^\%24(fallback|rtl|(digit|separator)TransformTable|fallback8bitEncoding|link(PrefixExtension|Trail|PrefixCharset)|date(Formats|Preferences|PreferenceMigrationMap)|defaultDateFormat|digitGroupingPattern).*%3D&files=\.php%24
[2]: f8b5fe95f7/gateway_common/messages/MessagesEs_419.php (11)
[3]: 2537439aee/messages/MessagesEs_419.php (11)

Bug: T342418
Change-Id: Ia3dffea390d4efdfa3a3cea549d079507718ef48
2023-07-28 16:32:59 +02:00
Lucas Werkmeister
274fd222df LocalisationCache: Expand tests
To ensure that Ia3dffea390 and I7ec2d87c0f don’t change this behavior.

Bug: T342418
Change-Id: I4646b1c84116f51b6c2a826a41dc5c975d3d205c
2023-07-28 16:30:52 +02:00
Lucas Werkmeister
7b8859c70c language: Move tests from /cache to /language
The classes were already moved in change I62c701d574 (commit
051e127bdb).

Ideally, the tests should have a namespace, but the other tests in
/language are also unnamespaced, so let’s not do that yet.

Change-Id: Ieef8728a1f474ce6b16fa534c9697e1e89a4a36d
2023-07-28 15:23:06 +02:00
Amir Sarabadani
e33818cd08 Fix space after comma in single-line array declaration
We are introducing a new phpcs sniff to make sure this doesn't happen

That sniff found this so far.

Bug: T342297
Change-Id: Ibce3f3d28e7d2cb5b0ff7230f584e76446965ddc
2023-07-24 19:04:59 +02:00
Umherirrender
66a85aeed7 tests: Use instanceof in LanguageConverterFactoryTest
Also use ::class for class names

instanceof is not exactly the same as compare with get_class,
but that is only relevant for sub-sub-types,
which are not in use on converters

Change-Id: Ib07e14bd57211920d72f7e27668bf32c604ae03c
2023-07-21 06:02:05 +00:00
Fomafix
458d319798 LanguageIntegrationTest: Replace call of deprecated Language::factory
Only update test cases that tests non-deprecated functions.
Test cases that tests deprecated functions can be removed together with
the removal of the deprecated functions.

Also consistently use
  $this->getServiceContainer()
instead of
  MediaWikiServices::getInstance()

Change-Id: Iac40d6c66a31dd699ab8771244c701232e4354e8
2023-07-17 18:59:56 +00:00
Daimona Eaytoy
0e55aa602a Inject extension namespaces into NamespaceInfo
The service was previously accessing the global ExtensionRegistry
singleton, making it lose its statelessness. Dependencies should always
be injected, so add constructor parameters for that.

Simplify tests accordingly.

Change-Id: Iae375a81cab411fab607cba0addb2088131b3c81
2023-07-16 22:53:26 +02:00
daniel
63a610b8c7 Deprecate HookContainer::getHandlerCallbacks
There should be no need to call hook handlers directly,
this should only be done by HookContainer.

Change-Id: I8fa46c2eb6a40ad98e564c31dcfb103825608426
2023-06-23 00:26:40 +00:00
Winston Sung
ab1a809acc Revert "Implement Language Converter for yue (Cantonese)"
This partially reverts Iee936baa0a42370a723b34b09a791bf0917dcdf4
 (commit 504c1a9faf).

Bug: T59106
Change-Id: I935cc23cbc2838c4338c5fb2220d8ec4cfb750a9
2023-06-13 05:35:54 +00:00
Lucas Werkmeister
5f2bfc44ce Simplify HookContainer (v2)
This reverts change I50c3d1c5df (commit b0317287bc), thus reinstating
change I7d690a1172 (commit d139eb07fe). The only change from the
original is in getHookMethodName(), additionally replacing '-' with '_'
(not just ':' and '\'). The original commit message follows:

This converts all hook handlers to the same internal representation.
This is done lazily, when the hook is run for the first time.

The logic for temporarily disabling handlers by calling scopedRegister()
with the $replace parameter set has been greatly simplified.

There are some minor changes to the class's interface and behavior,
none of which should be breaking changes:
* run() will emit deprecation warnings if and only if it was called
  with the deprecationVersion option set, for all kinds of handlers.
  The idea is that deprecated hooks should emit a warning either from
  run(), or from emitDeprecationWarnings(). The latter happens if the
  hook is listed in DeprecatedHooks.
* register() now also accepts hook handlers declared in the way that
  extensions register hooks.
* Attempts to call register() with an invalid hook definition now
  result in an invalidArgumentException.
* Attempts to call register() for a deprecated hook will consistently
  result in a deprecation warning.
* The internal getRegisteredHooks() method has been removed in favor
  of the identical getHookNames() method.
* The internal getLegacyHandlers method has been removed in favor
  of getHandlerDescriptions() and getHandlerCallbacks().
* The call order changed so that dynamically registered handlers
  are called last, instead of getting called before handler objects
  from extensions.

Bug: T338213
Change-Id: I6efb09e314ad2b124a33a757fdda2a07ae0d8f7c
2023-06-06 12:06:23 +02:00
Lucas Werkmeister
b0317287bc Revert "Simplify HookContainer"
This apparently caused some change in how hook handlers are called (it
now calls e.g.  AbuseFilterHookHandler::onAbuseFilter-generateUserVars()
instead of AbuseFilterHookHandler::onAbuseFilter_generateUserVars()),
causing both test failures and errors on Beta.

This reverts commit d139eb07fe.

Bug: T338213
Change-Id: I50c3d1c5dfd2d7eeac59992156a8a644cf0197e5
2023-06-06 11:12:18 +02:00
daniel
d139eb07fe Simplify HookContainer
This converts all hook handlers to the same internal representation.
This is done lazily, when the hook is run for the first time.

The logic for temporarily disabling handlers by calling scopedRegister()
with the $replace parameter set has been greatly simplified.

There are some minor changes to the class's interface and behavior,
none of which should be breaking changes:
* run() will emit deprecation warnings if and only if it was called
  with the deprecationVersion option set, for all kinds of handlers.
  The idea is that deprecated hooks should emit a warning either from
  run(), or from emitDeprecationWarnings(). The latter happens if the
  hook is listed in DeprecatedHooks.
* register() now also accepts hook handlers declared in the way that
  extensions register hooks.
* Attempts to call register() with an invalid hook definition now
  result in an invalidArgumentException.
* Attempts to call register() for a deprecated hook will consistently
  result in a deprecation warning.
* The internal getRegisteredHooks() method has been removed in favor
  of the identical getHookNames() method.
* The internal getLegacyHandlers method has been removed in favor
  of getHandlerDescriptions() and getHandlerCallbacks().
* The call order changed so that dynamically registered handlers
  are called last, instead of getting called before handler objects
  from extensions.

Change-Id: I7d690a1172af44a90b957b2274d68e51b7f09938
2023-06-04 15:36:38 +02:00
Liangent
504c1a9faf Implement Language Converter for yue (Cantonese)
This only implement unidirectional yue-Hant => yue-Hans per community consensus.

Bug: T59106
Change-Id: Iee936baa0a42370a723b34b09a791bf0917dcdf4
2023-05-20 16:11:11 +00:00