User:Mesidast/Fix ITN Talk.js
Appearance
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:Mesidast/Fix ITN Talk. |
// Script by [[User:Mesidast]] to fix ITN Talk templates
// Version 2.2
if (ITNautoSummary == null) var ITNautoSummary = true; //generate a short summary
if (ITNshowDiff == null) var ITNshowDiff = true; //show diff after pressing button
if (ITNmarkMinor == null) var ITNmarkMinor = true; //mark as minor
function ITN_Fix() {
var textbox = $("#wpTextbox1");
var summary = $("#wpSummary");
if ( !textbox ) {
return false;
}
var txt = textbox.val();
var original = txt;
txt = txt.replace(/\{\{ITN talk *\| *([0-9]{1,2}) *\| *([a-zA-Z]+) *\| *([0-9]{4}) *\| *oldid\d*=([0-9]+) *[^}]*\}\}/g, "{{ITN talk|date=$1 $2 $3|oldid=$4}}");
txt = txt.replace(/(\{\{ITN talk[\S ]*\}\})\n{1}(\{\{[T|t]alk header[\S ]*\}\})/g, "$2\n$1");
// Only insert the edit summary when something has changed
if (txt !== original) {
textbox.val(txt);
if (ITNautoSummary) summary.val(ITN_EditSummary(summary.val()));
if (ITNmarkMinor) document.editform.wpMinoredit.checked = true;
if (ITNshowDiff) $("#wpDiff").click();
}
}
function ITN_EditSummary(sum) {
var ITNsum = "Fix [[Template:ITN talk|ITN]] parameters";
if (sum.indexOf(ITNsum) == -1) {
if (sum.match(/[^\*\/\s][^\/\s]?\s*$/)) {
sum += " | ";
}
sum += ITNsum;
}
return sum;
}
$(function () {
if(document.forms.editform) {
mw.util.addPortletLink('p-tb', 'javascript:ITN_Fix()', 'Fix ITN Talk', 'ca-formatcitations', 'Fix old ITN talk date parameters');
}
});