Commit graph

164 commits

Author SHA1 Message Date
Máté Szabó
8e14ff1bc0 phpunit: Remove superfluous Title::clearCaches() calls
Why:

- Various tests have been calling Title::clearCaches() on an ad-hoc
  basis at the end of test methods, or in tearDown(), to work around
  stale Title instances persisting across tests in Title's internal
  caches.
- MediaWikiIntegrationTestCase takes care of this since
  Ie6cac7e1282f794277dfc8ff3673f12e9969818c, making these calls
  unnecessary.

What:

- Remove now-redundant Title::clearCaches() calls from tearDown()
  overrides and the end of test methods.
- Preserve in-test Title::clearCaches() calls that are likely
  intended to force internal caches to reflect changes happening
  within the test itself.

Bug: T395214
Change-Id: Ib5d42389cef20f3839c7f7a80041d002f0f09449
(cherry picked from commit 6483181044496c339ad497cc885319b20de7f6e7)
2025-05-27 12:37:31 +00:00
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
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
2024-10-16 20:58:33 +02:00
jenkins-bot
4627fe60af Merge "Add namespace to remaining parts of Wikimedia\Mime and Wikimedia\Stats" 2024-10-03 14:16:24 +00:00
jenkins-bot
db7ee3db99 Merge "Add namespace to remaining parts of Wikimedia\ObjectCache" 2024-10-03 14:02:47 +00:00
James D. Forrester
cc28acc455 Add namespace to remaining parts of Wikimedia\Mime and Wikimedia\Stats
Bug: T353458
Change-Id: If0137003ab625017d322d57870448a02569668c3
2024-09-27 16:19:10 -04:00
James D. Forrester
53b67ae0a6 Add namespace to remaining parts of Wikimedia\ObjectCache
Bug: T353458
Change-Id: I3b736346550953e3b2977c14dc3eb10edc07cf97
2024-09-27 16:19:10 -04:00
Bartosz Dziewoński
531ba3aad0 resourceloader: Add/change ResourceLoaderModifyEmbeddedSourceUrls hook
We've discovered some new requirements.

Follow-up to 31f614f732.
The hook was not in a release yet, so we can rename it.

Bug: T371530
Change-Id: I82d8ae69c27a38c45eab5d19c063f0b9515b8ec8
2024-09-27 20:28:30 +02:00
Timo Tijhof
e03380c714 ResourceLoader: Fix content-links compat
This never worked because it looked for `element` instead of `elements`.
The test repeated the same mistake.

Bug: T278576
Bug: T255717
Change-Id: I9bfceb6b8bd761244af6eda0e2ae08e98238aa76
2024-09-17 03:22:14 +00:00
Timo Tijhof
123da635a1 ResourceLoader: Fix SkinModule aliases to not override existing keys
While not documented or tested, aliases previously not only adding
but also replaced values.

Instead, emit a warning to inform skin developers of this conflict.

Note that the `content-links => elements` alias already behaves
this way (only if not already set), which the other aliases would
now be consistent with.

Change-Id: I66ae66b37bba14b2f65710f3d32f17d4e9a5a7a3
2024-09-17 03:22:04 +00:00
Timo Tijhof
3d924e4ed1 ResourceLoader: Minor doc blocks and coding style cleanup
* Function alls are either complete on one line or one arg
  per line. Avoid confusing calls where the args are on their
  own line as this creates visual ambiguity over how many args
  are passed, and what each piece belongs to. For example, is
  `true` or `false` passed as 2nd arg to applyFeaturesCompatibility?

* Replace comment about list-form behaviour with something that
  provides intention and insight instead of merely repeating what
  can already be seen from the code.

* Fix malformed `@param` docs that used variable as part of sentence.

* Use named data providers to ease PHPUnit debugging,
  and to make code coverage reports on doc.wikimedia.org more useful.

Change-Id: I2efd6cc7ac59c80684c9411025c4226473a36d43
2024-09-17 03:20:15 +00:00
Timo Tijhof
3ee96d47b6 ResourceLoader: Reduce deprecation clutter in SkinModule
* Move docs for deprecated aliases from top-level mentions into
  footnotes under primary docs. Still easy to search for, but no
  longer advertised as important for skin devs to know about
  or scan past when reading.

* Fix bug in 'legacy' logic where the key was not unset, thus
  mandating a needless entry in FEATURES constant. With the bug
  fixed, this internal entry is no longer needed.

* Fix bug in 'interface' logic where the key was not unset
  when the value is false. This would break the "skins.vector.styles"
  module otherwise, and had a similar workaround in place that
  is now no longer needed.

* Remove other unneeded entries in FEATURES for keys that were
  already being unset by applyFeaturesCompatibility().

* Remove deprecation warnings in favour of letting ResourceModules
  give a stable interface from ResourceLoader to skin.json.

* Add missing test to confirm no-op behaviour.

Bug: T374262
Change-Id: I9f4b1d48127d0afe67bada44d8dc4472507f9506
2024-09-16 20:17:34 -07:00
jenkins-bot
29b407432c Merge "ResourceLoader: Test DependencyStore with indirect styles dependencies" 2024-09-09 18:36:11 +00:00
Hannah Okwelum
9fffe0a559 ResourceLoader: Test DependencyStore with indirect styles dependencies
Bug: T343492
Change-Id: Ic6f34fbedd47962e2df9cb00c32df6fc93912c02
2024-09-09 18:07:35 +00:00
Umherirrender
441017cb54 ResourceLoader: Add missing documentation to class properties
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Change-Id: I90ecf85cb6f639af4be1947ccfbfb16d5b84cab3
2024-09-07 21:25:51 +02:00
jenkins-bot
3909efa52e Merge "Fix typo in browser vendor prefix" 2024-09-06 12:45:58 +00:00
Jon Robson
6bd260d7b2 Fix typo in browser vendor prefix
This is preventing icons from displaying in older Chrome browsers

Change-Id: I017da77ccda5763dc0312859127c453ba69e4029
2024-09-05 22:19:48 -07:00
Umherirrender
0a69e0bc53 tests: Use const for some static data in test files
Change-Id: Id7ccd48e3bf626095e2d3929831b5d87ed0be948
2024-09-01 23:24:11 +02:00
Roan Kattouw
5842c2c487 CodexModule: Also print dev mode warning when loading full library
We were only showing the development mode warning when Codex was used in
code splitting mode, but not when the full library was being loaded.

Bug: T314507
Change-Id: I22e9707b659b004ef1059f8b13feaf3f61b7ca28
2024-08-23 16:49:22 -07:00
Roan Kattouw
8a39d83175 Codex: Allow a local development version to be used
Developers can use this to test their local version of Codex with
MediaWiki by pointing $wgCodexDevelopmentDir to their local clone of the
Codex repo, e.g. $wgCodexDevelopmentDir = '/home/yourname/git/codex';

Setting $wgCodexDevelopmentDir affects where the following things come
from:
- Codex JS/CSS files for the full library
- Codex JS/CSS files for code-split chunks, and the manifest.json file
  that points to them
- Icons retrieved by CodexModule::getIcons()
- CSS-only icons imported in Less
- Design tokens imported in Less

Other changes in this patch:
- Add CodexModule::makeFilePath() to centralize the repeated path
  concatenation. This makes it easier to switch out the regular path for
  the dev mode path.
- Replace all uses of $IP (which is deprecated) and MW_INSTALL_PATH in
  CodexModule with the BaseDirectory config setting.
- Make CodexModule::getIcons() reset its static cache if the path to the
  icons file changes. Without this, it's impossible to make the unit
  tests pass.
- Move the i18n messages code from the CodexModule constructor to
  getMessages(). It can't be in the constructor because makeFilePath()
  doesn't work there (it fails because the Config object hasn't been set
  up yet).
- Add a 'mediawiki.skin.codex' import path so that we can stop
  hard-coding the path to the Codex mixins file. Without this, we can't
  make the Codex mixins come from the right place in development mode.
- Consider $wgCodexDevelopmentDir in setting the cache key for compiled
  Less code, since changing this setting can change the output of Less
  compilation (by changing design tokens, icons or mixins).
