* https://www.mediawiki.org/wiki/ResourceLoader
*/
class ResourceLoader {
-
- /**
- * @var int
- */
+ /** @var int */
protected static $filterCacheVersion = 7;
- /**
- * @var array
- */
+
+ /** @var array */
protected static $requiredSourceProperties = array( 'loadScript' );
- /**
- * @var array Module name/ResourceLoaderModule object pairs
- */
+ /** @var array Module name/ResourceLoaderModule object pairs */
protected $modules = array();
- /**
- * @var array Associative array mapping module name to info associative array
- */
+ /** @var array Associative array mapping module name to info associative array */
protected $moduleInfos = array();
/**
*/
protected $testModuleNames = array();
- /**
- * @var array e.g. array( 'source-id' => array( 'loadScript' => 'http://.../load.php' ) )
- */
+ /** @var array e.g. array( 'source-id' => array( 'loadScript' => 'http://.../load.php' ) ) */
protected $sources = array();
- /**
- * @var bool
- */
+ /** @var bool */
protected $hasErrors = false;
/**
wfProfileIn( __METHOD__ );
// Add 'local' source first
- $this->addSource( 'local', array( 'loadScript' => $wgLoadScript, 'apiScript' => wfScript( 'api' ) ) );
+ $this->addSource(
+ 'local',
+ array( 'loadScript' => $wgLoadScript, 'apiScript' => wfScript( 'api' ) )
+ );
// Add other sources
$this->addSource( $wgResourceLoaderSources );
// Check $name for validity
if ( !self::isValidModuleName( $name ) ) {
wfProfileOut( __METHOD__ );
- throw new MWException( "ResourceLoader module name '$name' is invalid, see ResourceLoader::isValidModuleName()" );
+ throw new MWException( "ResourceLoader module name '$name' is invalid, "
+ . "see ResourceLoader::isValidModuleName()" );
}
// Attach module
global $IP, $wgEnableJavaScriptTest;
if ( $wgEnableJavaScriptTest !== true ) {
- throw new MWException( 'Attempt to register JavaScript test modules but <code>$wgEnableJavaScriptTest</code> is false. Edit your <code>LocalSettings.php</code> to enable it.' );
+ throw new MWException( 'Attempt to register JavaScript test modules '
+ . 'but <code>$wgEnableJavaScriptTest</code> is false. '
+ . 'Edit your <code>LocalSettings.php</code> to enable it.' );
}
wfProfileIn( __METHOD__ );
$module['dependencies'][] = 'test.mediawiki.qunit.testrunner';
}
- $testModules['qunit'] = ( include "$IP/tests/qunit/QUnitTestResources.php" ) + $testModules['qunit'];
+ $testModules['qunit'] =
+ ( include "$IP/tests/qunit/QUnitTestResources.php" ) + $testModules['qunit'];
foreach ( $testModules as $id => $names ) {
// Register test modules
* @return array
*/
public function getTestModuleNames( $framework = 'all' ) {
- /// @todo api siteinfo prop testmodulenames modulenames
+ /** @todo api siteinfo prop testmodulenames modulenames */
if ( $framework == 'all' ) {
return $this->testModuleNames;
- } elseif ( isset( $this->testModuleNames[$framework] ) && is_array( $this->testModuleNames[$framework] ) ) {
+ } elseif ( isset( $this->testModuleNames[$framework] )
+ && is_array( $this->testModuleNames[$framework] )
+ ) {
return $this->testModuleNames[$framework];
} else {
return array();
$blobs = MessageBlobStore::get( $this, $modules, $context->getLanguage() );
} catch ( Exception $e ) {
MWExceptionHandler::logException( $e );
- wfDebugLog( 'resourceloader', __METHOD__ . ": pre-fetching blobs from MessageBlobStore failed: $e" );
+ wfDebugLog(
+ 'resourceloader',
+ __METHOD__ . ": pre-fetching blobs from MessageBlobStore failed: $e"
+ );
$this->hasErrors = true;
// Add exception to the output as a comment
$exceptions .= self::formatException( $e );
$scripts = $module->getScriptURLsForDebug( $context );
} else {
$scripts = $module->getScript( $context );
- // rtrim() because there are usually a few line breaks after the last ';'.
- // A new line at EOF, a new line added by ResourceLoaderFileModule::readScriptFiles, etc.
- if ( is_string( $scripts ) && strlen( $scripts ) && substr( rtrim( $scripts ), -1 ) !== ';' ) {
+ // rtrim() because there are usually a few line breaks
+ // after the last ';'. A new line at EOF, a new line
+ // added by ResourceLoaderFileModule::readScriptFiles, etc.
+ if ( is_string( $scripts )
+ && strlen( $scripts )
+ && substr( rtrim( $scripts ), -1 ) !== ';'
+ ) {
// Append semicolon to prevent weird bugs caused by files not
// terminating their statements right (bug 27054)
$scripts .= ";\n";
* @param string $script JavaScript code
* @return string
*/
- public static function makeCustomLoaderScript( $name, $version, $dependencies, $group, $source, $script ) {
+ public static function makeCustomLoaderScript( $name, $version, $dependencies,
+ $group, $source, $script
+ ) {
$script = str_replace( "\n", "\n\t", trim( $script ) );
return Xml::encodeJsCall(
"( function ( name, version, dependencies, group, source ) {\n\t$script\n} )",
* @param array $extraQuery Extra query parameters to add
* @return string URL to load.php. May be protocol-relative (if $wgLoadScript is procol-relative)
*/
- public static function makeLoaderURL( $modules, $lang, $skin, $user = null, $version = null, $debug = false, $only = null,
- $printable = false, $handheld = false, $extraQuery = array() ) {
+ public static function makeLoaderURL( $modules, $lang, $skin, $user = null,
+ $version = null, $debug = false, $only = null, $printable = false,
+ $handheld = false, $extraQuery = array()
+ ) {
global $wgLoadScript;
+
$query = self::makeLoaderQuery( $modules, $lang, $skin, $user, $version, $debug,
$only, $printable, $handheld, $extraQuery
);
*
* @return array
*/
- public static function makeLoaderQuery( $modules, $lang, $skin, $user = null, $version = null, $debug = false, $only = null,
- $printable = false, $handheld = false, $extraQuery = array() ) {
+ public static function makeLoaderQuery( $modules, $lang, $skin, $user = null,
+ $version = null, $debug = false, $only = null, $printable = false,
+ $handheld = false, $extraQuery = array()
+ ) {
$query = array(
'modules' => self::makePackedModulesString( $modules ),
'lang' => $lang,
* ResourceLoader module based on local JavaScript/CSS files.
*/
class ResourceLoaderFileModule extends ResourceLoaderModule {
-
/* Protected Members */
/** @var string Local base path, see __construct() */
protected $localBasePath = '';
+
/** @var string Remote base path, see __construct() */
protected $remoteBasePath = '';
+
/**
* @var array List of paths to JavaScript files to always include
* @par Usage:
* @endcode
*/
protected $scripts = array();
+
/**
* @var array List of JavaScript files to include when using a specific language
* @par Usage:
* @endcode
*/
protected $languageScripts = array();
+
/**
* @var array List of JavaScript files to include when using a specific skin
* @par Usage:
* @endcode
*/
protected $skinScripts = array();
+
/**
* @var array List of paths to JavaScript files to include in debug mode
* @par Usage:
* @endcode
*/
protected $debugScripts = array();
+
/**
* @var array List of paths to JavaScript files to include in the startup module
* @par Usage:
* @endcode
*/
protected $loaderScripts = array();
+
/**
* @var array List of paths to CSS files to always include
* @par Usage:
* @endcode
*/
protected $styles = array();
+
/**
* @var array List of paths to CSS files to include when using specific skins
* @par Usage:
* @endcode
*/
protected $skinStyles = array();
+
/**
* @var array List of modules this module depends on
* @par Usage:
* @endcode
*/
protected $dependencies = array();
+
/**
* @var array List of message keys used by this module
* @par Usage:
* @endcode
*/
protected $messages = array();
+
/** @var string Name of group to load this module in */
protected $group;
+
/** @var string Position on the page to load this module at */
protected $position = 'bottom';
+
/** @var bool Link to raw files in debug mode */
protected $debugRaw = true;
+
/** @var bool Whether mw.loader.state() call should be omitted */
protected $raw = false;
+
protected $targets = array( 'desktop' );
/**
* @endcode
*/
protected $modifiedTime = array();
+
/**
* @var array Place where readStyleFile() tracks file dependencies
* @par Usage:
$result = $compiler->cachedCompile( $source );
if ( !is_array( $result ) ) {
- throw new MWException( 'LESS compiler result has type ' . gettype( $result ) . '; array expected.' );
+ throw new MWException( 'LESS compiler result has type '
+ . gettype( $result ) . '; array expected.' );
}
$this->localFileRefs += array_keys( $result['files'] );