/**
* Blendet eine „Auto-Format“-Funktion in der Werkzeugleiste ein, die viele typische Wikifizierungs-Fehler
* automatisch korrigiert. Eine ausführliche Beschreibung ist auf der Diskussionsseite zu finden.
* (<nowiki> zur Umgehung von ].)
*/
( function( $, mw ) {
if ( !document.forms
|| ( mw.config.get( 'wgAction' ) !== 'edit' && mw.config.get( 'wgAction' ) !== 'submit' )
) {
return;
}
function escapeRE( s ) {
return s.replace( /(^{|}])/g, '\\$1' );
}
mw.libs = mw.libs || {};
mw.libs.autoFormatter = {
/**
* @param {HTMLAnchorElement}
* @return {boolean}
*/
click: function( clickedElement ) {
var e = document.forms.elements,
textbox = e,
summaryElement = e;
if ( !textbox ) {
return false;
}
/* Reset the button as fast as possible, even before triggering WikEd */
this.updateButton( clickedElement );
var syntaxHighlightingEnabled = this.toggleSyntaxHighlighting( false );
var context = this.fetchGlobalContext();
var hasChanges = this.cleanSelectedOrAllTextInElement( textbox, context, this.cleanText.bind( this ) );
/* Update the button as fast as possible the moment we have a result */
this.updateButton( clickedElement, context.visiblyChanged );
summaryElement.value = this.cleanSummary( summaryElement.value, context );
if ( syntaxHighlightingEnabled ) {
this.toggleSyntaxHighlighting( true );
}
if ( hasChanges ) {
mw.hook( 'AutoFormatterDoneWithChange' ).fire();
}
/* Do not follow the links href if the clicked element was a link */
return false;
},
/**
* @param {boolean} enable
* @return {boolean}
*/
toggleSyntaxHighlighting: function ( enable ) {
if ( window.wikEd && window.wikEd.useWikEd ) {
wikEd();
return true;
}
},
/**
* @return {Object}
*/
fetchGlobalContext: function() {
var lang = mw.config.get( 'wgContentLanguage' ),
local = window.autoFormatLocalisation,
context = {
lang: lang,
localisation: typeof local === 'undefined' || local === true ? lang : local
};
/* Sets an isDe property if the language code is "de", and so on */
context = true;
return context;
},
/**
* @param {HTMLAnchorElement}
* @param {boolean|undefined}
*/
updateButton: function( a, changed ) {
if ( !a || !a.nodeType || a.rel === 'autoFormatter' ) {
$( a && a.nodeType ? a : '' ).css( {
backgroundColor: changed ? '#DEF740' : '',
borderRadius: changed ? '3px' : '',
opacity: changed === false ? '.4' : ''
} );
} else if ( a && a.style ) {
a.style.color = changed === false ? 'silver' : ( changed ? 'green' : '' );
}
},
/**
* @param {HTMLTextAreaElement} e
* @param {Object}
* @param {function} cleanText
* @return {boolean} True when (relevant) changes have been made
*/
cleanSelectedOrAllTextInElement: function( e, context, cleanText ) {
var scroll = e.scrollTop,
s1 = e.selectionStart,
s2 = e.selectionEnd,
t;
context = context || {};
context.isDisambiguation = /\{\{\s*egriffsklärung\s*/.test( e.value );
/**
* @param {string} oldValue
* @return {string|boolean}
*/
function getCleanedTextIfChanged( oldValue ) {
var newValue = cleanText( oldValue, context );
/* Entfernte Leerräume am Textende zählen nie als Änderung */
oldValue = oldValue.replace( /\s+$/, '' );
newValue = newValue.replace( /\s+$/, '' );
/* Entfernte Leerräume am Zeilenende nicht als Änderung anzeigen, aber trotzdem ersetzen */
context.visiblyChanged = oldValue.replace( /+\n/g, '\n' ) !== newValue.replace( /+\n/g, '\n' );
/* Normalisierte Zeilenumbrüche nie als Änderung werten, das vermeidet Flackern */
if ( context.visiblyChanged || oldValue.replace( /\r+$/gm, '' ) !== newValue ) {
return newValue;
}
return false;
}
e.focus();
if ( typeof s1 === 'number' ) {
if ( s2 > s1 && ( s1 > 0 || s2 < e.value.length ) ) {
t = getCleanedTextIfChanged( e.value.substring( s1, s2 ) );
if ( t !== false ) {
var newValue = e.value.substr( 0, s1 ) + t + e.value.substr( s2 );
e.value = newValue;
/* Fix for Opera */
s2 = s1 + t.length + ( e.value.length - newValue.length );
e.selectionStart = s1;
e.selectionEnd = s2;
e.scrollTop = scroll;
}
return t !== false;
}
} else if ( typeof document.selection === 'object' ) {
var range = document.selection.createRange();
if ( range.text.length ) {
t = getCleanedTextIfChanged( range.text );
if ( t !== false ) {
range.text = t;
}
return t !== false;
}
}
context.isAll = true;
t = getCleanedTextIfChanged( $( e ).val() );
if ( t !== false ) {
/* Empty lines are always removed from the beginning of the page, no matter what */
$( e ).val( t.replace( /^\s*\n/, '' ) );
if ( typeof s1 === 'number' ) {
e.selectionStart = s1;
e.selectionEnd = s2;
e.scrollTop = scroll;
}
}
return t !== false;
},
/**
* @param {string} summary
* @param {Object} context
* @return {string}
*/
cleanSummary: function( summary, context ) {
context = context || this.fetchGlobalContext();
summary = this.cleanWikimediaLinks( summary );
summary = this.cleanInternalLinks( summary );
return this.cleanTypography( summary, context );
},
/**
* @param {string} t
* @param {Object} context
* @return {string}
*/
cleanText: function( t, context ) {
context = context || {};
/* Remove control characters, undefined code points, LINE/PARAGRAPH SEPARATOR, BOM */
t = t.replace( /+/g, '' );
t = t.replace(
/*+*\n/g,
'\n'
);
t = t.replace( /(^|==|) +\n/g, '$1\n' );
/* Unsichtbares weiches Trennzeichen sichtbar machen, egal wo */
t = t.replace( /(?:\xAD|&#*(?:shy|x0*AD\b|0*173\b);?)+/gi, '­' );
/* ZERO WIDTH SPACE nur im Lateinischen entfernen */
t = t.replace( /()\u200B+(?=)/g, '$1' );
/* LRM ist wirkungslos, wenn es neben einem LR-Zeichen steht */
t = t.replace( /\u200E+(?=ªµºÀ-ÖØ-öø-\u02B8]|$)/gi, '' );
t = t.replace( /()\u200E+/gi, '$1' );
t = t.replace( /\u200E+/g, '‎' );
t = this.backupNowikis( t );
t = this.cleanCharacterEntities( t );
t = this.cleanGalleries( t );
t = this.backupFilenames( t, context );
t = this.cleanHeadlines( t, context );
/* Einheitliche Schreibweisen für Schlüsselwörter incl. Leerzeichenausgleich */
t = t.replace(
/\{\{\s*(SEITENTITEL|DISPLAYTITLE):\s*/gi,
context.localisation === 'de' ? '{\{SEITENTITEL:' : context.localisation
? '{\{DISPLAYTITLE:'
: '{\{$1:'
);
t = t.replace(
/#(WEITERLEITUNG|REDIRECT)*\|]*|])(?:\s*\|]*)?\]+/gi,
context.localisation === 'de' ? '#WEITERLEITUNG ]' : context.localisation
? '#REDIRECT ]'
: '#$1 ]'
);
t = t.replace(
/\|]*|])\s*(?=|])/gi,
context.localisation === 'de' ? '[[Kategorie:$2' : context.localisation
? '[[Category:$2'
: '[[$1:$2'
);
t = this.cleanThumbnails( t, context );
t = this.cleanReferences( t, context );
t = this.cleanTags( t );
t = this.cleanExternalLinks( t );
t = this.cleanWikimediaLinks( t );
t = this.cleanInternalLinks( t );
t = this.cleanTemplates( t, context );
t = this.cleanISSNs( t );
/* Identify candidates for tables; might run to short, but better safe than sorry */
t = t.replace( /^{\|(\|(?!})|)+/gm, function ( $0 ) {
return $0
/* Remove empty row signature at the start */
.replace( /^(.*\n)\s*\|-+\n+/, '$1' )
/* Remove unused row signature at the end */
.replace( /\n\s*\|-.*\s*(?=\n$)/, '' )
/* Identify table header rows */
.replace( /^ *!.+/gm, function ( $0 ) {
/* Remove bold formatting from table headers */
return $0.replace( /'''(*)'''/g, '$1' );
} );
} );
t = t.replace(
/\bclass\s*=\s*(?:(") *(*? ?))?(?: *\bprettytable\b)+/g,
'class=$1$2wikitable'
);
/* Unnötige Leerzeichen bei HTML-Attributen, wichtig vor den Anführungszeichen */
t = t.replace( /]*\b *= +"/g, function( $0 ) {
return $0.replace( /(\b+\b) *= *"/g, '$1="' );
} );
/* Ersten Interlanguage-Link suchen; 9 wegen ] */
var i = t.search( /^\{2,3}(?:-{2,9})? *:/m ),
slice;
if ( i > 0 ) {
i = Math.max( i, t.indexOf( '<references', i ) );
slice = t.slice( i );
t = t.slice( 0, i );
}
t = this.cleanTypography( t, context );
t = this.cleanDates( t, context );
if ( slice ) {
t += slice;
}
t = this.cleanDuplicateLinks( t );
t = this.cleanUnits( t, context );
t = this.cleanNonBreakingSpaces( t );
t = this.cleanISBNs( t );
t = this.cleanPMIDs( t );
t = this.cleanCategories( t, context );
t = this.cleanNewlines( t, context );
t = this.cleanRedundantTemplateParameters( t );
t = this.cleanTemplatesByRules( t );
t = this.executeUserReplacements( t );
t = this.restoreFilenames( t );
return this.restoreNowikis( t );
},
cleanCharacterEntities: function( t ) {
var entities = {
/* Unicodeblock Basis-Lateinisch (U+0000 bis U+007F) */
'grave': '`',
/* Unicodeblock Lateinisch-1, Ergänzung (U+0080 bis U+00FF) */
'cent': '¢', 'pound': '£', 'yen': '¥', 'sect': '§', 'laquo': '«', 'deg': '°',
'plusmn': '±', 'pm': '±', 'sup2': '²', 'sup3': '³', 'acute': '´', 'centerdot': '·',
'middot': '·', 'raquo': '»', 'frac14': '¼', 'frac12': '½', 'half': '½',
'frac34': '¾', 'Auml': 'Ä', 'Ouml': 'Ö', 'times': '×', 'Uuml': 'Ü', 'szlig': 'ß',
'auml': 'ä', 'ouml': 'ö', 'div': '÷', 'divide': '÷', 'uuml': 'ü',
/* Unicodeblock Allgemeine Interpunktion (U+2000 bis U+206F) */
'ndash': '–', 'mdash': '—', 'lsquo': '‘', 'rsquo': '’', 'rsquor': '’',
'lsquor': '‚', 'sbquo': '‚', 'ldquo': '“', 'rdquo': '”', 'rdquor': '”',
'bdquo': '„', 'ldquor': '„', 'dagger': '†', 'Dagger': '‡', 'ddagger': '‡',
'bull': '•', 'bullet': '•', 'hellip': '…', 'mldr': '…', 'permil': '‰', 'prime': '′',
'Prime': '″', 'lsaquo': '‹', 'rsaquo': '›',
/* Unicodeblock Währungszeichen (U+20A0 bis U+20CF) */
'euro': '€',
/* Unicodeblock Pfeile (U+2190 bis U+21FF) */
'rarr': '→', 'harr': '↔',
/* Unicodeblock Mathematische Operatoren (U+2200 bis U+22FF) */
'minus': '−', 'infin': '∞', 'ap': '≈', 'approx': '≈', 'asymp': '≈', 'ne': '≠',
'le': '≤', 'leq': '≤', 'ge': '≥', 'geq': '≥'
};
/* Limit to U+FFFF because of compatibility reasons, keep 𐀏 intact */
t = t.replace(
/&(#x({2,4})|#(\d{3,5})|{2,9}\d{0,2})\b(?!);?/gi,
function( $0, $1, $2, $3 ) {
if ( $2 ) {
$3 = parseInt( $2, 16 );
}
/* Don't decode spaces and control characters */
if ( $3 > 160 && $3 < 8191
|| $3 > 8207 && $3 < 8232
|| $3 > 8239 && $3 < 8287
|| $3 > 8303 && $3 < 55296
) {
return String.fromCharCode( $3 );
}
return entities || entities || $0;
}
);
t = t.replace( /&#*(?:amp|x0*26|0*38)\b;?/gi, '&' );
t = t.replace( /&(?!)/gi, '&' );
/* Geschützte Leerzeichen einheitlich als " ", vereinfacht viele folgende Suchmuster */
return t.replace( /&#*(?:nbsp|x0*A0\b|0*160\b);?/gi, ' ' );
},
cleanTags: function( t ) {
t = t.replace( /(<\/?s)trike\b/gi, '$1' );
t = t.replace(
/<sub\s*(>*<)\s*(?:su\s*+|+\s*su)\s*>/gi,
'<sub$1/sub>'
);
t = t.replace(
/<sup\s*(>*<)\s*(?:su\s*+|+\s*su)\s*>/gi,
'<sup$1/sup>'
);
/* Drop default font attributes */
t = t.replace(
/(<font\b*?)\s+fa\w+(?:*(?:Arial|Helvetica(?:\W?N\w*)?|sans\W?serif)\b)+*(?=\s\w+\s*=|>)/gi,
'$1'
);
t = t.replace(
/(<font\b*?)\s+size*(?:-1\b|2\b|100\b*\d*%|1(?:\.0*)?em\b)*/gi,
'$1'
);
/* Remove tags with no content and no attributes */
t = t.replace(
/<(\w+)\s*(\s\w*)?>\s*<\/\1\b*>/gi,
function( $0, $1, $2 ) {
if ( ( $2 && /^ref/i.test( $1 ) ) || /^r$/i.test( $1 ) ) {
return '<' + $1.toLowerCase() + ( $2 || '' ) + ' />';
}
return $2 && /\bclear:/i.test( $2 ) ? $0 : '';
}
);
/* Remove inline elements with no attributes */
while ( /<(font|span)\s*>\s*(?:<(?!\1)|)*?\s*<\/\1*>/i.test( t ) ) {
t = t.replace( /<(font|span)\s*>\s*((?:<(?!\1)|)*?)\s*<\/\1*>/gi, '$2' );
}
t = t.replace(
/<font\s+color*(#{3,6}|{3,20})*>((?:<(?!font)|)*?)<\/font*>/gi,
'<span style="color:$1;">$2<\/span>'
);
t = t.replace(
/<font\s+size*(?:-|)*>((?:<(?!font)|)*?)<\/font*>/gi,
'<small>$1<\/small>'
);
t = t.replace(
/<font\s+size*(?:0|3)*>((?:<(?!font)|)*?)<\/font*>/gi,
'<span style="font-size:larger;">$1<\/span>'
);
/* Merge nested inline tags */
t = t.replace(
/<(abbr|cite|mark|q|s|small|u)\s*><(font|span)\s+style\s*=\s*?(*?);??\s*>(*)<\/\2\s*>\s*(?=<\/\1\s*>)/gi,
'<$1 style="$3;">$4'
);
t = t.replace(
/(<span\b*?)\s+style\s*=\s*?(*?);??\s*><span\s+style\s*=\s*?(*?);??\s*>(*)<\/span\s*>\s*(?=<\/span\s*>)/gi,
'$1 style="$2; $3;">$4'
);
/* Verschiedenste Formen von HTML-Zeilenumbrüchen durch einheitliche ersetzen */
t = t.replace( /<(?:*br\b)+\s*(\s\w*?)?*>/gi, '<br$1 />' );
/* Unnötige HTML-Zeilenumbrüche entfernen, wenn sowieso ein Absatz folgt */
t = t.replace( / *<br \/>(?=\n)/gi, '' );
t = t.replace(
/<(ref|small|su)\b\s*(\s\w*?)?\s*><small\s*>(*)<\/small\s*><\/\1\s*>/gi,
'<$1$2>$3<\/$1>'
);
t = t.replace(
/<small\s*><(ref|small|su)\b\s*(\s\w*?)?\s*?( ?\/|>*<\/\1)\s*><\/small\s*>/gi,
'<$1$2$3>'
);
/* Drop old navigation bar wrapper, see ] */
return t.replace(
/<div\s+class*BoxenVerschmelzen*>\s*(\{\{*\}\})\s*<\/div>/gi,
'$1'
);
},
cleanGalleries: function( t ) {
return t.replace(
/<gallery\b(*)>(+)<\/gallery\b*>/gi,
function( $0, $1, $2 ) {
return '<gallery' + $1 + '>' + $2
.replace( /^(\s*)\]*)\]\]?\s*$/gm, '$1$2' )
.replace( /^(\s*)\[+/gm, '$1' ) + '<\/gallery>';
}
);
},
cleanHeadlines: function( t, context ) {
/* Fettung zumindest kompletter Überschriften ist unerwünscht */
t = t.replace( /^(=+) *'''(+)''' *(?==+$)/gm, '$1 $2 ' );
/* Repariert kaputte Überschriften, entfernt Doppelpunkte, setzt Leerzeichen */
t = t.replace( /^(={1,6}) *(.*) *:? *\1$/gm, '$1 $2 $1' );
/* Normalize "External links" headlines, use "Weblinks" in German */
return t.replace(
/^== *(?:Externer?|External)?(?: |\s)*(?:Weblinks?|Links?|Webseiten?|Websites?) *=+/gim,
context.isDe ? '== Weblinks ==' : '== External links =='
);
},
cleanThumbnails: function( t, context ) {
return t.replace(
/(\|]+)(\|]+)/gi,
function ( $0, $1, $2 ) {
/* Remove empty parameters */
$2 = $2.replace( /\|\s*(?:\|\s*)+/g, '|' )
/* Remove obsolete "right" next to a "thumb" */
.replace(
/\|\s*r(?:echts|ig+)\s*\|\s*(?:mini|miniatur|thumb)\s*\|\s*/gi,
'|thumb|'
)
.replace(
/\|\s*(?:mini|miniatur|thumb)\s*\|\s*r(?:echts|ig+)\s*\|\s*/gi,
'|thumb|'
)
/* Strip duplicate parameters */
.replace( /(?:\s*\|\s*(?:mini|miniatur|thumb)){2,}\s*(?=\||$)/gi, '|thumb' )
.replace(
/\|\s*(?:mini|miniatur|thumb)\s*\|\s*(.*?)\s*\|\s*(?:mini|miniatur|thumb)\s*(?=\||$)/gi,
'|thumb|$1'
)
.replace(
/\|\s*(?:hochkan|uprigh)t(*\|.*?)\s*\|\s*(?:hochkan|uprigh)t*(?=\||$)/gi,
'|upright$1'
)
/* Remove redundant "alt" that don't add anything, but repeat the description */
.replace(
/\|\s*(?:alt\s*=\s*(+?)\s*\|(?=\s*\1\s*(?:\||$))|(+?)\s*\|\s*alt\s*=\s*(?=\2\s*(?:\||$)))/gi,
'|'
);
if ( context.localisation === 'de' ) {
/* Set the order to "thumb|upright" if one isn't localized */
$2 = $2.replace(
/\|\s*(?:upright(*)\|\s*(?:mini|miniatur|thumb)|(?:hochkan|uprigh)t(*)\|\s*thumb)\s*\|\s*/gi,
'|mini|hochkant$1$2|'
)
/* Änderung von "miniatur" in "mini" nur zusammen mit anderen Änderungen */
.replace(
/\|\s*miniatur\s*\|\s*(left|none|cent+|*framed?|frameless|upright)\s*\|\s*/gi,
'|mini|$1|'
)
.replace(
/\|\s*(left|none|cent+|*framed?|frameless|upright)\s*\|\s*miniatur\s*\|\s*/gi,
'|$1|mini|'
)
.replace( /\|\s*(?:miniature|thumb)\s*(\||$)\s*/gi, '|mini$1' )
.replace( /\|\s*right\s*\|\s*/gi, '|rechts|' )
.replace( /\|\s*left\s*\|\s*/gi, '|links|' )
.replace( /\|\s*none\s*\|\s*/gi, '|ohne|' )
.replace( /\|\s*cent+\s*\|\s*/gi, '|zentriert|' )
.replace( /\|\s**framed?\s*\|\s*/gi, '|gerahmt|' )
.replace( /\|\s*frameless\s*\|\s*/gi, '|rahmenlos|' )
.replace(
/\|\s*(?:hochkan|uprigh)t*(*)\s*\|\s*/gi,
function ( $0, $1 ) {
return '|hochkant' + ( $1 ? '=' + $1.replace( /,/, '.' ) : '' ) + '|';
}
);
}
/* Use canonical (untranslated) vertical-align values from the CSS standard */
return $1 + $2.replace( /\|\s*grundlinie\s*\|\s*/g, '|baseline|' )
.replace( /\|\s*tief(?:gestellt)?\s*\|\s*/g, '|sub|' )
.replace( /\|\s*(?:hoch(?:gestellt)?|sup)\s*\|\s*/g, '|super|' )
.replace( /\|\s*oben\s*\|\s*/g, '|top|' )
.replace( /\|\s*text-oben\s*\|\s*/g, '|text-top|' )
.replace( /\|\s*mitte\s*\|\s*/g, '|middle|' )
.replace( /\|\s*unten\s*\|\s*/g, '|bottom|' )
.replace( /\|\s*text-unten\s*\|\s*/g, '|text-bottom|' );
}
);
},
cleanExternalLinks: function( t ) {
t = t.replace( /\b(?:http(s?)(?::+\/*|\/\/+:*)\b)+/gi, 'http$1://' );
/* Doppelte eckige Klammern um Weblinks vereinfachen */
t = t.replace( /\]*?) *\]\]?(?!\])/gi, '' );
/* Weblinks mit senkrechtem Strich reparieren */
t = t.replace( /(\|]*?) *\| *(?=|]+\])/gi, '$1 ' );
/* Schrägstriche am Ende einfacher Domains ergänzen */
t = t.replace( /(\*\w\.\w+) +/gi, '$1/ ' );
/* Domains klein schreiben, egal ob beschriftet oder nicht */
return t.replace( /\bhttps?:\/\/\b**/g, function( $0 ) {
return $0.toLowerCase();
} );
},
cleanWikimediaLinks: function( t ) {
if ( typeof window.autoFormatWikimediaLinks !== 'undefined'
&& !window.autoFormatWikimediaLinks
) {
return t;
}
var wiki = mw.config.get( 'wgDBname' ).replace( /wiki$/i, '' ),
ns = mw.config.get( 'wgFormattedNamespaces' );
/* Permanente Weblinks in Spezialseiten-Syntax umwandeln */
var permaLinkReplace = function( $0, $1, $2, $3, $4 ) {
var m = /^(\d*(*))(.*)$/.exec( $3 );
/* Must use {{fullurl:…}} when there are more parameters than title and oldid */
if ( m && m ) {
/* {{fullurl::|oldid=…}} with no page name is not possible any more */
if ( !$2 ) {
return $0;
}
return '[{\{fullurl:' + ( $1 === wiki ? '' : $1 + ':' )
+ $2.replace( /_/g, ' ' ) + '|oldid=' + m + '}}' + m
+ ( typeof $4 === 'string' ? ' ' + $4 : '' ) + ']';
} else {
return '[[:' + $1 + ':' + ( $1 === wiki ? ns : 'Special' )
+ ':Permanent' + ( $1 === 'de' ? 'er ' : '' ) + 'Link/' + $3
+ ( typeof $4 === 'string' ? '|' + $4 : '' ) + ']]';
}
};
/* Weblinks auf Sprachversionen (auch auf die eigene) in Wikilinks umwandeln */
var interWikiReplace = function( $0, $1, $2, $3 ) {
/* Auf Alternative ausweichen, wenn Parameter enthalten wind */
var m = /^(*)\?(*)(.*)$/.exec( $2 );
try {
return m ? '[{\{fullurl:' +
( $1 === wiki ? '' : $1 + ':' ) +
decodeURIComponent( m ).replace( /_/g, ' ' ) + '|' + m + '}}' + m +
( typeof $3 === 'string' ? ' ' + $3 : '' ) + ']' :
'[[:' + $1 + ':' + $2.replace( /_/g, ' ' ) +
( typeof $3 === 'string' ? '|' + $3 : '' ) + ']]';
} catch ( ex ) {
return $0;
}
};
/* Alle projektinternen Weblinks protokollrelativ machen */
t = t.replace( /\+\.wikipedia\.org\b)/gi, '[//' );
/* Schreibweise ] reparieren */
t = t.replace(
/\+)\.wikipedia\.org\/w\/*\?(?:title=(|]*)&)?oldid=(|]+?) *\|+ *(|]*?) *\]+/gi,
permaLinkReplace
);
t = t.replace(
/\+)\.wikipedia\.org\/wiki\/(|]*?) *\|+ *(|]*?) *\]+/gi,
interWikiReplace
);
/* Schreibweise umwandeln */
t = t.replace(
/\+)\.wikipedia\.org\/w\/*\?(?:title=(|]*)&)?oldid=(|]+) +(|]+?) *\]+/gi,
permaLinkReplace
);
t = t.replace(
/\+)\.wikipedia\.org\/wiki\/(|]*) +(|]+?) *\]+/gi,
interWikiReplace
);
/* Schreibweise umwandeln */
t = t.replace(
/\+)\.wikipedia\.org\/w\/*\?(?:title=(|]*)&)?oldid=(|]+) *\]+/gi,
permaLinkReplace
);
t = t.replace(
/\+)\.wikipedia\.org\/wiki\/(|]*) *\]+/gi,
interWikiReplace
);
/* Verbliebene projektinterne Weblinks ohne eckige Klammern ebenfalls umwandeln */
t = t.replace(
/\bhttps?:\/\/(+)\.wikipedia\.org\/w\/*\?(?:title=(|]*)&)?oldid=({|}]*{|}])(?=|$)/gim,
permaLinkReplace
);
return t.replace(
/\bhttps?:\/\/(+)\.wikipedia\.org\/wiki\/({|}]*{|}])(?=|$)/gim,
interWikiReplace
);
},
cleanInternalLinks: function( t ) {
var wiki = mw.config.get( 'wgDBname' ).replace( /wiki$/i, '' ),
ns = mw.config.get( 'wgFormattedNamespaces' );
/* Unnötig gewordene Vorlage in Spezialseiten-Syntax umwandeln */
t = t.replace(
/\{\{\s*Permalink\s*\|*\|\s*(\d+(?: ?#*?)?)\s*(?:(\|)\s*(*?))?\s*\}\}/gi,
']'
);
/* Make selected "fullurl" parser function calls more compact */
t = t.replace(
/\{\{\s*fullurl:\s*(+)\|\s*(?:diff=prev&oldid=(\d+)|oldid=(\d+)&diff=prev)\s*\}\}/gi,
'{\{fullurl:$1|diff=$2$3}}'
);
/* https://www.mediawiki.orghttps://wiki386.com/de/Help:Lint_errors/multi-colon-escape */
t = t.replace( /\[\[::+/gi, '[[:' );
/* Wikilinks mit unnötigem Präfix ":w:de:", "w:de:" oder ":de:" vereinfachen */
t = t.replace(
new RegExp(
'\\[\\[ *(?::? *w *)?: *' + wiki
+ ' *: *(((?:Bild|Datei|File|Image|ategore?) *:)?]*\\S) *\\]\\]',
'gi'
),
function( $0, $1, $2 ) {
return ']';
}
);
/* Anker in internen Links dekodieren */
t = t.replace(
/(\{|]*#)(|]+)(?=\|?|}]*\]\])/g,
function( $0, $1, $2 ) {
try {
/* Kodierung einiger Zeichen beibehalten (%25, %5B, %5D, %7B-%7D) */
return $1 + decodeURIComponent( $2.replace( /\.(?=||40|60)/g, '%' ) ).
replace( /{|}]/g, function( $0 ) {
return '%' + $0.charCodeAt( 0 ).toString( 16 ).toUpperCase();
} );
} catch ( ex ) {
return $0;
}
}
);
/* Sonstige kodierte Linkziele dekodieren */
t = t.replace(
/\{|}]*%{|}]*)(?=#?{|}]*\|?{|}]*\]\])/gi,
function( $0, $1 ) {
try {
/* Kodierung einiger Zeichen beibehalten (%25, %3C, %3E, %5B, %5D, %7B-%7D) */
return '{|}]/g, function( $0 ) {
return '%' + $0.charCodeAt( 0 ).toString( 16 ).toUpperCase();
} );
} catch ( ex ) {
return $0;
}
}
);
/* Verbliebene Unterstriche aus Links entfernen */
t = t.replace(
/\_{|}]+_{|}]+(?=\|?{|}]*\]\])/g,
function( $0 ) {
return $0.replace( /_/g, ' ' );
}
);
/* Save relevant spaces at the beginning of links */
t = t.replace( /(?: +|(\S))(\|]\|) +/g, '$1 $2' );
/* Save relevant spaces at the end of links */
t = t.replace( /(\|]\||]*|]) +]](?: +|(?=\S))/g, '$1]] ' );
/* ] wird zu ]- und ]s zu ], weil besser lesbar;
MediaWiki akzeptiert hier wirklich nur Kleinbuchstaben, ä, ö, ü und ß */
t = t.replace(
/\|]+?) *(\||]+?)(?:(-+)]](?!)|]](*))/g,
']$3'
);
t = t.replace( /(^|)\|]+)\|('{2,5}) *\2 *\3]](?!')/g, '$1$3]$3' );
var unmaskLinks = typeof window.autoFormatMaskedLinks === 'undefined'
|| window.autoFormatMaskedLinks,
capitalLinks = /^\w+wiki$/.test( mw.config.get( 'wgDBname' ) );
/* ]s werden zu ]s weil kürzer und besser lesbar */
return t.replace(
new RegExp(
'\\|])(|]*)\\| *(|]\\2)('
+ ( unmaskLinks ? '|]' : '' )
+ '*?) *]]',
'g'
),
function( $0, $1, $2, $3, $4 ) {
return ( capitalLinks
? $1.toLowerCase() !== $3.charAt().toLowerCase()
: $1 !== $3.charAt() )
? $0
: ']' + $4;
}
);
},
cleanDuplicateLinks: function( t ) {
/* Remove links from dates that start with a year (e.g. ISO) */
t = t.replace(
/\\d{3}\W+(?:3|\d|0?)\W+(?:3|\d|0?))\]+/g,
'$1'
);
/* Never link dates and years in Persondata templates */
var re = /\{\{\s*P(erson(?:endaten|data)\b*\|\s*(?:GEBURTSD|STERBED|DATE)*={|}]*)\{|}]+)\]+/i;
while ( re.test( t ) ) {
t = t.replace( re, '{\{P$1$2' );
}
/* Exclude articles with titles like "1. März" or "March 1" */
if ( /^(3|\d|)\.? \S+$/.test( mw.config.get( 'wgTitle' ) )
|| /^\w+ (3|\d|)$/.test( mw.config.get( 'wgTitle' ) )
|| /\ategore?:(Tag|Days of the year)]|\{\{(Artikel Jahr|Year nav)\s*/i.test( t )
) {
return t;
}
/* Exclude files and infoboxes from the start of the article */
var m = /^(?:\s*\]*\]\]|])*\]\])*(?:\s*\{\{(?:\{\{*\}\}|)*\}\})+/.exec( t ),
start = m ? m.length : 0,
found = ,
a = ;
/* Unlink years that are linked more than one time */
re = /\\d{3}) *\]\]/g;
/* Jeweils ersten Fund eines Jahres merken, danach entlinken */
while ( m = re.exec( t ) ) {
if ( m.index >= start ) {
found] ? a.push( m ) : found] = true;
}
}
var r = '',
p = 0;
for ( var i = 0; i < a.length; i++ ) {
r += t.slice( p, a.index ) + a;
p = a.index + a.length;
}
return p ? r + t.slice( p ) : t;
},
cleanDates: function( t, context ) {
var months = mw.config.get( 'wgMonthNames' ) || ['', 'Januar', 'Februar', 'März', 'April',
'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
if ( context.isDe && /österreichbezogen\b/i.test( t ) ) {
months = 'Jänner';
}
/* Add missing space between day and month */
t = t.replace( new RegExp( '((?:3|\\d|0?)\\.?)(?=(?:' +
months.slice( 1 ).join( '|' ) + ')\\b)', 'g' ), '$1 ' );
/* No non-breaking space between month and year */
t = t.replace( new RegExp( '(\\b(?:3|\\d|0?)\\.?(?:| )+(?:' +
months.slice( 1 ).join( '|' ) + '))(?:\xA0| )(?=\\d{3}\\b)', 'g' ), '$1 ' );
if ( !context.isFi ) {
/* Missverständliches deutsches Datumsformat durch Langform ersetzen */
var separator = context.isEn || context.isTe || context.isTr || context.isSv ? ' ' : '. ';
t = t.replace(
/( +|)(3|\d|0?)\. *(1|0?)\. *(?=\d{3}?](?!\w*\d))/g,
function( $0, $1, $2, $3 ) {
return $1 + ( $2 | 0 ) + separator + months + ' ';
}
);
}
/* Unspaced dashes in "1850–14 January" are bad style in German and English */
var dash = context.isRu ? '—' : '–';
separator = context.isDe ? ' bis ' : ' – ';
t = t.replace(
/(\b +\d{3}'*) * *('*(?:3|\d|0?)\.?) *({2,}\b)/g,
function( $0, $1, $2, $3 ) {
for ( var i = months.length; --i; ) {
if ( $3 === months ) {
return $1 + separator + $2 + ' ' + $3;
}
}
return $0;
}
);
/* Bis-Striche in 4-stellige Jahreszahlenbereiche einsetzen */
t = t.replace(
/()(?:\\d{3}) *\]\]|(\d{3})) * *(?:\\d{3}) *\]\]|(1\d{3}|20\d\d))(?=?|}])/g,
function( $0, $1, $2, $3, $4, $5 ) {
return ( $2 || $3 ) < ( $4 || $5 ) ? $1 + ( $2 || $3 ) + dash + ( $4 || $5 ) : $0;
}
);
/* Bis-Striche in 2-stellige Jahreszahlenbereiche einsetzen */
t = t.replace(
/((?:1\d|20)(\d\d)) * *(?=(1|\d)?(?:|]|$)|\?)/g,
function( $0, $1, $2, $3 ) {
return !$3 || $2 < $3 ? $1 + dash : $0;
}
);
/* "1980 – 90" becomes "1980–1990" in the German Wikipedia, "1980–90" otherwise */
var full = typeof window.autoFormatShortYearRanges !== 'undefined'
? window.autoFormatShortYearRanges : context.isDe;
t = t.replace(
/((1\d|20)(\d\d)) *– *(?!(?:3|\d|0)\.? {2,}\b)(?=(\d\d)?(?:|$))/g,
function( $0, $1, $2, $3, $4 ) {
return $3 < $4 ? $1 + '–' + ( full ? $2 : '' ) : $0;
}
);
/* ISSNs aber ohne Bis-Striche, wichtig nach den Jahreszahlen */
return t.replace( /(IS\wN\W*\d{4})–(?=\d)/g, '$1-' );
},
/**
* @param {string} t
* @param {Object} context
* @return {string}
*/
cleanTypography: function( t, context ) {
/* Double quotes */
if ( context.isDe || context.isRu ) {
t = t.replace(
/(^|)(?:"|,,)(?!)(*)"(?=}-]|$)/g,
context.isRu || /\bschweizbezogen\b/i.test( t )
&& ( t.indexOf( '«' ) !== -1 || t.indexOf( '„' ) === -1 )
? '$1«$2»'
: '$1„$2“'
);
}
t = t.replace(
/\{\{\s*((?:Zitat|")\s*\|\s*(?:(?:1|Text)\s*=)?*)/gi,
function( $0, $1 ) {
return '{\{' + $1.replace( /„(+)“/g, '‚$1‘' );
}
);
if ( !context.isEn ) {
/* Replace exactly three dots with ellipsis */
t = t.replace( /(^|)\.\.\.(?=}“]|$)/gm, '$1…' );
}
t = t.replace( /(?:| )*†(?: | )*(?=)/gi, '; † ' );
t = t.replace(
/\( *(*\d(?: | )*i?B)(?:ytes?)?() *({3,4}(?:\W+Datei)?) *\)/g,
'($3$2 $1)'
);
t = t.replace(
/\( *({3,4}(?:\W+Datei)?)() *(*\d)(?: | )*(i?B)(?:ytes?)? *\)/g,
function( $0, $1, $2, $3, $4 ) {
$3 = $3.replace( context.isDe ? /\b\.(?=\d{3}\b)/g : /\b,(?=\d{3}\b)/g, '' );
$3 = $3.replace( /^(\d*),(?=\d*$)/, '$1.' );
$3 = ( $4.charAt() === 'M' ? Math.round( $3 * 10 ) / 10 : Math.round( $3 ) ) || $3;
return '(' + $1 + ( context.isDe ? ( '; ' + $3 ).replace( /\./, ',' ) : $2 + ' ' + $3 )
+ ' ' + $4 + ')';
}
);
/* Bis-Striche bei Seitenzahlen */
t = t.replace(
/\b(Sp?\.|Seiten?|Spalten?) *(\d+) * *(?=\d+(?:|}“]|$))/g,
'$1 $2–'
);
/* English Wikipedia also uses en dashes */
if ( !context.isIt ) {
t = t.replace(
/(\xC0-\u024F“]) +-(,?) +(?=)/g,
'$1 –$2 '
);
}
return t;
},
cleanUnits: function( t, context ) {
/* Prozentwerte erhalten seit Mitte 2007 automatisch ein geschütztes Leerzeichen */
t = t.replace( /(\S)(?:\xA0| )(?=%)/gi, '$1 ' );
if ( context.isDe || context.isRu ) {
t = t.replace(
/(?\d+(?:\d+)?)(?=%|»“](?! *))/gi,
'$1 '
);
t = t.replace(
/((?:\d|\b)?m) *<\s*>\s*()\s*<\/\w\s*>(?={|}–“])/g,
function( $0, $1, $2 ) {
return $1 + ( { '2': '²', '3': '³' } || $2 );
}
);
}
/* Maßeinheiten immer mit Leerzeichen */
return t.replace(
/(?\d+(?:\d+)?) ?(k|Ki?B|k?Hz|(?:i?B|Hz)|cm|ha|m|)(?=?)/g,
'$1 $2'
);
},
cleanNonBreakingSpaces: function( t ) {
/* Paragraf, Abs. und Satz mit geschützten Leerzeichen */
t = t.replace(
/§(?: *| )(\d\w* +Ab?s?\.)(?: *| )(\d+ +S\.) *(?=\d)/gi,
'§ $1 $2 '
);
t = t.replace( /§(?: *| )(\d\w* +Ab?s?\.) *(?=\d)/gi, '§ $1 ' );
t = t.replace( /§ *(?=\d)/gi, '§ ' );
/* No non-breaking spaces in headlines */
return t.replace( /^=.* .*=$/gim, function( $0 ) {
return $0.replace( /(?: |\s)+/gi, ' ' );
} );
},
cleanISBNs: function( t ) {
t = t.replace( /\bISBN\W*(?:\d+­(?=\d))+/gi, function ( $0 ) {
return $0.replace( /­/g, '' );
} );
/* ISBNs mit Bindestrichen gliedern */
return t.replace(
/(^|)(?:(ISBN\d?\s*=\s*)|ISBN(?:-?1\b| *1:)?:?\s*)(9-?7-?-?)?({8,}\b)/gim,
function( $0, $1, $2, $3, $4 ) {
return $1 + ( $2 || 'ISBN ' ) + ( $3 || '' ).replace( /^9\D*7\D*(\d)\D*/, '97$1-' ) + $4.
/* Remove all dashes */
replace( /+/gi, '' ).
/* Group 0 for English books */
replace( /^0(\d)(\d{6})\B/, '0$1-$2-' ).
replace( /^0(\d\d)(\d{5})\B/, '0$1-$2-' ).
replace( /^0(7\d{3}|8\d\d)(\d{4})\B/, '0$1-$2-' ).
replace( /^0(8\d{3})(\d{3})\B/, '0$1-$2-' ).
replace( /^0(9\d{4})(\d\d)\B/, '0$1-$2-' ).
replace( /^0(9\d{5})(\d)\B/, '0$1-$2-' ).
/* Group 1 for English books */
replace( /^1(0\d)(\d{6})\B/, '1$1-$2-' ).
replace( /^1(\d\d)(\d{5})\B/, '1$1-$2-' ).
replace( /^1(4\d{3}|5\d\d)(\d{4})\B/, '1$1-$2-' ).
replace( /^1(5\d{3}|\d{4}|8\d{3}|86\d\d|869\d)(\d{3})\B/, '1$1-$2-' ).
replace( /^1(869\d\d|8\d{4}|9\d{4}|99\d{3})(\d\d)\B/, '1$1-$2-' ).
replace( /^1(999\d{4})(\d)\B/, '1$1-$2-' ).
/* Group 3 for German books */
replace( /^3(0|1\d)(\d{6})\B/, '3$1-$2-' ).
replace( /^3(03|\d\d)(\d{5})\B/, '3$1-$2-' ).
replace( /^3(03\d|7\d{3}|8\d\d)(\d{4})\B/, '3$1-$2-' ).
replace( /^3(03\d\d|8\d{3}|95\d\d|9\d{3})(\d{3})\B/, '3$1-$2-' ).
replace( /^3(9\d{4})(\d\d)\B/, '3$1-$2-' ).
replace( /^3(95\d{4}|9\d{5})(\d)\B/, '3$1-$2-' ).
/* Add missing dash after group */
replace( /^(|6\d\d|8\d|9|9\d|99\d|999\d\d)\B/, '$1-' );
}
);
},
cleanISSNs: function( t ) {
return t.replace(
/(^|)ISSN *(\|?)*((?:\d*){7}\b)/gi,
function( $0, $1, $2, $3 ) {
return $1 + 'ISSN' + ( $2 || ' ' ) + $3.replace( /+/gi, '' )
.replace( /^(.{4})/, '$1-' );
}
);
},
cleanPMIDs: function( t ) {
return t.replace(
/(^|)PMID*(?=\d+\b)/gi,
'$1PMID '
);
},
cleanReferences: function( t, context ) {
t = t.replace(
/<\s*references\s*(\s\b*?)?\s*(?:\/|>\s*<\s*\/\s*references)\s*>/gi,
'<references$1 />'
);
t = t.replace( /<\s*references\s*(\s\b*?)?\s*>/gi, '<references$1>' );
t = t.replace( /<\s*\/\s*references\s*>/gi, '<\/references>' );
if ( context && context.isAll ) {
var re = /(<references*)>/g,
m;
while ( m = re.exec( t ) ) {
if ( t.indexOf( '<\/references>', m.index ) < 0 ) {
t = t.slice( 0, m.index ) + m + ' />' + t.slice( m.index + m.length );
}
}
}
t = t.replace( /< *ref*? *(?=name *=)/gi, '<ref ' );
// Unconfuse equal signs and double quotes.
t = t.replace( /< *ref*name *+ *=+\s**/gi, '<ref name="' );
// Replace duplicate "ref" with "name".
t = t.replace(
/< *ref*? *ref(?:*name)?(?= *=(?!\s*name\b))/gi,
'<ref name'
);
// Remove duplicate "name".
t = t.replace( /< *ref*? *name+? *(?=name *=)/gi, '<ref ' );
// Remove duplicate equal signs.
t = t.replace( /< *ref*name *=*(?==)/gi, '<ref name ' );
// Add missing leading quote.
t = t.replace(
/< *ref*? *name+*(?!group\b)(*)/gi,
'<ref name="$1"'
);
// Add missing trailing quote.
t = t.replace(
/< *ref*? *name*(*?)*\s*?(?= ?\bgroup\b|(?: ?\/)?>(?!*">))/gi,
'<ref name="$1"'
);
// Add quotes when there is a spacing issue anyway.
t = t.replace(
/< *ref\s+name(?= +=|= |=+\/>)+(?!group\b)((?:|\/(?!>))*)(?:\s+(?=))?/gi,
'<ref name="$1"'
);
// Fix remaining spacing issues.
t = t.replace( /< *ref\s+name *=+ *(?!group\b)/gi, '<ref name=' );
t = t.replace( /<ref name=("*"|'*')\s*group *=+ */gi, '<ref name=$1 group=' );
t = t.replace( /< *ref\s*(\s\b*?)\s*(?:\/+|>\s*<\s*\/+\s*ref) *>/gi, '<ref$1 />' );
/* Zeilenumbrüche in Einzelnachweisen nur oben im Artikel entfernen */
var i = t.indexOf( '<references' ),
slice;
if ( i > 0 ) {
slice = t.slice( i );
slice = slice.replace( /< *ref\s*(\s\b*?)?\s*>*/gi, '<ref$1>' );
slice = slice.replace( /(?:(\n*)|*)<\s*\/+\s*ref\s*>/gi, '$1<\/ref>' );
t = t.slice( 0, i );
}
t = t.replace( /< *ref\s*(\s\b*?)?\s*>\s*/gi, '<ref$1>' );
t = t.replace( /\s*<\s*\/+\s*ref\s*>/gi, '<\/ref>' );
if ( slice ) {
t += slice;
}
/* Leerzeichen zwischen Satzende und <ref> oder zwei <ref> entfernen */
t = t.replace( /(|<ref\b*(?:\/|>*<\/ref)>) +(?=<ref)/gi, '$1' );
/* Zwei gleiche Satzzeichen vor und nach einem <ref> auf eins kürzen */
return t.replace( /()(<ref\b*(?:\/|>*<\/ref)>)\1/gi, '$1$2' );
},
cleanCategories: function( t, context ) {
if ( !context.isDe && !context.isEn ) {
return t;
}
t = t.replace(
/\{\{\s*(SORTIERUNG|DEFAULT ?\w*SORT\w*)\s**/gi,
context.localisation === 'de' ? '{\{SORTIERUNG:' : context.localisation ? '{\{DEFAULTSORT:' : '{\{$1:'
);
/* Match every character thats in one of the two replacement maps or should be deleted */
var re = //g;
/* Unicodeblock Lateinisch-1, Ergänzung (U+0080 bis U+00FF) */
var trSet1 = '"/?¡¢£¤¥©ª«¬®°±²³·¹º»¿ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝàáâãäåçèéêëìíîïðñòóôõö÷øùúûüýÿ';
var trSet2 = ' cL YCa R 23 1o AAAAAACEEEEIIIIDNOOOOOxOUUUUYaaaaaaceeeeiiiidnooooo ouuuuyy';
/* Unicodeblock Lateinisch, erweitert-A (U+0100 bis U+017F) */
trSet1 += 'ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŔŕŖŗŘř';
trSet2 += 'AaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnnNnOoOoOoRrRrRr';
trSet1 += 'ŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſ';
trSet2 += 'SsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzs';
/* Unicodeblock Lateinisch, erweitert-B (U+0180 bis U+024F) */
trSet1 += 'ǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǤǥǦǧǨǩǪǫǬǭǸǹǺǻǾǿȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚț';
trSet2 += 'AaIiOoUuUuUuUuUueAaAaGgGgKkOoOoNnAaOoAaAaEeEeIiIiOoOoRrRrUuUuSsTt';
/* Unicodeblock Kyrillisch (U+0400 bis U+04FF) */
trSet1 += '\u0400ІЈ\u040DЎАБВГДЕЗИЙКЛМНОПРСТУФЦЪЫЭабвгдезийклмнопрстуфцъыэ\u0450іј\u045DўҐґҚқҮүҰұҺһӐӑӒӓӖӗ';
trSet2 += 'EIJIUABWGDESIJKLMNOPRSTUFZAYEabwgdesijklmnoprstufzayeeijiuGgQqUuUuHhAaAaEe';
/* Unicodeblock Lateinisch, weiterer Zusatz (U+1E00 bis U+1EFF) */
trSet1 += 'ḀḁḂḃḄḅḆḇḈḉḊḋḌḍḎḏḐḑḒḓḔḕḖḗḘḙḚḛḜḝḞḟḠḡḢḣḤḥḦḧḨḩḪḫḬḭḮḯḰḱḲḳḴḵḶḷḸḹḺḻḼḽḾḿṀṁṂṃṄṅṆṇṈṉṊṋṌṍṎṏṐṑṒṓṔṕṖṗ';
trSet2 += 'AaBbBbBbCcDdDdDdDdDdEeEeEeEeEeFfGgHhHhHhHhHhIiIiKkKkKkLlLlLlLlMmMmMmNnNnNnNnOoOoOoOoPpPp';
trSet1 += 'ṘṙṚṛṜṝṞṟṠṡṢṣṤṥṦṧṨṩṪṫṬṭṮṯṰṱṲṳṴṵṶṷṸṹṺṻṼṽṾṿẀẁẂẃẄẅẆẇẈẉẊẋẌẍẎẏẐẑẒẓẔẕẖẗẘẙẚẛ\u1E9C\u1E9D\u1E9F';
trSet2 += 'RrRrRrRrSsSsSsSsSsTtTtTtTtUuUuUuUuUuVvVvWwWwWwWwWwXxXxYyZzZzZzhtwyasssd';
trSet1 += 'ẠạẢảẤấẦầẨẩẪẫẬậẮắẰằẲẳẴẵẶặẸẹẺẻẼẽẾếỀềỂểỄễỆệỈỉỊịỌọỎỏỐốỒồỔổỖỗỘộỚớỜờỞởỠỡỢợỤụỦủỨứỪừỬửỮữỰựỲỳỴỵỶỷỸỹ';
trSet2 += 'AaAaAaAaAaAaAaAaAaAaAaAaEeEeEeEeEeEeEeEeIiIiOoOoOoOoOoOoOoOoOoOoOoOoUuUuUuUuUuUuUuYyYyYyYy';
/* Unicodeblock Allgemeine Interpunktion (U+2000 bis U+206F) */
trSet1 += '\u2012—―\u2016‗‘‚\u201B“”„\u201F†‡•′″‹›−';
trSet2 += ' ';
var trMap = {
'&': 'und', '¼': '14', '½': '12', '¾': '34',
'Æ': 'Ae', 'Þ': 'Th', '\u1E9E': 'SS', 'ß': 'ss', 'æ': 'ae', 'þ': 'th', 'IJ': 'Ij',
'ij': 'ij', 'Œ': 'Oe', 'œ': 'oe', 'Ǣ': 'Ae', 'ǣ': 'ae', 'Ǽ': 'Ae', 'ǽ': 'ae',
/* Unicodeblock Griechisch und Koptisch (U+0370 bis U+03FF) */
'Ά': 'Alpha', 'Έ': 'Epsilon', 'Ή': 'Eta', 'Ί': 'Iota', 'Ό': 'Omikron',
'Ύ': 'Ypsilon', 'Ώ': 'Omega', 'ΐ': 'iota', 'Α': 'Alpha', 'Β': 'Beta', 'Γ': 'Gamma',
'Δ': 'Delta', 'Ε': 'Epsilon', 'Ζ': 'Zeta', 'Η': 'Eta', 'Θ': 'Theta', 'Ι': 'Iota',
'Κ': 'Kappa', 'Λ': 'Lambda', 'Μ': 'My', 'Ν': 'Ny', 'Ξ': 'Xi', 'Ο': 'Omikron',
'Π': 'Pi', 'Ρ': 'Rho', 'Σ': 'Sigma', 'Τ': 'Tau', 'Υ': 'Ypsilon', 'Φ': 'Phi',
'Χ': 'Chi', 'Ψ': 'Psi', 'Ω': 'Omega', 'Ϊ': 'Iota', 'Ϋ': 'Ypsilon', 'ά': 'alpha',
'έ': 'epsilon', 'ή': 'eta', 'ί': 'iota', 'ΰ': 'ypsilon', 'α': 'alpha', 'β': 'beta',
'γ': 'gamma', 'δ': 'delta', 'ε': 'epsilon', 'ζ': 'zeta', 'η': 'eta', 'θ': 'theta',
'ι': 'iota', 'κ': 'kappa', 'λ': 'lambda', 'μ': 'my', 'ν': 'ny', 'ξ': 'xi',
'ο': 'omikron', 'π': 'pi', 'ρ': 'rho', 'ς': 'sigma', 'σ': 'sigma', 'τ': 'tau',
'υ': 'ypsilon', 'φ': 'phi', 'χ': 'chi', 'ψ': 'psi', 'ω': 'omega', 'ϊ': 'iota',
'ϋ': 'ypsilon', 'ό': 'omikron', 'ύ': 'ypsilon', 'ώ': 'omega',
/* Unicodeblock Kyrillisch (U+0400 bis U+04FF) */
'Ё': 'Jo', 'Ђ': 'Dje', 'Ѓ': 'Gje', 'Є': 'Je', 'Ѕ': 'Dze', 'Ї': 'Ji', 'Џ': 'Dsche',
'Ж': 'Sch', 'Х': 'Ch', 'Ч': 'Tsch', 'Ш': 'Sch', 'Щ': 'Schtsch', 'Ю': 'Ju',
'Я': 'Ja', 'ж': 'sch', 'х': 'ch', 'ч': 'tsch', 'ш': 'sch', 'щ': 'schtsch',
'ю': 'ju', 'я': 'ja', 'ё': 'jo', 'ђ': 'dje', 'ѓ': 'gje', 'є': 'je', 'ѕ': 'dze',
'ї': 'ji', 'Ғ': 'Gh', 'ғ': 'gh', 'Ң': 'Ng', 'ң': 'ng', 'Ӕ': 'Ae', 'ӕ': 'ae',
/* Unicodeblock Alphabetische Präsentationsformen (U+FB00 bis U+FB4F) */
'ff': 'ff', 'fi': 'fi', 'fl': 'fl', 'ffi': 'ffi', 'ffl': 'ffl', 'ſt': 'st', 'st': 'st'
};
trSet1 += context.isDe ? "–" : "'-–";
trSet2 += context.isDe ? " " : "'--";
var trReplace = function( $0, $1, $2 ) {
return $1 + $2.replace( /&#?\w+;/g, ' ' ).replace( re, function( $0 ) {
/* Some characters are replaced with the empty charAt(-1) on purpose */
return trMap || trSet2.charAt( trSet1.indexOf( $0 ) );
} ).replace( /(\S) +(?= |$)/g, '$1' ).replace( /(\S)# */g, '$1 #' );
};
t = t.replace( /(\{\{(?:SORTIERUNG|DEFAULT\w*SORT\w*):)(+)(?=\}\})/g, trReplace );
t = t.replace( /(\ategore?:|]+\|)(|]+)(?=\]\])/g, trReplace );
/* Groß-/Kleinschreibung wird seit dem 8. März 2011 ignoriert */
var title = escapeRE( mw.config.get( 'wgTitle' ) );
t = t.replace(
new RegExp( '\\{\\{(?:SORTIERUNG|DEFAULT\\w*SORT\\w*):\\s*' + title + '\\}\\}\\s*', 'gi' ),
''
);
var m = /\{\{(?:SORTIERUNG|DEFAULT\w*SORT\w*):(*)/.exec( t );
t = t.replace( new RegExp( '(\\ategore?:|]*)\\|'
+ ( m && escapeRE( m ) || title ) + '\\s*(?=\\]\\])', 'gi' ), '$1' );
return t.replace(
/(\ategore?:)()/g,
function( $0, $1, $2 ) {
return $1 + $2.toUpperCase();
}
);
},
cleanNewlines: function( t, context ) {
/* Mehrfache Leerzeilen auf einzelne reduzieren */
t = t.replace( context && context.isDisambiguation ? /\n{3,}(?=\n)/g : /\n{3,}/g, '\n\n' );
/* Keine Leerzeile vor einzeiligen <references /> */
t = t.replace( /(==\n)\n+(?=<references*\/>\n\n)/gi, '$1' );
/* Leerzeile nach Einzelnachweisen */
t = t.replace(
/(<\/?references*>)\s*(?=\{\{Navi(?:gationsleiste |Block)|\{\{SORTIERUNG:|\{\{DEFAULT\w*SORT\w*:|\ategore?:)/gi,
'$1\n\n'
);
/* Leerzeile zwischen Listen/bestimten Vorlagen und Kategorienblock */
t = t.replace(
/(\{\{(?:Begriffsklärung|Coordinate|Navi(?:gationsleiste |Block)|Normdaten)*\}\}|^\* **)\s*(?=\{\{SORTIERUNG:|\{\{DEFAULT\w*SORT\w*:|\ategore?:)/gim,
'$1\n\n'
);
/* Split categories into separate lines (don't make this a look-ahead, it's slow!) */
t = t.replace( /() *(\ategore?:]*\]\])/gi, '$1\n$2' );
t = t.replace( /(\ategore?:]*\]\]) *(?!|$)/gi, '$1\n' );
t = t.replace(
/(\ategore?:]*\]\]\n) *(?!\ategore?:||$)/gi,
'$1\n'
);
/* Keine Leerzeile zwischen SORTIERUNG und Kategorie */
t = t.replace(
/(\{\{(?:SORTIERUNG|DEFAULT\w*SORT\w*):*\}\})\s*(?=\ategore?:)/gi,
'$1\n'
);
/* Two empty lines in front of English stub templates */
return t.replace(
/(\ategore?:]*\]\])\s*(?=\{\{+-stub\b)/gi,
'$1\n\n\n'
);
},
cleanTemplates: function( t, context ) {
var de = context.isDe;
t = t.replace( /\{\{\s*:?\s*(?:Vorlage|Template)\s*:\s*/gi, '{\{' );
/* Unterstriche aus allen Vorlagennamen entfernen */
t = t.replace(
/(?:^|)\{\{(*_*)/gi,
function( $0, $1 ) {
return /^+\}$/.test( $1 )
? $0
: $0.replace( /_+(?=)/, '' ).replace( /+/g, ' ' ).replace( /\{ +/, '{' );
}
);
/* Drop empty templates */
t = t.replace(
/\{\{(?:Datum|e?dtsx?|Format(?:Date\d*|Num\w*|Zahl\w*)|Literatur|nts|Sort(?:Date\d*|Key\w*))*\}\}(?!\})/gi,
''
);
/* Remove empty unnamed parameters from otherwise named templates */
t = t.replace( /(\{\{*?) *\|(?=\n+ *\|*=)/g, '$1' );
/* Wirkungslose Leerzeilen aus Vorlagen entfernen */
while ( /^\{\{(?:<(?:br|file>)*>|)*\n\n+ */m.test( t ) ) {
t = t.replace( /^(\{\{(?:<(?:br|file>)*>|)*\n)\n+(?= *)/gm, '$1' );
}
/* Use the "Commons category" template instead of "Commons" with a category */
t = t.replace( /\{\{\s*Commons *(?:cat|category)?\s*\|\s*ategore?\s*:\s*/gi,
de ? '{\{Commonscat|' : '{\{Commons category|' );
/* Projektweit einheitliche Schreibweisen für häufig verwendete Vorlagen */
t = t.replace(
/\{\{\s*(-|Br|Breakafterimages|Clr)*(?=\}\})/gi,
de ? '{\{Absatz' : '{\{$1'
);
t = t.replace(
/\{\{\s*(?:Absatz|(Clear)(?:*(?:all|both))?)*(?=\}\})/gi,
de ? '{\{Absatz' : function( $0, $1 ) { return '{\{' + ( $1 || 'Clear' ); }
);
t = t.replace(
/\{\{\s*(?:Artikel über lebende Pe\w*|BLP)*(?=\}\})/gi,
de ? '{\{Artikel über lebende Person' : '{\{BLP'
);
t = t.replace(
/\{\{\s*(?:Belege|Quellen?)(?: *fehlen)?(?:*(?=\}\})| *(?=\s*\|))/gi,
'{\{Belege fehlen'
);
t = t.replace( /\{\{\s*(?:Benutzer(?:in)?|IP|User|Vandale)\s*\|\s*/gi,
de ? '{\{Benutzer|' : '{\{User|' );
t = t.replace( /\{\{\s*Commons(?:*(?=\}\})|\s*(\|)\s*)/gi, '{\{Commons$1' );
t = t.replace( /\{\{\s*Commons *cat(?:egory)?(?:*(?=\}\})|\s*(\|)\s*)/gi,
de ? '{\{Commonscat$1' : '{\{Commons category$1' );
t = t.replace( /\{\{\s*Dieser *Artikel\s*\|\s*/gi, '{\{Dieser Artikel|' );
t = t.replace( /\{\{\s*DOI\s*\|\s*/gi, '{\{DOI|' );
t = t.replace( /\{\{\s*dts(x?)\s*\|\s*/gi, '{\{dts$1|' );
t = t.replace( /\{\{\s*Erledigt*\}\}/gi, '{\{Erledigt|~~\~~}}' );
t = t.replace(
/\{\{\s*(?:Gefallen|Fallen|Verlust|Verschlechtert|Decrease|Down|Loss)*(?=\}\})/gi,
de ? '{\{Gefallen' : '{\{decrease'
);
t = t.replace(
/\{\{\s*(?:Gestiegen|Steigen|Gewinn|Profit|Verbessert|Increase|Gain)*(?=\}\})/gi,
de ? '{\{Gestiegen' : '{\{increase'
);
t = t.replace(
/\{\{\s*(?:Hauptartikel|Hauptseite|Main|Main *articles?|See *main)\s*\|\s*/gi,
de ? '{\{Hauptartikel|' : '{\{Main|'
);
t = t.replace( /\{\{\s*IMDb\s*\|\s*(\w+)\s*/gi, '{\{IMDb|$1' );
t = t.replace( /\{\{\s*(?:Internetquelle|Weblink)(?=\s*\|)/gi, '{\{Internetquelle' );
t = t.replace(
/\{\{\s*(?:In *TeX *konvertieren|TeX)(?:*(?=\}\})|\s*(\|)\s*)/gi,
'{\{In TeX konvertieren$1'
);
t = t.replace( /\{\{\s*lang\s*\|\s*/gi, '{\{lang|' );
t = t.replace( /\{\{\s*Link *(A)\s*\|\s*/gi, '{\{Link $1|' );
t = t.replace( /\{\{\s*nts\s*\|\s*/gi, '{\{nts|' );
t = t.replace( /\{\{\s*(?:Nur *Liste|Liste)(?:*(?=\}\})| *(?=\s*\|))/gi, '{\{Nur Liste' );
t = t.replace( /\{\{\s*Okina*\}\}/gi, '\u02BB' );
t = t.replace( /\{\{\s*Rotten *Tomatoes\s*\|\s*/gi, '{\{Rotten Tomatoes|' );
t = t.replace(
/\{\{\s*S(?:iehe *auch|ee*also)\s*\|\s*/gi,
de ? '{\{Siehe auch|' : '{\{See also|'
);
t = t.replace(
/\{\{\s*(?:SortDate|Datesort)\d*\s*\|\s*/gi,
de ? '{\{SortDate|' : '{\{dts|'
);
t = t.replace(
/\{\{\s*SortKey(Name)?\s*\|\s*/gi,
de ? '{\{SortKey$1|' : function( $0, $1 ) { return $1 ? '{\{sortname|' : '{\{sort|'; }
);
t = t.replace(
/\{\{\s*(?:(?:Toter|Bad|Broken|Dead)*Link|404|Dead|DL)*(?=)/gi,
de ? '{\{Toter Link' : '{\{dead link'
);
t = t.replace(
/\{\{\s*(u)nsign?(?:iert|ed)?\s*\|\s*/gi,
de ? '{\{$1nsigniert|' : '{\{$1nsigned|'
);
t = t.replace(
/\{\{\s*(?:Unverändert|Stabil|Steady|Nochange|Unchanged)*(?=\}\})/gi,
de ? '{\{Unverändert' : '{\{steady'
);
t = t.replace(
/\{\{\s*(?:Vorlage|Tl?1?|Temp|Template(?: *link)?)\s*\|\s*/gi,
de ? '{\{Vorlage|' : '{\{tl|'
);
t = t.replace(
/\{\{\s*Wik(ibooks|inews|iquote|isource|ivoyage|tionary)*(?=)/gi,
'{\{Wik$1'
);
/* Lower case German language template names "enS" and so on */
t = t.replace(
/\{\{\s*()(+S)(?:*(?=\}\})|\s*(\|)\s*)/g,
function( $0, $1, $2, $3 ) {
return '{\{' + $1.toLowerCase() + $2 + ( $3 || '' );
}
);
t = t.replace(
/\{\{\s*IMDb *()(\w+)\s*\|\s*/gi,
function( $0, $1, $2 ) {
return '{\{IMDb ' + ( de ? $1.toUpperCase() : $1.toLowerCase() ) + $2 + '|';
}
);
t = t.replace( /\(\{\{\s*B\s*((?:\|*){2,4})\}\}\)/gi, '{\{Bibel$1}}' );
/* Remove navigation bar wrapper if it contains a single navigation bar only */
t = t.replace( /\{\{\s*NaviBlock\s*\|*(+)*(?=\}\})/gi, '{\{$1' );
t = t.replace(
/\{\{\s*(NaviBlock*?)(?:-*)*(?=\}\})/gi,
function( $0, $1 ) {
return '{\{' + $1.replace( /\s*\|(?:-*)*/g, '\n|' ) + '\n';
}
);
t = t.replace( /\{\{\s*Normdaten\s*\|\s*PND\s*=\s*/g, '{\{Normdaten|TYP=p|GND=' );
t = t.replace( /\{\{\s*WBA\s*\|\s*/gi, '{\{Waybackarchiv|' );
t = t.replace(
/\*(\d{1,14})\/(\w+:*)*\}\}\s+(|]*)\]/gi,
'{\{Webarchiv | url=$2 | wayback=$1 | text=$3}}'
);
return t.replace( /(\|\s*(?:Breit|Läng)engrad\s*=\s**?)\/*(?=)/g, '$1' );
},
cleanRedundantTemplateParameters: function( t ) {
var parameters = window.redundantTemplateParameters || [
'(?:IMDb(?: Name| Titel)?|OFDb|Rotten Tomatoes)|2',
'Infobox (?:Arcade|Computer- und Videospiel|Musikalbum)|Titel',
'Infobox (?:Bahnhof|Band|Burg|Chemikalie|County \\(Vereinigte Staaten\\)|Eishockeyspieler|Flug(?:gesellschaft|hafen|zeug)|Fußballsaison|Gemeinde in '
+ '(?:Deutschland|Österreich)|Gemeindeverband in Deutschland|Hochschule|Landkreis|Medaillen|Militärische Einheit|Ort in '
+ '(?:den Niederlanden|den Vereinigten Staaten|der Türkei|Portugal)|Schiff|Schutzgebiet|Software|Stadion|Tennis(?:spieler|turnierjahrgang)|Unternehmen)|Name',
'Infobox (?:Berg|Burg|Fluss|Gebirgsgruppe|Insel|Ort|See|Stadt in Lateinamerika|Stausee|Verwaltungseinheit)|NAME',
'Infobox Brücke|BEZEICHNUNG',
'Infobox Fußballspieler|kurzname',
'Infobox Galaxie|Caption',
'Infobox Gemeinde in Italien|nomeComune',
'Infobox Gemeinde in Spanien|Gemeinde',
'Infobox Gemeinde in Spanien|nombre',
'Infobox Militärischer Konflikt|KONFLIKT',
'Infobox Nationalpark|title',
'Infobox Ort in der Schweiz|NAME_ORT',
'Infobox Ort in (?:Polen|Tschechien)|Ort',
'Infobox Ortsteil einer Gemeinde(?: in Deutschland)?|Ortsteil',
'Infobox PKW-Modell|Modell',
'Infobox (?:Publikation|Nationalpark)|titel',
'Infobox Schule|Schulname'
];
var title = '\\s*(?:' + escapeRE( mw.config.get( 'wgTitle' ) ) + '|\\{+\\w*\\}+)?\\s*';
for ( var i = parameters.length; i--; ) {
var m = /^(.+)\|(+)$/.exec( parameters );
if ( !m ) {
continue;
}
var number = m | 0;
var re = number ?
'\\s*(?:\\|*){' + ( number - 1 ) + '})\\|' + title + '(?=\\}\\})' :
'\\s*(?:\\|*)?)\\|\\s*' + m + '\\s*=' + title + '(?=\\||\\}\\})';
t = t.replace( new RegExp( '(\\{\\{ *' + m.replace( /_+/g, ' ' ) + re, 'g' ), '$1' );
}
return t;
},
cleanTemplatesByRules: function( t ) {
var rules = window.autoFormatTemplates || ;
for ( var rule in rules ) {
if ( !rules || !rules.name ) {
continue;
}
rule = rules;
/* Format muss minimalst |_=_ lauten */
if ( !rule.format ) {
rule.format = '';
}
if ( rule.format.indexOf( '|' ) < 0 ) {
rule.format = '|' + rule.format;
}
if ( rule.format.indexOf( '_' ) < 0 ) {
rule.format = rule.format.replace( '|', '|_' );
}
if ( rule.format.indexOf( '=' ) < 0 ) {
rule.format += '=';
}
if ( rule.format.match( /_+/g ).length < 2 ) {
rule.format += '_';
}
var re = new RegExp( '\\{\\{*' + rule.name.replace( /+/g, '+' )
+ '(\\s*<!*>)?*\\|', 'gi' ),
m,
a = ;
while ( m = re.exec( t ) ) {
a.push( m );
}
for ( var i = a.length; i--; ) {
t = this.cleanTemplateByRule( t, rule, a.index + 2, a );
}
}
return t;
},
cleanTemplateByRule: function( t, rule, start, comment ) {
var parameters,
p = '',
pos = start - 1,
nesting = { '[': 0, '{': 0 };
while ( ++pos < t.length ) {
var c = t.charAt( pos );
if ( c === '[' || c === '{' ) {
nesting++;
} else if ( c === ']' && nesting-- <= 0 ) {
return t;
} else if ( c === '}' && nesting-- <= 0 ) {
/* Parsing started after opening brackets, so stop before closing */
if ( t.charAt( pos + 1 ) !== '}' ) {
return t;
}
if ( parameters ) {
parameters.push( p );
}
break;
} else if ( c === '|' && nesting <= 0 && nesting <= 0 ) {
if ( parameters ) {
parameters.push( p );
} else {
parameters = ;
}
p = '';
}
p += c;
}
if ( pos >= t.length || nesting > 0 ) {
return t;
}
var m = /((_+)#*)( *)*((_+)#*)( *)/.exec( rule.format );
var kMax = m ? m.length : 0,
kMin = m ? m.length : 0,
kFix = m ? m.length : 0,
vMax = m ? m.length : 0,
vMin = m && m.length > 1 ? m.length : 0,
vFix = m ? m.length : 0;
var result = rule.name + ( comment || '' ) + ( /\n$/.test( rule.format ) ? '\n' : '' );
for ( var f, i = 0; parameters && i < parameters.length; i++ ) {
p = parameters;
if ( !( m = /^\s*\|*((*?) *)*=*(*? *)\s*$/.exec( p ) ) ) {
/* Leere unbenannte Parameter verwerfen, wenn ein benannter folgt */
if ( !/^\s*\|-*\s*$/.test( p ) || ( parameters && parameters.indexOf( '=' ) < 1 ) ) {
result += p;
}
continue;
}
p = rule.parameters && typeof rule.parameters] !== 'undefined' ? rule.parameters] : m;
/* Parameter verwerfen, die in den Regeln mit false oder ähnlich markiert sind */
if ( !p ) {
continue;
}
for ( f = 0; ( f < kFix || kMax && p.length > kMax ) && /\s$/.test( p ); f++ ) {
p = p.slice( 0, -1 );
}
for ( f = 0; ( f < vFix || vMax && m.length > vMax ) && /\s$/.test( m ); f++ ) {
m = m.slice( 0, -1 );
}
while ( p.length < kMin ) {
p += ' ';
}
while ( m.length < vMin ) {
m += ' ';
}
result += rule.format.replace( /_+#*(*)_+#*/, p.replace( /\$/g, '$$$$' ) + '$1' +
m.replace( /\$/g, '$$$$' ) );
}
if ( rule.format.indexOf( '\n' ) >= 0 ) {
if ( typeof rule.trim === 'undefined' || rule.trim ) {
result = result.replace( /+$/gm, '' );
}
/* Schließendes }} immer auf eine eigene Zeile, wenn irgendein Umbruch im Spiel ist */
result = result.replace( /\n+\s*$/, '' ) + '\n';
}
return t.slice( 0, start ) + result + t.slice( pos );
},
executeUserReplacements: function( t ) {
var from,
replacements = window.autoFormatReplacements || {};
for ( from in replacements ) {
var to = replacements;
/* Wenn die Ersetzungen kein assoziatives Objekt sondern ein 2-dimensionales Array sind */
if ( typeof to === 'object' && to.length > 1 ) {
from = to;
to = to;
}
/* If the search pattern is a regular expression already, 'function' is for older Chrome */
if ( typeof from === 'object' || typeof from === 'function' ) {
t = t.replace( from, to );
continue;
}
/* Leere Suchmuster sicherheitshalber nicht zulassen */
if ( /^\s*$/.test( from ) || typeof to !== 'string' ) {
continue;
}
/* Die meisten Regex-Zeichen maskieren, außer Zeichenklassen */
from = from.replace( /()/g, '\\$1' );
to = to.replace( /\$/g, '$$$$' );
/* Wortgrenzen beachten */
from = from.replace( /^(?=\w|\\d)/, '\\b' ).replace( /(\w)$/, '$1\\b' );
var a = ;
for ( var re = /\\/g, m, i = 1; m = re.exec( from ); a.push( m ) ) {
to = to.replace( m, '$' + i++ );
}
for ( i = a.length; i--; ) {
from = from.slice( 0, a.index ) + ( a === '\\d' ? '(\\d+)' :
'(+)' ) +
from.slice( a.index + 2 );
}
/* Look-ahead verwenden, wenn ein Platzhalter in Suchmuster und Ersatz am Ende steht */
if ( /\+\)\\b$/.test( from ) && new RegExp( '\\$' + a.length + '$' ).test( to ) ) {
from = from.replace( /(+)\)\\b$/, '?=$1\\b)' );
to = to.replace( /\$\d+$/, '' );
}
/* Allow optional spaces after dots in the search pattern */
from = from.replace( /\\\.(?=)/g, '\\.(?:| )*' );
t = t.replace( new RegExp( from, 'g' ), to );
}
return t;
},
backupNowikis: function( t ) {
this.nowikis = ;
var re = /<(nowiki|includeonly|syntaxhighlight|source|html|pre|code|graph|mapframe|score|templatedata|templatestyles|timeline|hiero|math)\b(?!\s*\/>)*?<\/\1\s*>/gi;
var m;
while ( m = re.exec( t ) ) {
delete m.input;
this.nowikis.push( m );
}
for ( var i = this.nowikis.length; i--; ) {
var placeholder = '<nowiki>' + i + '<\/nowiki>';
t = t.slice( 0, this.nowikis.index ) + placeholder +
t.slice( this.nowikis.index + this.nowikis.length );
if ( /^<\w+\s*>\s*<\/\w+\s*>$/.test( this.nowikis ) ) {
this.nowikis = /^no/i.test( this.nowikis ) ? '<nowiki />' : '';
} else if ( /^s/i.test( this.nowikis ) ) {
this.nowikis = this.nowikis.replace( /^(<)\w+|\w+\s*(?=>$)/g, '$1syntaxhighlight' );
}
this.nowikis = placeholder;
delete this.nowikis.index;
}
return t;
},
restoreNowikis: function( t ) {
for ( var i = 0, len = this.nowikis.length, index = 0; i < len; i++ ) {
index = t.indexOf( this.nowikis, index );
if ( index >= 0 ) {
t = t.slice( 0, index ) + this.nowikis +
t.slice( index + this.nowikis.length );
}
}
delete this.nowikis;
return t;
},
backupFilenames: function( t, context ) {
/* Dateinamen retten incl. Vereinheitlichung als "Datei:" */
this.files = ;
var ns = mw.config.get( 'wgFormattedNamespaces' ),
ext = mw.config.get( 'wgFileExtensions' ) || ['png', 'gif', 'jpg', 'jpeg', 'tiff',
'tif', 'xcf', 'pdf', 'mid', 'ogg', 'ogv', 'svg', 'djvu', 'oga', 'flac', 'wav', 'webm'];
/* Match <gallery> lines, ] and template parameters with file names */
var m,
re = new RegExp(
'(^ *|\\|]*?) *(?=|])|'
+ '(^ *|\\|\\n?(?:{|}]*=)? *)\\s*({|}]*\\.(?:'
+ ext.join( '|' ) + '))(?= *)|'
+ '(\\|\\s*Commons(?:cat)? *= *)({|}]*)(?=)',
'gim'
);
while ( m = re.exec( t ) ) {
var o = ( m || ( m ? m : m ) ).length;
m.index += o;
m.l = m.length - o;
/* Multiple underscores and spaces never have a meaning in filenames */
m = ( m ? m : m || m ).replace( /(?:|%20|%5F|%C2%A0| )+/gi, ' ' );
this.files.push( m );
}
var r = '',
p = 0;
for ( var i = 0; i < this.files.length; i++ ) {
this.files = '<file>' + i + '<\/file>';
r += t.slice( p, this.files.index );
if ( this.files ) {
/* Einheitliche Schreibweise und Leerzeichenausgleich */
r += ( context.localisation && !/\w:$/.test( this.files ) ? ns : this.files ) + ':';
}
r += this.files;
p = this.files.index + this.files.l;
}
return p ? r + t.slice( p ) : t;
},
restoreFilenames: function( t ) {
/* Gerettete Dateinamen wieder einsetzen */
var r = '',
p = 0;
for ( var index, i = 0; i < this.files.length; i++ ) {
if ( ( index = t.indexOf( this.files, p ) ) < 0 ) {
continue;
}
r += t.slice( p, index ) + this.files;
p = index + this.files.length;
delete this.files;
}
if ( p ) {
t = r + t.slice( p );
}
/* Fehlschläge nochmal versuchen, passiert bspw. bei umsortierten Galeriezeilen */
for ( i = this.files.length; i--; ) {
if ( this.files ) {
t = t.replace( this.files, this.files );
}
}
delete this.files;
return t;
}
};
var label = window.autoFormatterButtonLabel || 'Auto-Format';
mw.loader.using( 'user.options', function() {
if ( mw.user.options.get( 'usebetatoolbar' ) ) {
mw.loader.using( 'ext.wikiEditor', function() {
$( function() {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'main',
'group': 'format',
'tools': {
'autoFormatter': {
'label': label,
'type': 'button',
'icon': '//upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Broom_icon.svg/22px-Broom_icon.svg.png',
'action': {
'type': 'callback',
'execute': function() { return mw.libs.autoFormatter.click( this ); }
}
}
}
} );
} );
} );
} else if ( mw.user.options.get( 'showtoolbar' ) ) {
mw.loader.using( 'mediawiki.action.edit', function() {
mw.toolbar.addButton(
'//upload.wikimedia.org/wikipedia/commons/2/2e/Button_broom.png',
label,
'', '', '',
'mw-customeditbutton-autoFormatter'
);
$( function() {
$( '#mw-customeditbutton-autoFormatter' ).click( function() {
return mw.libs.autoFormatter.click( this );
} );
} );
} );
} else {
$( function() {
/* Notfalls als Link unter dem Bearbeitungsfenster */
var b = $( '.editButtons' ),
c = b.children().last(),
a = $( '<a href="#">' + label + '<\/a>' );
( c.is( 'span' ) ? c : b ).append( $( '.mw-editButtons-pipe-separator', b ).first().clone() );
a.click( function() { return mw.libs.autoFormatter.click( this ); } );
b.append( a );
} );
}
} );
} )( jQuery, mediaWiki );
// </nowiki>