Commit graph

1619 commits

Author SHA1 Message Date
Aryeh Gregor
747bc81ac0 Use MainConfigNames instead of string literals
Part 1, proof of concept. Hundreds of files left to go. These changes
brought to you in large part by vim macros.

Bug: T305805
Change-Id: I44789091e9f6394c800a11b29f22528c8dcacf71
2022-04-11 17:53:27 +03:00
Timo Tijhof
3de8b6d6d8 resourceloader: Disable mw.loader.store on safemode pages
On special pages where disallowUserJs() is used, or when setting
safemode=1 by hand to index.php, disable mw.loader.store.

OutputPage already normalizes disallowUserJs() to safemode=1 as
passed on to ResourceLoaderClientHtml and ResourceLoaderContext.

Use it in the startup mode to disable this feature.

Invert the internal substitution variable to avoid confusing
double negatives, and to match the config name.

Bug: T145498
Change-Id: I2fdba968b4703ec8826bdaf91340bdead058f02b
2022-04-01 22:37:40 +01:00
jenkins-bot
232353c19b Merge "phan: Remove PhanPossiblyUndeclaredVariable suppression" 2022-03-31 14:36:57 +00:00
jenkins-bot
71c65e05e0 Merge "Apply logo variant override in ResourceLoaderSkinModule" 2022-03-30 23:42:20 +00:00
Umherirrender
6caf78c2c8 phan: Remove PhanPossiblyUndeclaredVariable suppression
Make phan stricter about conditional variable declaration
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T259172
Change-Id: I1f200ac37df7448453688bf464a8250c97313e5d
2022-03-30 19:47:15 +00:00
Umherirrender
7aa0884029 phan: Remove PhanTypePossiblyInvalidDimOffset suppression
Make phan stricter about array keys
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T304887
Depends-On: I3105a5fd4826f8667b5232834defc5ec93be32a1
Depends-On: Ie9610a6e83731468311edb3ed17f80fc509de385
Change-Id: I701f12ab94478c3b8e7fd82110ade74a8e6b04ef
2022-03-28 23:26:49 +02:00
Func
fbe6443942 Apply logo variant override in ResourceLoaderSkinModule
Logo variant override is available for 'wordmark' and 'tagline' in
the new Vector skin and has been used for a while, but the 'logo'
feature built in the core didn't take variants into account.
The logic should be pushed down to ResourceLoaderSkinModule so that
behavior can be consistent between skins and core.

Also, old code use $title->getPageViewLanguage() to determine the
variant of logo, which is a wrong behavior. Logos should be in the
interface language instead of the content variant.

Bug: T273578
Change-Id: Ifb3cc45600d57cf9c72757016148684cd7ab1400
2022-03-28 13:22:07 +08:00
jenkins-bot
a9bae3a83f Merge "resourceloader: Add Module::getSkins to skip irrelevant modules from startup" 2022-03-25 01:17:51 +00:00
Siddharth VP
92372d3786 resourceloader: Add Module::getSkins to skip irrelevant modules from startup
Registering fewer modules reduces the size of the startup module.

The current skin is read from the skin parameter to the load.php
request. Modules can opt-in by specifying skins in which they are
relevant, by overriding getSkins() of ResourceLoaderModule.

Bug: T253582
Bug: T236603
Change-Id: I08a1a59b4eab90d380ca8f874bb6dbba2f399590
2022-03-24 23:38:51 +00:00
Tim Starling
97b8262d1f Use UserRigorOptions directly
Conventionally, public constants are accessed via their declaring
class, except for self:: which is an acceptable shortcut.

Change-Id: If05eab72140267e6ef54736710d751d7f24a7860
2022-03-25 10:06:34 +11:00
Jon Robson
210b3b726c Remove the ResourceLoaderSkinModule legacy feature stylesheet
Bug: T304325
Change-Id: Ibd1edd2b50056a15e99576e3d42f7eba01f31fc4
2022-03-23 10:20:09 -07:00
Timo Tijhof
6522ff4ae2 resourceloader: Set class-wide @covers and ignore coverage of HookRunner
Change-Id: I49379986f0e7c05fb3442f0de9f496f151c4bed5
2022-03-20 15:17:21 +00:00
Jon Robson
9bd3af32fc Update installer to reflect modern logos
There are now 4 types of logos, only one of which is needed.
Update documentation in installer to reflect this.
Also make it possible to drag and drop files into the installer
and see live previews of what the logos will look like to aid
setup.

The 1x is no longer required.

Bug: T255913
Change-Id: I58226ae8fb02c32d2eeea65a50aaabbc193cb51c
2022-03-10 16:48:39 +00:00
Timo Tijhof
58bc56cd81 resourceloader: Document optimisation in WikiModule::isKnownEmpty
* Explain the optimisation in this method.
* Improve overall docs.
* Bring the getTitleInfo() fetch closer to where it is needed,
  which is also a micro optimisation in itself by not fetching
  in case of the early return (though that's a rare case).

Bug: T299288
Change-Id: I104cf20ab5a944ec382c5807e8bf1bf18979d426
2022-02-23 21:46:28 +00:00
Roan Kattouw
77f86c7e38 resourceloader: Pass exports parameter to package modules
This adds support for the `exports` alias for `module.exports`, but only
to package modules, per the discussion on T284511. This makes it easier
to use external libraries that use UMD, since UMD tests whether
typeof exports === "object", and if not, it adds the library to the
global scope instead of exporting it.

This is a breaking change for package modules that were expecting
exports to be undefined; in practice, this means modules that were
expecting UMD wrappers to add to the global scope have to be updated to
expect it to export the library instead. However, most UMD wrappers in
MW core are in non-package files, which are not affected by this change.

The affected libraries are updated accordingly:
- Codex used the global scope. This library is very new and nothing uses
  the global window.codex variable yet, so we don't need to provide
  backwards compatibility for it.
- Pako was patched to have its UMD wrapper look at module instead of
  exports; remove this patch since it's now unnecessary

Bug: T284511
Change-Id: Ie2e965cee001fb7f10b2b3e3f796d9511f6b63d2
2022-02-22 15:02:27 +00:00
Roan Kattouw
d84a3ecbed Add Codex v0.1.0-alpha.2
Bug: T299148
Change-Id: I414698b1c8251a5e873a2b6385b61051f32f54c0
2022-02-14 19:59:53 -08:00
Siddharth VP
8033ea475b Add hook to allow extensions to prevent preferences being exported client-side
Helps reduce the size of the user.options module by not adding options that are
unlikely to be of use in JavaScript.

Bug: T251994
Change-Id: I7701d094a3e905edeab7571dca34db5b20a13d68
2022-02-03 01:44:54 +00:00
jenkins-bot
2becc606d3 Merge "Try not to discard Excimer timeout exceptions" 2022-02-03 00:28:16 +00:00
Tim Starling
ca71e69fc6 Try not to discard Excimer timeout exceptions
Don't catch and discard exceptions from the RequestTimeout library,
except when the exception is properly handled and the code seems to be
trying to wrap things up.

In most cases the exception is rethrown. Ideally it should instead be
done by narrowing the catch, and this was feasible in a few cases. But
sometimes the exception being caught is an instance of the base class
(notably DateTime::__construct()). Often Exception is the root of the
hierarchy of exceptions being thrown and so is the obvious catch-all.

Notes on specific callers:

* In the case of ResourceLoader::respond(), exceptions were caught for API
  correctness, but processing continued. I added an outer try block for
  timeout handling so that termination would be more prompt.
* In LCStoreCDB the Exception being caught was Cdb\Exception not
  \Exception. I added an alias to avoid confusion.
* In ImageGallery I added a special exception class.
* In Message::__toString() the rationale for catching disappears
  in PHP 7.4.0+, so I added a PHP version check.
* In PoolCounterRedis, let the shutdown function do its thing, but
  rethrow the exception for logging.

Change-Id: I4c3770b9efc76a1ce42ed9f59329c36de04d657c
2022-02-02 16:27:44 +11:00
Timo Tijhof
7b33f838ba resourceloader: Omit ES6-only modules from registry in ES5 context
This change exposes the requiresES6 flag to the public API,
specifically via getState() by not registering modules that
aren't available / can't be loaded in the context.

This actually simplifies the code a fair bit, and partially reverts
the added logic from I45670c910ff12.

Bug: T299677
Change-Id: I96a03796628a74ace93579d45a582711400c09c1
2022-02-01 22:58:46 +00:00
jenkins-bot
7f310922f7 Merge "resourceloader: Change SkinModule list mode to not add implicit features" 2022-01-26 22:06:58 +00:00
Jon Robson
57dcba01b2 resourceloader: Change SkinModule list mode to not add implicit features
If a skin e.g. Minerva is using an opt-in policy then it has already
decided what features to load. It should not be subjected to features
it hasn't requested.

This was leading to content-external-links being loaded in Minerva
since 8c1afd97a3.

Bug: T298433
Change-Id: I621621bc2d30ee9ce00decbdee0f55c4db65abc1
2022-01-26 21:51:19 +00:00
Tim Starling
54c735354f Stop using is_resource() where possible
* Enforce the ban on is_resource in phpcs
* In OrderedStreamingForkController, the comment was incorrect. I
  confirmed using a small test script that if the child closes one end
  of a socket pair, the other end will still be open, and is_resource()
  will still return true, and fclose() will not fail. The issue was
  introduced in c82d30d19c, it was not present in the
  CirrusSearch copy of the class.
* Allow is_resource() for debug logging.
* Allow is_resource() for parameter validation where a stream may be
  passed to a function, since there is no alternative.

Bug: T260735
Change-Id: I59a752f7bb4b043ddfb2434b52a02f9221bf54db
2022-01-26 10:03:23 +11:00
Siddharth VP
1fa10ef036 resourceloader: Use named constants for groups
Makes the code easier to follow, in particular to identify functionality of the various groups.

Change-Id: Ib2dae5757e9325f9706ff2a9f760f311475fe615
2022-01-19 21:21:00 +00:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
Siddharth VP
38295f9226 Fix typos in comments (N-R)
Change-Id: I2d1bdb7531ff5126114a391550c2615ea6e244b3
2022-01-09 23:14:44 +05:30
Timo Tijhof
15604de346 resourceloader: Implement debug=2 request splitting
== What ==

Change debug mode 2 to behave more like production mode:

* use module scope (no longer global scope).
* load modules concurrently (no longer each module serially).
* bundle files (no longer each file separately).

What remains different in debug=2 from production mode:

* disable minification.
* disable batching (one module per request).

== How ==

* Limit the old logic (getScriptURLsForDebug) to just legacy debug.
* Set maxQueryLength=0 for non-legacy debug, to ensure each module
  still gets its own dedicated request for easy debugging, and to
  get concurrency to make more optimal use of server and browser
  capacity.

This does not effect package file modules much, as those already
worked in this way. The only difference for package file modules
is that they now load faster (see below) by eliminating the
in-between request.

== Alternative approach ==

An alternative approach, which I considered, is to modify
Module::buildContent(), around where we currently call
getScriptURLsForDebug for DEBUG_LEGACY, and add a conditional branch
for DEBUG_MAIN which would always return an array with a single URL,
to `load.php?modules=:name`. Much like getScriptURLsForDebug does by
default, but without the legacy-specific overrides to that method from
e.g. FileModule.

I decided against this because the mw.loader client handles such
script-arrays in a global FIFO fashion, tailored for legacy debug mode
where it crucial to only serially queue>load>execute one script file
of one module at any given time (because the raw files can't have a
"mw.loader.implement" closure and thus execute immediately on arrival,
with no other coordination for file order and module dependency order).
This would make debug=2 slow, possibly slower than debug=1 since in
debug=1 at least we consolidate most PHP roundtrips in a single batch,
and most other scripts can be served quickly as static file by Apache.

By letting the client act like it does for production mode, and
proactively split its requests, we get a few benefits compared to
this alternative approach:

* Fewer requests and shorter request dependency chain.
  There is no in-between request for the "page module batch" that fans
  out to individual module reqs. Instead, the client makes those reqs
  directly.

* All module requests are discovered and queued with the browser in
  one go, letting the server handle them as quickly as it can.
  In production, probably all in parallel. Locally, mediawiki-docker
  seems to handle about 6 at time (this depite having 10 php-fpm
  proccess). I suspect that maybe due to a poor interactions between
  HTTP1 connection reuse and keep-alive timeouts, or perhaps unneeded
  session locks with sqlite.

* The browser can spend time parsing/compiling other requests at the
  same time as one of them executes.

* No additional client-side logic.
* No increase in client payload.

Bug: T85805
Change-Id: I232310eb624e0204484ec9f3d715d5b6b8532fe8
2022-01-07 12:39:05 +01:00
Timo Tijhof
009f224ec1 resourceloader: Allow debug=2 on JavaScriptTest, and misc whitespace
* Use the int result of `ResourceLoader::inDebugMode()` directly in
  SpecialJavaScriptTest so that debug=2 is passed on to the next
  request, like it does on regular page views.

  This is likely temporary, because
  part of T85805 is to make debug=true default to debug=2, and
  part of T250045 is to hardcode debug=2 for JavaScriptTest.

* Add a few line breaks to improve HTML output readability in debug
  mode. This is a no-op for prod as they get minified away.

  Today I learned: PHP string heredoc and nowdoc syntax strip not
  only the shared common indentation (which I knew), it also strips
  the first and last newline. Hence, switching ClientHtml to use
  double quotes.

* Document the order in which lang/skin/debugScripts execute.

Bug: T85805
Bug: T250045
Change-Id: I2ad179401cee6cf6ba30c0b462f0d48a8529ba74
2022-01-06 19:03:27 +00:00
Timo Tijhof
64febce451 resourceloader: Improve wgResourceLoaderMaxage docs, minor clean up
The docs for wgResourceLoaderMaxage still described the "server"
and "client" subkeys, which have not existed since MW 1.35. This
was essentially a new configuration structure, add the `@since`
annotation to reflect this.

Clean up the ResourceLoader class and group together related class
members in a more logical way. Currently going for what I see various
other core components do:

* Constants: public, then private.
* Static: public, then private.
* Members: public (none), then ctor-assigned/injected stuff, then
  those with defaults that start as-is.

Make most protected members private, except for those intentionally
made protected for use in tests. This class is not meant to be
extended, is not marked as stable for that purpose, and Codesearch
shows no extensions that do so.

Remove unused internal '$testModuleNames' field. This was removed in
5f47d994bc and accidentally reintroduced (unused) with 440dfcf6d8,
presumably due to a bad rebase.

Bug: T32956
Change-Id: I041a320d05c9e5f30ac9cc9270ce82c4d19a957f
2022-01-06 18:52:45 +00:00
Kosta Harlan
891b51b258 Prefer is_dir/is_file to file_exists
Mirco-optimisation for performance, part II.

Change-Id: Ie8d5332a510bd18456ebc4a851f4d47f6a010dcb
2022-01-04 11:03:09 +01:00
Siddharth VP
72e245d73b resourceloader: Disable supportsURLLoading() for packaged wiki modules
Packaged modules don't support URL-loading. It leads to two mw.loader.implement() calls with the same module name, giving an exception.

A similar override of supportsURLLoading() is already being done in ResourceLoaderFileModule.

Bug: T198758
Change-Id: Id4589a597ccfc4266b3e63d10f75b146aa7a287a
2021-12-21 21:57:50 +05:30
Siddharth VP
c71d4366f5 resourceloader: Add support for JSON pages in ResourceLoaderWikiModule
This will be used in the Gadgets extension.

Bug: T198758
Change-Id: Ib4556d09c4d393269e32771aab00f59a5f630e1b
2021-12-16 16:07:04 +00:00
Roan Kattouw
46e13380d3 resourceloader: Increment CACHE_VERSION for wikimedia/minify 2.2.6
We upgraded to version 2.2.6 of wikimedia/minify a few weeks ago, but
broken minifications from that version have lingered in the minification
cache. Bump the cache version to fix this.

Bug: T296058
Follows-Up: I6bceffda0c7ff4f4d92e15e85ae8719426ff4c3f
Change-Id: I7560c8ae54f3132cb33e8823dbfb467fef0cfc31
2021-12-16 15:37:02 +00:00
jenkins-bot
7032a10719 Merge "Remove some more comments that literally repeat the code" 2021-12-13 20:13:26 +00:00
jenkins-bot
6b6254a646 Merge "Add content-media print styles" 2021-12-09 18:03:43 +00:00
Thiemo Kreuz
b4c63c64ae Remove some more comments that literally repeat the code
Nothing to learn from these.

You can find a longer explanation in the comments in I93751e6.

Change-Id: I195aae70fc282b58be5b18160783f27d38605d15
2021-12-09 19:01:36 +01:00
Arlo Breault
28062181f9 Add content-media print styles
* Magnify clip isn't present in print styling
* Print and screen thumbborder are different
* Print thumbinner and thumbimage borders are absent

Bug: T287965
Change-Id: Ie1dac57412da7da3e73eb39ef20a6077923860d6
2021-12-09 11:42:05 -05:00
Roan Kattouw
5bd107c968 Upgrade Vue to the migration build of Vue 3
* Upgrade Vue to @vue/compat version 3.2.23
* Migrate Vue.createMwApp to Vue 3 API
* Add backwards-compatible wrapper emulating Vue 2 behavior for
  new Vue( { el: '#foo', ... } ) and
  new Vue( ... ).$mount( '#foo' )
* Make @vue/composition-api an alias for vue, for b/c
* Convert resources/src/vue/ to ES6
* Ignore resource/src/vue/ for jsduck, since it doesn't support ES6
* VueComponentParser: Remove check for only one root node

Bug: T251974
Co-Authored-By: Lucas Werkmeister <lucas.werkmeister@wikimedia.de>
Depends-On: Ica0c0d0d6247383796d39199e50a9aff917f5b53
Change-Id: Ibd618765f962f57984994604c61b1aff9e6a778d
2021-12-07 19:31:43 +00:00
Arlo Breault
d8b625013c Rename content.thumbnails.less with -screen
Follow up to I076fddda07dd734f76277376ba6361bff68b7c36

Also, adds a comment about -legacy being frozen.

Change-Id: Iced54fb31c967975248bfc9908d904fa41824307
2021-11-30 15:02:04 -05:00
jenkins-bot
e252029b27 Merge "Pull out commonality between thumbnails and print styles" 2021-11-30 16:54:00 +00:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
jenkins-bot
8f06a29d56 Merge "Use getWithSetCallback() instead of get() + set()" 2021-11-19 00:18:27 +00:00
Daimona Eaytoy
e0d3b3e8fc Use getWithSetCallback() instead of get() + set()
This allows the backend to do whatever it can to ensure atomicity, and
is also easier to read, since the intent is obvious.

Change-Id: Ibbfecd92a2c6d9a5997ca37ea101e068bd1e8202
2021-11-18 18:58:13 +00:00
Timo Tijhof
6f061f4db2 resourceloader: Bundle user.defaults as part of mediawiki.base
== Background ==

The `user.options` module is private, and thus has to be embedded in
the page HTML. This data is quite large. For example, on enwiki the
finalized mw.user.options object is about 3KB serialized/compressed
(7KB uncompressed).

The `user.defaults` module is an implementation detail of
`user.options`, and was created to accomplish mainly two things:

* Save significant data transfers by allowing it to be cached
  client-side without being part of the article.
* Ensure consistency between articles and allow faster deployment of
  changes, by not being part of the cacheable article HTML.

All our pageviews already load `user.defaults`, as a dependency of
the popular `mediawiki.api` and `mediawiki.user` modules. These are
used by `mediawiki.page.ready` (queued on all pages), and on Wikipedia
these are also loaded on all pages by ULS, VisualEditor, EventLogging,
and more.

As such, in practice, bundling "user.defaults" with "mediawiki.base"
will not cause the data to be loaded more often than before.

== What ==

* Add virtual "user.json" package file with the same data that
  was previously exported by ResourceLoaderUserDefaultsModule,
  and pass it to mw.user.options.set() from base module's entry point.

  An alternative way would be to use a "user.js" file, which would
  return a generated "mw.user.options.set()" expression. I went
  for exporting it as JSON for improved maintainability (reducing
  the amount of JS code written in PHP), and because it performs
  slightly better. The JS file would implicitly come with a file
  closure (tiny bit more bytes), and would then be lazy executed
  (tiny bit more time).

  The chosen approach allows the browser to compile the JSON
  off-the-main-thread ahead of time while the module response downloads.
  Then when the module executes, we can reference the JSON object
  and use it directly.

* Update internal dependency from `user.options`.

* Remove `user.defaults` module without deprecation. It is an internal
  module with no direct use anywhere in Git (Codeseach), and no use
  anywhere on-wiki (Global Search).

Change-Id: Id3916f94f75078808951863dea2b3a9c71b0e30c
2021-11-18 04:41:09 +00:00
jenkins-bot
41530b637a Merge "resourceloader: Remove internal debug check in makeLoaderImplementScript()" 2021-11-17 01:18:29 +00:00
jenkins-bot
33d28f4499 Merge "resourceloader: Restore minification of embedded 'user.options'" 2021-11-17 01:18:23 +00:00
Timo Tijhof
eb9359afa2 resourceloader: Only load LanguageFallback data if module has languageScripts
Change-Id: I955283c9df1601ab4fa69b472268194210f30bb4
2021-11-11 00:40:20 +00:00
Arlo Breault
7eb9972ba0 Pull out commonality between thumbnails and print styles
This helps highlight what's different between the two.

Change-Id: I076fddda07dd734f76277376ba6361bff68b7c36
2021-11-09 21:11:31 -05:00
jenkins-bot
4f15011bb1 Merge "resourceloader: Use UserIdentity in some cases" 2021-11-09 21:36:08 +00:00
jenkins-bot
73170eddad Merge "resourceloader: Fix null type docs for FileModule::getPackageFiles" 2021-11-09 21:36:02 +00:00