Commit graph

49 commits

Author SHA1 Message Date
Roan Kattouw
8a39d83175 Codex: Allow a local development version to be used
Developers can use this to test their local version of Codex with
MediaWiki by pointing $wgCodexDevelopmentDir to their local clone of the
Codex repo, e.g. $wgCodexDevelopmentDir = '/home/yourname/git/codex';

Setting $wgCodexDevelopmentDir affects where the following things come
from:
- Codex JS/CSS files for the full library
- Codex JS/CSS files for code-split chunks, and the manifest.json file
  that points to them
- Icons retrieved by CodexModule::getIcons()
- CSS-only icons imported in Less
- Design tokens imported in Less

Other changes in this patch:
- Add CodexModule::makeFilePath() to centralize the repeated path
  concatenation. This makes it easier to switch out the regular path for
  the dev mode path.
- Replace all uses of $IP (which is deprecated) and MW_INSTALL_PATH in
  CodexModule with the BaseDirectory config setting.
- Make CodexModule::getIcons() reset its static cache if the path to the
  icons file changes. Without this, it's impossible to make the unit
  tests pass.
- Move the i18n messages code from the CodexModule constructor to
  getMessages(). It can't be in the constructor because makeFilePath()
  doesn't work there (it fails because the Config object hasn't been set
  up yet).
- Add a 'mediawiki.skin.codex' import path so that we can stop
  hard-coding the path to the Codex mixins file. Without this, we can't
  make the Codex mixins come from the right place in development mode.
- Consider $wgCodexDevelopmentDir in setting the cache key for compiled
  Less code, since changing this setting can change the output of Less
  compilation (by changing design tokens, icons or mixins).
- Add unit tests for (the non-dev mode behavior of)
  CodexModule::getIcons() and the i18n message key handling.

Bug: T314507
Change-Id: I11c6a81a1ba34fe10f4b1c98bf76f0db40c1ce98
2024-08-22 17:20:24 -07:00
Ebrahim Byagowi
697e19e461 Add MediaWiki\Registration namespace to registration classes
Bug: T353458
Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
2024-08-10 10:08:22 +00:00
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
Umherirrender
8d97313f81 Fix some line indent
Change-Id: I8f82724197d20f9289d80e138d80310f1eab29f2
2024-04-20 00:25:15 +02: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
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
Martin Urbanec
6ec01553c5 Move StaticUserOptionsLookup to the MediaWiki\User\Options namespace
Follow-up to I9822eb1553870b876d0b8a927e4e86c27d83bd52,
I missed the Static class in that patch.

Bug: T352284
Change-Id: I42653491c19dde5de99e0661770e2c81df5d7e84
2023-11-29 14:08:40 -05:00
Daimona Eaytoy
48a1c0bb2f Autofix spacing around commas
This was done automatically using the
`Universal.WhiteSpace.CommaSpacing` sniff, which will be included in the
next release of the MW PHPCS config.

Some of these have been adjusted manually where the autofix broke
vertical alignment.

Change-Id: I54a4668d8a2759b9d7de47742c943a535a04e211
2023-10-25 01:08:44 +02:00
Amir Sarabadani
f5abfb8d58 Bump codesniffer to 42.0.0
Most noisily, this enables MediaWiki.Arrays.OneSpaceInlineArray.

Change-Id: I8ab11399c67ce7e3ab1b6249b591452774393428
2023-09-27 15:06:32 -04: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
jenkins-bot
30b06ec9c8 Merge "General whitespace clean-up of tabs followed by multiple spaces" 2023-09-06 14:14:51 +00:00
James D. Forrester
35b934ffcb General whitespace clean-up of tabs followed by multiple spaces
Change-Id: I22090062274dceec96d43e23eb227a7e3b1e36fa
2023-09-06 14:28:43 +01:00
Timo Tijhof
30f515ec1d ResourceLoader: adopt SourceMap header instead of inline comment
Follows-up 7c2c016e46 (I086e275148). This separates the link from
the response such that when it gets copied elsewhere, hosted elsewhere,
saved offline, proxied, archived, or otherwise served from a different
place or with different content; the header is most likely naturally
not copied along.

