wiki.techinc.nl/includes/resourceloader/ResourceLoaderFilePath.php

72 lines
2 KiB
PHP
Raw Normal View History

resourceloader: Allow skins to provide additional styles for any module The newly introduced $wgResourceModuleSkinStyles global enables skins to provide additional stylesheets to existing ResourceLoader module. This both makes it easier (or at all possible) to override default styles and lowers the style footprint by making it possible not to load styles unused on most pages. ---- Example: Use the file 'foo-styles.css' for the 'mediawiki.foo' module when using the MySkin skin: $wgResourceModuleSkinStyles['myskin'] = array( 'mediawiki.foo' => 'foo-styles.css', 'remoteSkinPath' => 'MySkin', 'localBasePath' => __DIR__, ); For detailed documentation, see the doc comment in DefaultSettings.php. For a practical usage example, see Vector.php. ---- Implementation notes: * The values defined in $wgResourceModuleSkinStyles are embedded into the modules as late as possible (in ResourceLoader::register()). * Only plain file modules are supported, setting module skin styles for other module types has no effect. * ResourceLoader and ResourceLoaderFileModule now support loading files from arbitrary paths to make this possible, defined using ResourceLoaderFilePath objects. * This required some adjustments in seemingly unrelated places for code which didn't handle the paths fully correctly before. * ResourceLoader and ResourceLoaderFileModule are now a bit more tightly coupled than before :( * Included a tiny example change for the Vector skin, a lot more of similar cleanup is possible and planned for the future. * Many of the non-essential mediawiki.* modules defined in Resources.php should be using `'skinStyles' => array( 'default' => … )` instead of `'styles' => …` to allow more customizations, this is also planned for the future after auditing which ones would actually benefit from this. Change-Id: Ica4ff9696b490e35f60288d7ce1295766c427e87
2014-06-26 14:29:31 +00:00
<?php
/**
* An object to represent a path to a JavaScript/CSS file, along with a remote
* and local base path, for use with ResourceLoaderFileModule.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
/**
* An object to represent a path to a JavaScript/CSS file, along with a remote
* and local base path, for use with ResourceLoaderFileModule.
*/
class ResourceLoaderFilePath {
/** @var string Local base path */
protected $localBasePath;
/** @var string Remote base path */
protected $remoteBasePath;
/**
* @var string Path to the file */
protected $path;
/**
* @param string $path Path to the file.
* @param string $localBasePath Base path to prepend when generating a local path.
* @param string $remoteBasePath Base path to prepend when generating a remote path.
*/
public function __construct( $path, $localBasePath, $remoteBasePath ) {
$this->path = $path;
$this->localBasePath = $localBasePath;
$this->remoteBasePath = $remoteBasePath;
}
/**
* @return string
*/
public function getLocalPath() {
return "{$this->localBasePath}/{$this->path}";
}
/**
* @return string
*/
public function getRemotePath() {
return "{$this->remoteBasePath}/{$this->path}";
}
/**
* @return string
*/
public function getPath() {
return $this->path;
}
}