/**
* Register core modules and runs registration hooks.
- * @param Config $config [optional]
- * @param LoggerInterface $logger [optional]
+ * @param Config|null $config [optional]
+ * @param LoggerInterface|null $logger [optional]
*/
public function __construct( Config $config = null, LoggerInterface $logger = null ) {
global $IP;
* Register a module with the ResourceLoader system.
*
* @param mixed $name Name of module as a string or List of name/object pairs as an array
- * @param array $info Module info array. For backwards compatibility with 1.17alpha,
+ * @param array|null $info Module info array. For backwards compatibility with 1.17alpha,
* this may also be a ResourceLoaderModule object. Optional when using
* multiple-registration calling style.
* @throws MWException If a duplicate module registration is attempted
* Source IDs are typically the same as the Wiki ID or database name (e.g. lowercase a-z).
*
* @param array|string $id Source ID (string), or [ id1 => loadUrl, id2 => loadUrl, ... ]
- * @param string|array $loadUrl load.php url (string), or array with loadUrl key for
+ * @param string|array|null $loadUrl load.php url (string), or array with loadUrl key for
* backwards-compatibility.
* @throws MWException
*/
}
/**
- * Return whether the definition of a module corresponds to a simple ResourceLoaderFileModule
- * or one of its subclasses.
+ * Whether the module is a ResourceLoaderFileModule (including subclasses).
*
* @param string $name Module name
* @return bool
if ( isset( $info['object'] ) ) {
return false;
}
- if (
- isset( $info['class'] ) &&
- $info['class'] !== ResourceLoaderFileModule::class &&
- !is_subclass_of( $info['class'], ResourceLoaderFileModule::class )
- ) {
- return false;
- }
- return true;
+ return (
+ // The implied default for 'class' is ResourceLoaderFileModule
+ !isset( $info['class'] ) ||
+ // Explicit default
+ $info['class'] === ResourceLoaderFileModule::class ||
+ is_subclass_of( $info['class'], ResourceLoaderFileModule::class )
+ );
}
/**
$strContent = isset( $styles['css'] ) ? implode( '', $styles['css'] ) : '';
break;
default:
- $scripts = isset( $content['scripts'] ) ? $content['scripts'] : '';
+ $scripts = $content['scripts'] ?? '';
if ( is_string( $scripts ) ) {
if ( $name === 'site' || $name === 'user' ) {
// Legacy scripts that run in the global scope without a closure.
$strContent = self::makeLoaderImplementScript(
$implementKey,
$scripts,
- isset( $content['styles'] ) ? $content['styles'] : [],
+ $content['styles'] ?? [],
isset( $content['messagesBlob'] ) ? new XmlJsCode( $content['messagesBlob'] ) : [],
- isset( $content['templates'] ) ? $content['templates'] : []
+ $content['templates'] ?? []
);
break;
}
* Set the state of modules with the given names to the given states
*
* @param string $name
- * @param string $state
+ * @param string|null $state
* @return string JavaScript code
*/
public static function makeLoaderStateScript( $name, $state = null ) {
* Registers modules with the given names and parameters.
*
* @param string $name Module name
- * @param string $version Module version hash
- * @param array $dependencies List of module names on which this module depends
- * @param string $group Group which the module is in
- * @param string $source Source of the module, or 'local' if not foreign
- * @param string $skip Script body of the skip function
+ * @param string|null $version Module version hash
+ * @param array|null $dependencies List of module names on which this module depends
+ * @param string|null $group Group which the module is in
+ * @param string|null $source Source of the module, or 'local' if not foreign
+ * @param string|null $skip Script body of the skip function
* @return string JavaScript code
*/
public static function makeLoaderRegisterScript( $name, $version = null,
* Register sources with the given IDs and properties.
*
* @param string $id Source ID
- * @param string $loadUrl load.php url
+ * @param string|null $loadUrl load.php url
* @return string JavaScript code
*/
public static function makeLoaderSourcesScript( $id, $loadUrl = null ) {
* startup module if the client has adequate support for MediaWiki JavaScript code.
*
* @param string $script JavaScript code
- * @param string $nonce [optional] Content-Security-Policy nonce (from OutputPage::getCSPNonce)
+ * @param string|null $nonce [optional] Content-Security-Policy nonce
+ * (from OutputPage::getCSPNonce)
* @return string|WrappedString HTML
*/
public static function makeInlineScript( $script, $nonce = null ) {
* @param array $modules
* @param string $lang
* @param string $skin
- * @param string $user
- * @param string $version
+ * @param string|null $user
+ * @param string|null $version
* @param bool $debug
- * @param string $only
+ * @param string|null $only
* @param bool $printable
* @param bool $handheld
* @param array $extraQuery
* Returns LESS compiler set up for use with MediaWiki
*
* @since 1.27
- * @param array $extraVars Associative array of extra (i.e., other than the
- * globally-configured ones) that should be used for compilation.
+ * @param array $vars Associative array of variables that should be used
+ * for compilation. Since 1.32, this method no longer automatically includes
+ * global LESS vars from ResourceLoader::getLessVars (T191937).
* @throws MWException
* @return Less_Parser
*/
- public function getLessCompiler( $extraVars = [] ) {
+ public function getLessCompiler( $vars = [] ) {
+ global $IP;
// When called from the installer, it is possible that a required PHP extension
// is missing (at least for now; see T49564). If this is the case, throw an
// exception (caught by the installer) to prevent a fatal error later on.
}
$parser = new Less_Parser;
- $parser->ModifyVars( array_merge( $this->getLessVars(), $extraVars ) );
- $parser->SetImportDirs(
- array_fill_keys( $this->config->get( 'ResourceLoaderLESSImportPaths' ), '' )
- );
+ $parser->ModifyVars( $vars );
+ $parser->SetImportDirs( [
+ "$IP/resources/src/mediawiki.less/" => '',
+ ] );
$parser->SetOption( 'relativeUrls', false );
return $parser;