/**
* TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
* @see https://meta.wikimedia.org/wiki/TemplateScript
* @update-token [[File:Pathoschild/templatescript.js]]
*/
// License: CC0
// <nowiki>
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
pathoschild.TemplateScript.add({
name:'collapse lists',
script: function(editor) {
editor
.replace(/\n\n;/g, '\n;')
.replace(/\n\n:/g, '\n:')
.replace(/\n\n\*/g, '\n*')
.appendEditSummary('[[User:Opencooper/Wikitext gotchas#list_spaces|Delete spaces between list items so a single list is created]]')
.options({ minor: true, watch: true })
.clickDiff();
}
});
pathoschild.TemplateScript.add({
name:'\'s italics fix',
script: function(editor) {
editor
.replace(/'''s/g, "''{{'s}}")
.appendEditSummary('[[User:Opencooper/Wikitext gotchas#italics_fix|Use template to space italics]]')
.options({ minor: true, watch: true })
.clickDiff();
}
});
pathoschild.TemplateScript.add({
name:'nihongo',
script: function(editor) {
editor
.replace(/'''''(.*?) \((.*?)\)/, "{{nihongo|'''''$1|$2}}")
.appendEditSummary('Use template for Japanese text')
.options({ minor: true, watch: true })
.clickDiff();
}
});
pathoschild.TemplateScript.add({
name:'curly quotes',
script: function(editor) {
editor
.replace(/(File:[^|\n]+)“/g, "$1<<€€")
.replace(/(File:[^|\n]+)”/g, "$1€€>>")
.replace(/(File:[^|\n]+)‘/g, "$1<€€")
.replace(/(File:[^|\n]+)’/g, "$1€€>")
.replace(/“|”/g, "\"")
.replace(/‘|’/g, "'")
.replace(/<<€€/g, "“")
.replace(/€€>>/g, "”")
.replace(/<€€/g, "‘")
.replace(/€€>/g, "’")
.appendEditSummary('curly quotes to straight per [[MOS:CURLY]]')
.options({ minor: true, watch: true })
.clickDiff();
}
});
pathoschild.TemplateScript.add({
name:'indentation formatting',
script: function(editor) {
editor
.appendEditSummary('[[User:Opencooper/Proper indentation|Proper quote formatting]]')
.options({ minor: false, watch: true });
}
});
pathoschild.TemplateScript.add({
name:'math indentation',
script: function(editor) {
editor
.replace(/\n:+[ \t]*<math>/g, "\n<math display=\"block\">")
.appendEditSummary('[[User:Opencooper/Proper indentation|Proper indentation for accessibility]]')
.options({ minor: false, watch: false })
.clickDiff();
}
});
pathoschild.TemplateScript.add({
name:'chem indentation',
script: function(editor) {
editor
.replace(/^:/g, "{{in5}}")
.appendEditSummary('[[User:Opencooper/Proper indentation|Proper indentation for accessibility]]')
.options({ minor: false, watch: false })
.clickDiff();
}
});
pathoschild.TemplateScript.add({
name:'redundant quote marks',
script: function(editor) {
editor
.appendEditSummary('quotation marks in a blockquote are redundant ([[MOS:BLOCKQUOTE]])');
}
});
pathoschild.TemplateScript.add({
name:'noitalquote',
script: function(editor) {
editor
.appendEditSummary('[[MOS:NOITALQUOTE]]');
}
});
pathoschild.TemplateScript.add({
name:'external links',
script: function(editor) {
editor
.replace(/([^>])\[http.*? (.*?)\]/g, "$1$2")
.appendEditSummary('external links don\'t belong in the body ([[WP:EXT]])')
.options({ minor: false, watch: false })
.clickDiff();
}
});
pathoschild.TemplateScript.add({
name:'lang tag',
script: function(editor) {
editor
.appendEditSummary('use template for non-English text')
.options({ minor: true, watch: false });
}
});
/*
pathoschild.TemplateScript.add({
name:'nihongo errors',
script: function(editor) {
editor
.replace(/\{\{nihongo4?\|([^|]*?)\|?\|?\|?\}\}/ig, "$1")
.appendEditSummary('fix nihongo errors')
.options({ minor: true, watch: false })
.clickDiff();
}
});
pathoschild.TemplateScript.add({
name:'nihongo2 errors',
script: function(editor) {
editor
.replace(/\{\{nihongo(3|4)?\|/ig, "{{nihongo2|")
.appendEditSummary('fix nihongo errors')
.options({ minor: true, watch: false })
.clickDiff();
}
});
*/
pathoschild.TemplateScript.add({
name:'see also',
script: function(editor) {
editor
.appendEditSummary('already in body ([[MOS:SEEALSO]])')
.options({ minor: false, watch: true });
}
});
pathoschild.TemplateScript.add({
name:'endash',
script: function(editor) {
editor
.appendEditSummary('dash to endash ([[MOS:ENDASH]])')
.options({ minor: true, watch: true });
}
});
pathoschild.TemplateScript.add({
name:'center tag',
script: function(editor) {
editor
.replace(/<\/?center>/g, "")
.appendEditSummary('the center tag is deprecated ([[WP:HTML5#center]])')
.options({ minor: true, watch: true })
.clickDiff();
}
});
pathoschild.TemplateScript.add({
name:'nobold',
script: function(editor) {
editor
.replace(/'''/g, "")
.appendEditSummary('[[MOS:NOBOLD]]')
.options({ minor: true, watch: true })
.clickDiff();
}
});
pathoschild.TemplateScript.add({
name:'interlanguage',
script: function(editor) {
editor
.replace(/\[\[:([a-z]{2}):(.*?)\|(.*?)\]\]/g, "{{ill|$3|$1|$2|lt=$3}}")
.replace(/\|([^|]+)\|lt=\1}}/g, "|$1}}")
.replace(/{{ill\|([^|]+)\|(\w+)\|\1}}/g, "{{ill|$1|$2}}")
.appendEditSummary('converting interlanguage links per [[MOS:EGG]]')
.options({ minor: false, watch: false })
.clickDiff();
}
});
pathoschild.TemplateScript.add({
name:'unbulleted list',
script: function(editor) {
editor
.replace(/(\|[^=]*=)(.*<br\/?>.*)/g, "$1{{ubl|$2}}")
.replace(/<br\/?>/g, " | ")
.appendEditSummary('[[MOS:UBLIST]]')
.options({ minor: false, watch: false })
.clickDiff();
}
});
});
// </nowiki>