Merge "Allow extensions to register additional namespaces in extension.json"

This commit is contained in:
jenkins-bot 2019-01-14 22:12:28 +00:00 committed by Gerrit Code Review
commit 99705da7b4
3 changed files with 33 additions and 3 deletions

View file

@ -39,6 +39,9 @@
"Models": { "Models": {
"sanitized-css": "css" "sanitized-css": "css"
} }
},
"TemplateStyles": {
"Namespaces": []
} }
}, },
"callback": "TemplateStylesHooks::onRegistration", "callback": "TemplateStylesHooks::onRegistration",

View file

@ -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'
) { ) {

View file

@ -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 ],
]; ];
} }