- Add unit tests for (the non-dev mode behavior of)
  CodexModule::getIcons() and the i18n message key handling.

Bug: T314507
Change-Id: I11c6a81a1ba34fe10f4b1c98bf76f0db40c1ce98
2024-08-22 17:20:24 -07:00
jenkins-bot
22163e47a7 Merge "Add MediaWiki\Registration namespace to registration classes" 2024-08-10 11:33:27 +00:00
Ebrahim Byagowi
697e19e461 Add MediaWiki\Registration namespace to registration classes
Bug: T353458
Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
2024-08-10 10:08:22 +00:00
James D. Forrester
f7ce0a0976 Move remaining four classes in includes/content into Content namespace
Bug: T353458
Change-Id: Ia0f3e22078550be410c4b87faf6aa4eabe6e270d
2024-08-10 10:40:53 +02:00
jenkins-bot
6a909bce4e Merge "Add namespace to WikitextContent" 2024-08-07 04:03:24 +00:00
Ebrahim Byagowi
4c270a72ac Add namespace to WikitextContent
It adds MediaWiki\Content namespace to WikitextContent
and two classes related.

Change-Id: Ib74e4c5b3edac6aa0e35d3b2093ce1d0b794cb6d
2024-08-06 17:42:51 +03:30
Fomafix
594e9fb023 Use MainConfigNames in tests
Change-Id: I6f79b3a36ce6605b86604fa9a99d55e8b8e67f7b
2024-08-06 13:58:47 +00:00
jenkins-bot
9c80f489cf Merge "resourceloader: Add ResourceLoaderModifyStartupSourceUrls hook" 2024-08-01 03:25:14 +00:00
Gergő Tisza
31f614f732 resourceloader: Add ResourceLoaderModifyStartupSourceUrls hook
Add a hook to StartUpModule that can modify the source URLs
that get embedded into the startup module JS in the form of
mw.loader.addSource() parameters.

The intended use case is preserving relevant URL information,
especially in the case of the 'local' source which is a
relative URL, when the URL pattern of the load.php URL
that generates the startup module code is different from the
URL pattern of the page that loads that load.php URL.

(E.g. $wgLoadScript is set to a different domain than the
current page, to canonicalize load.php URLs for a site
that's reachable via multiple domains, but then by default
the local source is a relative URL which would be
interpreted relative to the URL of the page that executes
the startup module code, so it would result in calls to
non-canonical load.php URLs).

Bug: T365162
Bug: T371530
Change-Id: I199ab779abd0596b836ae43dcc5f2f2a489c9274
2024-07-31 17:02:35 +00:00
Timo Tijhof
f6b850ea20 ResourceLoader: Limit injection of valid skins to names only
Follows-up I0191a812f044a5c04c:

* $installedSkins was named after MediaWiki's SkinFactory and its
  return value was not a list of skins, or actually a registry
  of skin names and PHP classes (subclasses of "Skin"). This
  information is of no use to ResourceLoader as it cannot construct
  skin objects (skins would require an RequestContext such used on
  index.php).

  Change its format to an actual list, and rename to reflect its
  local purpose.

* Simplify logic to: If not set, or, we do validation and the
  value is not valid.

* Update docs to explain what "perform validation" means.

Change-Id: Ic8544d99055a7b7c7e55496006b5971e4e4fa14f
2024-07-23 22:07:19 +00:00
Derick Alangi
ee508c5e31 ResourceLoader: Inject installed skins to ResourceLoader Context
RL\Context::class depends on SkinFactory to get the installed skins
to check if the skin from the URL is in the list of installed skins
or defaults to 'fallback'.

Most instantiators of RL\Context already have a fallback skin specified
so instead of relying on SkinFactory in the constructor of Context,
let's get the list of installed skins in RL entry point and pass that
instead.

In tests, OutputPage, etc, they're all using a fake request which will
eventually default to the 'fallback' or 'apioutput' or related skin.

NOTE: In ContextTest.php, adjust callers of ::getResourceLoader() to
use `self` instead of `$this` since it's defined as a static method.

