Override extracting paramters in ext.templateData.data resource module

This commit is contained in:
Luqgreg 2018-08-28 14:39:01 +02:00
parent df30141d1f
commit 98d379c464

View file

@ -42,8 +42,33 @@
}
};
var TemplateDataSuggestions = {
init: function() {
var original = mw.TemplateData.SourceHandler.prototype.extractParametersFromTemplateCode;
mw.TemplateData.SourceHandler.prototype.extractParametersFromTemplateCode = function( templateCode ) {
var infobox, source,
params = original(templateCode),
infoboxRegex = /<infobox.*?<\/infobox>/gs,
sourceRegex = /<[^<\/>]*? source="([^"]*)"[^>]*>/g;
while( ( infobox = infoboxRegex.exec(templateCode) ) !== null ) {
while( ( source = sourceRegex.exec(infobox) ) !== null ) {
if ( $.inArray( source[1], params ) === -1 ) {
params.push( source[1] );
}
}
}
return params;
}
}
}
mw.hook('wikipage.content').add(function($content) {
MediaCollection.init($content);
CollapsibleGroup.init($content);
});
mw.loader.using('ext.templateDataGenerator.data').then(function() {
TemplateDataSuggestions.init();
});
})(window, jQuery);