diff --git a/.eslintrc.json b/.eslintrc.json index 1a49e0ab..6cd5dc3f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,7 +2,8 @@ "root": true, "extends": "wikimedia", "env": { - "browser": true + "browser": true, + "commonjs": true }, "globals": { "mw": false, diff --git a/extension.json b/extension.json index a538ee45..9ba21c22 100644 --- a/extension.json +++ b/extension.json @@ -6,7 +6,7 @@ "license-name": "GPL-2.0-or-later", "type": "parserhook", "requires": { - "MediaWiki": ">= 1.29.0" + "MediaWiki": ">= 1.33.0" }, "ConfigRegistry": { "categorytree": "GlobalVarConfig::newInstance" @@ -41,8 +41,16 @@ }, "ResourceModules": { "ext.categoryTree": { - "scripts": "ext.categoryTree/ext.categoryTree.js", - "styles": "ext.categoryTree/ext.categoryTree.css", + "localBasePath": "modules/ext.categoryTree", + "remoteExtPath": "CategoryTree/modules/ext.categoryTree", + "styles": "ext.categoryTree.css", + "packageFiles": [ + "ext.categoryTree.js", + { + "name": "data.json", + "callback": "CategoryTreeHooks::getDataForJs" + } + ], "targets": [ "desktop", "mobile" @@ -78,17 +86,10 @@ "remoteExtPath": "CategoryTree/modules" }, "Hooks": { - "ArticleFromTitle": [ - "CategoryTreeHooks::articleFromTitle" - ], - "SpecialTrackingCategories::preprocess": [ - "CategoryTreeHooks::onSpecialTrackingCategoriesPreprocess" - ], - "SpecialTrackingCategories::generateCatLink": [ - "CategoryTreeHooks::onSpecialTrackingCategoriesGenerateCatLink" - ], + "ArticleFromTitle": "CategoryTreeHooks::articleFromTitle", + "SpecialTrackingCategories::preprocess": "CategoryTreeHooks::onSpecialTrackingCategoriesPreprocess", + "SpecialTrackingCategories::generateCatLink": "CategoryTreeHooks::onSpecialTrackingCategoriesGenerateCatLink", "SkinBuildSidebar": "CategoryTreeHooks::onSkinBuildSidebar", - "MakeGlobalVariablesScript": "CategoryTreeHooks::getConfigVars", "ParserFirstCallInit": "CategoryTreeHooks::setHooks", "OutputPageMakeCategoryLinks": "CategoryTreeHooks::outputPageMakeCategoryLinks", "BeforePageDisplay": "CategoryTreeHooks::addHeaders", diff --git a/includes/CategoryTreeHooks.php b/includes/CategoryTreeHooks.php index e6e1ed5d..9d777801 100644 --- a/includes/CategoryTreeHooks.php +++ b/includes/CategoryTreeHooks.php @@ -245,15 +245,20 @@ class CategoryTreeHooks { } /** - * MakeGlobalVariablesScript hook - * @param array &$vars + * Get exported data for the "ext.categoryTree" ResourceLoader module. + * + * @internal For use in extension.json only. + * @return array Data to be serialised as data.json */ - public static function getConfigVars( array &$vars ) { + public static function getDataForJs() { global $wgCategoryTreeCategoryPageOptions; - // Look this is pretty bad but Category tree is just whacky, it needs to be rewritten + // Look, this is pretty bad but CategoryTree is just whacky, it needs to be rewritten $ct = new CategoryTree( $wgCategoryTreeCategoryPageOptions ); - $vars['wgCategoryTreePageCategoryOptions'] = $ct->getOptionsAsJsStructure(); + + return [ + 'defaultCtOptions' => $ct->getOptionsAsJsStructure(), + ]; } /** diff --git a/modules/ext.categoryTree/ext.categoryTree.js b/modules/ext.categoryTree/ext.categoryTree.js index 91e0b69d..537c5804 100644 --- a/modules/ext.categoryTree/ext.categoryTree.js +++ b/modules/ext.categoryTree/ext.categoryTree.js @@ -24,7 +24,8 @@ */ ( function () { - var loadChildren; + var loadChildren, + data = require( './data.json' ); /** * Expands a given node (loading it's children if not loaded) @@ -144,10 +145,7 @@ ctTitle = $link.attr( 'data-ct-title' ); ctMode = $linkParentCTTag.data( 'ct-mode' ); ctMode = typeof ctMode === 'number' ? ctMode : undefined; - ctOptions = $linkParentCTTag.attr( 'data-ct-options' ); - if ( !ctOptions ) { - ctOptions = mw.config.get( 'wgCategoryTreePageCategoryOptions' ); - } + ctOptions = $linkParentCTTag.attr( 'data-ct-options' ) || data.defaultCtOptions; // Mode and options have defaults or fallbacks, title does not. // Don't make a request if there is no title.