mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateStyles
synced 2024-11-27 17:50:29 +00:00
Allow extensions to register additional namespaces in extension.json
Extensions can register additional namespaces by setting the "TemplateStylesNamespaces" attribte in their extension.json. This change is analogous to Ia5d34cb78fa6af. There isn't really a simpler way to do this here, as the config setting uses namespaces as keys, while the attribute is using them as values. Furthermore, keys with falsey values are ignored in the config setting, and attributes can't use the same setting architecture, as array_merge_recursive doesn't maintain numeric keys. Bug: T200914 Depends-On: I9e62a02ed2044c847e9ab2dcdfab094001f88986 Change-Id: I2fa9b822ee39bcc5f95a293c8c4aad4d53ede30a
This commit is contained in:
parent
c3b4da5cd1
commit
f121c39613
|
@ -39,6 +39,9 @@
|
|||
"Models": {
|
||||
"sanitized-css": "css"
|
||||
}
|
||||
},
|
||||
"TemplateStyles": {
|
||||
"Namespaces": []
|
||||
}
|
||||
},
|
||||
"callback": "TemplateStylesHooks::onRegistration",
|
||||
|
|
|
@ -227,7 +227,15 @@ class TemplateStylesHooks {
|
|||
* @return bool
|
||||
*/
|
||||
public static function onContentHandlerDefaultModelFor( $title, &$model ) {
|
||||
$enabledNamespaces = self::getConfig()->get( 'TemplateStylesNamespaces' );
|
||||
// Allow overwriting attributes with config settings.
|
||||
// Attributes can not use namespaces as keys, as processing them does not preserve
|
||||
// integer keys.
|
||||
$enabledNamespaces = self::getConfig()->get( 'TemplateStylesNamespaces' ) +
|
||||
array_fill_keys(
|
||||
ExtensionRegistry::getInstance()->getAttribute( 'TemplateStylesNamespaces' ),
|
||||
true
|
||||
);
|
||||
|
||||
if ( !empty( $enabledNamespaces[$title->getNamespace()] ) &&
|
||||
$title->isSubpage() && substr( $title->getText(), -4 ) === '.css'
|
||||
) {
|
||||
|
|
|
@ -117,10 +117,27 @@ class TemplateStylesHooksTest extends MediaWikiLangTestCase {
|
|||
*/
|
||||
public function testOnContentHandlerDefaultModelFor( $ns, $title, $expect ) {
|
||||
$this->setMwGlobals( [
|
||||
'wgTemplateStylesNamespaces' => [ 10 => true, 2 => false, 3000 => true, 3002 => true ],
|
||||
'wgNamespacesWithSubpages' => [ 10 => true, 2 => true, 3000 => true, 3002 => false ],
|
||||
'wgTemplateStylesNamespaces' => [
|
||||
10 => true,
|
||||
2 => false,
|
||||
3000 => true,
|
||||
3002 => true,
|
||||
3006 => false,
|
||||
],
|
||||
'wgNamespacesWithSubpages' => [
|
||||
10 => true,
|
||||
2 => true,
|
||||
3000 => true,
|
||||
3002 => false,
|
||||
3004 => true,
|
||||
3006 => true
|
||||
],
|
||||
] );
|
||||
|
||||
$reset = ExtensionRegistry::getInstance()->setAttributeForTest(
|
||||
'TemplateStylesNamespaces', [ 3004, 3006 ]
|
||||
);
|
||||
|
||||
$model = 'unchanged';
|
||||
$ret = TemplateStylesHooks::onContentHandlerDefaultModelFor(
|
||||
Title::makeTitle( $ns, $title ), $model
|
||||
|
@ -138,6 +155,8 @@ class TemplateStylesHooksTest extends MediaWikiLangTestCase {
|
|||
[ 3000, 'Test/test.css', true ],
|
||||
[ 3002, 'Test/test.css', false ],
|
||||
[ 2, 'Test/test.css', false ],
|
||||
[ 3004, 'Test/test.css', true ],
|
||||
[ 3006, 'Test/test.css', false ],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue