Commit graph

1335 commits

Author SHA1 Message Date
jenkins-bot
c564ae6722 Merge "resourceloader: Export ResourceModuleSkinStyles as extension attribute" 2020-03-30 23:24:31 +00:00
Timo Tijhof
69e9b31fc5 resourceloader: Export ResourceModuleSkinStyles as extension attribute
Instead of exporting this as a global variable, export it as an extension
attribute.

The $wgResourceModuleSkinStyles configuration variable will continue
to be supported for its main purpose of setting skin styles. However
it may no longer be used to read these settings. The canonical copy
of this is now restricted to the ResourceLoader class and not (yet)
made publicly available (I found no use cases for it).

This opens the door to making it lazy-loaded attribute, which would help
reduce the size of the "main" APCu cache key for ExtensionRegistry.

This is not possible with global variables as those must be exported
unconditionally from Setup.php.

Bug: T32956
Bug: T247265
Change-Id: I4ecf558d9c630c91959786d2573c34e619223cef
2020-03-30 16:08:00 -07:00
Holger Knust
50b62c49bf resourceloader: Add more $wgResourceModules documentation
Added documentation markup for $wgResourceModules in DefaultSettings.php
and added a reference to it in ResourceLoaderFileModule.php.

Bug:  T232566
Change-Id: Ib4c0bd55cc2a06f48ef36ceb069906f1d3a22826
2020-03-26 21:41:09 +00:00
Petr Pchelko
1e4beb3107 Hard deprecate Revision::newKnownCurrent
Bug: T246284
Change-Id: Iba93fdeb0a88e6fa4068f03367b23a1f670257c6
2020-03-18 11:52:44 -07:00
Timo Tijhof
e1c88d2fcb resourceloader: Merge 'user.tokens' module into 'user.options'
For back-compat, keep 'user.tokens' as deprecated alias to 'user.options'
for one release cycle (to be removed in MW 1.36).

== user.options ==

As before, 'user.options' arrives immediately on every page view,
embedded in the HTML. It has an async dependency on 'user.defaults',
which is not downloaded until there is a known demand on
'user.options'. Once that arrives, the implementation closure
of 'user.options' will execute, and the module becomes 'ready'.

== user.options "empty" ==

