Commit graph

17 commits

Author SHA1 Message Date
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
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
Tim Starling
69ad795df7 ResourceLoader: Have FileModule deliver additional path information
* Have FileModule::getScript() always return an array with a filePath
  or fakeFilePath, not a string. This allows source maps to be
  constructed.
* Make the scripts returned from Module::buildContent() always be an
  array. Module::getScript() may still return a string for b/c.
* In makeLoaderImplementScript(), interpret the new plainScripts array.
  Factor out the package file normalization loop from
  makeLoaderImplementScript().
* Fix missing base path in mediawiki.base.
* Improve relevant doc comments.

Bug: T47514
Change-Id: I392a8cce9a0febc707b6cb17412e3b723c9cc686
2023-08-23 04:06:20 +01:00
Tim Starling
f2a5946375 ResourceLoader: wrap module definitions in functions
This is an intermediate step towards the linked bug, to help untangle
the performance impacts.

Bug: T343407
Change-Id: I086f173f811fb44683f4a67bf6bc415d7e27f593
2023-08-11 00:36:52 +00:00
Tim Starling
8a4134ed21 ResourceLoader: deliver deprecation warnings as strings
It's awkward to construct a source map when the file contents is
modified after loading. Delivering deprecation warnings as JS code
seems like an odd convention anyway.

So, send the module deprecation warning as an additional parameter to
mediawiki.loader.implement().

Deprecation warnings are no longer displayed in only=scripts mode.

Remove deprecation tests from FileModuleTest since FileModule no longer
has any relevant deprecation code. Add tests to ModuleTest.

Deprecate Module::getDeprecationInformation().

Bug: T47514
Change-Id: I20938cf4ab78afc9a2d72fbd163a7c5f21755820
2023-08-03 14:10:16 +10:00
Tim Starling
c16af26ea9 ResourceLoader: Factor out the loop body of makeModuleResponse()
Bug: T47514
Change-Id: Ia33ce18812b31d26b6b7ab6e50639c01c9353389
2023-07-24 18:22:20 +10:00
Timo Tijhof
656ea1b045 ResourceLoader: Remove Module::getName check before $stats->timing()
Follows-up 2c93649672 (I2b2905d7452bd2), which added the conditional
in order to silently accept case where setName was not called.

getName() is not conditinally accessed elsewhere. It being undefined
would be an error condition on the part of the caller. In this case,
Wikibase forgot to call setName, which I1cc5c54db42ca fixes.

See also ResourceLoader::getModule(), which indicates values that
must be injected in production code. In tests we can sometimes be
lazy and skip a required injection, such as Config and HookContainer,
that we only use in certain methods that perhaps your test doesn't
call. However, upon finding that a test starts exposing such need,
the test need to be updated to provide or mock that value, instead of
tolerating the absence in production code.

This change also fixes a bug in the previous change which would have
theoretically emitted 'all' without the per-module metric, which
would invalidate percentage-based calculations in Graphite as the
total would no longer be equal to the sum.

Depends-On: I1cc5c54db42ca3a9da38ab56cf88cd71dc5b8343
Change-Id: I3c9b7a17b1331750c631b8dc3e9e7ee04d79884f
2023-04-14 08:34:07 +00:00
Tim Starling
25d0d37adc ResourceLoader: tweak comments and error messages
Change-Id: Ifcaefedf65b090a87ec1417808277ae6451302dc
2023-04-03 18:21:30 +10:00
James D. Forrester
6c7177349b ResourceLoader: Raise MW JavaScript startup requirement to ES6
The UA sniffs that overrode the feature tests are no longer needed.

* MSIE 10: Fine, rejected by feature checks.

* UC Mini "Speed Mode": Redundant, the version that this sniff
  matched is pre-ES6. Current versions of UC Mini don't appear to
  support enabling "Speed Mode" on random websites nor does it offer
  it for Wikipedia specifically.
  Details at https://phabricator.wikimedia.org/T178356#8740573.

* Google Web Light: Redundant, shutdown as of 2022.
  Any references or extensions that still reach the proxy, get
  redirected to our online URLs
  https://googleweblight.com/?lite_url=https://en.m.wikipedia.org/wiki/Banana
  https://phabricator.wikimedia.org/T152602
  https://en.wikipedia.org/wiki/Google_Web_Light

