User:Alexis Jazz/Factotum/MakeCitemap.js
Appearance
< User:Alexis Jazz | Factotum
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Alexis Jazz/Factotum/MakeCitemap. |
//MakeCitemap, irrevocably released as WTFPL Version 2[www.wtfpl.net/about/] by its author, Alexis Jazz
//Creates a Citemap.json for Bawl to use when inserting a reference with Web2Cit. See [[WP:Citemap.json]] and [[d:Q112131235]]
Bawl.openReplyForm(Bawl.replyLinkParamsFP);
Bawl.aceMirrorDisable();
var api = new mw.Api();
Bawl.newCitePostFix = {
de:'/Doku',
fr:'/Documentation',
};
api.post({action:'query',prop:'revisions',format:'json',titles:'MediaWiki:Citoid-template-type-map.json',rvprop:'content',rvslots:'*'}).then(function(data){
console.log('got MediaWiki:Citoid-template-type-map.json');
Bawl.newCitemap = {};
Bawl.newCitemap.templateTypeMap = JSON.parse(data.query.pages[Object.keys(data.query.pages)[0]].revisions[0].slots.main['*']);
Bawl.newCitemap.templateParamMap = {};
Bawl.citoidTemplates = Object.values(Bawl.newCitemap.templateTypeMap);
Bawl.citoidTemplatesArr = [];
Bawl.templateDataSucks = function(title) {
if ( ['en','sq'].includes(mw.config.get('wgContentLanguage')) && Bawl.citoidTemplates[Bawl.citoidInt] == 'Cite book' ) {
return '/TemplateData'; //EVERY TIME YOU USE AN INCONSISTENT TITLE GOD KILLS A KITTEN.
} else {
return (Bawl.newCitePostFix[mw.config.get('wgContentLanguage')] || '/doc' ); //PLEASE THINK OF THE KITTENS.
}
};
for ( Bawl.citoidInt=0;Bawl.citoidInt<Bawl.citoidTemplates.length;Bawl.citoidInt++) {
Bawl.templateDocName = 'Template:'+Bawl.citoidTemplates[Bawl.citoidInt]+Bawl.templateDataSucks(Bawl.citoidTemplates[Bawl.citoidInt]);
if ( ! Bawl.citoidTemplatesArr.includes(Bawl.templateDocName) ) {
console.log('add '+Bawl.templateDocName);
Bawl.citoidTemplatesArr.push(Bawl.templateDocName);
}
}
api.post({action:'query',prop:'revisions',format:'json',titles:Bawl.citoidTemplatesArr,rvprop:'content',rvslots:'*'}).then(function(data){
Bawl.templatesMapData = data; //for debugging
for ( Bawl.citoidInt=0;Bawl.citoidInt<Bawl.citoidTemplatesArr.length;Bawl.citoidInt++) {
if ( Object.keys(Bawl.templatesMapData.query.pages)[Bawl.citoidInt] == -1 ) {
console.log('no doc page');
continue;
}
console.log('process '+Object.keys(Bawl.templatesMapData.query.pages)[Bawl.citoidInt]);
Bawl.someTemplateRevData = data.query.pages[Object.keys(data.query.pages)[Bawl.citoidInt]];
Bawl.someTemplateJSONString = Bawl.someTemplateRevData.revisions[0].slots.main['*'].replace(/[^]*"citoid":[ \t]*\{([^\}]*)\}[^]*/,'{$1}');
console.log('JSON: '+Bawl.someTemplateJSONString);
Bawl.someTemplateMap = JSON.parse(Bawl.someTemplateJSONString);
Bawl.someTemplateTitle = data.query.pages[Object.keys(data.query.pages)[Bawl.citoidInt]].title.replace(/.*:/,'').replace(Bawl.templateDataSucks(data.query.pages[Object.keys(data.query.pages)[Bawl.citoidInt]].title.replace(/.*:/,'')),'');
Bawl.newCitemap[Bawl.someTemplateTitle+'params'] = Bawl.someTemplateMap;
Bawl.newCitemap.templateParamMap[Bawl.someTemplateTitle] = Bawl.someTemplateTitle+'params';
}
Bawl.UITextInput.setValue(JSON.stringify(Bawl.newCitemap));
});
});