Commit graph

242 commits

Author SHA1 Message Date
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
jenkins-bot
4a8ee34f09 Merge "Use str_starts_with/str_ends_with" 2022-05-03 02:37:12 +00:00
Aryeh Gregor
7b4b0135b9 Use str_starts_with/str_ends_with
All the other ways of doing it were ridiculous and much harder to read,
and usually required repeating the needle expression (to get its
length). I found these occurrences by grepping for various expressions,
but I undoubtedly missed some.

I didn't try replacing the many instances of strpos(...) === 0 with
str_starts_with(...), because I think they're readable enough as-is
(although less efficient). Likewise I didn't try porting strpos(...) !==
false to str_contains(...). For case-insensitive comparisons, Tim
Starling requested that we stick with substr_compare() because it's more
efficient than calling strtolower().

On PHP < 8 these functions will be included with a polyfill via
vendor/autoload.php. This is included at the beginning of
includes/AutoLoader.php, so if our autoloader has been included the
polyfill will be available. This means it should be safe to call these
functions from any code that would not be usable without our autoloader.

Three uses that Tim Starling identified as being performance-sensitive
have been split out to a separate commit for porting after the switch to
PHP 8.

Change-Id: I113a8d052b6845852c15969a2f0e6fbbe3e9f8d9
2022-05-02 10:59:58 +03:00
daniel
b56dde0d83 Remove access to config globals from more classes
Bug: T294739
Depends-On: I84056024b0d3a9dcddb1ab4dc8596118bb3fe8ea
Change-Id: If005958c76bbfabba74def4215c48fe94f297797
2022-04-28 18:36:28 +03:00
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
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
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
Siddharth VP
38295f9226 Fix typos in comments (N-R)
Change-Id: I2d1bdb7531ff5126114a391550c2615ea6e244b3
2022-01-09 23:14:44 +05:30
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
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
Timo Tijhof
eb9359afa2 resourceloader: Only load LanguageFallback data if module has languageScripts
Change-Id: I955283c9df1601ab4fa69b472268194210f30bb4
2021-11-11 00:40:20 +00:00
jenkins-bot
73170eddad Merge "resourceloader: Fix null type docs for FileModule::getPackageFiles" 2021-11-09 21:36:02 +00:00
Umherirrender
396444940c resourceloader: Fix null type docs for FileModule::getPackageFiles
The null check for the class property packageFiles needs change to
check the return value of the function instead, because Phan would
report an issue that a null value is used in the foreach.

Phan does not understand the relation between the return value and the
class property.
When using a local variable then Phan can check
that the value is never null when used.

Change-Id: I48ac8a8fe55ae7b4e13bc94d2f2d2ede01fbc68b
2021-11-09 21:04:27 +00:00
Umherirrender
d2baeb3083 resourceloader: Fix nullable documentation for property and return types
Change-Id: Ie8566c0e441d77ecd9cdf1220996deebdcd77fa7
2021-11-02 15:29:42 +01:00
Ammarpad
1cf4eab3ab ApiParse: Support hidden skins
Since $wgSkipSkins is meant to only 'remove skin from preferences',
it should not affect parsing with them.

So these skins need to be allowed here.

To achive this, this patch adds getInstalledSkins() method to SkinFactory
to provide the complete. The method supersedes getSkinNames() which does
the same thing but with ambiguous name.

Description of getAllowedSkins() has been corrected as it was slightly incorrect.

Bug: T237856
Change-Id: I0889b823d27f1a2830cc0205f5a21ed4de744e08
2021-09-20 09:29:24 +01:00
jenkins-bot
adfa9a9503 Merge "resourceloader: Fix debug mode for RL-to-RL cross-wiki module loads" 2021-09-16 01:40:13 +00:00
Umherirrender
a2e6ff11f3 resourceloader: Avoid same named variables in inner and outer foreach
Change-Id: I308ba9c607ba56b6d8ebf7d5f56d9e19d217d946
2021-09-04 00:28:20 +02:00
jenkins-bot
ceac7b68a6 Merge "resourceloader: Call getStyleFiles from FileModule::getFileHashes" 2021-09-02 18:10:06 +00:00
Arlo Breault
f07e73dd9a resourceloader: Call getStyleFiles from FileModule::getFileHashes
ResourceLoaderFileModule::getFileHashes had its own code to collect
style files that omitted the feature files that ResourceLoaderSkinModule
adds.  This deduplication should fix the issue where
wgParserEnableLegacyMediaDOM was adding an additional feature file but
didn't seem to be invalidating the cache.

Bug: T51097
Bug: T290273
Change-Id: I50cf73a79cb1ce2b3d80510e80948e3e6fc1791b
2021-09-02 17:51:10 +00:00
Fomafix
ff7f41f928 resourceloader: Append newline to JavaScript only if missing
In debug mode of a packageFiles module there is now only one newline
between the JavaScript code and the closing }.

This change reuses ResourceLoader::ensureNewline and make this to a
interal public static function.

Change-Id: I89519896e3dc56d966c4a63102904686bff6fac9
2021-08-28 12:25:11 +00:00
Timo Tijhof
b99458ceab resourceloader: Fix debug mode for RL-to-RL cross-wiki module loads
The native "foreign module source" feature, as used by the GlobalCssJs
extension, did not work correctly in debug mode as the urls returned
by the remote wiki were formatted as "/w/load.php...", which would
be interpreted by the browser relative to the host document, instead
of relative to the parent script.

For example:

1. Page view on en.wikipedia.org.

2. Script call to
   meta.wikimedia.org/w/load.php?debug=true&modules=ext.globalCssJs.user&user

   This URL is formatted by getScriptURLsForDebug on en.wikipedia.org,
   when building the article HTML. It knows the modules is on Meta, and
   formats it as such.

   So far so good.

3. meta.wikimedia.org responds with an array of urls for sub resources.
   That array contained URLs like "/w/load.php...only=scripts".

   These were formatted by getScriptURLsForDebug running on Meta,
   no longer with a reason to make it a Meta-Wiki URL as it isn't
   perceived as cross-wiki. It is indistinguishable from debugging
   a Meta-Wiki page view from its perspective.

This patch affects scenario 3 by always expanding it relative to the
current-request's wgServer. We still only do this in debug mode. There
is not yet a need to do this in non-debug mode, and if there was we'd
likely want to find a way to avoid it in the common case to keep
embedded URLs short.

The ResourceLoader::expandUrl() method is similar to the one in
Wikimedia\Minify\CSSMin.

Test Plan:

* view-source:http://mw.localhost:8080/w/load.php?debug=1&modules=site
  For Module base class.
  Before, the array entries were relative. After, they are full.
* view-source:http://mw.localhost:8080/w/load.php?debug=1&modules=jquery
  For FileModule.
  Before, the array entries were relative. After, they are full.
* view-source:http://mw.localhost:8080/wiki/Main_Page?debug=true
  Unchanged.
* view-source:http://mw.localhost:8080/wiki/Main_Page
  Unchanged.

Bug: T255367
Change-Id: I83919744b2677c7fb52b84089ecc60b89957d32a
2021-08-25 20:05:38 +00:00
Timo Tijhof
1367e356e7 resourceloader: Remove isFileModule() overhead from web requests
About 1.5% of load.php wall-time is spent in isFileModule() calls
during the ServiceWiring/getResourceLoader/register call early on.

Reduce the overhead of this cost by moving that logic to the Module
class.

There are two costs that we save this way:

1. The inherent cost of applying the skinStyles.

   This is now limited to only the modules that are constructed in a
   given web request. Thus, apart from the startup response (which
   constructs all modules), for regular load.php requests and all
   index.php page views, the vast majority of modules will never need
   to be constructed, and thus won't pay this cost.

2. The overhead of predicting (and class-loading) for whether a module
   is (or will become) a FileModule object.

   This is what isFileModule() does and is the main reason I wrote
   this patch. It involves class loading, and checks and conditions that
   run 1000+ times at WMF. This is eliminated now because we no longer
   have to calculate this decision. Instead, the logic applies when
   it needs to (due to FileModule implementing it), and doesn't
   when it doesn't!

