mediawiki.messagePoster: Introduce 'MessagePosterModule' extension attribute
This allows extensions to add additional files or dependencies to the 'mediawiki.messagePoster' module bundle. Bug: T235315 Change-Id: I17c34cbb26e786328d3d99beb0c0fa65e15ea084
This commit is contained in:
parent
0c97997c34
commit
34bff221ba
6 changed files with 83 additions and 13 deletions
|
|
@ -415,6 +415,10 @@
|
|||
"type": "object",
|
||||
"description": "A ResourceLoaderFileModule definition registered only when wgEnableJavaScriptTest is true."
|
||||
},
|
||||
"MessagePosterModule": {
|
||||
"type": "object",
|
||||
"description": "Additional JavaScript files and modules that will register content models with mw.messagePoster.factory."
|
||||
},
|
||||
"ConfigRegistry": {
|
||||
"type": "object",
|
||||
"description": "Registry of factory functions to create Config objects"
|
||||
|
|
|
|||
|
|
@ -491,6 +491,31 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"MessagePosterModule": {
|
||||
"type": "object",
|
||||
"description": "Additional JavaScript files and modules that will register content models with mw.messagePoster.factory.",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"localBasePath": {
|
||||
"type": "string",
|
||||
"description": "Prefix for local paths to files in $options, relative to extenion directory"
|
||||
},
|
||||
"scripts": {
|
||||
"type": "array",
|
||||
"description": "Scripts to include as array of file paths",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"type": "array",
|
||||
"description": "Modules which must load before these files",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ConfigRegistry": {
|
||||
"type": "object",
|
||||
"description": "Registry of factory functions to create Config objects"
|
||||
|
|
|
|||
|
|
@ -693,6 +693,30 @@ return [
|
|||
$rl->register( $config->get( 'ResourceModules' ) );
|
||||
Hooks::run( 'ResourceLoaderRegisterModules', [ &$rl ] );
|
||||
|
||||
$extRegistry = ExtensionRegistry::getInstance();
|
||||
$msgPosterAttrib = $extRegistry->getAttribute( 'MessagePosterModule' );
|
||||
$rl->register( 'mediawiki.messagePoster', [
|
||||
'localBasePath' => '',
|
||||
'debugRaw' => false,
|
||||
'scripts' => array_merge(
|
||||
[
|
||||
"$IP/resources/src/mediawiki.messagePoster/factory.js",
|
||||
"$IP/resources/src/mediawiki.messagePoster/MessagePoster.js",
|
||||
"$IP/resources/src/mediawiki.messagePoster/WikitextMessagePoster.js",
|
||||
],
|
||||
$msgPosterAttrib['scripts'] ?? []
|
||||
),
|
||||
'dependencies' => array_merge(
|
||||
[
|
||||
'oojs',
|
||||
'mediawiki.api',
|
||||
'mediawiki.ForeignApi',
|
||||
],
|
||||
$msgPosterAttrib['dependencies'] ?? []
|
||||
),
|
||||
'targets' => [ 'desktop', 'mobile' ],
|
||||
] );
|
||||
|
||||
if ( $config->get( 'EnableJavaScriptTest' ) === true ) {
|
||||
$rl->registerTestModules();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ class ExtensionProcessor implements Processor {
|
|||
'ResourceModuleSkinStyles',
|
||||
'OOUIThemePaths',
|
||||
'QUnitTestModule',
|
||||
'MessagePosterModule',
|
||||
'ExtensionMessagesFiles',
|
||||
'MessagesDirs',
|
||||
'type',
|
||||
|
|
@ -481,6 +482,18 @@ class ExtensionProcessor implements Processor {
|
|||
}
|
||||
$this->attributes['QUnitTestModules']["test.{$info['name']}"] = $data;
|
||||
}
|
||||
|
||||
if ( isset( $info['MessagePosterModule'] ) ) {
|
||||
$data = $info['MessagePosterModule'];
|
||||
$basePath = $data['localBasePath'] ?? '';
|
||||
$baseDir = $basePath === '' ? $dir : "$dir/$basePath";
|
||||
foreach ( $data['scripts'] ?? [] as $scripts ) {
|
||||
$this->attributes['MessagePosterModule']['scripts'][] = "$baseDir/$scripts";
|
||||
}
|
||||
foreach ( $data['dependencies'] ?? [] as $dependency ) {
|
||||
$this->attributes['MessagePosterModule']['dependencies'][] = $dependency;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function extractExtensionMessagesFiles( $dir, array $info ) {
|
||||
|
|
|
|||
|
|
@ -963,19 +963,6 @@ return [
|
|||
],
|
||||
'targets' => [ 'desktop', 'mobile' ],
|
||||
],
|
||||
'mediawiki.messagePoster' => [
|
||||
'scripts' => [
|
||||
'resources/src/mediawiki.messagePoster/factory.js',
|
||||
'resources/src/mediawiki.messagePoster/MessagePoster.js',
|
||||
'resources/src/mediawiki.messagePoster/WikitextMessagePoster.js',
|
||||
],
|
||||
'dependencies' => [
|
||||
'oojs',
|
||||
'mediawiki.api',
|
||||
'mediawiki.ForeignApi',
|
||||
],
|
||||
'targets' => [ 'desktop', 'mobile' ],
|
||||
],
|
||||
'mediawiki.notification' => [
|
||||
'styles' => [
|
||||
'resources/src/mediawiki.notification/common.css',
|
||||
|
|
|
|||
|
|
@ -3,6 +3,23 @@
|
|||
* Factory for MessagePoster objects. This provides a pluggable to way to script the action
|
||||
* of adding a message to someone's talk page.
|
||||
*
|
||||
* Usage example:
|
||||
*
|
||||
* function MyExamplePoster() {}
|
||||
* OO.inheritClass( MyExamplePoster, mw.messagePoster.MessagePoster );
|
||||
*
|
||||
* mw.messagePoster.factory.register( 'mycontentmodel', MyExamplePoster );
|
||||
*
|
||||
* The JavaScript files(s) that register message posters for additional content
|
||||
* models must be registered with MediaWiki via the `MessagePosterModule`
|
||||
* extension attribute, like follows:
|
||||
*
|
||||
* "MessagePosterModule": {
|
||||
* "localBasePath": "", // (required)
|
||||
* "scripts": [], // relative file path(s) (required)
|
||||
* "dependencies": [], // module name(s) (optional)
|
||||
* }
|
||||
*
|
||||
* @class mw.messagePoster.factory
|
||||
* @singleton
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue