Commit graph

139 commits

Author SHA1 Message Date
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
Timo Tijhof
be2dbcc219 ResourceLoader: Follow-up creation of ResourceLoaderEntryPoint
Follows-up Iadea44b7867f48a2be6ccbf00c0e56911a5af74e.

ResourceLoaderEntryPoint:
* Rename from Resource to ResourceLoader, as it is the entry point
  for ResourceLoader.
* Fix accidental use of ingroup on the file docblock
  instead of the class.
  https://phabricator.wikimedia.org/F42046908
* Fix broken "see" reference to "/load.php" on the ResourceEntryPoint
  class on doc.wikimedia.org. Files are indexed in Doxygen by full
  name without leading slash.
* Remove load.php from docgroup, akin to index.php.

tests:
* Remove unrelated Rest namespace from test suite.
* Remove redundant default values in newResourceLoader(),
  especially null values were confusing by showing an
  apparent intent to set a value without actually
  isplacing the default, given that isset/?? treat
  set null as not set.
* Simplify test by using the built-in startup module instead.

EntryPoint:
* Remove comment in test about doPostOutputShutdown.
  It sounded like it was explaining that we use getCapturedOutput()
  instead of run() because the latter calls doPostOutputShutdown
  which we want to avoid. Except, we don't avoid it,
  since run() is called and does call doPostOutputShutdown.
  Unclear what it was explaining.
* Improve docs around getCapturedOutput() in the base class,
  and make explicit that this seemingly unused complexity
  exists for the purpose of testing.

Bug: T354216
Change-Id: I5139fda90a3d5ac7ea1ed917c8045d1a09961d78
2024-02-22 22:30:39 +00:00
jenkins-bot
84a357a774 Merge "Revert "SkinModule - Ensure skins can easily override skin feature styles"" 2024-02-19 19:37:07 +00:00
Esanders
9783ee9482 Revert "SkinModule - Ensure skins can easily override skin feature styles"
This reverts commit afdc92987f.

Also reverts Ib44687b which was a follow-up.

Reason for revert: Caused T357929

Bug: T357929
Bug: T354975
Change-Id: Ic6d0b472cc2b26cb7c375bf9a5d2e03a4d6c6a18
2024-02-19 18:52:53 +00:00
Reedy
2295da3004 Fix more incorrect casing of MediaWiki
Change-Id: I331e5636823a0beae8d804148f648cfaffd6a1f8
2024-02-19 14:35:34 +00:00
Reedy
c8276f731a tests: Add more use statements in namespaced classes
Change-Id: I2629cfcb09fde6f18be824779a2c12c013ea0cb5
2024-02-18 21:31:02 +00:00
James D. Forrester
d6fd1436a3 tests: Namespace ResourceLoaderTestCase and friends
Leave class aliases behind because they might be being used somewhere,
but we don't normally flag these kinds of things in the release notes,
do we?

Bug: T357823
Change-Id: I7fc7f34494d5c4df81f6746d63df1d0f990f8ae9
2024-02-16 21:32:22 +00:00
jenkins-bot
fc685448e1 Merge "Namespace Message, move to appropriate directory" 2024-02-15 15:51:23 +00:00
jenkins-bot
70942c2378 Merge "SkinModule - Ensure skins can easily override skin feature styles" 2024-02-15 00:21:29 +00:00
Jan Drewniak
afdc92987f SkinModule - Ensure skins can easily override skin feature styles
Reorders ResourceLoader\\SkinModule style output so that all styles
produced by skins are output after styles that are produces by
skin "features" such as normalize.

Refactors & expands SkinModuleTest.php to include tests for default
values, print styles and correct style ordering.

Bug: T354975
Change-Id: I0000b4ad8eb2de40be293f0e693d873c282ea785
2024-02-14 17:44:01 -05:00
James D. Forrester
eeb5a740b3 Namespace Message, move to appropriate directory
Bug: T353458
Change-Id: I088cbc53fbcdb974e5b05b45a62e91709dacc024
2024-02-14 15:10:36 -05:00
jenkins-bot
19847b7710 Merge "CodexModule: Transform manifest to a more useful format, and cache" 2024-02-13 23:13:32 +00:00
jenkins-bot
f125422b7d Merge "flushOutputBuffer: improve error handling" 2024-02-11 23:43:22 +00:00
daniel
1b6e29d7af flushOutputBuffer: improve error handling
This improves handling of edge cases around flushing buffers:
- Distingush clearly between "headers sent" and "all output sent"
  states.
- Warn when trying to flush output after output was already sent to the
  client.
- Avoid looping indefinitely when failing to delete a buffer, to work
  around a quirk of PHP's zlib.compression buffer.

Follow-up: I4ea116d60030da92be14f0283ce4dc4877c4ca13
Bug: T356578
Change-Id: Iaf34a48b89e969b8e26328f0d2512ad22ef48212
2024-02-09 12:10:59 +01:00
Anne Tomasevich
919c95782f CodexModule: Add exception if @wikimedia/codex is required
Bug: T356345
Change-Id: I656061bb0ef95b207241423a6d8c25a1448b6f24
2024-02-08 18:18:46 -05:00
Roan Kattouw
06299ce04a CodexModule: Transform manifest to a more useful format, and cache
- Add a getCodexFiles() method that parses the manifest and transforms
  it to a more useful format based on actual file names rather than
  manifest keys
- Cache the result as a static class property, so that it's reused
  between all CodexModule instances
- Use the resulting data structure to simplify the rest of the code
- This also has the side effect of correctly throwing an error when a
  nonexistent file is requested (this wasn't the case before). Add a
  test case for this.
- Add a test for this new method in CodexModuleTest.php

Change-Id: Id527cef0e19fec7b54af3bf65a1de66f50d5fff0
2024-02-08 21:36:05 +00:00
Timo Tijhof
f7414e210b ResourceLoader: Follow-up resourceloader_build metric change
* $statName should be set, and was/is unconditionally used as a string.
  The added `?: 'na'` appears not to be needed.
  Follows-up Ida57415073 (1204f0dee4).

* Fix lazy setName() calls in tests to actually pass a valid non-empty
  string, like other tests do. Follows-up I1c03e3f470 (3a9744921d).

Change-Id: I1c8cd7d8c043845c0373a457b389213e5111976b
2024-02-07 21:22:30 +00:00
daniel
4ea8c705a3 ResourceLoader: Factor out ResourceEntryPoint from load.php
The idea is that all entry points should share the code in the
MediaWikiEntryPoint base class. This change by itself doesn't achieve much, it should be followed up by a change moving request handling logic from ResourceLoader into ResourceEntryPoint.

Bug: T354216
Change-Id: Iadea44b7867f48a2be6ccbf00c0e56911a5af74e
2024-02-02 17:06:31 -05:00
Ty Hopp
751d8a0ff4 CodexModuleTest: Invalid codex components definition
This patch adds test cases for the following scenarios:

- codexComponents defined as an empty array in the module definition
  file
- codexComponents defined as a non-array type in the module definition
  file

Bug: T353858
Change-Id: I055f837baab2bfce5ae840a472a9f8a2bf3847df
2024-01-29 19:08:57 +00:00
Roan Kattouw
9024a8ee02 CodexModuleTest: Add test for exception when requesting chunks
CodexModule throws an InvalidArgumentException if one of the elements
of the codexComponents array refers to a private chunk rather than a
public entry point file. Add a unit test asserting this behavior.

Also add an `isset()` to the check in CodexModule so that it doesn't
cause a PHP notice about a missing array index.

Bug: T353191
Change-Id: I3e31511aeeb42d825c308f047894f5eba28b0f27
2024-01-25 14:31:33 -08:00
Amir Sarabadani
167fbd0a20 Drop deprecated config $wgLogoHD
It has been deprecated since 1.35, hard deprecated since at least I9776d11d4e2d184

No grep result in wmf-config

Change-Id: I2c67bab3e3212f25a0cbce7301f5e32a082f76da
2024-01-24 19:46:04 +01:00
jenkins-bot
c3833b6681 Merge "CodexModule: Throw exception for non-entry points" 2024-01-17 18:56:18 +00:00
Anne Tomasevich
c8117c78ca CodexModule: Throw exception for non-entry points
If a generated chunk is listed in the codexComponents array,
an exception will be thrown informing the developer that the
item is not an export of Codex and cannot be required.

Text fixtures and expected values were updated to match
recent changes to the manifest that made composables
explict entries.

Bug: T353191
Change-Id: Ie3e35501993b1ad5d29ebecbcc8203e7f4ea8c81
2024-01-17 12:29:47 -05:00
Ty Hopp
6146b5ef98 CodexModuleTest: Missing codex components definition
This patch adds a test case for the scenario where a codex component is
not defined in the module definition file and a user attempts to require
it.

The scenario where the 'codexComponents' key is defined but is an empty
array will be tested separately after 984663 lands.

Bug: T353858
Change-Id: I717ac327848ff6f6baad83110e8d2f10c135e5f1
2024-01-17 13:11:48 +08:00
James D. Forrester
273cc042ae ResourceLoader: Drop targets system, deprecated in 1.41
Bug: T340802
Depends-On: Ie936afed7042d5a4713b027c30d7487565a35eaf
Change-Id: Icad30d62301be5d7390ebdf34e818519e3fe56c4
2024-01-12 16:42:38 -05:00
Timo Tijhof
53a3c8b417 ResourceLoader: Switch validateScriptFile() from JSMinPlus to Peast
This adds support for ES6 and ES7 syntax to user scripts, thus
matching the wikimedia/minify library.

Bug: T75714
Depends-On: I43d4619a32e37eb42e1aaa55a1f602962609c52b
Depends-On: If3b2b4a75013baeaa0d9b92cd10dfb06e5534153
Change-Id: Ie309e761f8b20640f7c0e85def0a3d1ccc8a658e
2024-01-06 22:33:46 +00:00