mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CategoryTree
synced 2024-11-27 17:51:00 +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,
|
"root": true,
|
||||||
"extends": "wikimedia",
|
"extends": "wikimedia",
|
||||||
"env": {
|
"env": {
|
||||||
"browser": true
|
"browser": true,
|
||||||
|
"commonjs": true
|
||||||
},
|
},
|
||||||
"globals": {
|
"globals": {
|
||||||
"mw": false,
|
"mw": false,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
"license-name": "GPL-2.0-or-later",
|
"license-name": "GPL-2.0-or-later",
|
||||||
"type": "parserhook",
|
"type": "parserhook",
|
||||||
"requires": {
|
"requires": {
|
||||||
"MediaWiki": ">= 1.29.0"
|
"MediaWiki": ">= 1.33.0"
|
||||||
},
|
},
|
||||||
"ConfigRegistry": {
|
"ConfigRegistry": {
|
||||||
"categorytree": "GlobalVarConfig::newInstance"
|
"categorytree": "GlobalVarConfig::newInstance"
|
||||||
|
@ -41,8 +41,16 @@
|
||||||
},
|
},
|
||||||
"ResourceModules": {
|
"ResourceModules": {
|
||||||
"ext.categoryTree": {
|
"ext.categoryTree": {
|
||||||
"scripts": "ext.categoryTree/ext.categoryTree.js",
|
"localBasePath": "modules/ext.categoryTree",
|
||||||
"styles": "ext.categoryTree/ext.categoryTree.css",
|
"remoteExtPath": "CategoryTree/modules/ext.categoryTree",
|
||||||
|
"styles": "ext.categoryTree.css",
|
||||||
|
"packageFiles": [
|
||||||
|
"ext.categoryTree.js",
|
||||||
|
{
|
||||||
|
"name": "data.json",
|
||||||
|
"callback": "CategoryTreeHooks::getDataForJs"
|
||||||
|
}
|
||||||
|
],
|
||||||
"targets": [
|
"targets": [
|
||||||
"desktop",
|
"desktop",
|
||||||
"mobile"
|
"mobile"
|
||||||
|
@ -78,17 +86,10 @@
|
||||||
"remoteExtPath": "CategoryTree/modules"
|
"remoteExtPath": "CategoryTree/modules"
|
||||||
},
|
},
|
||||||
"Hooks": {
|
"Hooks": {
|
||||||
"ArticleFromTitle": [
|
"ArticleFromTitle": "CategoryTreeHooks::articleFromTitle",
|
||||||
"CategoryTreeHooks::articleFromTitle"
|
"SpecialTrackingCategories::preprocess": "CategoryTreeHooks::onSpecialTrackingCategoriesPreprocess",
|
||||||
],
|
"SpecialTrackingCategories::generateCatLink": "CategoryTreeHooks::onSpecialTrackingCategoriesGenerateCatLink",
|
||||||
"SpecialTrackingCategories::preprocess": [
|
|
||||||
"CategoryTreeHooks::onSpecialTrackingCategoriesPreprocess"
|
|
||||||
],
|
|
||||||
"SpecialTrackingCategories::generateCatLink": [
|
|
||||||
"CategoryTreeHooks::onSpecialTrackingCategoriesGenerateCatLink"
|
|
||||||
],
|
|
||||||
"SkinBuildSidebar": "CategoryTreeHooks::onSkinBuildSidebar",
|
"SkinBuildSidebar": "CategoryTreeHooks::onSkinBuildSidebar",
|
||||||
"MakeGlobalVariablesScript": "CategoryTreeHooks::getConfigVars",
|
|
||||||
"ParserFirstCallInit": "CategoryTreeHooks::setHooks",
|
"ParserFirstCallInit": "CategoryTreeHooks::setHooks",
|
||||||
"OutputPageMakeCategoryLinks": "CategoryTreeHooks::outputPageMakeCategoryLinks",
|
"OutputPageMakeCategoryLinks": "CategoryTreeHooks::outputPageMakeCategoryLinks",
|
||||||
"BeforePageDisplay": "CategoryTreeHooks::addHeaders",
|
"BeforePageDisplay": "CategoryTreeHooks::addHeaders",
|
||||||
|
|
|
@ -245,15 +245,20 @@ class CategoryTreeHooks {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MakeGlobalVariablesScript hook
|
* Get exported data for the "ext.categoryTree" ResourceLoader module.
|
||||||
* @param array &$vars
|
*
|
||||||
|
* @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;
|
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 );
|
$ct = new CategoryTree( $wgCategoryTreeCategoryPageOptions );
|
||||||
$vars['wgCategoryTreePageCategoryOptions'] = $ct->getOptionsAsJsStructure();
|
|
||||||
|
return [
|
||||||
|
'defaultCtOptions' => $ct->getOptionsAsJsStructure(),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
( function () {
|
( function () {
|
||||||
var loadChildren;
|
var loadChildren,
|
||||||
|
data = require( './data.json' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expands a given node (loading it's children if not loaded)
|
* Expands a given node (loading it's children if not loaded)
|
||||||
|
@ -144,10 +145,7 @@
|
||||||
ctTitle = $link.attr( 'data-ct-title' );
|
ctTitle = $link.attr( 'data-ct-title' );
|
||||||
ctMode = $linkParentCTTag.data( 'ct-mode' );
|
ctMode = $linkParentCTTag.data( 'ct-mode' );
|
||||||
ctMode = typeof ctMode === 'number' ? ctMode : undefined;
|
ctMode = typeof ctMode === 'number' ? ctMode : undefined;
|
||||||
ctOptions = $linkParentCTTag.attr( 'data-ct-options' );
|
ctOptions = $linkParentCTTag.attr( 'data-ct-options' ) || data.defaultCtOptions;
|
||||||
if ( !ctOptions ) {
|
|
||||||
ctOptions = mw.config.get( 'wgCategoryTreePageCategoryOptions' );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mode and options have defaults or fallbacks, title does not.
|
// Mode and options have defaults or fallbacks, title does not.
|
||||||
// Don't make a request if there is no title.
|
// Don't make a request if there is no title.
|
||||||
|
|
Loading…
Reference in a new issue