* MeeGo: Redundant, discontinued and presumed rejected.
  Either way, unsupported.

* Opera Mini: Fine, rejected by checks.
  Details at https://phabricator.wikimedia.org/T178356#8740573.

* Ovi Browser: Redundant, discontinued and presumed rejected.
  Either way, unsupported.

* Google Glass: Improve UX (since 2013, T58008).

* NetFront: Redundant. Old versions are presumed rejected.
  Current versions are Chromium-based and presumed fine.
  The exclusion was not UX based, but due to jQuery explicitly not
  supporting it in 2013. This is no longer the case, so we can let
  the feature test lead the way here.

* PlayStation: Redundant, same story as NetFront.
  The version that matched the sniff is presumed rejected.
  Current versions probably fine, but even not, don't match
  our sniff so are already enabled today.

Bug: T178356
Change-Id: Ib6263ce3ffd11af5e501de8857f3e48a248c6210
2023-03-30 14:26:05 +01:00
Kosta Harlan
b0a13b0595 Adjust default targets in RL/Module
In Ia062ff2d8b8732b0d3498c1a614bbf6a3e3a7ddb, we changed the default
targets to desktop/mobile. This broke CI for PageTriage, which has a RL
module that extends ResourceLoader\Module, and which sets the default
targets for "desktop" only.

I am not sure if leaving ResourceLoader\Module as "desktop" only was a
deliberate choice or an oversight, but it seems to be more consistent to
have it defined as desktop/mobile. This will fix the issue for
PageTriage and other extensions that extend ResourceLoader\Module and
don't have any targets explicitly defined for their RL modules.

Follows-Up: Ia062ff2d8b8732b0d3498c1a614bbf6a3e3a7ddb

Bug: T127268
Bug: T328497
Change-Id: I48ed19912610a74af66d620510c192c7ba87039a
2023-02-01 22:50:01 +00:00
Lucas Werkmeister
2c93649672 Don’t track build statistics for unnamed modules
Module::getName() is allowed to return null (and there are some existing
modules where it returns null, such as Wikibase’s SitesModule). Passing
the null name directly into strtr() produces a warning in PHP 8.1, but
more importantly, it will also result in tracking the metric
`resourceloader_build.` without any stat name (under any PHP version).
Fix this by not tracking the individual module in this case.

Bug: T319219
Change-Id: I2b2905d7452bd2694c5c1af3272e0fb0e95ff144
2022-11-02 13:45:10 +01:00
DannyS712
65e3ff04ce ResourceLoader: readability cleanup and simplification in Module class
Use early returns to reduce nesting, unhoist variables,
should be a no-op in terms of functionality.

Change-Id: Ic6a63dccb982615b8b3e70aabd059dec70244374
2022-06-28 04:46:53 +00:00
Adam Wight
360343afb3 ResourceLoader: Remove unchecked exception annotations
Also repair two `@see` annotations referring to methods that didn't
exist.

Bug: T240672
Change-Id: I2edb39554bcf46fdc83bd138ef7bb9065c2c0696
2022-06-22 00:25:57 +01:00
Tim Starling
3e2653f83b ResourceLoader namespace (attempt 2)
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader itself.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Revert of a241d83e0a.

Bug: T308718
Change-Id: Id08a220e1d6085e2b33f3f6c9d0e3935a4204659
2022-05-24 15:41:46 +00:00
Lucas Werkmeister (WMDE)
a241d83e0a Revert "ResourceLoader namespace"
This reverts commit e08ea8ccb9.

Reason for revert: Breaks Phan in extensions, and as far as I’m aware,
this change isn’t urgently needed for anything, so the simplest fix is
to revert it again for now. After PHP 7.4 it should be safer to try this
again (we hopefully won’t need the two “hack” classes by then).

Bug: T308443
Change-Id: Iff3318cbf97a67f821f78e60da62a583f63e389e
2022-05-16 14:43:33 +00:00
Tim Starling
e08ea8ccb9 ResourceLoader namespace
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader and
ResourceLoaderContext.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Change-Id: I92998ae6a82e0b935c13e02a183e7c324fa410a3
2022-05-16 14:41:27 +10:00
Renamed from includes/resourceloader/ResourceLoaderModule.php (Browse further)