diff options
author | Bartosz DziewoĆski <matma.rex@gmail.com> | 2022-05-24 02:42:21 +0200 |
---|---|---|
committer | Timo Tijhof <krinkle@fastmail.com> | 2022-05-27 22:40:41 +0100 |
commit | 566b185e9caa97a436ba4953005fc55ab2a889e4 (patch) | |
tree | d5b087117c39e19a9fb78ecf0e0e4e1824b05c8f /includes/ResourceLoader/FileModule.php | |
parent | 2c4635413e05fff4e21d1dbc2010a8fd7f814b24 (diff) | |
download | mediawikicore-566b185e9caa97a436ba4953005fc55ab2a889e4.tar.gz mediawikicore-566b185e9caa97a436ba4953005fc55ab2a889e4.zip |
resourceloader: Tweak RL\FilePath handling in packageFiles
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
Diffstat (limited to 'includes/ResourceLoader/FileModule.php')
-rw-r--r-- | includes/ResourceLoader/FileModule.php | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/includes/ResourceLoader/FileModule.php b/includes/ResourceLoader/FileModule.php index 63fa2d501603..f5f89009ae1f 100644 --- a/includes/ResourceLoader/FileModule.php +++ b/includes/ResourceLoader/FileModule.php @@ -704,7 +704,10 @@ class FileModule extends Module { */ protected function getLocalPath( $path ) { if ( $path instanceof FilePath ) { - return $path->getLocalPath(); + if ( $path->getLocalBasePath() !== null ) { + return $path->getLocalPath(); + } + $path = $path->getPath(); } return "{$this->localBasePath}/$path"; @@ -716,7 +719,10 @@ class FileModule extends Module { */ protected function getRemotePath( $path ) { if ( $path instanceof FilePath ) { - return $path->getRemotePath(); + if ( $path->getRemoteBasePath() !== null ) { + return $path->getRemotePath(); + } + $path = $path->getPath(); } if ( $this->remoteBasePath === '/' ) { @@ -1312,7 +1318,7 @@ class FileModule extends Module { $expanded['callbackParam'] ); if ( $callbackResult instanceof FilePath ) { - $expanded['filePath'] = $callbackResult->getPath(); + $expanded['filePath'] = $callbackResult; } else { $expanded['definitionSummary'] = $callbackResult; } @@ -1326,7 +1332,7 @@ class FileModule extends Module { $expanded['callbackParam'] ); if ( $callbackResult instanceof FilePath ) { - $expanded['filePath'] = $callbackResult->getPath(); + $expanded['filePath'] = $callbackResult; } else { $expanded['content'] = $callbackResult; } @@ -1405,7 +1411,7 @@ class FileModule extends Module { ); if ( $callbackResult instanceof FilePath ) { // Fall through to the filePath handling code below - $fileInfo['filePath'] = $callbackResult->getPath(); + $fileInfo['filePath'] = $callbackResult; } else { $fileInfo['content'] = $callbackResult; } |