wiki.techinc.nl/includes/resourceloader/ResourceLoaderFilePath.php
Bartosz Dziewoński 77f4bab8b7 Allow skins/extensions to define custom OOUI themes
This change follows I39cc2a735d9625c87bf4ede6f5fb0ec441d47dcc.

docs/extension.schema.v1.json
docs/extension.schema.v2.json
includes/registration/ExtensionProcessor.php
* The new extension attribute 'OOUIThemePaths' can be used to define
  custom OOUI themes. See I9187a63e509b601b8558ea82850fa828e5c8cc0a
  for an example usage.

includes/resourceloader/ResourceLoaderOOUIModule.php
* Add support for 'OOUIThemePaths'.
* Defining 'images' is now optional. I figure custom themes are
  unlikely to have or need them.
* Use ResourceLoaderFilePath objects to allow skin-/extension-defined
  OOUI module files to use skin/extension's base paths.
  This was previously used to support $wgResourceModuleSkinStyles,
  but only for 'skinStyles' - now ResourceLoaderFileModule needs
  to also handle it for 'skinScripts', and ResourceLoaderImageModule
  for 'images').

includes/resourceloader/ResourceLoaderFilePath.php
* Add getters for local/remote base paths, for when we need to
  construct a new ResourceLoaderFilePath based on existing one.

includes/resourceloader/ResourceLoaderFileModule.php
includes/resourceloader/ResourceLoaderImageModule.php
includes/resourceloader/ResourceLoaderOOUIImageModule.php
* Add or improve handling of ResourceLoaderFilePaths:
  * Replace `(array)` casts with explicit array wrapping, to avoid
    casting objects into associative arrays.
  * Use getLocalPath() instead of string concatenation.

tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php
* Some basic checks for the above.

Bug: T100896
Change-Id: I74362f0fc215b26f1f104ce7bdbbac1e106736ad
2019-07-10 22:08:14 +02:00

85 lines
2.2 KiB
PHP

<?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 getLocalBasePath() {
return $this->localBasePath;
}
/**
* @return string
*/
public function getRemoteBasePath() {
return $this->remoteBasePath;
}
/**
* @return string
*/
public function getPath() {
return $this->path;
}
}