„Benutzer:Umherirrender/monobook.js“ – Versionsunterschied
Zur Navigation springen
Zur Suche springen
Inhalt gelöscht Inhalt hinzugefügt
Maintenance: mw:RL/MGU - Removed redundant module |
K script fehler vermeiden |
||
Zeile 69: | Zeile 69: | ||
} |
} |
||
} |
} |
||
/* im Bearbeitenmodus */ |
|||
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' ) { |
|||
/* ergänzt zum label für Zusammenfassungszeile ein Auswahlmenü */ |
|||
// span of the label |
|||
var spanLabel = document.getElementById( "wpSummaryLabel" ); |
|||
//nur, wenn unter der Textbox steht |
|||
if ( spanLabel && spanLabel.parentNode && spanLabel.parentNode.className === "editOptions" ) { |
|||
//the select |
|||
var summarySelect = document.createElement( "select" ); |
|||
summarySelect.name = "summarySelect"; |
|||
summarySelect.id = "summarySelect"; |
|||
summarySelect.onchange = function() { |
|||
var summarySelect = document.getElementById( "summarySelect" ); |
|||
var option = summarySelect.getElementsByTagName( "option" )[ summarySelect.selectedIndex ]; |
|||
var summary = document.getElementById( "wpSummary" ); |
|||
//append with a space |
|||
if (summary.value === "") { |
|||
summary.value = option.value; |
|||
} |
|||
//für vorbelegungen |
|||
else if (summary.value.substring(0,2) === " |") { |
|||
summary.value = option.value + summary.value; |
|||
} else { |
|||
summary.value += " " + option.value; |
|||
} |
|||
}; |
|||
// the label |
|||
var label = spanLabel.getElementsByTagName ( "label" )[0]; |
|||
// set default |
|||
var optionFirst = document.createElement( "option" ); |
|||
summarySelect.appendChild ( optionFirst ); |
|||
//Zeile kann link enthalten, suche Text |
|||
var child = label.firstChild; |
|||
while (!child.data) { |
|||
child = child.firstChild; |
|||
} |
|||
//text setzen |
|||
optionFirst.value = ""; |
|||
optionFirst.text = child.data; |
|||
var summaryOption = getSummaryOption(); |
|||
if ( summaryOption && summaryOption.length ) { |
|||
//set options |
|||
for (var i = 0; i < summaryOption.length; i++) { |
|||
var option = document.createElement( "option" ); |
|||
summarySelect.appendChild ( option ); |
|||
option.value = summaryOption[i]; |
|||
option.text = summaryOption[i]; |
|||
} |
|||
} |
|||
//make visible - hidden by my css |
|||
spanLabel.style.display="block"; |
|||
//remove label |
|||
spanLabel.removeChild( label ) ; |
|||
//append select |
|||
spanLabel.appendChild( summarySelect ); |
|||
//Link zum leeren der Zusammenfassung |
|||
spanLabel.appendChild( document.createTextNode( ' | ' ) ); |
|||
var $aLeeren = $( document.createElement( 'a' ) ); |
|||
$aLeeren.click( function () { |
|||
var summary = document.getElementById( 'wpSummary' ); |
|||
if ( summary ) { |
|||
summary.value = ''; |
|||
} |
|||
} ); |
|||
$aLeeren.text( 'leeren' ); |
|||
spanLabel.appendChild( $aLeeren[0] ); |
|||
//vordefinierten Text entfernen |
|||
spanLabel.appendChild( document.createTextNode( ' | ' ) ); |
|||
var $aEntfernen = $( document.createElement( 'a' ) ); |
|||
$aEntfernen.click( function () { |
|||
var summary = document.getElementById( 'wpSummary' ); |
|||
if ( summary ) { |
|||
var index = summary.value.indexOf( ' |' ); |
|||
if ( index !== -1 ) { |
|||
summary.value = summary.value.substring( 0, index ); |
|||
} |
|||
} |
|||
} ); |
|||
$aEntfernen.text( 'entfernen' ); |
|||
spanLabel.appendChild ( $aEntfernen[0] ); |
|||
//bei falsche auswahl |
|||
spanLabel.appendChild( document.createTextNode( ' | ' ) ); |
|||
var $aFalsch = $( document.createElement( 'a' ) ); |
|||
$aFalsch.click( function () { |
|||
var summary = document.getElementById( 'wpSummary' ); |
|||
if ( summary ) { |
|||
var index = summary.value.indexOf( ' |' ); |
|||
if ( index !== -1 ) { |
|||
summary.value = summary.value.substring( index ); |
|||
} else { |
|||
summary.value = ''; |
|||
} |
|||
} |
|||
} ); |
|||
$aFalsch.text( 'falsch' ); |
|||
spanLabel.appendChild ( $aFalsch[0] ); |
|||
} |
|||
var textbox = document.getElementById("wpTextbox1"); |
|||
//falls man nicht darf, braucht es auch keine Auswahl |
|||
if(textbox && !textbox.getAttribute("readonly")) { |
|||
/* setzt ein Auswahlmenü für Textvorlagen */ |
|||
var textTemplateSelect = document.createElement( "select" ); |
|||
textTemplateSelect.name = "textTemplateSelect"; |
|||
textTemplateSelect.id = "textTemplateSelect"; |
|||
textTemplateSelect.onchange = function() { |
|||
var textTemplateSelect = document.getElementById( "textTemplateSelect" ); |
|||
var textTemplateOutput = document.getElementById( "textTemplateOutput" ); |
|||
var option = textTemplateSelect.getElementsByTagName( "option" )[ textTemplateSelect.selectedIndex ]; |
|||
// extra behandlung für katsort |
|||
if( option.text === 'katsort' ) { |
|||
var textarea = document.getElementById( 'wpTextbox1' ); |
|||
if( textarea ) { |
|||
var content = textarea.value; |
|||
//bereits vorhanden? |
|||
if( content.match( /\{\{\s*(?:SORTIERUNG|DEFAULTSORT|DEFAULTSORTKEY|DEFAULTCATEGORYSORT)\s*:[^\}]*\}\}/i ) ) { |
|||
textTemplateOutput.style.backgroundColor = 'red'; |
|||
} else { |
|||
//ersetze den ersten Kategorieeintrag durch SORTIERUNG und den Kategorieeintrag |
|||
textarea.value = content.replace( /\s*\[\[\s*(?:kategorie|category)\s*:([^\|\]]*)\|?([^\]]*)\]\]/i, |
|||
'\n\n{{SORTIERUNG:$2}}\n[[Kategorie:$1]]' ); |
|||
} |
|||
} |
|||
} |
|||
//SLAs am Anfang ins Textfeld einfügen |
|||
else if( option.value.match( /\{\{SLA\|/ ) ) { |
|||
var textarea = document.getElementById( 'wpTextbox1' ); |
|||
if( textarea ) { |
|||
textarea.value = option.value + '\n' + textarea.value; |
|||
} |
|||
} |
|||
textTemplateOutput.value = option.value; |
|||
textTemplateOutput.select(); |
|||
}; |
|||
var textTemplateOutput = document.createElement( "input" ); |
|||
textTemplateOutput.name = "textTemplateOutput"; |
|||
textTemplateOutput.id = "textTemplateOutput"; |
|||
textTemplateOutput.size = "60"; |
|||
// set default |
|||
var optionTextvorlage = document.createElement( "option" ); |
|||
textTemplateSelect.appendChild ( optionTextvorlage ); |
|||
optionTextvorlage.value = ""; |
|||
optionTextvorlage.text = "Textvorlage auswählen"; |
|||
//set options |
|||
setOptionsToSelect(textTemplateSelect, getTextTemplateOption() ); |
|||
//set on window before textarea - div to avoid line feed |
|||
var div = document.createElement( "div" ); |
|||
div.appendChild(textTemplateSelect); |
|||
div.appendChild(textTemplateOutput); |
|||
textbox.parentNode.insertBefore(div, textbox); |
|||
} |
|||
} |
|||
function setOptionsToSelect( select, desc, subdesc ) { |
|||
for (var id in desc) { |
|||
var value = desc[id], subdescfordesc = null, option, optgroup, subid; |
|||
if( typeof( value ) === 'object' ) { |
|||
subdescfordesc = value; |
|||
} |
|||
//sofern Unterdefinitionen vorhanden sind |
|||
if ( subdescfordesc !== null ) { |
|||
optgroup = document.createElement( "optgroup" ); |
|||
select.appendChild ( optgroup ); |
|||
optgroup.label = id; |
|||
optgroup.value = id; |
|||
for ( subid in subdescfordesc ) { |
|||
option = document.createElement( "option" ); |
|||
optgroup.appendChild ( option ); |
|||
option.value = subdescfordesc [ subid ]; |
|||
option.text = subid; |
|||
} |
|||
} else { |
|||
option = document.createElement( "option" ); |
|||
select.appendChild ( option ); |
|||
option.value = value; |
|||
option.text = id; |
|||
} |
|||
} |
|||
} |
|||
/* angezeigter Text für die Zusammenfassung */ |
|||
function getSummaryOption() { return [ |
|||
"aw", |
|||
"SLA", |
|||
"katsort", |
|||
"navifix", |
|||
"linkfix", |
|||
"dateifix", |
|||
"typo", |
|||
"reihenfolge", |
|||
"PDfix", |
|||
"PD ergänzt", |
|||
"korrigiere Vorlageneinbindung", |
|||
"Vorlage existiert nicht", |
|||
"Vorlagen existieren nicht", |
|||
"Vorlageneinbindung überflüssig", |
|||
"nowiki, damit keine Vorlageneinbindung entsteht", |
|||
"nowiki, damit keine Vorlageneinbindungen entstehen", |
|||
"nowiki, damit keine Vorlagen- und Dateieinbindungen entstehen", |
|||
"ich erlaube mir, die Seite zu leeren, um [[Spezial:Fehlende Vorlagen]] zu entlasten", |
|||
"+{{[[Vorlage:Dokumentation|Dokumentation]]}}", |
|||
"Doku ausgelagert", |
|||
"Metadaten ausgelagert", |
|||
"[[Wikipedia:Vermeide Selbstreferenzen]]", |
|||
"[[Vorlage:PNDfehlt|PNDfehlt]] ist nur optional sichtbar, daher kein Aufzählungszeichen", |
|||
"Keine browserspezifischen Anpassungen", |
|||
"[[Hilfe:Einzelnachweise#Mehrspaltigkeit und alternative Formatierungen]]", |
|||
"Lokale Anpassungen einer Systemnachricht auch für die Sprachvariante, durch Einbindung der Systemnachricht", |
|||
"Vorlagenparameter damit Systemnachricht in Sprachvarianten einbindbar ist", |
|||
"Keine Vorlagenkategorien in Artikelkategorien", |
|||
"Keine Vorlagen in Artikelkategorien", |
|||
"Keine Benutzerseiten in Artikelkategorien", |
|||
"Keine Benutzerkategorien in Artikelkategorien", |
|||
"Keine Dateien in Artikelkategorien", |
|||
"Keine Dateikategorien in Artikelkategorien", |
|||
"-lagewunsch, Koordinaten bereits vorhanden", |
|||
"-lagewunsch, bereits durch Infobox", |
|||
"Koordinaten in Infobox übertragen", |
|||
"Toolbar-Müll entfernt" |
|||
]; } |
|||
/* angezeigter Text als Textvorlage - links der angezeigte Text - rechts der gesetzte Text */ |
|||
function getTextTemplateOption() { return { |
|||
"katsort": "{{SORTIERUNG:}}", |
|||
'erledigt': '{{erledigt|~~~~}}', |
|||
"SLAs": { |
|||
"SLA": "{{SLA| --~~~~}}", |
|||
"SLA (Vorlage)": "<noinclude>{{SLA| --~~~~}}</noinclude>", |
|||
"Tastaturtest": "{{SLA|Tastaturtest --~~~~}}", |
|||
"Verschieberest": "{{SLA|Verschieberest --~~~~}}", |
|||
"Verschieberest (Vorlage)": "<noinclude>{{SLA|Verschieberest --~~~~}}</noinclude>", |
|||
"Weiterleitung": "{{SLA|Unnötige Weiterleitung --~~~~}}", |
|||
"Weiterleitung (NS)": "{{SLA|Unnötige Weiterleitung zwischen Namensräumen --~~~~}}", |
|||
"lokale Dateiseite": "{{SLA|Unnötige Bildbeschreibungsseite für Commonsbild --~~~~}}", |
|||
"auf Commons": "{{SLA|Informationen bereits auf Commons --~~~~}}", |
|||
"nach Commons": "{{SLA|nach Commons übertragen --~~~~}}", |
|||
"lokale Dateikat": "{{SLA|Keine lokale Kategorisierung von Commonsdateien --~~~~}}" |
|||
}, |
|||
"Dokumentation": { |
|||
"Dokumentation": "{{Dokumentation}}", |
|||
"verwaist": "<noinclude>{{SLA|verwaiste Unterseite zu gelöschter Vorlage --~~~~}}</noinclude>", |
|||
"Dokuseite": "<noinclude>{{Dokumentation/Dokuseite}}</noinclude>", |
|||
"Metaseite": "<noinclude>{{Dokumentation/Metaseite}}</noinclude>", |
|||
"Testseite": "<noinclude>{{Dokumentation/Testseite}}</noinclude>", |
|||
"Wartungsseite": "<noinclude>{{Dokumentation/Wartungsseite}}</noinclude>", |
|||
"Druckversion": "<noinclude>{{Dokumentation/Druckversion}}</noinclude>", |
|||
"Unterseite": " <noinclude>{{Dokumentation/Unterseite}}</noinclude>", |
|||
"Preloadseite": "<noinclude>{{Dokumentation/Preloadseite}}</noinclude>" |
|||
} |
|||
}; } |
|||
});}); |
});}); |
||
Zeile 373: | Zeile 123: | ||
}()); |
}()); |
||
//</nowiki> __NOINDEX__ |
//</nowiki> __NOINDEX__ |
||
/** |
|||
* Dynamische Beschränkung der Eingabelänge des Begründungsfeldes bei |
|||
* Versionslöschungen, Seitenlöschungen, Benutzersperren und Seitenschutz |
|||
* see [[bugzilla:34467]] |
|||
* Something for [[MediaWiki:Group-sysop.js]] |
|||
*/ |
|||
if( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Revisiondelete' || mw.config.get( 'wgAction' ) === 'revisiondelete' || |
|||
mw.config.get( 'wgAction' ) === 'delete' || |
|||
mw.config.get( 'wgAction' ) === 'protect' || mw.config.get( 'wgAction' ) === 'unprotect' |
|||
) { |
|||
mw.loader.using( [ 'jquery.lengthLimit' ], function() { $( function() { |
|||
var reasonList = $( '#wpRevDeleteReasonList, #wpDeleteReasonList, #wpProtectReasonSelection' ); |
|||
var currentValReasonList = reasonList.val(); |
|||
reasonList.change( function() { |
|||
currentValReasonList = reasonList.val(); |
|||
}); |
|||
$( '#wpReason, #mwProtect-reason' ).byteLimit( 255, function( input ) { |
|||
if( currentValReasonList === 'other' || !currentValReasonList ) { |
|||
return input; |
|||
} else if( input ) { |
|||
return currentValReasonList + ': ' + input; // [[MediaWiki:Colon-separator]] |
|||
} else { |
|||
return currentValReasonList; |
|||
} |
|||
}); |
|||
});}); |
|||
} |
|||
(function() { |
(function() { |
Aktuelle Version vom 15. Januar 2022, 15:33 Uhr
/*
* @author Umherirrender - [[:de:User:Umherirrender]]
* develop with and for Internet Explorer 11+
*
* gegen Übernahmen spricht nichts, nur bitte nicht diese JavaScript-Seite direkt einbinden
* ohne Gewähr und ohne Support
*
* eigene Anpassungen für die deutschsprachige Wikipedia
*/
/*
* Anpassungen FlaggedRevs
* [[Benutzer:Umherirrender/monobook-flaggedrevs.js]]
*/
mw.loader.load( '//de.wikipedia.org/w/index.php?title=Benutzer:Umherirrender/monobook-flaggedrevs.js&action=raw&ctype=text/javascript' );
//<nowiki>
/*
* lokale Anpassungen
*/
mw.loader.using( [ 'mediawiki.util' ], function() { $( function () {
var wgNamespaceNumber = mw.config.get( 'wgNamespaceNumber' );
/* nur Systemnachrichten */
if( wgNamespaceNumber === 8 ) {
/* link zum translatewiki */
var messageName = mw.config.get( 'wgTitle' );
if( messageName.indexOf( '/' ) === -1 ) {
messageName += '/de';
}
mw.util.addPortletLink(
'p-tb',
'//translatewiki.net/wiki/MediaWiki:' + mw.util.wikiUrlencode( messageName ),
'Translatewiki',
't-translatewiki',
'Translatewiki',
'b',
'#t-recentchangeslinked'
);
}
/* nur Dateien */
if( wgNamespaceNumber === 6 ) {
/* setzt die hinzugefügten Hinweise bei Dateien sichtbar in den ersten head */
var firstHeading = $( '#firstHeading' );
var nc = $( '#Vorlage_NowCommons' );
if( nc.length ) {
var span = $( document.createElement( 'span' ) );
span.css( 'font-size', '50%' );
span.attr( 'id', 'hinweis-local-file-nc' );
span.text( ' (NowCommons)' );
firstHeading.append( span );
}
var sc = $( '#Vorlage_ShadowsCommons' );
if( sc.length ) {
var span = $( document.createElement( 'span' ) );
span.css( 'font-size', '50%' );
span.attr( 'id', 'hinweis-local-file-sc' );
span.text( ' (ShadowsCommons)' );
firstHeading.append( span );
}
}
/* nur im Vorschaumodus */
if ( mw.config.get( 'wgAction' ) === 'submit' ) {
//hinweis wenn noch keine Bearbeitungskommentar zum voreingestellten Text ergänzt wurde
var summary = $( '#wpSummary' );
if ( summary.length && summary.val().substring(0,2) === ' |' ) {
summary.css( 'background-color', 'FF6A6A' );
}
}
});});
// Funktionen in [[Benutzer:Umherirrender/monobook-tidy-up.js]] enthalten
(function() {
var loaded = false;
mw.loader.using( [ 'mediawiki.util' ], function() {
//Link für Suchen und Ersetzen
$( mw.util.addPortletLink(
'p-tb',
'#',
'Suchen und Ersetzen',
't-tidy-up-replace',
'tidy-up-replace',
null,
null
) ).click( function() {
if ( loaded ) {
tidyupReplace();
} else {
window.callbackMonobookTidyUpJs = 'tidyupReplace';
mw.loader.load( '//de.wikipedia.org/w/index.php?title=Benutzer:Umherirrender/monobook-tidy-up.js&action=raw&ctype=text/javascript' );
loaded = true;
}
} );
// Standardlink zum Quelltext aufräumen
$( mw.util.addPortletLink(
'p-tb',
'#',
'tidy-up',
't-tidy-up',
'tidy-up',
null,
null
) ).click( function() {
if ( loaded ) {
tidyup();
} else {
// load on demand
window.callbackMonobookTidyUpJs = 'tidyup';
mw.loader.load( '//de.wikipedia.org/w/index.php?title=Benutzer:Umherirrender/monobook-tidy-up.js&action=raw&ctype=text/javascript' );
loaded = true;
}
} );
} );
//nur Artikel und beim Öffnen des Bearbeitenmodus
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 && mw.config.get( 'wgAction' ) === 'edit' ) {
window.callbackMonobookTidyUpJs = 'tidyup';
mw.loader.load( '//de.wikipedia.org/w/index.php?title=Benutzer:Umherirrender/monobook-tidy-up.js&action=raw&ctype=text/javascript' );
loaded = true;
}
}());
//</nowiki> __NOINDEX__
(function() {
$( function() {
mw.loader.using( [ 'mediawiki.util' ], function() {
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' ) {
$( mw.util.addPortletLink(
'p-tb',
'#',
'Doppelte Argumente finden',
't-dupargs',
'Doppelte Argumente finden',
'b'
) ).one( 'click', function() {
mw.loader.using( [ 'mediawiki.api', 'jquery.textSelection' ], findDupArgs );
$( '#t-dupargs a' ).css( { color: 'grey' } );
} );
}
} );
} );
function findDupArgs() {
var api = new mw.Api();
var $textbox = $( '#wpTextbox1' );
if ( !$textbox.length ) {
return;
}
// Get the parsetree for the current content of the editform
api.post( {
action: 'parse',
title: mw.config.get( 'wgPageName' ),
text: $textbox.val(),
prop: 'parsetree',
contentmodel: mw.config.get( 'wgPageContentModel' )
} ).then( function( data ) {
if ( !data.parse || !data.parse.parsetree ) {
//badcontentformatforparsetree
mw.notify(
'Nur für WikiText-Seiten',
{ tag: 'badcontentformatforparsetree' }
);
return;
}
findDupArgsInParseTree( $textbox, data.parse.parsetree['*'] );
} ).fail( function( code, data ) {
mw.notify(
'Fehler beim ermitteln der doppelten Argumente' +
' (' + code + ( data && data.error && data.error.info ? ': ' + data.error.info : '' ) + ')',
{ tag: 'dupargs-error' }
);
} );
}
function findDupArgsInParseTree( $textbox, parsetree ) {
var xmlDoc = $.parseXML( parsetree );
var found = false;
// The xml tree walker
var walkTreeJ = function() {
var $node = $( this );
if ( this.nodeName === 'template' ) {
var allArgs = {};
$node.children( 'part' ).each( function() {
var $part = $( this ), name, found, start, end;
if ( $part.children( 'name' ).attr( 'index' ) ) {
name = $part.children( 'name' ).attr( 'index' );
} else {
name = $.trim( $part.children( 'name' ).text() );
}
value = $part.children( 'value' ).text();
if ( name in allArgs ) {
found = true;
start = calcLength( xmlDoc.firstChild, $part.children( 'name' )[0] );
end = start + calcLength( $part[0] );
$textbox.textSelection( 'setSelection', { start: start, end: end } );
$textbox.textSelection( 'scrollToCaretPosition' );
} else {
allArgs[name] = value;
}
} );
}
// recursive for all childs
$node.children().each( walkTreeJ );
};
// Start with the <root> and go through the whole tree
$( xmlDoc ).first().each( walkTreeJ );
if ( !found ) {
mw.notify(
'Alles in Ordnung. Konnte kein doppeltes Argument finden.',
{ tag: 'dupargs-error' }
);
}
}
/**
* Helper function to calculate the length of wikitext from the parsetree to show the position of the cursor
*/
var calcLength = function( node, stopNode ) {
var options = { stopNode: stopNode, stop: false };
var calcLengthInternal = function( node, options ) {
var value = 0;
if ( node === stopNode ) {
options.stop = true; // stop recursive calls
} else if ( node.nodeType === 3 ) {
value += node.nodeValue.length;
} else {
for ( var i = 0, len = node.childNodes.length; i < len; i++ ) {
var child = node.childNodes[i];
if ( child.nodeName === 'template' ) {
value += 2; // for {{
value += calcLengthInternal( child, options );
if ( options.stop ) {
break;
}
value += 2; // for }}
} else if ( child.nodeName === 'tplarg' ) {
value += 3; // for {{{
value += calcLengthInternal( child, options );
if ( options.stop ) {
break;
}
value += 3; // for }}}
} else if ( child.nodeName === 'ext' ) {
value += 2; // for <>
value += calcLengthInternal( child, options );
if ( options.stop ) {
break;
}
// close tag is a own text node
} else if ( child.nodeName === 'part' ) {
value += 1; // for |
value += calcLengthInternal( child, options );
if ( options.stop ) {
break;
}
} else {
value += calcLengthInternal( child, options );
if ( options.stop ) {
break;
}
}
}
}
return value;
};
return calcLengthInternal( node, options );
};
}());