MediaWiki:Gadget-formatuj.js
Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.
- Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
- Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
- Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
- Opera: Naciśnij klawisze Ctrl+F5.
/*<pre><nowiki>*/
// Dodaje opis w opisie zmian, o ile takiego nie było.
function dodajOpis( opis ) {
var wpS = document.forms.editform.wpSummary;
wpS.value = jQuery.trim( wpS.value );
if ( wpS.value.indexOf( opis ) < 0 ) {
if ( wpS.value.substring( wpS.value.length, wpS.value.length - 2 ) == "*\/" ) {
wpS.value = wpS.value + " " + opis;
} else {
if ( wpS.value.length > 0 ) {
wpS.value = wpS.value + ", " + opis;
} else {
wpS.value = opis;
}
}
}
}
function format() {
var txt = document.editform.wpTextbox1;
var old = txt.value;
txt.value = whitespace(txt.value);
txt.value = interpunkcja(txt.value);
txt.value = poprawCudzyslowy(txt.value);
txt.value = catFixer(txt.value);
txt.value = entities(txt.value);
txt.value = fixheadings(txt.value);
txt.value = fixsyntax(txt.value);
txt.value = linkfixer(txt.value, false);
//txt.value = imagefixer(txt.value);
txt.value = whitespace(txt.value);
txt.value = linksimplifyer(txt.value);
// txt.value = lamiemyInterWiki(txt.value);
txt.value = konceWiersza(txt.value);
// txt.value = zobaczKonceWiersza(txt.value);
txt.value = wielkoscZnakow(txt.value);
txt.value = sortujKategorie(txt.value);
txt.value = jQuery.trim(txt.value);
if (txt.value != jQuery.trim(old))
dodajOpis("formatowanie automatyczne");
}
function poprawCudzyslowy(str) {
// zamiana wszystkich cudzysłowów na proste "
str = str.replace(/[\u00AB\u00BB\u2018\u201A\u201C\u201D\u201E\u2039\u203A\u300C\u300D\u300E\u300F\uFE30\uFE41\uFE42\uFE43\uFE44]/gm, "\""); // \u2019
// otwarcie 201E „ 00AB « 201A ‚ zamknięcie 201D ” 00BB » 2019
do {
old = str;
// ważna kolejność, bo w obu jest sąsiedztwo z ' - dla '''a'''". powinien być nawias zamykający
// z drugiej strony: ''"'''Cośtam''' - otwierający
str = str.replace(/( '+|^|[\s\u201E=>\(\*\|])\"/gm, "$1\u201E");
str = str.replace(/\"([\s\u201D\:\.\!\?\)\]\}\<\;\'\,]|$)/gm, "\u201D$1");
str = str.replace(/(['])"/gm, "$1\u201E");
} while (old!=str);
do {
old = str;
str = str.replace(/(\u201E[^\u201D\u201E]*\u201E[^\u201D\u201E]*)\u201E/gm, "$1\"");
str = str.replace(/\u201D([^\u201D\u201E]*\u201D[^\u201D\u201E]*\u201D)/gm, "\"$1");
} while (old!=str);
do {
old = str;
str = str.replace(/(\u201E[^\u201D]*)\u201E/gm, "$1\u00AB");
str = str.replace(/(\u00AB[^\u201E\u201D\u00AB\u00BB]*)\u201D/gm, "$1\u00BB");
} while (old!=str);
do {
old = str;
str = str.replace(/^(\*\*[^\n]*)[\u201E\u201D\u00AB\u00BB]([^\n]*\(ang\.\))$/gm, '$1"$2');
} while (old!=str);
return str;
}
function zobaczKonceWiersza(str){
str = str.replace(/\n/gm, "!!!NNN!!!");
str = str.replace(/\r/gm, "!!!RRR!!!");
return jQuery.trim(str);
}
// "Nazwa używana w linku", // Nazwa do sortowania
// Ta tablica musi już być posortowana
var Jezyki=[
'aa','af','ak','als','am','ang','ab','ar','an',
'arc','roa-rup','frp','as','ast','gn','av','ay','az','id','ms','bm',
'bn','zh-min-nan','map-bms','jv','su','ban','ba','be','be-x-old','bh',
'bi','bo','bs','br','bug','bg','bxr','ca','ceb','cv','cs','ch',
'ny','sn',
'tum','cho','co','za','cy','da','pdc','de','dv','nv','dz','mh','et',
'na','el','eml','en','myv','es','eo','ext','eu','ee','to','fab','fa','fo','fr','fy','ff',
'fur','ga','gv','sm','gd','gl','gan','ki','glk','gu','got','zh-classical','hak','xal','ko','ha','haw',
'hy','hi','ho','hsb','hr','io','ig','ilo','bpy','ia','ie','iu','ik','os','xh','zu',
'is','it','he','kl','pam','kn','kr','ka','ks','csb','kk','kk-cn','kk-kz','kw','rw','ky',
'rn','sw','kv','kg','ht','kj','ku','lad','lbe','lo','ltg','la','lv','lb','lij','lt',
'li','ln','jbo','lg','lmo','hu','mk','mg','ml','mt','mi','mr','mzn','chm','cdo','mdf','mo',
'mn','mus','my','nah','fj','nl','nds-nl','cr','ne','new','ja','nap','ce',
'pih','no','nn','nrm','nov','oc','or','om','ng','hz','ug','uz','pa',
'pi','pag','pap','ps','km','pms','nds','pl','pt','kaa','kk-tr','ty','ksh','ro',
'rmy','rm','qu','ru','se','sa','sg','sc','sah','sco','stq','st','tn','sq','scn',
'si','simple','sd','ss','sk','cu','sl','szl','so','sr','sh','fi','sv','tl',
'ta','kab','roa-tara','tt','te','tet','th','vi','ti','tg','tpi','chr','chy',
've','tr','tk','tw','udm','uk','ur','vec','vo','fiu-vro','wa',
'vls','war','wo','wuu','ts','ii','yi','yo','zh-yue','cbk-zam','diq','zea','bat-smg',
'zh','zh-tw','zh-cn'];
function sortujKategorie(str){
var ds="";
if (str.search(/\{\{(DEFAULTSORT|SORTUJ)\:[^\n\[\]]*\}\}/gmi) != -1) {
var p=str.search(/\{\{(DEFAULTSORT|SORTUJ)\:[^\n\[\]]*\}\}/gmi);
var f=str.match(/\{\{(DEFAULTSORT|SORTUJ)\:[^\n\[\]]*\}\}/gmi)[0];
ds=f+"\n";
str=str.substring(0,p)+" "+str.substring(p+f.length,str.length);
}
var kat="";
while (str.search(/\[\[Kategoria\:[^\n\[\]]*\]\]/gmi) != -1) {
var p=str.search(/\[\[Kategoria\:[^\n\[\]]*\]\]/gmi);
var f=str.match(/(\[\[Kategoria\:[^\n\[\]]*\]\])/gmi)[0];
kat=kat+f+"\n";
str=str.substring(0,p)+" "+str.substring(p+f.length,str.length);
}
kat = kat.replace(/(\[\[Kategoria\:[^\n\[\]]*\|)\*\]\]/gmi, "$1!]]");
if (kat.search(/\[\[Kategoria\:[^\n\[\]]*\|[^\n\[\]\!]+\]\]/gmi) != -1) {
if (ds=="") {
ds = kat.match(/\[\[Kategoria\:[^\n\[\]]*\|[^\n\[\]\!]+\]\]/gmi)[0];
ds = ds.replace(/\[\[Kategoria\:[^\n\[\]]*\|([^\n\[\]\!]+)\]\]/gmi, "$1");
if (ds==mw.config.get('wgPageName')) ds=""; else ds = "{{SORTUJ:" + ds + "}}\n";
}
kat = kat.replace(/(\[\[Kategoria\:[^\n\[\]]*)\|[^\n\[\]\!]+\]\]/gmi, "$1]]");
}
var ilink="";
var i;
for (i=0; i<Jezyki.length; i++ ) {
var sr="\\[\\["+Jezyki[i]+"\\:[\^\\n\[\\]]*\\]\\]";
while (str.search(sr,"gmi") != -1) {
var p=str.search(sr,"gmi");
var f=str.match(sr,"gmi")[0];
ilink=ilink+"\n"+f;
str=str.substring(0,p)+" "+str.substring(p+f.length,str.length);
}
}
str=konceWiersza(str)+"\n\n\n"+ds+kat+ilink;
return jQuery.trim(str);
}
function wielkoscZnakow(str){
str = str.replace(/^\x2a\x2a ?Autor\:? /gmi, "** Autor: ");
str = str.replace(/^\x2a\x2a ?Opis\:? /gmi, "** Opis: ");
str = str.replace(/^\x2a\x2a ?Pochodzenie\:/gmi, "** Opis:");
str = str.replace(/^\x2a\x2a ?Komentarz\:/gmi, "** Opis:");
str = str.replace(/^\x2a\x2a ?[ŹŻZ]r[óou]d[łl][oó]\:?/gmi, "** Źródło:");
str = str.replace(/^\x2a\x2a ?Postać\:?/gmi, "** Postać:");
str = str.replace(/^\x2a\x2a ?Zobacz też\:?/gmi, "** Zobacz też:");
str = str.replace(/^\x2a\x2a ?Postacie?\:?/gmi, "** Postacie:");
str = str.replace(/\[\[Plik\: */gmi, "[[Plik:");
str = str.replace(/\[\[Image\: */gmi, "[[Plik:");
str = str.replace(/\[\[Grafika\: */gmi, "[[Plik:");
str = str.replace(/\[\[Plik\: *Plik\: */gmi, "[[Plik:");
str = str.replace(/\[\[Plik\: *Grafika\: */gmi, "[[Plik:");
str = str.replace(/\[\[Plik\: *Image\: */gmi, "[[Plik:");
// Inne
// Porządki w biogramach w linii nazwiska
str = str.replace(/w[łl]a[śs][ćc]\./gi, "właśc.");
str = str.replace(/, ur\./gi, "; ur.");
str = str.replace(/, ([0-9]{3,4}\u2013[0-9]{3,4})/gi, "; $1");
// Wymieniamy w linkach [[w:pl: na [[w:
str = str.replace(/\[\[w\:pl\:/gi, "[[w:");
// Zmieniamy skrót strony na s.
str = str.replace(/ str(\.|ona) ?([0-9]+\.?)/gi, " s. $2");
// Usuwamy przecinek pomiędzy miejsce wydania i rok
str = str.replace(/(Warszawa|Kraków|Wrocław|Gdańsk), (20|1[7-9])([0-9]{2})/gi, "$1 $2$3");
return jQuery.trim(str);
}
function konceWiersza(str){
// Usuwamy podwójne wiersze przed **
str = str.replace(/\n*(\n\x2a\x2a)/gm, "$1");
// Wstawiamy podwójne wiersze przed *
str = str.replace(/([^\n\=])(\n)(\x2a[^\x2a])/gm, "$1$2$2$3");
str = str.replace(/\=[\n\r]*([\n])\x2a/gm, "=$1*");
// Usuwamy podwójny koniec wiersza przed pierwszą *
var l="\n";
l=l.length;
if (str.indexOf("\n\n*")+l*2==str.indexOf("*"))
str = str.substring(0,str.indexOf("\n\n*"))+str.substring(str.indexOf("\n\n*")+l);
// Zamiana Zobacz też na '''Zobacz też:'''
str = str.replace(/^Zobacz te.\:?$/gm, "'''Zobacz też:'''");
str = str.replace(/^\=\=\=Zobacz te.\=\=\=$/gm, "==Zobacz też==");
// Usuwamy podwójne wiersze, jeśli wczesniej była sekwencja Zobacz też:''
var org; do { org=str;
str = str.replace(/(Zobacz te.)\:?(\'\'\'[^=]*)\n(\n\x2a)/gm, "$1:$2$3");
// Usuwamy podwójne wiersze, jeśli wczesniej była sekwencja ==Zobacz też==''
str = str.replace(/\=\=Zobacz te.\:?\=\=([^=]*)\n(\n\x2a)/gm, "==Zobacz też==$1$2");
// Usuwamy podwójne wiersze, jeśli wczesniej była sekwencja ==Obsada==''
str = str.replace(/\=\=Obsada\:?\=\=([^=]*)\n(\n\x2a)/gm, "==Obsada==$1$2");
// Usuwamy <br /> z końca wiersza jeśli w następnym jest **
str = str.replace(/<br \/>\n+\*/gm, "\n*");
} while (org != str);
return jQuery.trim(str);
}
function interpunkcja(str){
var org;
do {
org=str;
// ((?:^[^\n\[]+)|(?:\][^\n\[^\]]+)) na początku wiersza zabezpiecza przed zmianą w [ ]
// ((?:^[^\n\[\{]?)|(?:\][^\n\[\]\{]+)|(?:\}[^\n\{\}\[]+)) [ ] oraz { }
// Usuwamy spację przed znakiem interpunkcyjnym
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))([a-zA-Ząśżźćęń󳥌ŻŹĆĘŃÓŁ]+)(?: +)([\.\,\;\!\?\)\:])/gm, "$1$2$3");
// Usuwamy spację za znakiem interpunkcyjnym
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\()(?: +)([a-zA-Ząśżźćęń󳥌ŻŹĆĘŃÓŁ]+)/gm, "$1$2$3");
// Wstawiamy spację przed znakiem interpunkcyjnym
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))([a-zA-Ząśżźćęń󳥌ŻŹĆĘŃÓŁ]+)(\()([^\)\n]+( ))/gm, "$1$2 $3$4$5");
// Wstawiamy spację za znakiem interpunkcyjnym
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))([\.\,\;\!\?\)\:])([a-zA-Ząśżźćęń󳥌ŻŹĆĘŃÓŁ]*)([a-zA-Ząśżźćęń󳥌ŻŹĆĘŃÓŁ]+)/gm, "$1$2 $3$4");
// Usuwamy spacje w wielokropku
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\.)(?: +)(\.)/gm, "$1$2$3");
// Usuwamy spację w znacznikach formatowania
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))([\'\}])(?: +)(\')/gm, "$1$2$3");
// Usuwamy spację w znacznikach formatowania
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\')(?: +)([\{])/gm, "$1$2$3");
// Usuwamy spację w znacznikach formatowania
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\{)(?: +)(\{)/gm, "$1$2$3");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\})(?: +)(\})/gm, "$1$2$3");
// Usuwamy spacje przed i za : jeśli przed i za jest cyfra (formatowanie czasu), przecinek dla liczb
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d)(?: *)([\:])(?: +)(\d)/gm, "$1$2$3$4");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d)(?: +)([\:])(\d)/gm, "$1$2$3$4");
// str = str.replace(/\.\.\./g, "...");
// Myślniki przerabiamy na Unicode
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\&mdash\;)/gm, "$1\u2014");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\&ndash\;)/gm, "$1\u2013");
// Myślnik w tekście cytatu oraz tekstach opisu
// str = str.replace(/((?:^[^\[\{]*)|(?:\][^\[\]\{]*)|(?:\}[^\{\}\[]*))(.*)[\-\u2014]/g, "$1$2\u2013");
// Myślnik w tekście cytatu oraz tekstach opisu, ale nie pomiędzy cyframi
//str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(.*[^0-9\x2a ]) *[\u2014] *([^0-9 ])/gm, "$1$2 \u2014 $3");
//Wszystkie myślniki poza [] i {}
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))[\u002d\u2014\u2212] /gm, "$1\u2013 ");
//Usuwanie spacji w zakresach
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))([^0-9\[\{\u2013 ]) ?[\u2013] ?([^\n0-9 ])/gm, "$1$2 \u2013 $3");
// Myślnik w zakresie dat 1-1
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d) ?[\u002d\u2014\u2013] ?(\d)/gm, "$1$2\u2013$3");
// p.n.e. n.p.m.
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(.\.) ?(.\.) ?(.\.)/gm, "$1$2$3$4");
// n.e.
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(.\.) ?(.\.)/gm, "$1$2$3");
// m. in.
str = str.replace(/m\. *in\./gm, "m.in.");
// '''[[...]]''' (...) to
str = str.replace(/^(\'{3,5}\[\[[^\n\[\]]*\]\]\'{3,5}(?: \([^\n\)]*\))?) ?(?:(?:to)|(?:[\u002d\u2013\u2014\u2212\,]))/gmi, "$1 \u2013");
// Myślnik za myślnikiem w znaczniku formatowania
str = str.replace(/[\-\u2014\u2013] ?[\-\u2014\u2013] ?[\-\u2014\u2013] ?[\-\u2014\u2013]/g, "----");
str = str.replace(/[\-\u2014\u2013] ?[\-\u2014\u2013]/g, "--");
str = str.replace(/\< ?\! ?[\-\u2014\u2013] ?[\-\u2014\u2013]/g, "<!--");
str = str.replace(/[\-\u2014\u2013] ?[\-\u2014\u2013] ?\>/g, "-->");
// usuwamy right jeśli jest thumb
str = str.replace(/(\[\[Plik\:[^\]]*\|thumb[^\]]*)\|right/gi, "$1");
str = str.replace(/(\[\[Plik\:[^\]]*)\|right([^\]]*\|thumb)/gi, "$1$2");
str = str.replace(/(\[\[Plik\:[^\]]*\|mały[^\]]*)\|right/gi, "$1");
str = str.replace(/(\[\[Plik\:[^\]]*)\|right([^\]]*\|mały)/gi, "$1$2");
// usuwamy px jeśli jest thumb
str = str.replace(/(\[\[Plik\:[^\]]*\|thumb[^\]]*)\|\d\d?\d?px/gi, "$1");
str = str.replace(/(\[\[Plik\:[^\]]*)\|\d\d?\d?px([^\]]*\|thumb)/gi, "$1$2");
str = str.replace(/(\[\[Plik\:[^\]]*\|mały[^\]]*)\|\d\d?\d?px/gi, "$1");
str = str.replace(/(\[\[Plik\:[^\]]*)\|\d\d?\d?px([^\]]*\|mały)/gi, "$1$2");
// zmieniamy thumb na mały
str = str.replace(/(\[\[Plik\:[^\]]*\|)thumb/gi, "$1mały");
// podwójne odstępy między wierszami bez sensu
str = str.replace(/(\]\]\n)\n(\[\[)/gm, "$1$2");
str = str.replace(/(\]\]\n)\n(\'{3,5}\[\[)/gm, "$1$2");
// URL-e
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))([a-zA-Z]*\.) ?(pl|com|net|gov|de|org|net|eu|press|info)/gm, "$1$2$3");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))([a-zA-Z]*\.) ?([a-zA-Z]*\.)(pl|com|net|gov|de|org|net|eu|press|info)/gm, "$1$2$3$4");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))([a-zA-Z]*\.) ?([a-zA-Z]*\.)([a-zA-Z]*\.)(pl|com|net|gov|de|org|net|eu|press|info)/gm, "$1$2$3$4$5");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))([a-zA-Z]*\.) ?([a-zA-Z]*\.)([a-zA-Z]*\.)([a-zA-Z]*\.)(pl|com|net|gov|de|org|net|eu|press|info)/gm, "$1$2$3$4$5$6");
// Poprawa dat
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d\d\d)[\-\u2013\u2014\. ](?:01|1|I)[\-\u2013\u2014\. ](\d\d)/gm, "$1$3 stycznia $2");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d\d\d)[\-\u2013\u2014\. ](?:02|2|II)[\-\u2013\u2014\. ](\d\d)/gmi, "$1$3 lutego $2");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d\d\d)[\-\u2013\u2014\. ](?:03|3|III)[\-\u2013\u2014\. ](\d\d)/gmi, "$1$3 marca $2");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d\d\d)[\-\u2013\u2014\. ](?:04|4|IV)[\-\u2013\u2014\. ](\d\d)/gmi, "$1$3 kwietnia $2");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d\d\d)[\-\u2013\u2014\. ](?:05|5|V)[\-\u2013\u2014\. ](\d\d)/gmi, "$1$3 maja $2");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d\d\d)[\-\u2013\u2014\. ](?:06|6|VI)[\-\u2013\u2014\. ](\d\d)/gmi, "$1$3 czerwca $2");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d\d\d)[\-\u2013\u2014\. ](?:07|7|VII)[\-\u2013\u2014\. ](\d\d)/gmi, "$1$3 lipca $2");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d\d\d)[\-\u2013\u2014\. ](?:08|8|VIII)[\-\u2013\u2014\. ](\d\d)/gmi, "$1$3 sierpnia $2");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d\d\d)[\-\u2013\u2014\. ](?:09|9|IX)[\-\u2013\u2014\. ](\d\d)/gmi, "$1$3 września $2");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d\d\d)[\-\u2013\u2014\. ](?:10|10|X)[\-\u2013\u2014\. ](\d\d)/gm, "$1$3 października $2");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d\d\d)[\-\u2013\u2014\. ](?:11|11|XI)[\-\u2013\u2014\. ](\d\d)/gmi, "$1$3 listopada $2");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d\d\d)[\-\u2013\u2014\. ](?:12|12|XII)[\-\u2013\u2014\. ](\d\d)/gmi, "$1$3 grudnia $2");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d)[\-\u2013\u2014\. ](?:01|1|I)[\-\u2013\u2014\. ](\d\d\d\d)/gm, "$1$2 stycznia $3");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d)[\-\u2013\u2014\. ](?:02|2|II)[\-\u2013\u2014\. ](\d\d\d\d)/gmi, "$1$2 lutego $3");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d)[\-\u2013\u2014\. ](?:03|3|III)[\-\u2013\u2014\. ](\d\d\d\d)/gmi, "$1$2 marca $3");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d)[\-\u2013\u2014\. ](?:04|4|IV)[\-\u2013\u2014\. ](\d\d\d\d)/gmi, "$1$2 kwietnia $3");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d)[\-\u2013\u2014\. ](?:05|5|V)[\-\u2013\u2014\. ](\d\d\d\d)/gmi, "$1$2 maja $3");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d)[\-\u2013\u2014\. ](?:06|6|VI)[\-\u2013\u2014\. ](\d\d\d\d)/gmi, "$1$2 czerwca $3");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d)[\-\u2013\u2014\. ](?:07|7|VII)[\-\u2013\u2014\. ](\d\d\d\d)/gmi, "$1$2 lipca $3");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d)[\-\u2013\u2014\. ](?:08|8|VIII)[\-\u2013\u2014\. ](\d\d\d\d)/gmi, "$1$2 sierpnia $3");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d)[\-\u2013\u2014\. ](?:09|9|IX)[\-\u2013\u2014\. ](\d\d\d\d)/gmi, "$1$2 września $3");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d)[\-\u2013\u2014\. ](?:10|10|X)[\-\u2013\u2014\. ](\d\d\d\d)/gm, "$1$2 października $3");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d)[\-\u2013\u2014\. ](?:11|11|XI)[\-\u2013\u2014\. ](\d\d\d\d)/gmi, "$1$2 listopada $3");
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))(\d\d)[\-\u2013\u2014\. ](?:12|12|XII)[\-\u2013\u2014\. ](\d\d\d\d)/gmi, "$1$2 grudnia $3");
// W numerach ISBN powinny być minusy
str = str.replace(/(ISBN ?[\d\-]*)[\u2013\u2014]/gmi, "$1-");
// Usuwam 0 sprzed pierwszej liczby
str = str.replace(/((?:^[^\n\[\{]*)|(?:\][^\n\[\]\{]*)|(?:\}[^\n\{\}\[]*))0(\d (?:stycznia|lutego|marca|kwietnia|maja|czerwca|lipca|sierpnia|września|października|listopada|grudnia) \d\d\d\d)/gmi, "$1$2");
// W pierwszym wierszu przecinek na dywiz
// str = str.replace(/^((?:\[[^\n]*\]\n)*[^\,\n\u2012\u2013\[]*(?:\([^\)\(\n\[]*\))?)\,/, "$1\u2013");
// Usuwam przecinek przed numerem czasopisma
str = str.replace(/(\u201D\]?), nr /gmi, "$1 nr ")
// W pierwszym wierszu ''''' na '''
str = str.replace(/^''('''[^\n']*''')''/, "$1");
} while (org != str);
return jQuery.trim(str);
}
function whitespace(str){
str = str.replace(/\t/g, " ");
// Standaryzujemy końce wiersza
str = str.replace(/(\r)(\n)/gm, "$2");
str = str.replace(/\r/gm, "\n");
str = str.replace(/(\r)(\n)/gm, "$2");
str = str.replace(/^ ? ? (\n)/gm, "$1");
str = str.replace(/(\n\n)\n+/gm, "$1");
str = str.replace(/== ? ?\n(\n)==/gm, "==$1==");
str = str.replace(/\n(\n\* ?\[?http)/gm, "$1");
str = str.replace(/^ ? ? (\n)/gm, "$1");
str = str.replace(/\n(\n\*)/gm, "$1");
str = str.replace(/[ \t][ \t]+/g, " ");
str = str.replace(/([=\n]\n)\n+/gm, "$1");
str = str.replace(/ *(\n)/gm, "$1");
//* bullet points
str = str.replace(/^([\*#]+) /gm, "$1");
str = str.replace(/^([\*#]+)/gm, "$1 ");
//==Headings==
str = str.replace(/^(={1,4}) ?(.*?) ?(={1,4})$/gm, "$1$2$3");
//dash — spacing
str = str.replace(/ ?(–|–|–|–|–) ?/g, "$1");
str = str.replace(/ ?(—|—|—|—|—) ?/g, "$1");
str = str.replace(/([^1-9])(—|—|—|—|—|–|–|–|–|–)([^1-9])/g, "$1 $2 $3");
//Spacje na końcach i początkach wierszy
str = str.replace(/ ? ?<br \/> ? ?/gi, "<br />");
str = str.replace(/^ /g, "");
str = str.replace(/ $/g, "");
return jQuery.trim(str);
}
function entities(str){
//str = str.replace(//g, "");
str = str.replace(/–|–|–/g, "–");
str = str.replace(/—|—|—/g, "—");
// str = str.replace(/(cm| m|km|mi)<sup>2</sup>/g, "$1²");
str = str.replace(/²/g, "²");
str = str.replace(/°/g, "°");
return jQuery.trim(str);
}
//Fix ==See also== and similar section common errors.
function fixheadings(str)
{
if( !str.match(/= ?See also ?=/) )
str = str.replace(/(== ?)(see also:?|related topics:?|related articles:?|internal links:?|also see:?)( ?==)/gi, "$1See also$3");
str = str.replace(/(== ?)(external links?:?|outside links?|web ?links?:?|exterior links?:?)( ?==)/gi, "$1External links$3");
str = str.replace(/(== ?)(references?:?)( ?==)/gi, "$1References$3");
str = str.replace(/(== ?)(sources?:?)( ?==)/gi, "$1Sources$3");
str = str.replace(/(== ?)(further readings?:?)( ?==)/gi, "$1Further reading$3");
return str;
}
function catFixer(str){
str = str.replace(/\[\[ ?[Cc]ategory ?: ?/g, "[[Kategoria:");
str = str.replace(/\[\[ ?[Kk]ategoria ?: ?/g, "[[Kategoria:");
return jQuery.trim(str);
}
//fixes many common syntax problems
function fixsyntax(str)
{
//replace html with wiki syntax
if( !str.match(/'<\/?[ib]>|<\/?[ib]>'/gi) )
{
str = str.replace(/<i>(.*?)<\/i>/gi, "''$1''");
str = str.replace(/<b>(.*?)<\/b>/gi, "'''$1'''");
}
str = str.replace(/<br\/>/gi, "<br />");
str = str.replace(/<br>/gi, "<br />");
str = str.replace(/ ? ?<br \/> ? ?/gi, "<br />");
return jQuery.trim(str);
}
//formats links in standard fashion
function linkfixer(str, checkImages)
{
str = str.replace(/\]\[/g, "] [");
var m = str.match(/\[?\[[^\]]*?\]\]?/g);
if (m)
{
for (var i = 0; i < m.length; i++)
{
var x = m[i].toString();
var y = x;
//internal links only
if ( !y.match(/^\[?\[http:\/\//i) && !y.match(/^\[?\[image:/i) )
{
if (y.indexOf(":") == -1 && y.substr(0,3) != "[[_" && y.indexOf("|_") == -1)
{
if (y.indexOf("|") == -1)
y = y.replace(/_/g, " ");
else
y = y.replace( y.substr(0, y.indexOf("|")), y.substr(0, y.indexOf("|")).replace(/_/g, " "));
}
y = y.replace(/ ?\| ?/, "|").replace("|]]", "| ]]");
}
str = str.replace(x, y);
}
}
//repair bad internal links
str = str.replace(/\[\[ ?([^\]]*?) ?\]\]/g, "[[$1]]");
str = str.replace(/\[\[([^\]]*?)( |_)#([^\]]*?)\]\]/g, "[[$1#$3]]");
//repair bad external links
str = str.replace(/\[?\[http:\/\/([^\]]*?)\]\]?/gi, "[http://$1]");
str = str.replace(/\[http:\/\/([^\]]*?)\|([^\]]*?)\]/gi, "[http://$1 $2]");
return jQuery.trim(str);
}
//fixes images
function imagefixer(str)
{
//remove external images
str = str.replace(/\[?\[image:http:\/\/([^\]]*?)\]\]?/gi, "[http://$1]");
str = str.replace(/\[?\[grafika:http:\/\/([^\]]*?)\]\]?/gi, "[http://$1]");
str = str.replace(/\[?\[plik:http:\/\/([^\]]*?)\]\]?/gi, "[http://$1]");
//fix links within internal images
var m = str.match(/\[?\[image:[^\[\]]*?(\[?\[[^\]]*?\]*?[^\[\]]*?)*?\]+/gi);
if (m)
{
for (var i = 0; i < m.length; i++)
{
var x = m[i].toString();
var y = x;
y = y.replace(/^\[\[i/i, "I").replace(/\]\]$/, "");
y = y.replace(/(\[[^\]]*?)$/, "$1]");
y = linkfixer(y, true);
y = "[[" + y + "]]";
str = str.replace(x, y);
}
}
var m = str.match(/\[?\[grafika:[^\[\]]*?(\[?\[[^\]]*?\]*?[^\[\]]*?)*?\]+/gi);
if (m)
{
for (var i = 0; i < m.length; i++)
{
var x = m[i].toString();
var y = x;
y = y.replace(/^\[\[g/i, "G").replace(/\]\]$/, "");
y = y.replace(/(\[[^\]]*?)$/, "$1]");
y = linkfixer(y, true);
y = "[[" + y + "]]";
str = str.replace(x, y);
}
}
var m = str.match(/\[?\[plik:[^\[\]]*?(\[?\[[^\]]*?\]*?[^\[\]]*?)*?\]+/gi);
if (m)
{
for (var i = 0; i < m.length; i++)
{
var x = m[i].toString();
var y = x;
y = y.replace(/^\[\[p/i, "P").replace(/\]\]$/, "");
y = y.replace(/(\[[^\]]*?)$/, "$1]");
y = linkfixer(y, true);
y = "[[" + y + "]]";
str = str.replace(x, y);
}
}
return jQuery.trim(str);
}
//simplifies some links e.g. [[Dog|dog]] to [[dog]] and [[Dog|dogs]] to [[dog]]s
function linksimplifyer(str){
var m = str.match(/\[\[([^\[]*?)\|([^\[]*?)\]\]/g);
if (m)
{
for (var i = 0; i < m.length; i++)
{
var n_arr = m[i].toString().match(/\[\[([^\[]*?)\|([^\[]*?)\]\]/);
var n = n_arr[0];
var a = n_arr[1];
var b = n_arr[2];
if (b.indexOf(a) == 0 || b.indexOf(TurnFirstToLower(a)) == 0)
{
var k = n.replace(/\[\[([^\]\|]*?)\|(\1)([a-zA-Ząśżźćęń󳥌ŻŹĆĘŃÓŁ]*?)\]\]/i, "[[$2]]$3");
str = str.replace(n, k);
}
}
}
str = str.replace(/\[\[([^\]\|]+)\|([^\]\|]+)\]\]([A-Za-z\'][A-Za-z]*)([\.\,\;\:\"\!\?\s\n])/g, "[[$1|$2$3]]$4");
return str;
}
//turns first character to lowercase
function TurnFirstToLower( input ) {
if ( input == "" ) {
return "";
}
input = jQuery.trim( input );
var temp = input.substr( 0, 1 );
return temp.toLowerCase() + input.substr( 1, input.length );
}
//entities that should never be unicoded
function noUnicodify( str ) {
str = str.replace( " & ", " & " );
str = str.replace( "&", "&amp;" ).replace( "&lt;", "&amp;lt;" ).replace( "&gt;", "&amp;gt;" ).replace( "&quot;", "&amp;quot;" ).replace( "&apos;", "&amp;apos;" );
str = str.replace( "−", "&minus;" ).replace( "×", "&times;" );
str = str.replace( " ", "&nbsp;" ).replace( " ", "&thinsp;" ).replace( "­", "&shy;" );
str = str.replace( "′", "&prime;" );
str = str.replace( /&(#0?9[13];)/, "&$1" );
str = str.replace( /&(#0?12[345];)/, "&$1" );
return str;
}
toolbarGadget.addButton( {
title: 'Formatuj tekst',
alt: "Formatuj",
id: "fmt_img_btn",
oldIcon: '//upload.wikimedia.org/wikipedia/commons/c/c1/Button_wikiquote.png',
newIcon: '//upload.wikimedia.org/wikipedia/commons/c/c1/Button_wikiquote.png',
onclick: function() {
format();
}
} );
toolbarGadget.addButton( {
title: 'Wstaw znaczniki br (wersja 1)',
alt: 'Wstaw znaczniki br',
oldIcon: '//upload.wikimedia.org/wikipedia/commons/c/c5/Button_br.png',
newIcon: '//upload.wikimedia.org/wikipedia/commons/c/c5/Button_br.png',
onclick: function() {
// Jeśli tekst jest zaznaczony, to wstawia łamanie wiersza zamiast każdego końca wiersza
// Jeśli tekst nie jest zaznaczony to usuwa końce wiersza za znakiem <br />
var $textbox = jQuery( document.editform.wpTextbox1 );
var oldContent = $textbox.textSelection( 'getSelection' );
var selection = true;
if ( oldContent == "" ) {
selection = false;
oldContent = $textbox.val();
}
oldContent = jQuery.trim( oldContent );
var tmp = oldContent;
var newContent;
do {
newContent = tmp;
tmp = tmp.replace( /<br \/>\r?\n([^\s])/gi, "<br />$1" );
tmp = tmp.replace( /(\*[^\n\r]*)\r?\n([^\=\*\:\n\r])/gi, "$1<br />$2" );
if ( selection ) {
tmp = tmp.replace( /\r?\n([^\s])/gi, "<br \/>$1" );
}
tmp = jQuery.trim( tmp );
} while ( tmp != newContent );
if ( oldContent != newContent ) {
if ( selection ) {
$textbox.textSelection( 'encapsulateSelection', {
peri: newContent,
replace: true
} );
} else {
$textbox.val( newContent );
}
dodajOpis( "łamanie wierszy" );
}
}
} );
toolbarGadget.addButton( {
title: 'Usuń znaczniki br (wersja 1)',
alt: 'Usuń znaczniki br',
oldIcon: '//upload.wikimedia.org/wikipedia/commons/f/f3/Button_brrm.png',
newIcon: '//upload.wikimedia.org/wikipedia/commons/f/f3/Button_brrm.png',
onclick: function() {
var $textbox = jQuery( document.editform.wpTextbox1 );
var oldContent = jQuery.trim( $textbox.val() );
var newContent = oldContent;
newContent = newContent.replace( /<br\/?>/gi, "<br \/>" );
newContent = newContent.replace( /<br \/>([^\r\n])/gi, "<br \/>\n$1" );
newContent = jQuery.trim( newContent );
if ( oldContent != newContent ) {
$textbox.val( newContent );
dodajOpis( "łamanie wierszy" );
}
}
} );
/*</nowiki></pre>*/