User:The Evil IP address/vector.js: Difference between revisions

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
Content deleted Content added
No edit summary
updated scripts, migrated deprecated functions
Line 1: Line 1:
/* global $, mw, pathoschild */
// <source lang=javascript>


popupRevertSummaryPrompt=true;
popupRevertSummaryPrompt=true;
Line 11: Line 11:
if ( document.getElementById('ca-edit') ) {
if ( document.getElementById('ca-edit') ) {
var obj = document.getElementById('ca-edit');
var obj = document.getElementById('ca-edit');
var temp = String(wgRestrictionEdit);
var temp = String(mw.config.get('wgRestrictionEdit'));
if (temp == 'autoconfirmed') {
if (temp == 'autoconfirmed') {
farbe = '#ffa500';
farbe = '#ffa500';
Line 17: Line 17:
farbe = '#ff6a6a';
farbe = '#ff6a6a';
}
}
}
}
if ( document.getElementById('ca-viewsource') ) {
if ( document.getElementById('ca-viewsource') ) {
var obj = document.getElementById('ca-viewsource');
var obj = document.getElementById('ca-viewsource');
Line 56: Line 56:
$(function () {
$(function () {
if (document.forms.editform) {
if (document.forms.editform) {
addPortletLink('p-cactions', 'javascript:wpTextboxReplace()', 'Replace', 'ca-replace',
mw.util.addPortletLink('p-cactions', 'javascript:wpTextboxReplace()', 'Replace', 'ca-replace',
'Regexp replace for the edit window', 'R', document.getElementById('ca-history'));
'Regexp replace for the edit window', 'R', document.getElementById('ca-history'));
}
}
Line 64: Line 64:
// [[Category:Wikipedia scripts]]
// [[Category:Wikipedia scripts]]


/*************
/**
* TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
*** Regex menu framework
*** by [[m:user:Pathoschild]] <http://meta.wikimedia.org/wiki/User:Pathoschild/Scripts/Regex_menu_framework>
* @see https://meta.wikimedia.org/wiki/TemplateScript
* @update-token [[File:pathoschild/templatescript.js]]
*** - adds a sidebar menu of user-defined scripts.
*/
*************/
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
importScriptURI('http://meta.wikimedia.org/w/index.php?title=User:Pathoschild/Scripts/Regex_menu_framework.js&action=raw&ctype=text/javascript');
pathoschild.TemplateScript.add([ // add your own templates or scripts here
{
/* menu links */
name: 'General article fixes',
// In the function below, add more lines like "regexTool('link text','function_name()')" to add
script: function(context) { // own script of gen. fixes for articles
// links to the sidebar menu. The function name is the function defined in rfmscripts() below.
// Some workarounds
function rmflinks() {
// ([\s\S]+): JavaScript can't match newlines with ".", thus it needs to be done by using regex for whitespace character and non-whitespace characters
regexTool('Custom regex','custom()'); // a default tool which performs regex input in a dynamic form
// (\n): if stuff needs to explicitely match a newline, wrap it into brackets and then reference it by using $1 (or similar) in the replace string
regexTool('General article fixes','generalfixes()'); // own script of gen. fixes for articles
}
// first fix
context.helper
/* scripts */
.replace(/\{\{template:/gi,'{{'); // template is the default
// Below, define the functions linked to from rmflinks() above. These functions can use any JavaScript,
// but there is a set of simplified tools documented at
// then, let's bypass redirects so we can use proper names for further fixes
// http://meta.wikimedia.org/wiki/User:Pathoschild/Script:Regex_menu_framework .
context.helper

.replace(/\{\{(facts?|(source|os cite|ref(erence)?|cit(e|ation))[\s-]?needed|uncited|(a|c)n|needs citation|sourceme|cit(e|ation) missing|proveit|(really|source|ref|are you sure)\?|refplease|need cite|cite ref pls|needsref|bollocks)(\||\}{2})/gi,'{{Citation needed$8') // {{Citation needed}} and similar
// Some workarounds
.replace(/\{\{(commons?\s?cat|commonscat\simages|commonscategory|commons2|catistcommons|Cms-catlist-up)(\||\}{2})/gi,'{{Commons category$2') // {{Commons category}}
// ([\s\S]+): JavaScript can't match newlines with ".", thus it needs to be done by using regex for whitespace character and non-whitespace characters
.replace(/\{\{(Article\s?issues|Issues|AI)(\||\}{2})/gi,'{{Multiple issues$2') // {{Multiple issues}}
// (\n): if stuff needs to explicitely match a newline, wrap it into brackets and then reference it by using $1 (or similar) in the replace string
.replace(/\{\{(wikimedia|sister\s?links2?)(\||\}{2})/gi,'{{Sister project links$2') // {{Sister project links}}
.replace(/\{\{(CI|cleanup[\s-]?cat|few\s?cat(s|egories)|improve[\s-]?cat(s|egories)|more\s?cat(egories|s|egory)?|cat(egory|egories)?[\s-]?improve|more cats)(\||\}{2})/gi,'{{Cat improve$6') // {{Cat improve}}
function generalfixes() {
.replace(/\{\{(attention\s?(\(on talk page\)|needed|see talk)?|clean[\s-]up(-since|quality|date|pitt)?|cl?u|tidy|unfinished|attn|ugly|improve|quality)(\||\}{2})/gi,'{{Cleanup$4') // {{Cleanup}}
// first fix
.replace(/\{\{(cleanup(-clarity|\s?confusing)|simplify|unclear)/gi,'{{Confusing') // {{Confusing}}
regex(/\{\{template:/gi,'{{'); // template is the default
.replace(/\{\{((g|grammar)\s?check|(cleanup-)?copy-?edit|cleanup-english|ortogramrevision|grammar)/gi,'{{Copy edit') // {{Copy edit}}
// then, let's bypass redirects so we can use proper names for further fixes
.replace(/\{\{(cleanup-(references|citation|refs)|ref-cleanup|citation-?style|ref(erence)?[\s-]style|citestyle|cleanrefs|refs?clean)/gi,'{{Citation style') // {{Citation style}}
regex(/\{\{(facts?|(source|os cite|ref(erence)?|cit(e|ation))[\s-]?needed|uncited|(a|c)n|needs citation|sourceme|cit(e|ation) missing|proveit|(really|source|ref|are you sure)\?|refplease|need cite|cite ref pls|needsref|bollocks)(\||\}{2})/gi,'{{Citation needed$8'); // {{Citation needed}} and similar
.replace(/\{\{(internal\s?links|dep|dead end page|needs links|deadend)/gi,'{{Dead end') // {{Dead end}}
regex(/\{\{(commons?\s?cat|commonscat\simages|commonscategory|commons2|catistcommons|Cms-catlist-up)(\||\}{2})/gi,'{{Commons category$2'); // {{Commons category}}
regex(/\{\{(Article\s?issues|Issues|AI)(\||\}{2})/gi,'{{Multiple issues$2'); // {{Multiple issues}}
.replace(/\{\{(essay-opinion|essay-entry|essaylike|cleanup-?essay)/gi,'{{Essay-like') // {{Essay-like}}
regex(/\{\{(wikimedia|sister\s?links2?)(\||\}{2})/gi,'{{Sister project links$2'); // {{Sister project links}}
.replace(/\{\{(expansion|very\s?short|too-short)/gi,'{{Expand') // {{Expand}}
.replace(/\{\{(cleanup[\s-]fiction-as-fact|in\s?universe)/gi,'{{In-universe') // {{In-universe}}
regex(/\{\{(CI|cleanup[\s-]?cat|few\s?cat(s|egories)|improve[\s-]?cat(s|egories)|more\s?cat(egories|s|egory)?|cat(egory|egories)?[\s-]?improve|more cats)(\||\}{2})/gi,'{{Cat improve$6'); // {{Cat improve}}
.replace(/\{\{(no-?intro(duction)?|no\s?lead(\ssection)?|missingintro|intro[\s-]?missing|opening|leadsection)/gi,'{{Lead missing') // {{Lead missing}}
regex(/\{\{(attention\s?(\(on talk page\)|needed|see talk)?|clean[\s-]up(-since|quality|date|pitt)?|cl?u|tidy|unfinished|attn|ugly|improve|quality)(\||\}{2})/gi,'{{Cleanup$4'); // {{Cleanup}}
.replace(/\{\{(lead section|(expand|short)\s?lead|(lead)?too\s?short(\s2)?|short intro|intro-tooshort|expandlede)/gi,'{{Lead too short')
regex(/\{\{(cleanup(-clarity|\s?confusing)|simplify|unclear)/gi,'{{Confusing'); // {{Confusing}}
.replace(/\{\{(vagueintro|(intro|lead)-?rewrite|intro|lead|lede)/gi,'{{Lead rewrite');
regex(/\{\{((g|grammar)\s?check|(cleanup-)?copy-?edit|cleanup-english|ortogramrevision|grammar)/gi,'{{Copy edit'); // {{Copy edit}}
regex(/\{\{(cleanup-(references|citation|refs)|ref-cleanup|citation-?style|ref(erence)?[\s-]style|citestyle|cleanrefs|refs?clean)/gi,'{{Citation style'); // {{Citation style}}
// now let's start with the real 'general' fixes
regex(/\{\{(internal\s?links|dep|dead end page|needs links|deadend)/gi,'{{Dead end'); // {{Dead end}}
context.helper
regex(/\{\{(essay-opinion|essay-entry|essaylike|cleanup-?essay)/gi,'{{Essay-like'); // {{Essay-like}}
.replace(/\[\[Image:/gi,'[[File:') // New namespace name
regex(/\{\{(expansion|very\s?short|too-short)/gi,'{{Expand'); // {{Expand}}
.replace(/\|thumb\|right/g,'|thumb') // Thumbs are defaulted to right
regex(/\{\{(cleanup[\s-]fiction-as-fact|in\s?universe)/gi,'{{In-universe'); // {{In-universe}}
.replace(/<gallery>([\s\S]*\n)Image:([\s\S]+)<\/gallery>/gi,'<gallery>$1File:$2</gallery>') // namespace within galleries
regex(/\{\{(no-?intro(duction)?|no\s?lead(\ssection)?|missingintro|intro[\s-]?missing|opening|leadsection)/gi,'{{Lead missing'); // {{Lead missing}}
.replace(/\[\[File:(.+)_(.+)_(.+)_(.+)_(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4 $5 $6 $7 $8.$9') // remove underscores from filenames (7) -- MAXIMUM
regex(/\{\{(lead section|(expand|short)\s?lead|(lead)?too\s?short(\s2)?|short intro|intro-tooshort|expandlede)/gi,'{{Lead too short');
.replace(/\[\[File:(.+)_(.+)_(.+)_(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4 $5 $6 $7.$8') // remove underscores from filenames (6)
regex(/\{\{(vagueintro|(intro|lead)-?rewrite|intro|lead|lede)/gi,'{{Lead rewrite');
.replace(/\[\[File:(.+)_(.+)_(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4 $5 $6.$7') // remove underscores from filenames (5)
// now let's start with the real 'general' fixes
regex(/\[\[Image:/gi,'[[File:'); // New namespace name
.replace(/\[\[File:(.+)_(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4 $5.$6') // remove underscores from filenames (4)
.replace(/\[\[File:(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4.$5') // remove underscores from filenames (3)
regex(/\|thumb\|right/g,'|thumb'); // Thumbs are defaulted to right
.replace(/\[\[File:(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3.$4') // remove underscores from filenames (2)
regex(/\<gallery\>([\s\S]*\n)Image:([\s\S]+)\<\/gallery\>/gi,'<gallery>$1File:$2</gallery>'); // namespace within galleries
regex(/\[\[File:(.+)_(.+)_(.+)_(.+)_(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4 $5 $6 $7 $8.$9'); // remove underscores from filenames (7) -- MAXIMUM
.replace(/\[\[File:(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2.$3') // remove underscores from filenames (1)
.replace(/\{\{Commons\|Category:(.+)(\|\1)?\}\}/gi,'{{Commons category|$1}}') // Wrong template ({{Commons|Category:Somethin}} - {{Commons category|Something}}
regex(/\[\[File:(.+)_(.+)_(.+)_(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4 $5 $6 $7.$8'); // remove underscores from filenames (6)
.replace(/\{\{Commons\|Category:(.+)\|(.+)\}\}/gi,'{{Commons category|$1|$2}}') // {{Commons|Category:Somethin|Different text}} - {{Commons category|Something|different text}}
regex(/\[\[File:(.+)_(.+)_(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4 $5 $6.$7'); // remove underscores from filenames (5)
.replace(/\{\{Multiple issues\|([\w\s-]+)=((January|February|March|April|May|June|July|August|September|October|November|December)\s\d{4})\}\}/g,'{{$1|date=$2}}') // only one concern within {{Multiple issues}}
regex(/\[\[File:(.+)_(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4 $5.$6'); // remove underscores from filenames (4)
.replace(/\{\{Multiple issues\}\}/g,'') // please specify issues within {{Multiple issues}}
regex(/\[\[File:(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4.$5'); // remove underscores from filenames (3)
regex(/\[\[File:(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3.$4'); // remove underscores from filenames (2)
.replace(/\{\{DEFAULTSORT\|(.+)\}\}/g,'{{DEFAULTSORT:$1}}') // usage of magic words
regex(/\[\[File:(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2.$3'); // remove underscores from filenames (1)
.replace(/(={2,6})\s*'''(.+)'''\s*\1(\n)/g, '$1$2$1$3') // unnecessary bolding removed from headings
.replace(/(={2,6})\s*(.+):\s*\1(\n)/g, '$1$2$1$3') // remove colon from headings
regex(/\{\{Commons\|Category:(.+)(\|\1)?\}\}/gi,'{{Commons category|$1}}'); // Wrong template ({{Commons|Category:Somethin}} - {{Commons category|Something}}
.replace(/(<br>|<\br>|<\/br\s>|<br\/>|<br\/\s>)/gi,'<br />') // proper <br />
regex(/\{\{Commons\|Category:(.+)\|(.+)\}\}/gi,'{{Commons category|$1|$2}}'); // {{Commons|Category:Somethin|Different text}} - {{Commons category|Something|different text}}
.replace(/\*\[http:\/\/([\S]+) official (web\s?)?site\]/gi,'*{{Official|http://$1}}') // usage of {{Official}}
regex(/\{\{Multiple issues\|([\w\s-]+)=((January|February|March|April|May|June|July|August|September|October|November|December)\s\d{4})\}\}/g,'{{$1|date=$2}}'); // only one concern within {{Multiple issues}}
.replace(/\{\{lifetime\|/gi,'{{subst:ltm|') // subst: {{lifetime}}
regex(/\{\{Multiple issues\}\}/g,''); // please specify issues within {{Multiple issues}}
.replace(/(==+)\s*external\s*links\s*(==+)/gi,'$1External links$1') // fix headers
regex(/\{\{DEFAULTSORT\|(.+)\}\}/g,'{{DEFAULTSORT:$1}}'); // usage of magic words
.replace(/(==+)\s*references\s*(==+)/gi,'$1References$1')
regex(/(={2,6})\s*'''(.+)'''\s*\1(\n)/g, '$1$2$1$3'); // unnecessary bolding removed from headings
.replace(/&deg;/g, '°') // convert HTML entity into actual character
regex(/(={2,6})\s*(.+):\s*\1(\n)/g, '$1$2$1$3'); // remove colon from headings
.replace(/\&dagger\;/g, '†')
regex(/(<br>|<\br>|<\/br\s>|<br\/>|<br\/\s>)/gi,'<br />'); // proper <br />
.replace(/\&ndash\;/g, '–')
regex(/\*\[http:\/\/([\S]+) official (web\s?)?site\]/gi,'*{{Official|http://$1}}'); // usage of {{Official}}
.replace(/\&mdash\;/g, '—')
regex(/\{\{lifetime\|/gi,'{{subst:ltm|'); // subst: {{lifetime}}
.replace(/\&rarr\;/g, '→')
regex(/(==+)\s*external\s*links\s*(==+)/gi,'$1External links$1'); // fix headers
.replace(/\&larr\;/g, '←')
regex(/(==+)\s*references\s*(==+)/gi,'$1References$1');
.replace(/\&rt\;/g, '>')
regex(/&deg;/g, '°'); // convert HTML entity into actual character
regex(/\&dagger\;/g, '');
.replace(/\&lt\;/g, '<')
regex(/\&ndash\;/g, '');
.replace(/\&hellip\;/g, '')
regex(/\&mdash\;/g, '');
.replace(/º/g, '°')
regex(/\&rarr\;/g, '');
.replace(/&sup2;/g, '²')
regex(/\&larr\;/g, '');
.replace(/&sup3;/g, '³')
.replace(/<\/b>/gim, '\'\'\'') // HTML2Wiki
regex(/\&rt\;/g, '>');
regex(/\&lt\;/g, '<');
.replace(/<li>/g, '*')
regex(/\&hellip\;/g, '');
.replace(/<\/li>/g, '')
regex(/º/g, '°');
.replace(/<ul>/g, '')
regex(/&sup2;/g, '²');
.replace(/<\/ul>/g, '')
.replace(/<br \/>(\n){2}/g, '\n\n') // unnecessary <br />
regex(/&sup3;/g, '³');
regex(/\<\/b\>/gim, '\'\'\''); // HTML2Wiki
.replace(/<\/i>/gim, '\'\'')
regex(/\<li\>/g, '*');
.replace(/<b>/gim, '\'\'\'')
regex(/\<\/li\>/g, '');
.replace(/<i>/gim, '\'\'')
.replace(/\t/g, ' ') // replace tabulators with spaces
regex(/\<ul\>/g, '');
.replace(/ +/g, ' ') // reduce unnecessary spaces
regex(/\<\/ul\>/g, '');
regex(/\<br \/\>(\n){2}/g, '\n\n'); // unnecessary <br />
.replace(/ (\n)/g, '$1') // remove spaces at the end of a line
.replace(/\[\[[ \t]*([^\]|]+?)[ \t]*\|[ \t]*([^\] \t]+?)[ \t]*\]\]/g, '[[$1|$2]]') // link syntax
regex(/\<\/i\>/gim, '\'\'');
.replace(/\[\[([^|\]]+)\|\1([^|\] \t]+)\]\]/g, '[[$1]]$2')
regex(/\<b\>/gim, '\'\'\'');
.replace(/(\n)\|image=Replace[\s_]this[\s_]image[\s_](fe)?male\.svg/gi,'$1|image=') // remove placeholders
regex(/\<i\>/gim, '\'\'');
.replace(/(\n)\|image=\[\[File:Replace[\s_]this[\s_]image[\s_](fe)?male\.svg.+\1/gi,'$1|image=$1')
regex(/\t/g, ' '); // replace tabulators with spaces
.replace(/\[\[category:/g, '[[Category:') // capitalize categories
regex(/ +/g, ' '); // reduce unnecessary spaces
.replace(/\[\[Category: /g, '[[Category:')
regex(/ (\n)/g, '$1'); // remove spaces at the end of a line
.replace(/\[\[Category:a/g, '[[Category:A')
regex(/\[\[[ \t]*([^\]|]+?)[ \t]*\|[ \t]*([^\] \t]+?)[ \t]*\]\]/g, '[[$1|$2]]'); // link syntax
regex(/\[\[([^|\]]+)\|\1([^|\] \t]+)\]\]/g, '[[$1]]$2');
.replace(/\[\[Category:b/g, '[[Category:B')
.replace(/\[\[Category:c/g, '[[Category:C')
regex(/(\n)\|image=Replace[\s_]this[\s_]image[\s_](fe)?male\.svg/gi,'$1|image='); // remove placeholders
.replace(/\[\[Category:d/g, '[[Category:D')
regex(/(\n)\|image=\[\[File:Replace[\s_]this[\s_]image[\s_](fe)?male\.svg.+\1/gi,'$1|image=$1');
regex(/\[\[category:/g, '[[Category:'); // capitalize categories
.replace(/\[\[Category:e/g, '[[Category:E')
regex(/\[\[Category: /g, '[[Category:');
.replace(/\[\[Category:f/g, '[[Category:F')
regex(/\[\[Category:a/g, '[[Category:A');
.replace(/\[\[Category:g/g, '[[Category:G')
regex(/\[\[Category:b/g, '[[Category:B');
.replace(/\[\[Category:h/g, '[[Category:H')
regex(/\[\[Category:c/g, '[[Category:C');
.replace(/\[\[Category:i/g, '[[Category:I')
regex(/\[\[Category:d/g, '[[Category:D');
.replace(/\[\[Category:j/g, '[[Category:J')
regex(/\[\[Category:e/g, '[[Category:E');
.replace(/\[\[Category:k/g, '[[Category:K')
regex(/\[\[Category:f/g, '[[Category:F');
.replace(/\[\[Category:l/g, '[[Category:L')
regex(/\[\[Category:g/g, '[[Category:G');
.replace(/\[\[Category:m/g, '[[Category:M')
regex(/\[\[Category:h/g, '[[Category:H');
.replace(/\[\[Category:n/g, '[[Category:N')
regex(/\[\[Category:i/g, '[[Category:I');
.replace(/\[\[Category:o/g, '[[Category:O')
regex(/\[\[Category:j/g, '[[Category:J');
.replace(/\[\[Category:p/g, '[[Category:P')
regex(/\[\[Category:k/g, '[[Category:K');
.replace(/\[\[Category:q/g, '[[Category:Q')
regex(/\[\[Category:l/g, '[[Category:L');
.replace(/\[\[Category:r/g, '[[Category:R')
regex(/\[\[Category:m/g, '[[Category:M');
.replace(/\[\[Category:s/g, '[[Category:S')
regex(/\[\[Category:n/g, '[[Category:N');
.replace(/\[\[Category:t/g, '[[Category:T')
regex(/\[\[Category:o/g, '[[Category:O');
.replace(/\[\[Category:u/g, '[[Category:U')
regex(/\[\[Category:p/g, '[[Category:P');
.replace(/\[\[Category:v/g, '[[Category:V')
regex(/\[\[Category:q/g, '[[Category:Q');
.replace(/\[\[Category:w/g, '[[Category:W')
regex(/\[\[Category:r/g, '[[Category:R');
.replace(/\[\[Category:x/g, '[[Category:X')
regex(/\[\[Category:s/g, '[[Category:S');
.replace(/\[\[Category:y/g, '[[Category:Y')
regex(/\[\[Category:t/g, '[[Category:T');
.replace(/\[\[Category:z/g, '[[Category:Z')
regex(/\[\[Category:u/g, '[[Category:U');
.replace(/\[\[file:/g, '[[File:') // capitalize files
regex(/\[\[Category:v/g, '[[Category:V');
.replace(/\[\[File:\s+/g, '[[File:')
regex(/\[\[Category:w/g, '[[Category:W');
.replace(/\[\[File:a/g, '[[File:A')
regex(/\[\[Category:x/g, '[[Category:X');
.replace(/\[\[File:b/g, '[[File:B')
regex(/\[\[Category:y/g, '[[Category:Y');
.replace(/\[\[File:c/g, '[[File:C')
regex(/\[\[Category:z/g, '[[Category:Z');
.replace(/\[\[File:d/g, '[[File:D')
regex(/\[\[file:/g, '[[File:'); // capitalize files
.replace(/\[\[File:e/g, '[[File:E')
regex(/\[\[File:\s+/g, '[[File:');
.replace(/\[\[File:f/g, '[[File:F')
regex(/\[\[File:a/g, '[[File:A');
.replace(/\[\[File:g/g, '[[File:G')
regex(/\[\[File:b/g, '[[File:B');
.replace(/\[\[File:h/g, '[[File:H')
regex(/\[\[File:c/g, '[[File:C');
.replace(/\[\[File:i/g, '[[File:I')
regex(/\[\[File:d/g, '[[File:D');
.replace(/\[\[File:j/g, '[[File:J')
regex(/\[\[File:e/g, '[[File:E');
.replace(/\[\[File:k/g, '[[File:K')
regex(/\[\[File:f/g, '[[File:F');
.replace(/\[\[File:l/g, '[[File:L')
regex(/\[\[File:g/g, '[[File:G');
.replace(/\[\[File:m/g, '[[File:M')
regex(/\[\[File:h/g, '[[File:H');
.replace(/\[\[File:n/g, '[[File:N')
regex(/\[\[File:i/g, '[[File:I');
.replace(/\[\[File:o/g, '[[File:O')
regex(/\[\[File:j/g, '[[File:J');
.replace(/\[\[File:p/g, '[[File:P')
regex(/\[\[File:k/g, '[[File:K');
.replace(/\[\[File:q/g, '[[File:Q')
regex(/\[\[File:l/g, '[[File:L');
.replace(/\[\[File:r/g, '[[File:R')
regex(/\[\[File:m/g, '[[File:M');
.replace(/\[\[File:s/g, '[[File:S')
regex(/\[\[File:n/g, '[[File:N');
.replace(/\[\[File:t/g, '[[File:T')
regex(/\[\[File:o/g, '[[File:O');
.replace(/\[\[File:u/g, '[[File:U')
regex(/\[\[File:p/g, '[[File:P');
.replace(/\[\[File:v/g, '[[File:V')
regex(/\[\[File:q/g, '[[File:Q');
.replace(/\[\[File:w/g, '[[File:W')
regex(/\[\[File:r/g, '[[File:R');
.replace(/\[\[File:x/g, '[[File:X')
regex(/\[\[File:s/g, '[[File:S');
.replace(/\[\[File:y/g, '[[File:Y')
regex(/\[\[File:t/g, '[[File:T');
.replace(/\[\[File:z/g, '[[File:Z')
.replace(/\{\{([\s\S]+)\|(\n)([\d\w])([\s\S])\}\}/g,'{{$1$2|$3$4}}') // wrong {{Infobox}}
regex(/\[\[File:u/g, '[[File:U');
.replace(/<references \/>/gi, '{{Reflist}}');
regex(/\[\[File:v/g, '[[File:V');
regex(/\[\[File:w/g, '[[File:W');
context.helper
regex(/\[\[File:x/g, '[[File:X');
.setEditSummary('general fixes')
regex(/\[\[File:y/g, '[[File:Y');
.clickDiff();
regex(/\[\[File:z/g, '[[File:Z');
}
regex(/\{\{([\s\S]+)\|(\n)([\d\w])([\s\S])\}\}/g,'{{$1$2|$3$4}}'); // wrong {{Infobox}}
},
regex(/\<references \/\>/gi, '{{Reflist}}');
]);
setreason('general fixes'); // edit summary
});
doaction('diff'); // at the end, let's check the changes
}


//importScript('User:The Evil IP address/debug.js');
//importScript('User:The Evil IP address/debug.js');
Line 226: Line 225:
importScript('User:Ohconfucius/script/MOSNUM dates.js');
importScript('User:Ohconfucius/script/MOSNUM dates.js');
importScript('User:Ohconfucius/script/EngvarB.js'); //[[User:Ohconfucius/script/EngvarB.js]]
importScript('User:Ohconfucius/script/EngvarB.js'); //[[User:Ohconfucius/script/EngvarB.js]]

// </source>

Revision as of 04:55, 9 August 2015

/* global $, mw, pathoschild */

popupRevertSummaryPrompt=true;
popupFixRedirs=true;

importScript('User:Ale_jrb/Scripts/igloo.js'); // [[User:Ale_jrb/Scripts/igloo]]

// http://de.wikipedia.org/wiki/Benutzer:Stefan/Sperrstatus.js
$(function () {
   var farbe = '';
   if ( document.getElementById('ca-edit') ) {
       var obj  = document.getElementById('ca-edit');
       var temp = String(mw.config.get('wgRestrictionEdit'));
       if (temp == 'autoconfirmed') {
           farbe = '#ffa500';
       } else if (temp == 'sysop') {
           farbe = '#ff6a6a';
       }
   }
   if ( document.getElementById('ca-viewsource') ) {
       var obj = document.getElementById('ca-viewsource');
       farbe = '#ff0000';
   }
   if ( obj ) {
       obj.firstChild.style.backgroundColor = farbe;
   }
});


// Adds a "Replace" tab which pops up two prompt boxes; one for a regexp and one for a replacement
function wpTextboxReplace()
{
    var s = prompt("Search regexp:");
    var txt = document.editform.wpTextbox1;
    while ( true ) {
        if (!s) return;
        var s_r = new RegExp(s, 'mg');
        if (s_r.test(txt.value)) {
            var r = prompt("Replace /"+s+"/ with:");
            if(!r && r != '') return;
            txt.value = txt.value.replace(s_r, r);
            if (document.editform.wpSummary.value) {
                document.editform.wpSummary.value += ', s/' + s + '/' + r + '/mg';
            }
            else {
                document.editform.wpSummary.value = 's/' + s + '/' + r + '/mg';
            }
            return;
        }
        else {
            var s_0 = s;
            s = prompt('/' + s_0 + '/ does not match anything. Wanna try again?');
        }
    }
}
$(function () {
    if (document.forms.editform) {
        mw.util.addPortletLink('p-cactions', 'javascript:wpTextboxReplace()', 'Replace', 'ca-replace',
                       'Regexp replace for the edit window', 'R', document.getElementById('ca-history'));
    }
});


// [[Category:Wikipedia scripts]]

/**
 * 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]]
 */
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	pathoschild.TemplateScript.add([		// add your own templates or scripts here
		{
			name: 'General article fixes',
			script: function(context) { // own script of gen. fixes for articles
				// Some workarounds
				// ([\s\S]+): JavaScript can't match newlines with ".", thus it needs to be done by using regex for whitespace character and non-whitespace characters
				// (\n): if stuff needs to explicitely match a newline, wrap it into brackets and then reference it by using $1 (or similar) in the replace string
				
				// first fix
				context.helper
					.replace(/\{\{template:/gi,'{{'); // template is the default
					
				// then, let's bypass redirects so we can use proper names for further fixes
				context.helper
					.replace(/\{\{(facts?|(source|os cite|ref(erence)?|cit(e|ation))[\s-]?needed|uncited|(a|c)n|needs citation|sourceme|cit(e|ation) missing|proveit|(really|source|ref|are you sure)\?|refplease|need cite|cite ref pls|needsref|bollocks)(\||\}{2})/gi,'{{Citation needed$8') // {{Citation needed}} and similar
					.replace(/\{\{(commons?\s?cat|commonscat\simages|commonscategory|commons2|catistcommons|Cms-catlist-up)(\||\}{2})/gi,'{{Commons category$2') // {{Commons category}}
					.replace(/\{\{(Article\s?issues|Issues|AI)(\||\}{2})/gi,'{{Multiple issues$2') // {{Multiple issues}}
					.replace(/\{\{(wikimedia|sister\s?links2?)(\||\}{2})/gi,'{{Sister project links$2') // {{Sister project links}}
					.replace(/\{\{(CI|cleanup[\s-]?cat|few\s?cat(s|egories)|improve[\s-]?cat(s|egories)|more\s?cat(egories|s|egory)?|cat(egory|egories)?[\s-]?improve|more cats)(\||\}{2})/gi,'{{Cat improve$6') //  {{Cat improve}}
					.replace(/\{\{(attention\s?(\(on talk page\)|needed|see talk)?|clean[\s-]up(-since|quality|date|pitt)?|cl?u|tidy|unfinished|attn|ugly|improve|quality)(\||\}{2})/gi,'{{Cleanup$4') // {{Cleanup}}
					.replace(/\{\{(cleanup(-clarity|\s?confusing)|simplify|unclear)/gi,'{{Confusing') // {{Confusing}}
					.replace(/\{\{((g|grammar)\s?check|(cleanup-)?copy-?edit|cleanup-english|ortogramrevision|grammar)/gi,'{{Copy edit') // {{Copy edit}}
					.replace(/\{\{(cleanup-(references|citation|refs)|ref-cleanup|citation-?style|ref(erence)?[\s-]style|citestyle|cleanrefs|refs?clean)/gi,'{{Citation style') // {{Citation style}}
					.replace(/\{\{(internal\s?links|dep|dead end page|needs links|deadend)/gi,'{{Dead end') // {{Dead end}}
					.replace(/\{\{(essay-opinion|essay-entry|essaylike|cleanup-?essay)/gi,'{{Essay-like') // {{Essay-like}}
					.replace(/\{\{(expansion|very\s?short|too-short)/gi,'{{Expand') // {{Expand}}
					.replace(/\{\{(cleanup[\s-]fiction-as-fact|in\s?universe)/gi,'{{In-universe') // {{In-universe}}
					.replace(/\{\{(no-?intro(duction)?|no\s?lead(\ssection)?|missingintro|intro[\s-]?missing|opening|leadsection)/gi,'{{Lead missing') // {{Lead missing}}
					.replace(/\{\{(lead section|(expand|short)\s?lead|(lead)?too\s?short(\s2)?|short intro|intro-tooshort|expandlede)/gi,'{{Lead too short')
					.replace(/\{\{(vagueintro|(intro|lead)-?rewrite|intro|lead|lede)/gi,'{{Lead rewrite');
					
				// now let's start with the real 'general' fixes
				context.helper
					.replace(/\[\[Image:/gi,'[[File:') // New namespace name
					.replace(/\|thumb\|right/g,'|thumb') // Thumbs are defaulted to right
					.replace(/<gallery>([\s\S]*\n)Image:([\s\S]+)<\/gallery>/gi,'<gallery>$1File:$2</gallery>') // namespace within galleries
					.replace(/\[\[File:(.+)_(.+)_(.+)_(.+)_(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4 $5 $6 $7 $8.$9') // remove underscores from filenames (7) -- MAXIMUM
					.replace(/\[\[File:(.+)_(.+)_(.+)_(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4 $5 $6 $7.$8') // remove underscores from filenames (6)
					.replace(/\[\[File:(.+)_(.+)_(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4 $5 $6.$7') // remove underscores from filenames (5)
					.replace(/\[\[File:(.+)_(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4 $5.$6') // remove underscores from filenames (4)
					.replace(/\[\[File:(.+)_(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3 $4.$5') // remove underscores from filenames (3)
					.replace(/\[\[File:(.+)_(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2 $3.$4') // remove underscores from filenames (2)
					.replace(/\[\[File:(.+)_(.+)\.(\w+)/gi,'[[File:$1 $2.$3') // remove underscores from filenames (1)
					.replace(/\{\{Commons\|Category:(.+)(\|\1)?\}\}/gi,'{{Commons category|$1}}') // Wrong template ({{Commons|Category:Somethin}} - {{Commons category|Something}}
					.replace(/\{\{Commons\|Category:(.+)\|(.+)\}\}/gi,'{{Commons category|$1|$2}}') // {{Commons|Category:Somethin|Different text}} - {{Commons category|Something|different text}}
					.replace(/\{\{Multiple issues\|([\w\s-]+)=((January|February|March|April|May|June|July|August|September|October|November|December)\s\d{4})\}\}/g,'{{$1|date=$2}}') // only one concern within {{Multiple issues}}
					.replace(/\{\{Multiple issues\}\}/g,'') // please specify issues within {{Multiple issues}}
					.replace(/\{\{DEFAULTSORT\|(.+)\}\}/g,'{{DEFAULTSORT:$1}}') // usage of magic words
					.replace(/(={2,6})\s*'''(.+)'''\s*\1(\n)/g, '$1$2$1$3') // unnecessary bolding removed from headings
					.replace(/(={2,6})\s*(.+):\s*\1(\n)/g, '$1$2$1$3') // remove colon from headings
					.replace(/(<br>|<\br>|<\/br\s>|<br\/>|<br\/\s>)/gi,'<br />') // proper <br />
					.replace(/\*\[http:\/\/([\S]+) official (web\s?)?site\]/gi,'*{{Official|http://$1}}') // usage of {{Official}}
					.replace(/\{\{lifetime\|/gi,'{{subst:ltm|') // subst: {{lifetime}}
					.replace(/(==+)\s*external\s*links\s*(==+)/gi,'$1External links$1') // fix headers
					.replace(/(==+)\s*references\s*(==+)/gi,'$1References$1')
					.replace(/&deg;/g, '°') // convert HTML entity into actual character
					.replace(/\&dagger\;/g, '†')
					.replace(/\&ndash\;/g, '–')
					.replace(/\&mdash\;/g, '—')
					.replace(/\&rarr\;/g, '→')
					.replace(/\&larr\;/g, '←')
					.replace(/\&rt\;/g, '>')
					.replace(/\&lt\;/g, '<')
					.replace(/\&hellip\;/g, '…')
					.replace(/º/g, '°')
					.replace(/&sup2;/g, '²')
					.replace(/&sup3;/g, '³')
					.replace(/<\/b>/gim, '\'\'\'')  // HTML2Wiki
					.replace(/<li>/g, '*')
					.replace(/<\/li>/g, '')
					.replace(/<ul>/g, '')
					.replace(/<\/ul>/g, '')
					.replace(/<br \/>(\n){2}/g, '\n\n') // unnecessary <br />
					.replace(/<\/i>/gim, '\'\'')
					.replace(/<b>/gim, '\'\'\'')
					.replace(/<i>/gim, '\'\'')
					.replace(/\t/g, ' ') // replace tabulators with spaces
					.replace(/ +/g, ' ')   // reduce unnecessary spaces
					.replace(/ (\n)/g, '$1') // remove spaces at the end of a line
					.replace(/\[\[[ \t]*([^\]|]+?)[ \t]*\|[ \t]*([^\] \t]+?)[ \t]*\]\]/g, '[[$1|$2]]') // link syntax
					.replace(/\[\[([^|\]]+)\|\1([^|\] \t]+)\]\]/g, '[[$1]]$2')
					.replace(/(\n)\|image=Replace[\s_]this[\s_]image[\s_](fe)?male\.svg/gi,'$1|image=') // remove placeholders
					.replace(/(\n)\|image=\[\[File:Replace[\s_]this[\s_]image[\s_](fe)?male\.svg.+\1/gi,'$1|image=$1')
					.replace(/\[\[category:/g, '[[Category:')  // capitalize categories
					.replace(/\[\[Category: /g, '[[Category:')
					.replace(/\[\[Category:a/g, '[[Category:A')
					.replace(/\[\[Category:b/g, '[[Category:B')
					.replace(/\[\[Category:c/g, '[[Category:C')
					.replace(/\[\[Category:d/g, '[[Category:D')
					.replace(/\[\[Category:e/g, '[[Category:E')
					.replace(/\[\[Category:f/g, '[[Category:F')
					.replace(/\[\[Category:g/g, '[[Category:G')
					.replace(/\[\[Category:h/g, '[[Category:H')
					.replace(/\[\[Category:i/g, '[[Category:I')
					.replace(/\[\[Category:j/g, '[[Category:J')
					.replace(/\[\[Category:k/g, '[[Category:K')
					.replace(/\[\[Category:l/g, '[[Category:L')
					.replace(/\[\[Category:m/g, '[[Category:M')
					.replace(/\[\[Category:n/g, '[[Category:N')
					.replace(/\[\[Category:o/g, '[[Category:O')
					.replace(/\[\[Category:p/g, '[[Category:P')
					.replace(/\[\[Category:q/g, '[[Category:Q')
					.replace(/\[\[Category:r/g, '[[Category:R')
					.replace(/\[\[Category:s/g, '[[Category:S')
					.replace(/\[\[Category:t/g, '[[Category:T')
					.replace(/\[\[Category:u/g, '[[Category:U')
					.replace(/\[\[Category:v/g, '[[Category:V')
					.replace(/\[\[Category:w/g, '[[Category:W')
					.replace(/\[\[Category:x/g, '[[Category:X')
					.replace(/\[\[Category:y/g, '[[Category:Y')
					.replace(/\[\[Category:z/g, '[[Category:Z')
					.replace(/\[\[file:/g, '[[File:') // capitalize files
					.replace(/\[\[File:\s+/g, '[[File:')
					.replace(/\[\[File:a/g, '[[File:A')
					.replace(/\[\[File:b/g, '[[File:B')
					.replace(/\[\[File:c/g, '[[File:C')
					.replace(/\[\[File:d/g, '[[File:D')
					.replace(/\[\[File:e/g, '[[File:E')
					.replace(/\[\[File:f/g, '[[File:F')
					.replace(/\[\[File:g/g, '[[File:G')
					.replace(/\[\[File:h/g, '[[File:H')
					.replace(/\[\[File:i/g, '[[File:I')
					.replace(/\[\[File:j/g, '[[File:J')
					.replace(/\[\[File:k/g, '[[File:K')
					.replace(/\[\[File:l/g, '[[File:L')
					.replace(/\[\[File:m/g, '[[File:M')
					.replace(/\[\[File:n/g, '[[File:N')
					.replace(/\[\[File:o/g, '[[File:O')
					.replace(/\[\[File:p/g, '[[File:P')
					.replace(/\[\[File:q/g, '[[File:Q')
					.replace(/\[\[File:r/g, '[[File:R')
					.replace(/\[\[File:s/g, '[[File:S')
					.replace(/\[\[File:t/g, '[[File:T')
					.replace(/\[\[File:u/g, '[[File:U')
					.replace(/\[\[File:v/g, '[[File:V')
					.replace(/\[\[File:w/g, '[[File:W')
					.replace(/\[\[File:x/g, '[[File:X')
					.replace(/\[\[File:y/g, '[[File:Y')
					.replace(/\[\[File:z/g, '[[File:Z')
					.replace(/\{\{([\s\S]+)\|(\n)([\d\w])([\s\S])\}\}/g,'{{$1$2|$3$4}}') // wrong {{Infobox}}
					.replace(/<references \/>/gi, '{{Reflist}}');
					
				context.helper
					.setEditSummary('general fixes')
					.clickDiff();
			}
		},
	]);
});

//importScript('User:The Evil IP address/debug.js');
importScript('User:GregU/dashes.js');
//importScript('User:The Evil IP address/hdedit.js');
importScript('User:Ohconfucius/script/MOSNUM dates.js');
importScript('User:Ohconfucius/script/EngvarB.js');  //[[User:Ohconfucius/script/EngvarB.js]]