User:Erutuon/scripts/GadgetsDefinitionParser.js

// Could use this in the gadgets-definition script to grab list of dependencies // and then generate an explanation of how to copy the gadget to your userspace // and make changes, with mw.loader.using(dependencies, function { /* gadget text here */ }); // or mw.loader.using(dependencies, function { importScript("the userspace page where you put your copy of the gadget"); });. new mw.Api .get({		"action": "expandtemplates",		"title": "MediaWiki:Gadgets-definition",		"prop": "wikitext",		"text": ""	}) .then(obj => obj.expandtemplates.wikitext		.split("\n")		.filter(line => line.startsWith("*"))		.map(line => { const splitTrim = (list, sep) => list.split(sep).map(s => s.trim); const [name, rest] = splitTrim(line.replace(/^\*\s*/, ""), "["); const [options, pages] = splitTrim(rest, "]"); const optionObj = {}; for (const option of splitTrim(options, "|")) { const keyValue = splitTrim(option, "="); const value = keyValue[1]; if (value) { const key = keyValue[0]; // See mw:Extension:Gadgets. // "type" and "supportsUrlLoad" have single values, // while others have an array with comma separators. optionObj[key] = key === "type" || key === "supportsUrlLoad" ? value : splitTrim(value); } else { optionObj[keyValue[0]] = true; }			}			return { name, options: optionObj, pages: pages.split("|").filter(page => page.trim !== "").map(page => "MediaWiki:Gadget-" + page) };		}))		// .then(console.log).fail(console.error) ;