/** @var int */
protected static $filterCacheVersion = 7;
- /** @var array */
- protected static $requiredSourceProperties = array( 'loadScript' );
-
/** @var bool */
protected static $debugMode = null;
*/
protected $testModuleNames = array();
- /** @var array E.g. array( 'source-id' => array( 'loadScript' => 'http://.../load.php' ) ) */
+ /** @var array E.g. array( 'source-id' => 'http://.../load.php' ) */
protected $sources = array();
/** @var bool */
$this->config = $config;
// Add 'local' source first
- $this->addSource(
- 'local',
- array( 'loadScript' => wfScript( 'load' ), 'apiScript' => wfScript( 'api' ) )
- );
+ $this->addSource( 'local', wfScript( 'load' ) );
// Add other sources
$this->addSource( $config->get( 'ResourceLoaderSources' ) );
/**
* Add a foreign source of modules.
*
- * Source properties:
- * 'loadScript': URL (either fully-qualified or protocol-relative) of load.php for this source
- *
- * @param mixed $id Source ID (string), or array( id1 => props1, id2 => props2, ... )
- * @param array $properties Source properties
+ * @param array|string $id Source ID (string), or array( id1 => loadUrl, id2 => loadUrl, ... )
+ * @param string|array $loadUrl load.php url (string), or array with loadUrl key for
+ * backwards-compatability.
* @throws MWException
*/
- public function addSource( $id, $properties = null ) {
+ public function addSource( $id, $loadUrl = null ) {
// Allow multiple sources to be registered in one call
if ( is_array( $id ) ) {
foreach ( $id as $key => $value ) {
);
}
- // Validate properties
- foreach ( self::$requiredSourceProperties as $prop ) {
- if ( !isset( $properties[$prop] ) ) {
- throw new MWException( "Required property $prop missing from source ID $id" );
+ // Pre 1.24 backwards-compatability
+ if ( is_array( $loadUrl ) ) {
+ if ( !isset( $loadUrl['loadScript'] ) ) {
+ throw new MWException(
+ __METHOD__ . ' was passed an array with no "loadScript" key.'
+ );
}
+
+ $loadUrl = $loadUrl['loadScript'];
}
- $this->sources[$id] = $properties;
+ $this->sources[$id] = $loadUrl;
}
/**
/**
* Get the list of sources.
*
- * @return array Like array( id => array of properties, .. )
+ * @return array Like array( id => load.php url, .. )
*/
public function getSources() {
return $this->sources;
if ( !isset( $this->sources[$source] ) ) {
throw new MWException( "The $source source was never registered in ResourceLoader." );
}
- return $this->sources[$source]['loadScript'];
+ return $this->sources[$source];
}
/**
// Pre-fetch blobs
if ( $context->shouldIncludeMessages() ) {
try {
- $blobs = MessageBlobStore::get( $this, $modules, $context->getLanguage() );
+ $blobs = MessageBlobStore::getInstance()->get( $this, $modules, $context->getLanguage() );
} catch ( Exception $e ) {
MWExceptionHandler::logException( $e );
wfDebugLog(
$out .= self::makeLoaderStateScript( $states );
}
- // In only=script requests for modules that are not raw (e.g. not the startup module)
- // ensure the execution is conditional to avoid situations where browsers with an
- // unsupported environment do unconditionally execute a module's scripts. Otherwise users
- // will get things like "ReferenceError: mw is undefined" or "jQuery is undefined" from
- // legacy scripts loaded with only=scripts (such as the 'site' module).
- $out = self::makeLoaderConditionalScript( $out );
+ if ( $context->getOnly() === 'scripts' ) {
+ // In only=script requests for modules that are not raw (e.g. not the startup module)
+ // ensure the execution is conditional to avoid situations where browsers with an
+ // unsupported environment do unconditionally execute a module's scripts. Otherwise users
+ // will get things like "ReferenceError: mw is undefined" or "jQuery is undefined" from
+ // legacy scripts loaded with only=scripts (such as the 'site' module).
+ $out = self::makeLoaderConditionalScript( $out );
+ }
} else {
if ( count( $states ) ) {
$exceptions .= self::makeComment(
* Returns JS code which calls mw.loader.register with the given
* parameters. Has three calling conventions:
*
- * - ResourceLoader::makeLoaderRegisterScript( $name, $version, $dependencies, $group, $source, $skip ):
- * Register a single module.
+ * - ResourceLoader::makeLoaderRegisterScript( $name, $version,
+ * $dependencies, $group, $source, $skip
+ * ):
+ * Register a single module.
*
* - ResourceLoader::makeLoaderRegisterScript( array( $name1, $name2 ) ):
- * Register modules with the given names.
+ * Register modules with the given names.
*
* - ResourceLoader::makeLoaderRegisterScript( array(
* array( $name1, $version1, $dependencies1, $group1, $source1, $skip1 ),
* - ResourceLoader::makeLoaderSourcesScript( $id, $properties ):
* Register a single source
*
- * - ResourceLoader::makeLoaderSourcesScript( array( $id1 => $props1, $id2 => $props2, ... ) );
+ * - ResourceLoader::makeLoaderSourcesScript( array( $id1 => $loadUrl, $id2 => $loadUrl, ... ) );
* Register sources with the given IDs and properties.
*
* @param string $id Source ID
$less = new lessc();
$less->setPreserveComments( true );
- $less->setVariables( self::getLESSVars( $config ) );
+ $less->setVariables( self::getLessVars( $config ) );
$less->setImportDir( $config->get( 'ResourceLoaderLESSImportPaths' ) );
foreach ( $config->get( 'ResourceLoaderLESSFunctions' ) as $name => $func ) {
$less->registerFunction( $name, $func );
* @since 1.22
* @return array Map of variable names to string CSS values.
*/
- public static function getLESSVars( Config $config ) {
+ public static function getLessVars( Config $config ) {
$lessVars = $config->get( 'ResourceLoaderLESSVars' );
// Sort by key to ensure consistent hashing for cache lookups.
ksort( $lessVars );