Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Strg+F5
/*
[[Kategorie:Benutzer:ⵓ/Scripts]]
*/
/**
 * 
 * Original stammt von [[Benutzer:TMg/autoFormatter]]
 */
( function( $, mw ) {
		if ( !document.forms['editform']
		|| ( mw.config.get( 'wgAction' ) !== 'edit' && mw.config.get( 'wgAction' ) !== 'submit' )
	) {
		return;
	}

	if ( !mw.libs ) {
		mw.libs = {};
	}

	mw.libs.ARreplace = {
		click: function( a ) {
            var e = document.forms.editform.elements,
				textbox = e.wpTextbox1;
			if ( !textbox ) {
				return false;
			}

			if ( window.wikEd && window.wikEd.useWikEd ) {
				wikEd.UpdateTextarea();
			}

			if ( !a || !a.nodeType || a.rel === 'ARreplace' ) {
				$( a && a.nodeType ? a : '[rel=ARreplace]' ).css( {
					backgroundColor: '',
					opacity: ''
				} );
			}

			this.clickedElement = a;
			this.isAll = false;
			this.isDisambiguation = /\{\{\s*[Bb]egriffsklärung\s*[|}]/.test( textbox.value );
			this.lang = mw.config.get( 'wgContentLanguage' );
			this.localisation = typeof window.autoFormatLocalisation === 'undefined' ||
				window.autoFormatLocalisation === true ? this.lang : window.autoFormatLocalisation;

			var hasChanges = this.cleanElement( textbox );
			if ( window.wikEd && window.wikEd.useWikEd ) {
				wikEd.UpdateFrame();
			}
			if ( hasChanges ) {
				mw.hook( 'AutoFormatterDoneWithChange' ).fire(); 
			}
			return false;
		},
		isChanged: function( oldValue, newValue ) {
			/* 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 */
			var changed = oldValue.replace( /[\r ]+\n/g, '\n' ) !== newValue.replace( /[\r ]+\n/g, '\n' );

			var a = this.clickedElement;
			if ( !a || !a.nodeType || a.rel === 'ARreplace' ) {
				$( a && a.nodeType ? a : '[rel=ARreplace]' ).css( {
					backgroundColor: changed ? '#DEF740' : '',
					borderRadius: changed ? '3px' : '',
					opacity: changed ? '' : '.4'
				} );
			} else if ( a && a.style ) {
				a.style.color = changed ? 'green' : 'silver';
			}
			/* Normalisierte Zeilenumbrüche nie als Änderung werten, das vermeidet Flackern */
			return changed || oldValue.replace( /\r+$/gm, '' ) !== newValue;
		},
		cleanElement: function( e ) {
			var t;

			e.focus();
			if ( typeof e.selectionStart === 'number' ) {
				var scroll = e.scrollTop,
					s1 = e.selectionStart,
					s2 = e.selectionEnd;

				if ( s2 > s1 && ( s1 > 0 || s2 < e.value.length ) ) {
					t = this.cleanText( e.value.substring( s1, s2 ) );
					if ( t === false ) {
						return 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 );
				} else if ( !this.cleanAll( e ) ) {
					return false;
				}
				e.selectionStart = s1;
				e.selectionEnd = s2;
				e.scrollTop = scroll;
			} else if ( typeof document.selection === 'object' ) {
				var range = document.selection.createRange();
				if ( range.text.length ) {
					t = this.cleanText( range.text );
					if ( t !== false ) {
						range.text = t;
					}
				} else {
					return this.cleanAll( e );
				}
			} else {
				return this.cleanAll( e );
			}
		},
		cleanAll: function( e ) {
			this.isAll = true;
			var t = this.cleanText( $( e ).val() );
			if ( t !== false ) {
				$( e ).val( t.replace( /^\s*\n/, '' ) );
			}
			return t !== false;
		},
		
		
		cleanText: function( t ) {
			var oldValue = t;
			t = mw.libs.autoFormatter.backupFilenames( t );
			t = mw.libs.autoFormatter.backupNowikis( t );

			t = this.executeUserReplacements( t );

			t = mw.libs.autoFormatter.restoreFilenames( t );
			t = mw.libs.autoFormatter.restoreNowikis( t );
			if ( window.wikEd && window.wikEd.useWikEd ) {
                
               
                wikEd.DiffResponse(oldValue, t);

               
            }
			var changed = this.isChanged( oldValue, t );
			return changed ? t : false;
		},

		executeUserReplacements: function( t ) {
			var changeSummary=false,
			    addSummarytext='',
			    addhomelink=((/\[\[User:ⵓ\/ARreplace/i.test(document.forms.editform.elements.wpSummary.value))===false);
			var from,
				replacements = window.autoRegexpReplacements || {};

			for ( from in replacements ) {
				var told=t;
				var to = replacements[from];

				/* If the search pattern is a regular expression already*/
				if ( typeof to.find === 'object'  ) {
					t=t.replace( to.find, to.mend );
					if (told!=t && to.neat != 'undefined'){
						if (addSummarytext.indexOf(to.neat)>0){
							addSummarytext+='+';
						} else {
							addSummarytext+=' '+to.neat; 
						}
						changeSummary=true;
					}
					continue;
				}
				/* Leere Suchmuster sicherheitshalber nicht zulassen */
				if ( /^\s*$/.test( to.find ) || typeof to.mend !== 'string' ) {
					continue;
				}

				/* Die meisten Regex-Zeichen maskieren, außer Zeichenklassen */
				to.find = to.find.replace( /([$()*+.?^{|}])/g, '\\$1' );
				to.mend = to.mend.replace( /\$/g, '$$$$' );
				/* Wortgrenzen beachten */
				to.find = to.find.replace( /^(?=\w|\\d)/, '\\b' ).replace( /(\w)$/, '$1\\b' );
				var a = [];
				for ( var re = /\\[dw]/g, m, i = 1; m = re.exec( to.find ); a.push( m ) ) {
					to.mend = to.mend.replace( m[0], '$' + i++ );
				}
				for ( i = a.length; i--; ) {
					to.find = to.find.slice( 0, a[i].index ) + ( a[i][0] === '\\d' ? '(\\d+)' :
						'([A-Za-z\xB5\xC0-\xD6\xD8-\xF6\xF8-\u024F]+)' ) +
						to.find.slice( a[i].index + 2 );
				}
				/* Look-ahead verwenden, wenn ein Platzhalter in Suchmuster und Ersatz am Ende steht */
				if ( /\+\)\\b$/.test( to.find ) && new RegExp( '\\$' + a.length + '$' ).test( to.mend ) ) {
					to.find = to.find.replace( /([^()]+)\)\\b$/, '?=$1\\b)' );
					to.mend = to.mend.replace( /\$\d+$/, '' );
				}
				/* Allow optional spaces after dots in the search pattern */
				to.find = to.find.replace( /\\\.(?=[(\w\xC0-\u024F])/g, '\\.(?:[ \xA0]|&nbsp;)*' );
				t = t.replace( new RegExp( to.find, 'g' ), to.mend );
				if (told!=t && to.neat != 'undefined'){
					if (addSummarytext.indexOf(to.neat)>0){
						addSummarytext+='+';
					} else {
						addSummarytext+=' '+to.neat; 
					}
					changeSummary=true;
				}
			};
			if (addhomelink) {
				addSummarytext+=' [[User:ⵓ/ARreplace|→]] '
			};
			document.forms.editform.elements.wpSummary.value+=addSummarytext;
			document.forms.editform.elements.wpSummary.value.trim();
			return t;
		}
	};

	if ( mw.user.options.get( 'usebetatoolbar' ) ) {
		mw.loader.using( 'ext.wikiEditor', function() {
			$( document ).ready( function() {
				$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
					'section': 'main',
					'group': 'format',
					'tools': {
						'ARreplace': {
							'label': 'Auto-Regexp',
							'type': 'button',
							'icon': '//upload.wikimedia.org/wikipedia/commons/thumb/1/14/ARReplace.svg/22px-ARReplace.svg.png',
							'action': {
								'type': 'callback',
								'execute': function() { return mw.libs.ARreplace.click( this ); }
							}
						}
					}
				} );
			} );
		} );
	} else if ( mw.user.options.get( 'showtoolbar' ) ) {
		mw.loader.using( 'mediawiki.action.edit', function() {
			mw.toolbar.addButton( '//upload.wikimedia.org/wikipedia/commons/thumb/1/14/ARReplace.svg/22px-ARReplace.svg.png',
				'Auto-Regexp', '', '', '', 'mw-customeditbutton-ARreplace' );
			$( document ).ready( function() {
				$( '#mw-customeditbutton-ARreplace' ).click(
					function() { return mw.libs.ARreplace.click( this ); }
				);
			} );
		} );
	} else {
		$( document ).ready( function() {
			/* Notfalls als Link unter dem Bearbeitungsfenster */
			var b = $( '.editButtons' ),
				c = b.children().last();

			( c.is( 'span' ) ? c : b ).append( $( '.mw-editButtons-pipe-separator', b ).first().clone() );
			var a = $( '<a href="#">Auto-Regexp<\/a>' );
			a.click( function() { return mw.libs.ARreplace.click( this ); } );
			b.append( a );
		} );
	}
} )( jQuery, mediaWiki );