This is based on upstream experience by the jQuery Team where e.g.
distributions of jQuery, or concatenations, etc would lead to
confusing errors or inability to see any source in the devtools.

In the Wikimedia community we two similar use cases:

1. people sometimes copy load.php responses to a wiki page, e.g.
   as a way to "distribute" a ResoureLoader-built gadget or to
   fork/debug some core code.

2. the Internet Archive stores copies of our responses, but doesn't
   proactively download source map links.

For example, archiving
https://people.wikimedia.org/~krinkle/wikimedia-minify-2.5.0-test-sourcemap/combine.html
results in:

 > … /~krinkle/wikimedia-minify-2.5.0-test-sourcemap/combine.html
 > … /~krinkle/wikimedia-minify-2.5.0-test-sourcemap/combine.min.js
 > Archived at
 > http://web.archive.org/web/20230905211332/https://people.wikimedia.org/~krinkle/wikimedia-minify-2.5.0-test-sourcemap/combine.html

Bug: T47514
Change-Id: I3e85c2afb107ce1185651ab038379e4abe87a445
2023-09-06 00:47:46 +01:00
Tim Starling
7c2c016e46 ResourceLoader: Implement JavaScript source map support
In the debugger of Firefox and Chrome, without any special debug mode,
you will be able to see the original unminified JavaScript source, and
to set breakpoints in it and step through it.

Main visible changes:

* Add a config variable controlling the generation of source map links,
  off by default for now.
* For script responses, move errors to the bottom of the response. This
  avoids disturbing the source map.
* mw.loader.impl() calls will have less whitespace in debug mode,
  because minification is no longer done as a post-processing step on
  these calls.

Details:

* Use an index map when multiple responses are requested. This requires
  an update to the minify library.
* Add a boolean "sourcemap" query parameter which causes load.php to
  deliver source map output instead of regular minified content.
* Bundle sources into the source map and use two kinds of fake URL if a
  real debug URL is not available. "Open in new tab" on a fake URL is
  not functional.
* In the source map mode, respond with 404 if the version is mismatched
  or if the content type is unimplemented.
* Fix createLoaderURL() so that $extraQuery is not ignored when there
  are conflicting context parameters, so that we can successfully
  override the version. The source map version should match the
  delivered content, not the requested version.
* Since minification with source map tracking can't use filter(),
  add a new cache for module source maps and minification. Add hit rate
  stats.

Also:

* Fix unnecessary array_map() in getCombinedVersion()

Bug: T47514
Change-Id: I086e275148fdcac89f67a2fa0466d0dc063a17af
2023-08-28 21:33:28 +01: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
Daimona Eaytoy
1cb036c392 Avoid DB access in more non-Database tests
Bug: T155147
Change-Id: Iae2512c66c32b209ea8579beecb3de94a744da14
2023-08-06 16:07:27 +00:00
Daimona Eaytoy
f00ca670bc Fix DB usage in non-database tests
Some non-database tests are currently accessing the database. Fixing
them means either avoiding the DB access if it's possible and makes
sense for the test, or adding the `Database` group otherwise. In
particular:

- Replace global/static functions with services in a couple places to
  make testing easier.
- RevisionRendererTest needs to be in the Database group due to heavy
  global state usage (including DB) by Parser
- ActionFactoryIntegrationTest and SpecialPageFatalTest should be in
  the database group because they test many different classes, and some
  of which may use the database in the tested methods.
- SpecialUserLogoutTest must be in the database group because of User.
- Some pager tests are using wfGetDB directly.

Change-Id: I96eb2acf9a2cbfd17e81225db2773d5e8e30260b
2023-07-21 13:52:47 +02:00
Lucas Werkmeister
3c5a0c862f Html: Move encodeJsVar() + encodeJsCall() from Xml
These methods really belong in the Html class, not Xml. Leave behind
soft-deprecated Xml methods that forward to the Html ones, as well as a
class alias for HtmlJsCode (renamed from XmlJsCode).

