MediaWiki:Gadget-sk-local.js

Z Wikicytatów, wolnej kolekcji cytatów

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>*/

mw.config.set( 'wp-sk-summary', 'sprzątanie kodu' );
mw.config.set( 'wp-sk-sort-categories', true );
mw.config.set( 'wp-sk-categories-head', '\n\n' );
mw.config.set( 'wp-sk-fix-wikipedia-sections', false );

// 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 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 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\: *Plik\: */gmi, "[[Plik:" );
	str = str.replace( /\[\[Plik\: *Grafika\: */gmi, "[[Plik:" );
	str = str.replace( /\[\[Plik\: *Image\: */gmi, "[[Plik:" );
	// Inne
	// Wymieniamy w linkach [[w:pl: na [[w:
	str = str.replace( /\[\[w\:pl\:/gi, "[[w:" );
	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)/gmi, "$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)/gmi, "$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)/gmi, "$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)/gmi, "$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)/gmi, "$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)/gmi, "$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)/gmi, "$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)/gmi, "$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");
		// 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( / ?(–|&#150;|&ndash;|&#8211;|&#x2013;) ?/g, "$1" );
	str = str.replace( / ?(—|&#151;|&mdash;|&#8212;|&#x2014;) ?/g, "$1" );
	str = str.replace( /([^1-9])(—|&#151;|&mdash;|&#8212;|&#x2014;|–|&#150;|&ndash;|&#8211;|&#x2013;)([^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( /&#150;|&#8211;|&#x2013;/g, "&ndash;" );
	str = str.replace( /&#151;|&#8212;|&#x2014;/g, "&mdash;" );
	str = str.replace( /&sup2;/g, "²" );
	str = str.replace( /&deg;/g, "°" );

	return jQuery.trim( str );
}

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 );
}

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 );
}

wp_sk.projectSpecificCleanup = function( text ) {
	text = jQuery.trim( text );
	text = whitespace( text );
	text = interpunkcja( text );
	text = poprawCudzyslowy( text );
	text = entities( text );
	text = fixsyntax( text );
	text = linkfixer( text, false );
	text = whitespace( text );
	text = konceWiersza( text );
	text = wielkoscZnakow( text );
	text = jQuery.trim( text );
	return text;
};

if ( mw.user.options.get( 'gadget-autoformat' ) != '1' ) {
	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>*/