Before this change, UserOptionsModule used isKnownEmpty to consider the
module "empty" for logged-out users (as well as for logged-in users that
haven't yet set any preferences).

This was a mistake. It is invalid in ResourceLoader to mark a module as
"empty" if that module has dependencies (see also T191596 and c3f200849).

This broke the state machine. The impact was minimal given that it is unlikely
for features to read keys from mw.user.options for logged-out users, which
if attempted would have simply returned null for all keys.

== New HTML ==

The user.options module is always embedded (never empty), and always
has a dependency on user.defaults.

== Cached HTML ==

The cached HTML for anons sets user.options's state to ready without
waiting for any dependency. Per the above, this was already causing
subtle bugs with mw.user.options.get() likely returning null for anons,
which was fairly innocent. For tokens a bottom value of null would be
problematic as the default for tokens must be "+\" instead. To make
sure that is available for cached page views, set this directly
in mediawiki.base.js. The cached HTML does contain an implement call for
'user.tokens' that contains the same defaults, but new code will not
be asking for or waiting for user.tokens, so that is unused.

Bug: T235457
Change-Id: I51e01d6fa604578cd2906337bde5a4760633c027
2020-03-17 20:51:15 -07:00
jdlrobson
ecac8e1f96 Move contents of mediawiki.legacy.commonPrint into ResourceLoaderSkinModule
Use the existing `legacy` feature. It's assumed that this module was always
used with `mediawiki.legacy.shared` and minimizes disruptions given the
migration steps are identical to the approach taken in `mediawiki.legacy.shared`

The existing release notes are updated to reflect this.

Bug: T242177
Change-Id: I785321d86a5f26808eb83847a3dbbbe62c62698c
2020-03-14 00:16:16 +00:00
jenkins-bot
13e8e9d97f Merge ""Enable 'site' and 'site.styles' modules on mobile target (take 2)" 2020-03-13 20:04:33 +00:00
jenkins-bot
1e98ecf1c3 Merge "resourceloader: Support single-file component .vue files" 2020-03-12 22:16:10 +00:00
Roan Kattouw
ca46126e98 resourceloader: Support single-file component .vue files
Allows .vue files to be used in package modules as if they were .js
files: they can be added to the 'packageFiles' array in module
definitions, and require()d from JS files.

In the load.php output, each .vue file is transformed to a function that
contains the JS from the <script> tag, then a line that sets
module.exports.template to the contents of the <template> tag (encoded
as a string). The contents of the <style> tag are added to the module's
styles.

Internally, the type of a .vue file is inferred as 'script-vue', and the
file is parsed with VueComponentParser, which extracts the three parts.
After the transformation, the file's type is set to 'script+style', and
files of this type contribute to both getScript() and getStyles().

This change also adds caching to getPackageFiles(), because it now needs
to be called twice (in getScript() and getStyles()).

Change-Id: Ic0a5c771901450a518eb7d24456053956507e1ed
2020-03-12 14:32:41 -07:00
jdlrobson
73c20062e0 mediawiki.legacy.shared is merged into existing skin modules and removed
Skins that are using ResourceLoaderSkinModule will need to update their
features to include `legacy`

Note that Ic7af947cfd5a5df4218f006232ede4ee7ed36c62 for Vector
and I6471bc169f3c2a1f51e17b8ee26ac245b0374c18 for Monobook should
be merged in the same release as this patch to ensure these styles
do not disappear from those skins. Minerva or Timeless will not be impacted.

Changes for other skins including Modern and CologneBlue to follow
where needed.

Bug: T242177
Change-Id: Icb910a563273bde92a09b1bb92857d5b6e348baa
2020-03-12 13:17:24 -07:00
James D. Forrester
43939abbf7 resourceloader: Error in FileModule if provided path is a directory
Pre-PHP74, these would silently return false; now they throw an error.

Bug: T233012
Change-Id: I9bcb98fa1189c3d59a67a054c5b807d1495d82bb
2020-03-12 01:32:18 +00:00
James D. Forrester
8595db5546 resourceloader: Factor out file loading in ResourceLoaderFileModule
This file had six different almost-identical calls to the system
call file_get_contents(), which makes it hard to fix all nine of
them neatly.

Change-Id: I607f3cd3dbfa0f47f8d9766a27e581fdc127a0cf
2020-03-12 01:31:32 +00:00
Jdlrobson
13b72d0f7e "Enable 'site' and 'site.styles' modules on mobile target (take 2)
Will be used by MobileFrontend in I26644f49dff5.

Bug: T237050
Bug: T127268
Change-Id: I5166797d9b02346eda09ea86ad4056e466a891d3
2020-03-11 21:54:52 +00:00
Thiemo Kreuz
6b2c9deef5 Replace all new stdClass() with identical (object)[]
This should be the exact same. Its more a style change than anything.
So why do it then?
* I believe this is much less confusing than code mentioning a weird
"standard class". Barely anybody knows what this is, and what the
difference between "object" and "stdClass" is.
* The code is shorter.
* It's even faster. In my micro benchmark it's twice as fast.

Change-Id: I7ee0e8ae6d9264a89b6cd1dd861f0466ae620ccc
2020-03-04 21:18:30 +00:00
Timo Tijhof
95ec909e52 WikiMap: Add WikiMap::getCurrentWikiId() to make common use case easier
Change-Id: Ie225ebfc37c824e3167742137bbbc9f64aca5f5e
2020-03-03 16:04:21 +00:00
jenkins-bot
05b1712cbe Merge "resourceloader: Add more granular phan type information in various classes" 2020-02-27 21:21:26 +00:00
jenkins-bot
53c229bc2f Merge "resourceloader: Convert mediawiki.Uri to package files" 2020-02-26 01:32:04 +00:00
Timo Tijhof
f575721a06 Update all use of $wgVersion to MW_VERSION
Follows-up I04628de4152dd5.

Bug: T212738
Change-Id: I718474ec0d9fd29ac2c05477f0f2493615d8aff5
2020-02-25 02:16:12 +00:00
Timo Tijhof
007a0620db resourceloader: Convert mediawiki.Uri to package files
This replaces the client-side compiler for 'mediawiki.template.regexp',
with a simple PHP callback.

The regexp temple compiler is not used anywhere after this and will be
removed in a follow-up commit.

Bug: T233676
Change-Id: I1baa1465d88293d03975cadf2efdd57283427722
2020-02-24 17:45:31 +00:00
Timo Tijhof
a3ce1f9da7 resourceloader: Add more granular phan type information in various classes
* Where possible and easy to figure out, change `array` to something like
  `array<K,V>` or `V[]` for improved static analysis to catch/prevent
  regressions in CI.

* Minor doc improvements:
  - consistently use the imperative mood for method briefs,
  - consistently use @internal instead of @private,
  - explain in @throws why they happen to inform when they should be caught
    (and remove if they are not meant to be caught/handled by any caller).

* Simplify addSources() implementation as a simple loop instead recursing
  (not worth the complexity, only called once or twice at runtime).

* Use more granular exceptions to distinguish between errors that indicate
  a mistake on the caller (logic/invalid arguments error), and runtime
  errors (which are more circumstantial).

* Update register() unit test for bad 'moduleInfo' type to use
  a nested value, given that the second-parameter level type is
  now verified by the signature already.

Change-Id: Id98ba1f28cb7f1c72f0a3e82f4151bcbd0f3db77
2020-02-21 23:54:33 +00:00
James D. Forrester
56fd5aaaeb ResourceLoaderSkinModule: Don't hard-deprecate wgLogoHD just now
Bug: T245778
Bug: T245182
Change-Id: I5f6773516134651ee88079c3f5a7c12d9f3d4f31
2020-02-21 13:18:22 +00:00
Aaron Schulz
b6473c3efd resourceloader: fix SqlDependencyModuleStore::setMulti() to use upsert()
Follow-up to 5282a02961

Bug: T245570
Change-Id: I16c45d389f10b237c649aff34e3a2eaf40464757
2020-02-19 18:30:39 +00:00
jenkins-bot
d9d2a58b03 Merge "registration: Cache lazy-loaded attributes and make easier to use" 2020-02-18 14:00:43 +00:00
Kunal Mehta
a0ce12999a registration: Cache lazy-loaded attributes and make easier to use
This allows us to move things that are not used on every request (e.g.
'TrackingCategories') into separate cache entries to slim down the main
one.

At the same time, fold getLazyLoadedAttribute() into the standard and
already established getAttribute(), so that client code doesn't need to
be aware of whether something is lazy-loaded or not, it'll just work.

Everything is still cached using the load queue as part of the cache key
for instant invalidation, so if an extension.json file changes, the
lazy-loaded attribute cache will invalidate too.

The cache is populated whenever loadFromQueue() happens, but if it
happens to fall out of the cache, then getLazyLoadedAttribute() will
iterate over all the loaded extension/skin.json files to read that
value. Since we end up reading everything, we populate all of the
caches again.

The caching logic was split into two more private functions
(::getCache() and ::makeCacheKey()) for easier internal reuse.

Bug: T220994
Change-Id: I290926bbedfc964195d1f576a9e06349f9e5d5ea
2020-02-17 22:18:10 -08:00
James D. Forrester
9fb25f7d2e Follow-up 37a69a2f: ResourceLoaderSkinModule: Fix wfDeprecated() syntax
Change-Id: Iadeec9520867bc1b6ace885fd4d93b856f6373d4
2020-02-14 13:21:35 -08:00
Aaron Schulz
5282a02961 resourceloader: support tracking indirect module dependency paths via BagOStuff
This can be enabled via a configuration flag. Otherwise, SqlModuleDependencyStore
will be used in order to keep using the module_deps table.

Create a dependency store class, wrapping BagOStuff, that stores known module
dependencies. Inject it into ResourceLoader and inject the path lists into
ResourceLoaderModule directly and via callback.

Bug: T113916
Change-Id: I6da55e78d5554e30e5df6b4bc45d84817f5bea15
2020-02-13 17:26:36 +00:00
Derick A
35357ce3fe resourceloader: Dependency inject WANObjectCache into MessageBlobStore
Change-Id: I0f4c4e0e753574cf060331c944f44318eaca1fec
2020-02-12 22:16:42 +00:00
jenkins-bot
879488996e Merge "resourceloader: Separate style processing from style file loading" 2020-02-12 21:09:32 +00:00
jenkins-bot
7ca3d356bb Merge "resourceloader: Fix typographical errors in RL files" 2020-02-12 20:56:07 +00:00
Roan Kattouw
ca7fa28615 resourceloader: Separate style processing from style file loading
ResourceLoaderFileModule::readStyleFile() both reads a style file from
disk and processes it through LESS, CSSJanus and CSSMin. Factor out the
processing part into ResourceLoaderFileModule::processStyle(), which
takes a string of unprocessed CSS/LESS rather than a file. This is
needed for future support for styles that don't come (directly) from a
file, but are generated through packageFiles.

Other changes:
- Use a hash of the source instead of the file name in the cache keys
  for the LESS compilation output
- Also prefix the cache key with 'resourceloader' while we're changing
  it anyway
- LESS compilation no longer adds the source file itself as a dependency
- Don't pass down $flip, just use $this>getFlip()

Change-Id: I86e880d06af724f0fbae93e042c85e0395771912
2020-02-12 20:23:24 +00:00
Derick A
c9df2ea4d6 resourceloader: Avoid use of deprecatd Language::isValidBuiltInCode()
Change-Id: I33b929b93017e36387d29cddcc494b997f646b67
2020-02-10 15:15:26 +01:00
Derick A
873f833961 resourceloader: Fix typographical errors in RL files
Change-Id: I8486dcb70e143766a10e6e50bb99d491e6be322d
2020-02-09 21:53:26 +01:00
Derick A
fb5650684a resourceloader: Optimization - avoid repeated $this->getModule() calls
`$this->getModule()` returns a RL object or a null. The check above already
makes sure that $module is not null so we can just set file dependencies
from the RL object returned.

In addition, this is an optimization as we reduce repeated calls to
`$this->getModule()`. Similar logic already exist in the same file from
L#116 - L#118.

Change-Id: If50c28ff5cd8eb435c9fa4f277e2d1038b52ca74
2020-02-09 21:18:44 +01:00
jenkins-bot
30b2f833c2 Merge "resourceloader: Move site-level mw.config from startup to mediawiki.base" 2020-02-07 19:59:43 +00:00
Brad Jorsch
036cde7a04 resourceloader: Move site-level mw.config from startup to mediawiki.base
This data isn't needed for startup, and we can shave off a few K from
startup by moving it to mediawiki.base instead.

It was requested that this be done as a "package file", which
necessitated some other minor structural changes to mediawiki.base as
well.

Bug: T235350
Change-Id: I525a5203533089d5a542f83a847be58a10cb6319
2020-02-07 19:44:57 +00:00
jenkins-bot
af29679594 Merge "ResourceLoaderSkinModule: Restore previous behavior in getLogoData()" 2020-02-07 18:42:32 +00:00
Bartosz Dziewoński
68d10ec12d ResourceLoaderSkinModule: Restore previous behavior in getLogoData()
getAvailableLogos() can now also return multiple items if a 'wordmark'
logo is defined, but this method only cares about the DPI variants
('1x'/'1.5x'/'2x') and should return a string if there's only '1x'.

Bug: T244405
Change-Id: I69ddb1f9f97d06253b661caf112b48343cd2453f
2020-02-07 10:10:26 +08:00
jdlrobson
37a69a2f86 Restore wordmark to Vector printed media
A mistake was made when upstreaming this code from Vector. The
logo must apply in @print media type as well as @screen - not just
@screen - without this change space was being reserved but no logo
rendered.

Follow up to 7931d76b96

Bug: T232140
Change-Id: I0fa079becd722993fe83f15b4537ffb3831a87d8
2020-02-06 04:01:58 +00:00
jdlrobson
7931d76b96 Remove the need for Vector's ResourceLoaderLessModule and wgVectorPrintLogo
This allows us to remove code in Vector by using the newly added
wgLogos (see I569e0d800e147eabc7852567acd140108613f074)

The ResourceLoaderSkinModule with the logo feature enabled will surface
the horizontal wordmark at the top of pages for printed media.

Change-Id: I00899c16c0325f36b671baf17e88c2b5187b3526
Bug: T242177
Bug: T232140
2020-02-05 01:34:33 +00:00
jdlrobson
8cd2e13363 Deprecate access of logos directly from config, introduce wgLogos
Add getAvailableLogos static method and wgLogos config variable

Longterm we'll phase out wgLogo and wgLogoHD for this more extendable
config.

wgLogoHD is marked as deprecated. wgLogo continues to function as before
when wgLogos doesn't exist to cause minimum disruption.

From now on all logos should be accessed via getAvailableLogos. Patches
in Minerva and Vector follow. See I00899c16c0325f36b671baf17e88c2b5187b3526,
I569e0d800e147eabc7852567acd140108613f074 and
I013bd0904fe8c55efa49d14e84cf06ec1412896f.

Bug: T232140
Change-Id: I66a971631c623cc94b58eb0e5e5bad804789bf1c
2020-02-04 01:56:20 +00:00
jenkins-bot
8db5a0d27c Merge "resourceloader: Allow packageFiles callbacks to return a file" 2020-01-20 22:07:51 +00:00
jdlrobson
07910483d0 Add 'legacy' and 'i18n' features to ResourceLoaderSkinModule
The existing mediawiki.legacy styles module contains many legacy styles
as well as important i18n rules.

Begin migration of CSS rules from mediawiki.legacy to the
ResourceLoaderSkinModule, which can be tweaked by skins such as Minerva.

The mediawiki.legacy modules is updated to use this new 'legacy' feature
for backwards compatibility.

As agreed in the Frontend Standards Group, it is important we identify
the important rules and migrate them to this new module.

Bug: T169910
Bug: T217616
Change-Id: I1c1e2b912a41d29565e45e9e536c68ac46deb0e1
2020-01-14 17:33:44 +00:00
jenkins-bot
502c51a1b4 Merge "Revert "Enable 'site' and 'site.styles' modules on mobile target"" 2020-01-13 23:53:26 +00:00
Jdlrobson
7dc898a93b Revert "Enable 'site' and 'site.styles' modules on mobile target"
This reverts commit 34db191681. The dependencies are the wrong way round and I26644f49dff57249ebd7eb20818add8a7110de6b
should have been merged first. Right now mobile.site AND site are loading on mobile leading to a huge spike in CSS and JS (https://grafana.wikimedia.org/d/000000205/mobile-2g?orgId=1&fullscreen&panelId=69)

Change-Id: I034429932966ab844b7dae94a97c2bcc24952cb6
2020-01-13 23:12:27 +00:00
jenkins-bot
09884cd74b Merge "resourceloader: Remove JSParser cache in Module::validateScriptFile" 2020-01-11 01:45:53 +00:00
jdlrobson
34db191681 Enable 'site' and 'site.styles' modules on mobile target
Will be used by MobileFrontend in I26644f49dff5.

Bug: T237050
Bug: T127268
Depends-On: I329415b787136fcf9422a9deebfcd34f83b40f12
Change-Id: I7fd9abb672d80df273ffa067fa9d5c04230687ca
2020-01-11 00:18:38 +00:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Timo Tijhof
b94d9d376b resourceloader: Remove JSParser cache in Module::validateScriptFile
This is only rarely called and when it is, it is generally only
once or maybe a handful of times in the same request (e.g. number
of pages within a gadget).

The constructor performs no expensive logic, either.

Originally added via 0f201b19 (r91608), though unsure why.

Change-Id: I568028addaa2f60cb956b14ea7cc44ca46aaf7f5
2020-01-10 21:16:45 +00:00
James D. Forrester
41f8acfd52 Coding style: Auto-fix MediaWiki.Commenting.DocComment.*
Change-Id: Iea5a07e10712723970a15008eb367e0af226fcc3
2020-01-10 12:28:12 -08:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00