Bug: T341779
Change-Id: I99a5f9de1411d4eb5ee30226b4e8ace3ea8b2c3b
2023-07-14 13:42:02 -04:00
Timo Tijhof
6ef84a7218 ResourceLoader: Avoid new use of MWException
Follows-up I992ccde79a59ad51c.

* Soften the test to only asserting that an exception is thrown,
  the type isn't part of the API.

* Throw RuntimeException instead of MWException per T86704.

Bug: T86704
Bug: T328602
Change-Id: Ifaa5d659941d60789ca14f771648e5830bbef317
2023-04-10 18:47:45 -07:00
Roan Kattouw
aaecb49e9b ResourceLoader: Descriptive error for Less imports from codex-design-tokens
Importing Less files from @wikimedia/codex-design-tokens/ doesn't work,
on purpose. Instead of letting these imports fail with a nondescript
"file not found" error that doesn't help the developer understand why it
didn't work, provide a descriptive error message that points them in the
right direction.

Bug: T328602
Change-Id: I992ccde79a59ad51c7ebfe3ac7548a6e531f4a59
2023-03-30 16:19:38 -07:00
Roan Kattouw
7492234847 ResourceLoader: Add path remapping for Less imports
This replaces the hacky wrapper files in
resources/src/mediawiki.less/mediawiki.skin.codex-design-tokens/ and
resources/src/medawiki.less/@wikimedia/codex-icons/dist/ with real
import path aliasing/remapping.

Bug: T328602
Change-Id: I2df266cde90d1b8dad8d1d1367b67001e2b2984d
2023-03-28 16:18:44 -07:00
Tim Starling
be3018b268 Just another 80 or so PHPStorm inspection fixes (#4)
* Unnecessary regex modifier. I agree with this inspection which flags
  /s modifiers on regexes that don't use a dot.
* Property declared dynamically.
* Unused local variable. But it's acceptable for an unused local
  variable to take the return value of a method under test, when it is
  being tested for its side-effects. And it's acceptable for an unused
  local variable to document unused list expansion elements, or the
  nature of array keys in a foreach.

Change-Id: I067b5b45dd1138c00e7269b66d3d1385f202fe7f
2023-03-25 00:39:06 +00:00
Timo Tijhof
89c17acbf6 ResourceLoader: Silence failure of encodeJson() for $modules param
The $modules param is user controlled. We already catch invalid UTF-8
in server configurations. If something like that makes it here, the
only place it can come from is the client doing it intentionally,
such as the result of scanning tools.

Follows-up I89832142b, which silenced $modules formatting in a CSS
response. This patch also covers the case of a JS response, and adds a
test for both.

Bug: T331641
Change-Id: I03a0ec262203509f069654e7fa6fd8d8debd25d5
2023-03-23 11:20:59 -07:00
Umherirrender
ed169d991e Remove unused arguments to private functions
Found by phan dead detection

Change-Id: I93379b7b9a733206d0e53add04fcdb9478c58755
2023-02-08 19:00:47 +00:00
Umherirrender
abf2ea44e8 tests: Handle dynamic created properties on test classes
- Declare missing properties
- Remove unused or avoid set of properties
- Add AllowDynamicProperties

Bug: T314099
Change-Id: Ie631894f2ffbb616f6dd09851405d681f3eb8fcd
2023-01-13 21:03:42 +00:00
Umherirrender
fd516a98e1 Fix whitespaces after comma
Change-Id: Ide6de0a53661e6f650099d7b1f274a02699441df
2022-12-15 01:24:14 +01:00
Amir Sarabadani
bbe704b5c1 Reorg: Move some of request related classes to MediaWiki/Request
Redoing I5ea70120d74 but without moving WebRequest that caused issues
with phan-taint-plugin.

Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequestUpload

Bug: T321882
Change-Id: I832b133aaf61ee9f6190b0227d2f3de99bd1717b
2022-10-28 10:15:31 +00:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
Daimona Eaytoy
ee672592d8 tests: Replace assertRegExp with assertMatchesRegularExpression
And also assertNotRegExp -> assertDoesNotMatchRegularExpression. The
methods were renamed in PHPUnit 9.

Done automatically with:
  grep -rl assertRegExp tests/ | xargs sed -r -i "s/>assertRegExp\(/>assertMatchesRegularExpression\(/"
  grep -rl assertNotRegExp tests/ | xargs sed -r -i "s/>assertNotRegExp\(/>assertDoesNotMatchRegularExpression\(/"

Split out from Ifdba0f9e98eb6bce4590b7eb73170c51a697d7c6 so that it
remains smaller and easier to review.

Also make a test use MediaWikiUnitTestCase (it's already in the unit/
dir) so that it can access the forward-compat method.

Bug: T243600
Change-Id: Ifa279d5f201d7abeebece292141ebface8278046
2022-10-07 14:13:16 -04:00
Timo Tijhof
bb3e62a74a ResourceLoader: Add test for mw.loader.state missing response
Cover code in `respond()` and `makeModuleResponse()` relating to
responding for a module that does not exist (yet, or not anymore).

Change-Id: I17db551adf6efaf0272ae063be8b2b5c3a73abc7
2022-08-04 16:08:20 -07:00
jenkins-bot
8140c48132 Merge "ResourceLoader: Make testRespondInternalFailures more realistic" 2022-08-03 01:15:09 +00:00
Umherirrender
7b2fd4e0cd tests: Remove unneeded set of global $wgSkinLessVariablesImportPaths
Left over from previous patch set of 0c01d8c where
SkinLessVariablesImportPaths was first implemented as global,
but later as attribute SkinLessImportPaths in extension.json

Change-Id: Id98b220fc5593bac3f38007c535243354062e9f9
2022-08-03 00:34:57 +02:00
Derick Alangi
5e8cd2c838
Migrate from setMwGlobals() to overrideConfigValue(s)
Change-Id: I3f167d0e7d59a5aa091c3095a7d96c889d6e7e78
2022-08-02 10:14:10 +01:00
Timo Tijhof
7e643981f6 ResourceLoader: Make testRespondInternalFailures more realistic
Instead of letting getCombinedVersion() throw, let the exception
come from calling $module->getVersionHash(). This is in prep for
I2fe5ad104a6404 where I'll remove a redundant try-catch, and this
test will fail if it stays in this unrealisic/simplified way.

Change-Id: I3e1e53258d40525fa64dde27b0e441d75aeb4854
2022-07-31 18:39:48 -07:00
Umherirrender
dee77e59a1 tests: Remove resetServiceForTesting after overrideConfigValues
overrideConfigValues is documented to reset services as well

Change-Id: Ie13a699f6cd912b912d34adb97704bab3cbdff2d
2022-07-27 23:08:27 +02:00
jenkins-bot
a7ca83284d Merge "Fix tests so getName() doesn't return null" 2022-07-25 19:43:38 +00:00
Thiemo Kreuz
61ae7504df Replace trivial usa of mock builder with createMock() shortcut
createMock() does the same, but is much easier to read.

A small difference is that some of the replacements made in this
patch didn't use disableOriginalConstructor() before. In case this
was relevant we should see the respective test fail. If not we can
save some CPU cycles and skip these constructors.

Change-Id: Ib98fb06e0fe753b7a53cb087a47e1159515a8ad5
2022-07-15 16:43:48 +00:00
Mark A. Hershberger
3a9744921d Fix tests so getName() doesn't return null
In a comment on I248f828f69d404d2bad8fe8c878e6204ca4b021e, Krinkle
says a module name should never be null for RL.

Change-Id: I1c03e3f47086a1cbe7175deb6aca1357735978dc
2022-07-13 18:18:51 +00:00
Derick Alangi
ae22031299 ResourceLoader: Inject HookContainer & UserOptionsLookup to getUserDefaults
Change-Id: I328ee0f959f0898a7e2632dfcfa3e3bbb579106e
2022-07-01 00:53:37 +00: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 tests/phpunit/includes/resourceloader/ResourceLoaderTest.php (Browse further)