mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateStyles
synced 2024-11-24 16:26:05 +00:00
Merge "Allow extensions to register additional namespaces in extension.json"
This commit is contained in:
commit
99705da7b4
|
@ -39,6 +39,9 @@
|
||||||
"Models": {
|
"Models": {
|
||||||
"sanitized-css": "css"
|
"sanitized-css": "css"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"TemplateStyles": {
|
||||||
|
"Namespaces": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"callback": "TemplateStylesHooks::onRegistration",
|
"callback": "TemplateStylesHooks::onRegistration",
|
||||||
|
|
|
@ -227,7 +227,15 @@ class TemplateStylesHooks {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function onContentHandlerDefaultModelFor( $title, &$model ) {
|
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()] ) &&
|
if ( !empty( $enabledNamespaces[$title->getNamespace()] ) &&
|
||||||
$title->isSubpage() && substr( $title->getText(), -4 ) === '.css'
|
$title->isSubpage() && substr( $title->getText(), -4 ) === '.css'
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -117,10 +117,27 @@ class TemplateStylesHooksTest extends MediaWikiLangTestCase {
|
||||||
*/
|
*/
|
||||||
public function testOnContentHandlerDefaultModelFor( $ns, $title, $expect ) {
|
public function testOnContentHandlerDefaultModelFor( $ns, $title, $expect ) {
|
||||||
$this->setMwGlobals( [
|
$this->setMwGlobals( [
|
||||||
'wgTemplateStylesNamespaces' => [ 10 => true, 2 => false, 3000 => true, 3002 => true ],
|
'wgTemplateStylesNamespaces' => [
|
||||||
'wgNamespacesWithSubpages' => [ 10 => true, 2 => true, 3000 => true, 3002 => false ],
|
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';
|
$model = 'unchanged';
|
||||||
$ret = TemplateStylesHooks::onContentHandlerDefaultModelFor(
|
$ret = TemplateStylesHooks::onContentHandlerDefaultModelFor(
|
||||||
Title::makeTitle( $ns, $title ), $model
|
Title::makeTitle( $ns, $title ), $model
|
||||||
|
@ -138,6 +155,8 @@ class TemplateStylesHooksTest extends MediaWikiLangTestCase {
|
||||||
[ 3000, 'Test/test.css', true ],
|
[ 3000, 'Test/test.css', true ],
|
||||||
[ 3002, 'Test/test.css', false ],
|
[ 3002, 'Test/test.css', false ],
|
||||||
[ 2, '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