mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-13 18:36:54 +00:00
Separate sources extractor and add it to ext.templateDataGenerator.data
This commit is contained in:
parent
98d379c464
commit
0a6b0f9c70
|
@ -94,7 +94,8 @@
|
|||
"wgQueryPages": "PortableInfoboxHooks::onWgQueryPages",
|
||||
"AllInfoboxesQueryRecached": "PortableInfoboxHooks::onAllInfoboxesQueryRecached",
|
||||
"ArticlePurge": "PortableInfoboxHooks::onArticlePurge",
|
||||
"PageContentSave": "PortableInfoboxHooks::onPageContentSave"
|
||||
"PageContentSave": "PortableInfoboxHooks::onPageContentSave",
|
||||
"ResourceLoaderRegisterModules": "PortableInfoboxHooks::onResourceLoaderRegisterModules"
|
||||
},
|
||||
"SpecialPages": {
|
||||
"AllInfoboxes": "AllinfoboxesQueryPage"
|
||||
|
|
|
@ -49,4 +49,20 @@ class PortableInfoboxHooks {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function onResourceLoaderRegisterModules( ResourceLoader &$resourceLoader ) {
|
||||
global $wgResourceModules;
|
||||
|
||||
if( isset( $wgResourceModules['ext.templateDataGenerator.data'] ) ) {
|
||||
$wgResourceModules['ext.templateDataGenerator.data']['scripts'][] =
|
||||
'../PortableInfobox/resources/PortableInfoboxParams.js';
|
||||
|
||||
$resourceLoader->register(
|
||||
'ext.templateDataGenerator.data',
|
||||
$wgResourceModules['ext.templateDataGenerator.data']
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,33 +42,8 @@
|
|||
}
|
||||
};
|
||||
|
||||
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);
|
||||
|
|
29
resources/PortableInfoboxParams.js
Normal file
29
resources/PortableInfoboxParams.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
(function (window) {
|
||||
'use strict';
|
||||
|
||||
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.loader.using('ext.templateDataGenerator.data').then(function() {
|
||||
TemplateDataSuggestions.init();
|
||||
});
|
||||
})(window);
|
Loading…
Reference in a new issue