Bug: T32956
Change-Id: I0191a812f044a5c04c50c62163395c4a706c375c
2024-07-23 22:36:25 +01:00
Jon Robson
e977eea153 Support mask-image in ResourceLoader ImageModule
The feature would be opt in to retain backwards compatible
support while also moving closer to rendering icons
consistently with how Codex does.

An example of this in use are:
* Ie5c88e0aa243f73f2dc9f310d18fd59b831edc64
* I17fabdf276f6c33fb78c007d75cda6bb9e02d79b

Bug: T365764
Bug: T358246
Change-Id: I95caab8037ccceba73101da2eb3c601f39511377
2024-07-17 01:05:06 +00:00
jenkins-bot
82d91ed739 Merge "Use MainConfigNames constants in tests where possible" 2024-07-11 12:46:04 +00:00
thiemowmde
4bd95cd96b Use MainConfigNames constants in tests where possible
I believe this makes the code less brittle, and also makes it a bit
more obvious what these strings are meant to represent.

Change-Id: Ia39b5c80af4b495931d0a68fd091b783645dd709
2024-07-10 10:11:22 +00:00
Ebrahim Byagowi
fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30
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
Ebrahim Byagowi
6316a253aa Add namespace and deprecation alias to CssContent
This patch introduces a namespace declaration for the
MediaWiki\Content to CssContent and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I6ab25787893cb2195f8cd2ba125ed8dd5a60de43
2024-05-18 01:48:53 +03:30
Ebrahim Byagowi
f0c5cd0d33 Add namespace and deprecation alias to JavaScriptContentHandler
This patch introduces a namespace declaration for the
MediaWiki\Content to JavaScriptContentHandler and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: Ic30789d4e80a27004b6bc3b3ba891a7332a5e1ba
2024-05-17 15:06:40 +03:30
Ebrahim Byagowi
ccde5085de Add namespace and deprecation alias to JavaScriptContent
This patch introduces a namespace declaration for the
MediaWiki\Content to JavaScriptContent and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I87c17327911e28a461feaf2ff46242454cff257a
2024-05-17 13:51:18 +03:30
Roan Kattouw
3211083394 tests: Add CodexModule tests for full library mode
Also convert the data provider to a generator.

Change-Id: Id9cfe88d789f655ae7fc26ce48c7bba08fbee33e
2024-05-16 12:00:46 -04:00
Roan Kattouw
fe62ebafd2 CodexModule: Remove CODEX_MODULE_DIR, instead use CODEX_LIBRARY_DIR
CODEX_MODULE_DIR is always the /modules subdirectory of
CODEX_LIBRARY_DIR, so remove it and derive it that way instead.

- Update tests accordingly
- Rename test data files accordingly
- Use CODEX_LIBRARY_DIR in one place where we had neglected to use a
  constant

Change-Id: Ieb347c2d128f3addfb11f6aca79d63969434f342
2024-05-15 17:12:20 -04:00
Umherirrender
8d97313f81 Fix some line indent
Change-Id: I8f82724197d20f9289d80e138d80310f1eab29f2
2024-04-20 00:25:15 +02:00
Lucas Werkmeister
a0345ee3f3 ResourceLoader: Add WikiModule regression test for T360014
Bug: T360014
Change-Id: I591ee186083fbb1901ebeaf880f9e793c3b6cfed
2024-03-14 21:10:51 +00:00
Timo Tijhof
07d31822c7 ResourceLoader: Edit real pages in testGetPreloadedTitleInfo
Remove a bunch of mocking complexity in favour of real pages.
This is in prep for making a better regression test in change
I591ee186083f for T360014.

Bug: T360014
Change-Id: I2f99a542a6d17a8503213f68c3df6a1c5ca50c77
2024-03-14 14:10:39 -07:00
Timo Tijhof
39d2f7745c ResourceLoader: Refactor makeTitleInfo() in WikiModuleTest
Use TitleValue instead of Title::newFromText to reduce complexity of
this test.

Change `Project:Example/foo.js` example to NS_USER to be more
realistic, given that (afaik) there can't be a WikiModule with a
page in NS_PROJECT. It is true that people sometimes import project
pages containing JS via importScript over action=raw, but that
doesn't involve ResourceLoader.

Change-Id: Id2df9a0f17880e397b02d4c855d9e0287a8949ee
2024-03-14 18:57:51 +00:00
jenkins-bot
07ff1f5e70 Merge "ResourceLoader: Migrate wfGetDB call to ICP and move to WikiModule" 2024-03-11 19:50:59 +00:00
Timo Tijhof
3903c8cfec ResourceLoader: Migrate wfGetDB call to ICP and move to WikiModule
* Remove references to IDatabase from preloadModuleInfo() and with
  it the last reference to Rdbms in the ResourceLoader service
  (progressing T32956).

* Simplify WikiModule::preloadTitleInfo() so that it doesn't need
  an IDatabase object unless
  1) there are non-zero WikiModule objects in the batch, and
  2) there is a cache miss.

* Remove needless IDatabase parameters passed or mocked for this
  method. Note that WikiModule already had `@group Database` set
  since each WikiModule::getDB() is called and uses an unmocked
  database. The mocked database was only injected to satisfy the
  method signature.

Bug: T32956
Bug: T359522
Change-Id: I022f02d6e6bbae46c3258a7c07a1d6723506d8bc
2024-03-11 19:39:24 +01:00
Umherirrender
f3524224f0 build: Fix line indents
Fixed SkinModuleTest::provideGetFeatureFilePathsOrder as nesting of
arrays for parameters is wrong

Change-Id: I9875008adf62d284c48662ebfbd245d72e5be064
2024-03-11 00:14:16 +01:00
Timo Tijhof
c97b33d259 ResourceLoader: Add missing @group ResourceLoader to various cases
Bug: T359522
Change-Id: If40814e8084183299e1b345aee975f61b11e26fe
2024-03-09 21:25:44 +00:00
Jan Drewniak
9b3a215975 Output skin related styles after SkinModule feature styles
Changes SkinModule::getStyles to output config features
first, then skin customization styles last. This requires
using the ResourceLoader::makeCombinedStyles method to
first combine feature styles, then combine style related styles,
and return the concatenated result in SkinModule::getStyles().

The resulting stylesheet ordering is changed so that all
skin customization styles are always output after core styles,
which allows skins to override core-styles via cascade order instead
of increased specificity.

Previous output order:
- all (core+custom)
- print (core+custom)
- screen (core+custom)
- other custom

New output order:
- all (core)
- print (core)
- screen (core)
- other (core)
- all (custom)
- print (custom)
- screen (custom)
- other (custom)

SkinModule is refactored to separate logo-related style
generation, as well as skin feature generation, in order to maintain
testability. Tests are also refactored to better cover different
skin feature configurations.

Bug: T354975
Change-Id: I261742c0ae4c3d57353bf1854af66f39df6132f7
2024-02-29 11:56:57 -05:00
jenkins-bot
6b8a6138d4 Merge "tests: Add replacement for assertions deprecated in PHPUnit 9.6" 2024-02-25 00:09:20 +00:00
Daimona Eaytoy
89f583625a tests: Add replacement for assertions deprecated in PHPUnit 9.6
expectWarning() and friends have been deprecated in PHPUnit 9.6, and
removed in PHPUnit 10. Unfortunately, there is no simple replacement
because PHPUnit no longer converts them to exceptions in the first
place. In fact, Sebastian Bergmann explicitly stated that he does not
consider the use case of

> a library developer to verify a code block warns its consumer when
> certain action is performed

worth supporting.

So, add an ad-hoc replacement for all the deprecated methods. This is
quite ugly, but it's simple enough given the low number of usages.

On the bright side, this new method does not halt the test when the
warning is triggered. This seems to align with the developers'
expectation, seen in a few existing tests, that any code following the
notice will be executed.

Bug: T342110
Change-Id: I214abfed4280834840c115777ed78eb0a5570da9
2024-02-23 22:09:45 +01:00