User:Zackmann08/scripts/GenerateTable.js
//<nowiki>
jQuery(document).ready(function($) {
if(mw.config.get('wgPageName').toLowerCase().includes('sandbox') && mw.config.get('wgNamespaceNumber') != 0 && document.getElementsByName('wpTextbox1')[0]) {
mw.loader.using(['mediawiki.util']).done( function() {
var portletlink = mw.util.addPortletLink('p-tb','#','GenDepTable','t-gentdeptable');
$(portletlink).click(function(e) {
e.preventDefault();
generateDepTable();
});
});
}
// -------------------------------------------------------------------------------- //
function generateDepTable()
{
var mycontent = $('#wpTextbox1').textSelection('getContents');
// Copy the contents of the text window so we can modify it without problems
var original_text = mycontent;
const params_regex = /\{\{#invoke\:Check for deprecated parameters\|check([\s\S]*)\}\}<noinclude>/i;
var param_text = original_text.match(params_regex);
if (param_text == null){
alert('Match not found');
return;
}
param_text = original_text.match(params_regex)[1];
console.log(param_text);
param_text = param_text.replace(/\|\s*\_.*\n/g,'').replace(/^\n/,'');
var final_text = '== Pushpin map cleanup ==\n\nAs part of a larger refactor of [[Module:Location map]], I will be refactoring the way that this Infobox calls the location map code. The only noticeable change for most will be that the parameter names related to the pushpin maps will now all start with {{para|pushpin_...}}. This is part of a larger effort to make things consistent across Infoboxes. When this is done, ALL infoboxes using pushpin maps will use the same parameters. For more information about this, please see [[Module_talk:Location_map#Proposal_to_refactor_the_way_Template:Location_map_works_in_Infoboxes|this post]]. As part of this cleanup, I am also going to resolving any conflicting parameters that I can find and cleaning up parameter names that fail to conform to [[MOS:INFOBOXNAME]]. Note that this follows a long list of similar clean ups that I have done on countless other Infoboxes. The parameters I plan to replace are the following:\n\n{| class="wikitable"\n! Deprecate\n! Replace with\n'
const replace_regex = /\|\s([\w\s\(\)\-\']*)\s=\s(\w+)/g;
const replaces = param_text.matchAll(replace_regex);
var count = 0;
for (const replace of replaces) {
count = count + 1;
final_text = final_text + '|-\n| {{para|' + replace[1] + '}}\n| {{para|' + replace[2] + '}}\n'
}
if (param_text.split(/\n/).length -1 != count){
alert('One or more params, do not match replace_regex formula.');
}
final_text += '|}\n\nPlease chime in below with any questions, comments or concerns about this cleanup.'
$('#wpTextbox1').textSelection('setContents', final_text);
mw.notify('Success');
}
// -------------------------------------------------------------------------------- //
});
//</nowiki>
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.