Change-Id: Ia2db14f930800c96e767b94ef62fb00e9d52725b
2021-08-19 01:18:32 +00:00
DannyS712
4f9970f30b Fix a bunch of random typos
* yeild -> yield
* paramter -> parameter
* seperator -> separator
* neccesary -> necessary
* inital -> initial
* intial -> initial
* repsonse -> response
* retreived -> retrieved

Bug: T201491
Change-Id: I461941b027590997448f3bdd8a137a48bb338beb
2021-06-29 11:32:04 +00:00
jdlrobson
e5f09fd1bb Installer: Do not use mediawiki.skinning.interface module
The `mediawiki.skinning.interface` module includes the `toc` feature
which is enabled by default,
which requires a working localization environment which requires
DBLoadBalancer which is disabled at this entry point.

Instead use ResourceLoaderSkinModule directly with an opt-in
policy where toc feature is not disbled.

This means the definition in Resources.php is no longer
necessary so it is marked for deprecation. The installer
now works.

A unit test is added to make sure the installer stylesheet
doesn't break again.

Bug: T270027
Change-Id: I851fcd0e50e3a70158d5bfa1fdcae3cd278694d6
2021-04-15 11:11:32 -07:00
anjali041
480c126305 Fix typo in code 'defintion'
Changed the typo 'defintion' to 'definition'

Bug: T201491
Change-Id: I6e866283b5fd8a2b2f237a770942ac03f735c138
2021-04-10 14:22:52 +05:30
jenkins-bot
d48d5292a6 Merge "resourceloader: Allow modules to mark themselves as ES6-only" 2021-03-07 02:56:03 +00:00
Roan Kattouw
b267f7aa90 resourceloader: Allow modules to mark themselves as ES6-only
Modules that set "es6": true in their module definition will error when
a non-ES6 client tries to load them.

To detect ES6 support, this looks for native Promise support,
RegExp.prototype.flags, and non-BMP characters in variable names. All
browsers that lack full ES6 support fail at least one of those checks.

To flag modules as requiring ES6, this adds a ! to the end of their
version string. This takes up much less space than adding another
register() parameter (which would have to be at the end). It's hacky,
but we expect this feature to be relatively temporary, until we require
ES6 for running any JS at all (probably in about a year).

For distinguishing different types of errors thrown from
sortDependencies(), use e.name. We can't subclass Error properly because
that requires ES6.

Bug: T272104
Change-Id: I45670c910ff12eb422ae54c9fcf372e45c7b2bf1
2021-03-04 14:53:36 -05:00
Timo Tijhof
245bdafd9e resourceloader: Add wikimedia/minify package and remove local copies
- JavaScriptMinifier: The public interface for this internal class is
  ResourceLoader::filter which, except for one caller (minify.php)
  is indeed consistently used already, no other callers need replacing.

- CSSMin: Idem for minification, however, this class has some other
  method as well, which have a number of internal users, but none
  outside core. These have all been replaced in this commit.

- Remove pear/net_url2 as own dependency as this was only used by CSSMin
  and recently added there. This is now a dependency of wikimedia/minify
  instead. This was not part of the public API and no longer mentioned
  here in composer.json or RELEASE-NOTES. (It remains pinned in
  mediawiki-vendor, however.)

Bug: T273247
Depends-On: Iadff8c2112d5e53bd994ab4882006e8c644a2379
Depends-On: Id3c6dcc0b952a9efe34b3a9ed88b716101a51f87
Depends-On: I589be910f57289fd908b22db87241b0e52da60d4
Change-Id: I8d71fc64aeecdb31db218b02e361ae9bb0d19b48
2021-02-24 21:03:02 +00:00
Tim Starling
e2a91921c5 resourceloader: Fix FileModule resource URLs for document root wikis
Per the comment in extractBasePaths(), remoteBasePath is typically '/'
when MediaWiki is installed in the document root. CSSMin knows what to
do with that, but getRemotePath() was getting it wrong, generating an
invalid protocol-relative URL.

So, add a simple hack for this case.

Change-Id: I16abf482e3a1a4a548c571de0e81cb3c1bdf55e1
2021-02-24 05:27:55 +00:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
jenkins-bot
1976283835 Merge "Update a lot of unspecific "array" types in PHPDocs" 2020-11-13 21:48:24 +00:00
Brad Jorsch
cd54c03e86 resourceloader: Remove wfExpandUrl() coupling from CSSMin
There are three cases in CSSMin::remap where performs path
resolution.

