aboutsummaryrefslogtreecommitdiffstats
path: root/includes/ResourceLoader/FileModule.php
Commit message (Collapse)AuthorAgeFilesLines
* resourceloader: Remove getScriptURLsForDebug()Hannah Okwelum2025-02-171-21/+0
| | | | | Bug: T367441 Change-Id: I16db275bf60b80954b7e271fbeb3a86a9b8bf11e
* resourceloader: Fix hash computation for virtual files with versionFilePathRoan Kattouw2025-01-291-3/+2
| | | | | | | | | | A regression in 69ad795df7719a7854672140afa3a07269639978 caused virtual files with a versionFilePath to be silently dropped from the version hash computation. This caused changes in these files to not be reflected in the version hash of the file. Bug: T385055 Change-Id: Ibde41f07bb6fa7610660cb5b7a3f7aafbe9d6bd3
* resourceloader: Minor documentation correctionsBartosz Dziewoński2025-01-201-1/+5
| | | | | | | | Issues spotted while working on I03a9a6945ab27e9888ea21b03985ed713f0a9b50. Some code style improvements too. Change-Id: I409d0a1805aa7430cc86e53633f4f85ef8a76dcf
* ResourceLoader: Avoid CACHE_DB fallback for minify and less.php cacheTimo Tijhof2024-11-271-1/+1
| | | | | | | | | | | | | * For minify cache, we removed the CACHE_DB fallback in I086e275148 (7c2c016e46), but I forgot to do the same for the (now, mostly unused) static method. * For less.php cache, likewise don't bother storing these in the database if the install has no php-apcu, although keep a fallback to an in-process cache for now. Bug: T186673 Change-Id: Ic93e37c974c07aa74acdaaf5f990f5270f255546
* Use explicit nullable type on parameter argumentsUmherirrender2024-10-161-3/+3
| | | | | | | | | | | Implicitly marking parameter $... as nullable is deprecated in php8.4, the explicit nullable type must be used instead Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a Break one long line in SpecialPage.php Bug: T376276 Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
* Make use of the ??= and ?? operators where it makes sensethiemowmde2024-08-261-4/+2
| | | | | | | | This touches various production classes and maintenance scripts. The code should do the exact same as before. The main benefit is that the syntax avoids any repetition. Change-Id: I5c552125469f4d7fb5b0fe494d198951b05eb35f
* Codex: Allow a local development version to be usedRoan Kattouw2024-08-221-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* RL: Consider RTL styles are also generatedEbrahim Byagowi2024-08-121-0/+1
| | | | | | | | | | | | | | | | ResourceLoader currently declares styles are generated only if Less is involved but RTL CSS styles are also generated in the same way so let's treat them the same. This makes RL's debug mode matching better with non-debug mode so if a user uses ?debug=1 in an RTL wiki, they get CSS Janus transformed styles just as if Less was involved. I was seeing the issue for years but had to get to the bottom of it in I6c9544d7eee3b5885f4fd30265e906fe22a8c223 as this bit was part of the confusion I had to debug the issue there. Change-Id: Ib10bec85da969881be590e3d95d5f9474f2eb6e9
* Add MediaWiki\Registration namespace to registration classesEbrahim Byagowi2024-08-101-1/+1
| | | | | Bug: T353458 Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
* ResourceLoader: Use getParsedFiles() since Less_Parser::AllParsedFiles() is ↵Hannah Okwelum2024-05-301-1/+1
| | | | | | | | deprecated Will be removed in I341d5c57182a00f550d4ffb4d210fcdd. Change-Id: I944cdc75d50ea90c2ef1ac1a736ee88fffe8b565
* fix: use objectcachefactory methods instead of deprecated objectcache methodsIrina Balaban2024-05-051-2/+2
| | | | | Bug: T363770 Change-Id: Ie732f6925ec2b1316a60bebbe3c27f963c9dacb1
* ResourceLoader: Add module property skipStructureTestTim Starling2024-03-111-0/+8
| | | | | | | | | Allow extensions with very special modules that can't be called in a testing environment to skip ResourcesTest::testRespond(). Needed by If1186797fd047d4f for ext.wikisource.OCR. Change-Id: Id02915d9633c2d8209d2ff2e60f6748095ec10fe
* Drop old ResourceLoader class aliases, deprecated since 1.39James D. Forrester2024-01-311-3/+0
| | | | | | | Depends-On: Iff15a2e13a3507ef1ab5cfa504ca1a1c8d2b2a60 Depends-On: Icf8331e35acf6fe51a8303ee639921b9e4f3e6bb Depends-On: I5a5af003026db69b279ddde0b0dedbfcfe7d70fd Change-Id: I5929a2f760c8d21c1cb2542a19220a91ac7240e4
* ResourceLoader: Drop targets system, deprecated in 1.41James D. Forrester2024-01-121-11/+0
| | | | | | Bug: T340802 Depends-On: Ie936afed7042d5a4713b027c30d7487565a35eaf Change-Id: Icad30d62301be5d7390ebdf34e818519e3fe56c4
* ResourceLoader/FileModule: Use callbackParam instead of callbackParamsFomafix2023-12-031-1/+1
| | | | Change-Id: I009dacba94a5e49dc196ad86871dd729581a397e
* ResourceLoader: Preserve newlines in Vue templates in debug modeRoan Kattouw2023-11-211-2/+3
| | | | | | | | | | Ironically, our replacements to improve readability of Vue templates in debug mode actually ended up eating newlines in the string that is sent to the Vue template compiler. This caused bugs when inline comments were used in multi-line JS expressions in templates. Bug: T351771 Change-Id: I6b3ad5736a836ba75f57a49fd9b7ca2e237074c0
* Reorg: Move three output related classes to includes/Output/Amir Sarabadani2023-09-051-1/+1
| | | | | | | | | | And namesapce them: - StreamFile - OutputHandler - OutputPage Bug: T321882 Change-Id: Iedf8d88c595e580f2d8f0734c92aa5c45618ba33
* ResourceLoader: Have FileModule deliver additional path informationTim Starling2023-08-231-29/+18
| | | | | | | | | | | | | | | | * 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
* ResourceLoader: deliver deprecation warnings as stringsTim Starling2023-08-031-6/+1
| | | | | | | | | | | | | | | | | | | 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
* ResourceLoader: Switch Resources.php to MW_INSTALL_PATHTimo Tijhof2023-07-311-4/+3
| | | | | | | | | | | | | | | | | | | | Follows-up Ib4caa80bb700, which introduced MW_INSTALL_PATH as alternative to $IP, but also introduced $wgBaseDirectory. Its not clear to me whether we actually want/need $wgBaseDirectory long-term as it introduces significant complexity for a distinction that remains theoretical, not enforced, and lacking a use case. But, at least here we don't need it as these all explicitly reference files that are in the source tree. Mocking the path differently would fail the tests. There are some individual methods (OutputPage, used via SkinModule) that do not make assumptions on file paths and work with any file paths at runtime. Those indeed need $wgBaseDirectory for DI and testability. Change-Id: I56c28d36e2d7bbf7ec5a8f2f5ae99b291e7ee4e8
* ResourceLoader: Allow FileModule scripts to be generated with a callbackTim Starling2023-05-091-213/+342
| | | | | | | | | | | | | | | | | | | | | | | To implement source maps, we want FileModule::getScript() to return an array with path information, but that would break subclasses of FileModule which concatenate to the return value of parent::getScript(). So allow scripts to be generated by a callback, eliminating the need for concatenation in subclasses. * Factor out most of the loop body of expandPackageFiles() into expandFileInfo(). Add 'name' to the return value. Ensure 'filePath' is always a FilePath object since we need that to safely return it to ResourceLoader later. Document the return value. * Make sure the base path is always set in FilePath objects returned by expandFileInfo(). * Factor out the loop body of the final stage of file info expansion into readFileInfo(). Retain filePath, do not unset it. * Assert that $fileInfo['content'] is definitely set. * Convert array_map() in getDefinitionSummary() to a loop. * Migrate LanguageDataModule. Bug: T47514 Change-Id: I97d61b5793159cea365740e0563f7b733e0f16de
* ResourceLoader: Use JSON_THROW_ON_ERROR when loading data filesTim Starling2023-04-281-1/+1
| | | | | | | | Otherwise content ends up being null, and a less specific exception is thrown. Depends-On: Id951da0d4ffa31f4593b2396c806dd6081670d36 Change-Id: Ic2ccd76df70ffba0ed25100925db3dd3086c5e8c
* ResourceLoader: tweak comments and error messagesTim Starling2023-04-031-11/+12
| | | | Change-Id: Ifcaefedf65b090a87ec1417808277ae6451302dc
* ResourceLoader: Raise MW JavaScript startup requirement to ES6James D. Forrester2023-03-301-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Adjust default targets in RL/ModuleKosta Harlan2023-02-011-3/+0
| | | | | | | | | | | | | | | | | | | 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
* ResourceLoader: Default File modules to mobile and desktop targetsJon Robson2023-01-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | If not specified, going forward all modules which do not define targets should be assumed to be mobile AND desktop. I think this is a fair expectation given that most new features should be built with mobile in mind. This also avoids the issue where features are unexpectedly not shipped to mobile. The work in T324723 has ensured that all modules that need to remain desktop only have been marked as such. After the audit, we can be reasonably confident that enabling the remaining modules is okay, given these modules run in isolated parts of the UI (not on every page view). I'm assuming CI is catching all offenders here. If not, any impacted modules would require a trivial update to explicitly define modules as mobile only. This would allow us to see clearly which modules are depending on the target system and strategize around updating them. Once this patch is merged we can focus on fixing the modules we've identified as mobile or desktop targeted and finally dismantling the targets system altogether. Bug: T127268 Change-Id: Ia062ff2d8b8732b0d3498c1a614bbf6a3e3a7ddb
* Merge "Make use of ?:, ?? and ??= operators in mostly trivial cases"jenkins-bot2022-12-161-4/+1
|\
| * Make use of ?:, ?? and ??= operators in mostly trivial casesthiemowmde2022-12-051-4/+1
| | | | | | | | | | | | | | | | | | | | The motivation is to make the code less confusing. I hope this is the case. ?? is an older PHP 7.0 feature. ??= was added in PHP 7.4, which we can finally use. Change-Id: Id807affa52bd1151a74c064623b41d950a389560
* | Clean up redundant array manipulationMatěj Suchánek2022-12-111-6/+0
| | | | | | | | | | | | PHP does this implicitly. Change-Id: I009a7c93d44fb5e8c430c971cfc637fa04a8e68d
* | Revert "resourceloader: Modern ES6 code should be forced to target mobile"Kosta Harlan2022-12-061-18/+0
|/ | | | | | | | | This reverts commit 15622ea09a48ea9ceef5f12583794427755a7dc1. Reason for revert: T324525 Bug: T323542 Change-Id: I496ce3589f0322e7ac0f109081fa5e0587f48f94
* resourceloader: Modern ES6 code should be forced to target mobileJon Robson2022-11-301-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | First step towards constraining how the targets system can be used with the eventual goal of dismantling target system altogether. As part of the many modernization efforts in place, we should be targeting mobile experiences by default. For now I am targeting only modules that are writing ES6 code for desktop only. In future this should be expanded to modules using packageFiles and modules targetting mobile only. The implication of this change is that any ES6 module that has not specified targets, will now automatically load on mobile site. In the case of the 3 depends-on there doesn't seem to be any problem with targeting mobile as the way these modules are loaded is restricted based on context. We will log warnings to inform us where modules disobey this rule. Bug: T323542 Depends-On: I2e31ba2bd2aea192f428531f6c92afa551448fef Change-Id: Iff6bfbba406dec5b8c8be644dbf21ee3b3879fda
* Use short array destructuring instead of list()Tim Starling2022-10-211-2/+2
| | | | | | | | Introduced in PHP 7.1. Because it's shorter and looks nice. I used regex replacement. Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
* Remove unused key variable from foreach loopsUmherirrender2022-09-211-1/+1
| | | | Change-Id: Id2d91e30a6f7cc4eb93427b50efc1c5c77f14b75
* Merge "ResourceLoader: replace FileModule::collateFilePathListByOption with ↵jenkins-bot2022-06-231-19/+13
|\ | | | | | | private helper"
| * ResourceLoader: replace FileModule::collateFilePathListByOption with private ↵DannyS7122022-06-231-19/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | helper All callers provide 'media' for $option and 'all' for $default, just use those values directly. Class is not stable to extend so this protected method is not part of the stable interface, codesearch shows no code on gerrit outside of core that calls the method. Since the $option parameter is removed, the name no longer makes sense, renamed and made private. Change-Id: I875942d5b8c339031fd302f547c9cf16328c9bf2
* | Merge "FileModule: replace 'master' with 'primary' in comments"jenkins-bot2022-06-221-2/+2
|\ \
| * | FileModule: replace 'master' with 'primary' in commentsDannyS7122022-06-221-2/+2
| |/ | | | | | | | | Bug: T254646 Change-Id: Iaf61e868ffa4e70e518a74f679cf7cd0df5e6834
* / Remove deprecated and unused FileModule::compileLessFile()DannyS7122022-06-221-14/+0
|/ | | | | | Deprecated since 1.35 Change-Id: If2c86c1cd269e814257d43a1c9dd0c35fc15e55f
* ResourceLoader: Remove unchecked exception annotationsAdam Wight2022-06-221-1/+0
| | | | | | | | Also repair two `@see` annotations referring to methods that didn't exist. Bug: T240672 Change-Id: I2edb39554bcf46fdc83bd138ef7bb9065c2c0696
* resourceloader: Improve internal type hints in FileModule classTimo Tijhof2022-05-291-102/+56
| | | | | | | | | | | | | | | | | | | Follows-up I56a0ee74595404e1, I38a0761ae4633 and I6c3d186de1877f73d4. Remove most "Usage" examples as these are internal and mostly-normalized class fields. This is not where end-users should look for documentation. Besides, many of the examples were wrong or outdated, and almost all were incomplete. It also had an inherent dilimma between describing all possible valid input and describing what we actually store in that instance variable after normalization in the class constructor. The usage docs have long been moved to the MW config file, so we can omit that. In its stead, place more complete and accurate type hints for Phan to understand the possible code paths, in particular to reflect the use of FilePath objects. Change-Id: I1cc002f350785d3f46f79be5defb7b3cadbebf34
* resourceloader: Allow using FilePath directly in 'packageFiles' arrayBartosz Dziewoński2022-05-271-2/+2
| | | | | | This already works in 'scripts', 'styles' etc. Change-Id: I56a0ee74595404e1c40483b84400056d6f87b07d
* resourceloader: Tweak RL\FilePath handling in packageFilesBartosz Dziewoński2022-05-271-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | ResourceLoader's FilePath is designed to allow a FileModule to include files that exist outside of the module's localBasePath, to allow skins and extensions to extend core MediaWiki modules. This is accomplished by having the FileModule use the FilePath's localBasePath instead, in FileModule::getLocalPath. (Similarly for remoteBasePath, but these are going out of fashion.) However, the code processing 'packageFiles' did not handle this right: it used FilePath's localBasePath when it appeared as a 'file', but not when it was returned by a 'callback' or 'versionCallback', using the FileModule's localBasePath instead in that case. Most existing uses of FilePath in 'packageFiles' required the same base path as the module, so it was convenient to avoid providing it twice. To keep that convenience (already relied on by some extensions too) while also allowing skins and extensions to add files from their own directories to existing modules, the code processing 'packageFiles' now uses FilePath's base paths in all cases, but they are optional, and will fall back to the FileModule's paths when not provided. Follow-up to 2890bca27db3636348b1a052e9e4d23a6bb1e272. Change-Id: I38a0761ae4633a567b685b52c1d73b6ce280ffb7
* ResourceLoader namespace (attempt 2)Tim Starling2022-05-241-0/+1489
| | | | | | | | | | | | | | | | | | 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 a241d83e0a6dabedf. Bug: T308718 Change-Id: Id08a220e1d6085e2b33f3f6c9d0e3935a4204659
* Revert "ResourceLoader namespace"Lucas Werkmeister (WMDE)2022-05-161-1489/+0
| | | | | | | | | | | | This reverts commit e08ea8ccb9932f9924a613056afcb2d01c8c7b39. 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
* ResourceLoader namespaceTim Starling2022-05-161-0/+1489
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