mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CategoryTree
synced 2024-11-27 09:43:06 +00:00
Remove 'wgCategoryTreePageCategoryOptions' export from pageview HTML
This was internal to CategoryTree JS code and only needed on very few pages. Export it as part of the module that needs it, instead. Given this is computed and not a plain config var, use callback to generate the value. Bug: T219342 Change-Id: I790a98128b0a3317e27ac0d5fda08d48aeb640dc
This commit is contained in:
parent
904bba5eeb
commit
c839756b32
|
@ -2,7 +2,8 @@
|
|||
"root": true,
|
||||
"extends": "wikimedia",
|
||||
"env": {
|
||||
"browser": true
|
||||
"browser": true,
|
||||
"commonjs": true
|
||||
},
|
||||
"globals": {
|
||||
"mw": false,
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue