„MediaWiki:Gadget-uploadtools.js“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
K workaround bug 48319 |
s. Disk |
||
Zeile 41: | Zeile 41: | ||
$('#mw-htmlform-description').before($(mw.html.element('div', {id: 'mw-description-preview'}))); |
$('#mw-htmlform-description').before($(mw.html.element('div', {id: 'mw-description-preview'}))); |
||
} |
} |
||
$('input[name="wpUpload"]').after($(mw.html.element('input', {value: previewText, type: 'button'})).click(function(){ |
$('input[name="wpUpload"]').after($(mw.html.element('input', {value: previewText, type: 'button', id: 'wpPreview', title: previewText + ' [p]', accesskey: 'p'})).click(function(){ |
||
if (typeof wikEd != 'undefined'&& wikEd.useWikEd) { // if WikEd is active |
if (typeof wikEd != 'undefined'&& wikEd.useWikEd) { // if WikEd is active |
||
wikEd.UpdateTextarea(); // transfer WikEd to $editbox |
wikEd.UpdateTextarea(); // transfer WikEd to $editbox |
||
Zeile 59: | Zeile 59: | ||
}); //getJSON |
}); //getJSON |
||
})); //click |
})); //click |
||
mw.util.updateTooltipAccessKeys($('#wpPreview')); |
|||
}); //ready |
}); //ready |
||
//</nowiki> |
//</nowiki> |
Version vom 18. Mai 2013, 21:23 Uhr
/**
* Lädt die Informationsvorlage beim Hochladen direkt im Beschreibungsfeld
* und ermöglicht eine Vorschau der Beschreibung auf [[Spezial:Hochladen]]
* wird in [[MediaWiki:Common.js]] eingebunden
* Code von [[Benutzer:Schnark]]
* <nowiki>
*/
$(document).ready(function(){
var $editbox = $('#wpUploadDescription');
if ($editbox.length != 1) return; // exits silently if not exactly one #wpUploadDescription is found
var parseAsSummary; // Fallunterscheidung für Vorschaufunktion
if (mw.util.getParamValue('wpForReUpload') != '1') { // Kein Upload von neuer Dateiversion?
parseAsSummary = false; // bei Upload der ersten Dateiversion wird eingegebener Text auf der Seite erscheinen
if (typeof wikEd != 'undefined' && wikEd.useWikEd) { // if WikEd is active
wikEd.UpdateTextarea(); // transfer WikEd to $editbox
}
if ($editbox.val() === '') {
$editbox.val('{{Information\n' +
'|Beschreibung = \n' +
'|Quelle = \n' +
'|Urheber = \n' +
'|Datum = \n' +
'|Genehmigung = \n' +
'|Andere Versionen = \n' +
'|Anmerkungen = \n' +
'}}');
}
if (typeof wikEd != 'undefined' && wikEd.useWikEd) { // if WikEd is active
wikEd.UpdateFrame(); // transfer $editbox to WikEd
}
} else {
parseAsSummary = true; // bei Upload von neuer Dateiversion wird eingegebener Text nur im Log erscheinen
}
if (!mw.config.get('wgEnableAPI')) return;
var previewText = 'Vorschau';
if ($('#mw-description-preview').length === 0) {
$('#mw-htmlform-description').before($(mw.html.element('div', {id: 'mw-description-preview'})));
}
$('input[name="wpUpload"]').after($(mw.html.element('input', {value: previewText, type: 'button', id: 'wpPreview', title: previewText + ' [p]', accesskey: 'p'})).click(function(){
if (typeof wikEd != 'undefined'&& wikEd.useWikEd) { // if WikEd is active
wikEd.UpdateTextarea(); // transfer WikEd to $editbox
}
var param = {action: 'parse',
title: 'Datei:' + ($('#wpDestFile').val() || 'Beispiel.jpg'), //Titel, Datei:Beispiel.jpg als Standard
prop: 'text|categories|langlinks', //categories und langlinks noch nicht verwendet
pst: '',
text: '', //text wird benötigt, wenn title angegeben (bug 48319), wird eventuell überschrieben
format: 'json'};
param[ parseAsSummary ? 'summary' : 'text' ] = $editbox.val(); //Inhalt des Eingabefeldes entweder als Kommentar oder als Text parsen
$.getJSON(mw.util.wikiScript('api'), param, function (json) {
var content = parseAsSummary ? 'parsedsummary' : 'text'; //Geparster Inhalt entweder in parsedsummary oder in text
if (!json || !json.parse || !json.parse[content] || !json.parse[content]['*']) return;
var html = '<p><strong>' + previewText + ':</strong><p>' + json.parse[content]['*'];
$('#mw-description-preview').html(html);
}); //getJSON
})); //click
mw.util.updateTooltipAccessKeys($('#wpPreview'));
}); //ready
//</nowiki>