Manual:$wgResourceModules

From MediaWiki.org
Jump to navigation Jump to search
Other languages:
English • ‎français • ‎polski • ‎日本語 • ‎한국어
ResourceLoader: $wgResourceModules
Array of all extra defined modules that can later be loaded during the output.
Introduced in version:1.17.0 (r72349)
Removed in version:still in use
Allowed values:(multi-dimensional array)
Default value:[]

Examples[edit]

Here is a basic example for usage in an extension. You would put this in your extension.json file.

"ResourceModules": {
    "ext.myExtension.foo": {
        "scripts": "modules/ext.MyExtension.foo.js",
        "styles": [
            "modules/ext.MyExtension.foo.css",
            "modules/ext.MyExtension.bar.css"
        ],
        "messages": [
            "myextension-foo-label"
        ],
        "dependencies": [
            "jquery.cookie",
            "jquery.tabIndex"
        ]
    }
},
"ResourceFileModulePaths": {
    "localBasePath": "",
    "remoteExtPath": "MyExtension"
},

The above example will create a module called 'ext.MyExtension.foo', which includes the script /extensions/MyExtension/modules/myExtension.foo.js, the style /extensions/MyExtension/modules/myExtension.foo.css, and so on. It also ensures that two modules 'jquery.cookie' and 'jquery.tabIndex' are available before execution.


Details[edit]

By default modules are registered as an instance of ResourceLoaderFileModule. You find the according code in resources/Resources.php. Here is the documentation:

scripts
Scripts to always include.
File path string or array of file path strings.
languageScripts
Scripts to include in specific language contexts.
Array keyed by language code containing file path string or array of file path strings.
skinScripts
Scripts to include in specific skin contexts.
Array keyed by skin name containing file path string or array of file path strings.
debugScripts
Scripts to include in debug contexts.
File path string or array of file path strings.
dependencies
Modules which must be loaded before this module.
Module name string or array of module name strings.
styles
Styles to always include in the module.
File path string, or list of file path strings. The included file can be automatically wrapped in a @media query by specifying the file path as the key in an object, with the value specifying the media query. Examples below:
  'example' => [
    'styles' => 'foo.css'
  ],
  'example' => [
    'styles' => [
      'foo.css',
      'bar.css',
    ],
  ],
  'example.media' => [
    'styles' => [
      'foo.css' => [ 'media' => 'print' ],
    ],
  ],
  'example.mixed' => [
    'styles' => [
      'foo.css',
      'bar.css' => [ 'media' => 'print' ],
    ],
  ],
{
  "example": {
    "styles": [
      "foo.css",
      "bar.css"
    ]
  },
  "example.media": {
    "styles": {
      "foo.css": { "media": "print" }
    }
  },
  "example.mixed": {
    "styles": {
      "0": "foo.css",
      "bar.css": { "media": "print" }
    }
  },
}
skinStyles
Styles to include in specific skin contexts.
Array keyed by skin name containing file path string or array of file path strings.
messages
Messages to always load
Array of message key strings.
group
Group which this module should be loaded together with
Group name string.
See detailed documentation before using this.
class
Alternate subclass of ResourceLoader (rather than default ResourceLoaderFileModule). If this is used, some of the other properties may not apply, and you can specify your own arguments. Since MediaWiki 1.30, it may now specify a callback function as an alternative to a plain class name, using the factory key in the module description array. This allows dependency injection to be used for ResourceLoader modules.
Class name of alternate subclass
skipFunction
Function that returns true when the module should be skipped. Intended for when the module provides a polyfill that is not required in modern browsers
Filename of a JavaScript file with a top-level return (it should not be wrapped in a function)
localBasePath
Base path to prepend to all local paths in $options. Defaults to $IP .
Base path
remoteBasePath
Base path to prepend to all remote paths in $options. Defaults to $wgScriptPath.
Base path
remoteExtPath
Equivalent of remoteBasePath, but relative to $wgExtensionAssetsPath.
Base path

Loading module[edit]

See also ResourceLoader/Migration guide (developers)#Adding a module to the page :

$this->getOutput()->addModules( 'ext.myExtension' );

See also