Участник:Jack who built the house/moduleListExtract.js

/**
 * Скрипт для использования в консоли. Выводит в удобном виде список доступных модулей MediaWiki, 
 * разделяя их по группам так, как их делит сам движок (механизм частично взят оттуда).
 */

var module, moduleList = [];
for (var key in mw.loader.moduleRegistry) {
	module = mw.loader.moduleRegistry[key];
	if (module.state === 'ready') {
		moduleList.push(key);
	}
}

var splits, b, bSource, bGroup, bSourceGroup, source, group, i, modules, moduleMap, lastDotIndex, prefix, suffix, lastSource;
var registry = mw.loader.moduleRegistry;
var hasOwn = ({}).hasOwnProperty;
var modulesString = '';

function buildModulesString(moduleMap, source, group) {
	console.log(moduleMap)
	var p, prefix, arr = [];
	for (prefix in moduleMap) {
		p = prefix === '' ? '' : prefix + '.';
		arr.push(p + moduleMap[prefix].join(', '));
	}
	modulesString = modulesString + (lastSource !== source ? '\'\'\'' + source + '\'\'\'\n' : '') +
		(group !== 'null' ? '\'\'' + group + '\'\'\n' : '') + arr.join('\n') + '\n\n';
	lastSource = source;
}

moduleList.sort();
splits = {};
for (b = 0; b < moduleList.length; b++) {
	bSource = registry[moduleList[b]].source;
	bGroup = registry[moduleList[b]].group;
	if (!hasOwn.call(splits, bSource)) {
		splits[bSource] = {};
	}
	if (!hasOwn.call(splits[bSource], bGroup)) {
		splits[bSource][bGroup] = [];
	}
	bSourceGroup = splits[bSource][bGroup];
	bSourceGroup.push(moduleList[b]);
}
for (source in splits) {
	for (group in splits[source]) {
		modules = splits[source][group];
		moduleMap = {};
		for (i = 0; i < modules.length; i++) {
			lastDotIndex = modules[i].lastIndexOf('.');
			prefix = modules[i].substr(0, lastDotIndex);
			suffix = modules[i].slice(lastDotIndex + 1);
			if (!hasOwn.call(moduleMap, prefix)) {
				moduleMap[prefix] = [];
			}
			moduleMap[prefix].push(suffix);
		}
		if (!$.isEmptyObject(moduleMap)) {
			buildModulesString(moduleMap, source, group);
		}
	}
}

console.log(modulesString);
Prefix: a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9

Portal di Ensiklopedia Dunia

Kembali kehalaman sebelumnya