1. Absolute local path URLs to full URL.
   Example: url(/static/foo.png), url(/w/index.php?…), etc.

   These previously used wfExpandUrl(), which got the server
   name and protocol directly from $wgServer.

   We will now use the $remote parameter to get this information
   instead, which is generally set to something like
   https://wiki/w/resources/foo, and thus naturally contains
   the server name and protocol.

   The resolution is powered by the Net_URL2 library, allowing
   this to work outside Mediawiki as well.

   Some tests needed to change because they were calling CSSMin::remap
   with an incomplete $remote dummy values like "/" or "/w, because
   the test author (past me) was trying to be clever by not supplying
   it, knowing MW would ignore it. Now that it is consistently used,
   like normal calls from ResourceLoader would, the expected values
   will always be based on http://localhost/w, instead of sometimes
   the competing $wgServer value of `https://expand.example`.

2. Relative local path to full URL
   Example: url(foo.png), url(../foo.png), url(bar/foo.png)

   These were already using $remote. The only change is that
   they now use Net_URL2 library instead of blind string
   concatenation. One of the benefits of this is that we will
   no longer need to call wfRemoveDotSegments() to get rid
   of things like double slashes or redundant "../" sequences.
   Previously, thing like "foo//bar" or "foo/../bar" were cleaned
   up only due to wfRemoveDotSegments(). This is now naturally
   handled by Net_URL2.

3. Remote URLs
   Example: url(http://example.org/bar.png), url(//example.org/bar.png)

   This is generally not used in source code, but gadgets may use this,
   e.g. for upload.wikimedia.org or cross-wiki imports.

Other changes:

* One test case used spaces within the URL string in CSS, which the
  net_url2 library represents with percent-encoding instead.
  Same thing either way.

Bug: T88914
Change-Id: Ibef70cc934c0ee8260a244c51bca9fb88c1c0d88
2020-11-05 19:59:02 +00:00
Thiemo Kreuz
b0130ca649 Update a lot of unspecific "array" types in PHPDocs
This includes fixing some mistakes, as well as removing
redundant text that doesn't add new information, either because
it literally repeats what the code already says, or is actually
duplicated.

Change-Id: I3a8dd8ce57192deda8916cc444c87d7ab1a36515
2020-10-28 11:01:33 +01:00
Thiemo Kreuz
1fc8d79ac6 Remove documentation that literally repeats the code
For example, documenting the method getUser() with "get the User
object" does not add any information that's not already there.
But I have to read the text first to understand that it doesn't
document anything that's not already obvious from the code.

Some of this is from a time when we had a PHPCS sniff that was
complaining when a line like `@param User $user` doesn't end
with some descriptive text. Some users started adding text like
`@param User $user The User` back then. Let's please remove
this.

Change-Id: I0ea8d051bc732466c73940de9259f87ffb86ce7a
2020-10-27 19:20:26 +00:00
Timo Tijhof
0c01d8cc52 resourceloader: Add skin-based 'mediawiki.skin.variables.less' import
Add the SkinLessImportPaths attribute for skin-specific LESS import
paths, which skins can use to override the mediawiki.skin.variables.less
file.

As a starting point, add the following 5 variables:

* device widths (3x)
  To help phase out 'mediawiki.ui/variables'. These are
  commonly used by MobileFrontend.

* @font-family-sans
  Recommended by Volker. Used by multiple skins.

* @border-radius-base
  Recommended by Volker as example of something that we currently
  hardcode in MediaWiki core for Vector and OOUI/WikimediaUI
  in 'mediawiki.widgets.datetime' but should instead be allowed
  to vary by skin and OOUI theme.

  Remove the hardcoded value for '@border-radius-base' in
  various places in favour of importing from mediawiki.skin.
  The default is a bare default of 0 (as border-radius is off
  by default in the browser).

  The value for Vector is restored there by I47da304667811.
  The value for MonoBook is improved by I000f319ab31b.

Bug: T112747
Change-Id: Icf86c930a3b5524254bb549624737d3b9dccb032
2020-09-15 10:05:53 +00:00
Ammar Abdulhamid
ca1224dc44 Deprecate Skin methods moved to SkinFactory
* Skin::getAllowedSkins
* Skin::getSkinNames

Both are hard-deprecated and their equivalents in
SkinFactory should be used instead.

Bug: T257993
Depends-On: Ib8e4ec28f6755abec7e33476efefa78dcc2c6b78
Depends-On: Icc945ce1e3287a3b25152702818e5b2a90232677
Change-Id: I9595248ae5410361a5db50d1b95df1e513ac5a2c
2020-08-26 12:45:52 -07:00
Aaron Schulz
5e0fa6ecc8 resourceloader: store relative paths in less compilation cache
Bug: T253055
Change-Id: Iac911eaeaf26ff8b85642dbc908a8a1e08d0d234
2020-07-21 14:33:59 -07:00
jenkins-bot
b2ce2db332 Merge "resourceloader: Add some typehints and misc clean up" 2020-07-02 03:02:02 +00:00
Timo Tijhof
91c73f6bac resourceloader: Add some typehints and misc clean up
* Add a void return hint to methods that are not meant to return
  anything. This helps catch accidental return statements in the
  future, lets Phan better understand how methods are meant to be
  used, and might also allow PHP to better optimise the compiled
  code form (speculation).

  I did not, however, add it to publicly extended methods as that
  might mess with strict mode.

* Remove the internal getResourceLoader() method from MessageBlobStore.
  This has been redundant since 3edaa0b37c.
  The method was protected, and not considered stable to subclass
  for extensions. Hence not a breaking change.

* Add Throwable typehint to formatException() and friends.
  This is the narrowest one I could add given that the methods
  called from here already enforce the same typehint.
  Update the doc to match for now. There isn't a reason right now
  to limit this only to Exception, and given this is the method
  and not the catch statement itself, does not change behaviour.

* Remove unused ResourceLoader->getHookContainer().
  Added within 1.35 cycle, safe to remove.

* Remove unexpected `@since` for `@internal` getHookRunner().

* Remove redundant `@internal` from ResourceLoaderMwUrlModule
  methods, which itself is already `@internal`.

Change-Id: I68d33ff6feca7ef95282a7ff03eb9332adfde31c
2020-07-02 03:05:59 +01:00
Umherirrender
bc5cb7ae64 phan: Enable redundant_condition_detection
Remove duplicate casts
Suppress false positives

Bug: T248438
Change-Id: I2f89664a4bcd3b39b15e7cf850adda2f0c90ae6f
2020-07-01 20:13:07 +00:00
Roan Kattouw
8c6c1c9adc VueComponentParser: Use RemexHtml instead of PHP's HTML parser
This fixes an issue with HTML tags inside the <script> tag.
Remex also doesn't throw errors on attributes like @click, although it
does mangle them when producing DOM. To work around this, don't use DOM
serialization for the template HTML, but parse everything again using a
Remex parse+serialize pipeline that extracts the template and
(optionally) removes comments and strips whitespace.

One important effect of this change is that we'll have to forbid
self-closing tags in Vue templates, because Remex doesn't handle those
correctly (or rather, handles them *too* correctly). But on the up side,
we can now allow shorthands for v-bind/v-on/v-slot again.

Bug: T253334
Bug: T255587
Depends-On: I2253a2317187fe0d781ba5bfefab95e0f97d0a80
Change-Id: Id9a9728b7163601cc60bc587be07b70977d41970
2020-06-22 19:54:15 +00:00
Timo Tijhof
d7e2a20785 resourceloader: Improve packageFiles/skinScripts error message
The uppercase spelling would I think be confusing, as the actual
options are lowercase, which should be quoted when referred to
in natural language.

Bug: T251957
Change-Id: Ib97a2bc790799990f3e4b622b20636965a93fca1
2020-06-11 23:22:21 +01:00
Vas Jaremchuk
323b5968e7 resourceloader: skinScripts cannot be used alongside packageFiles
The new exception was added in ResourceLoaderFileModule.php that
packageFiles and skinScripts are incompatible.

Bug: T251957
Change-Id: Id51763b9049b9b2041c4c1c47575d1a6cb3452b0
2020-06-11 20:29:40 +00: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
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
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
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