/**
* Preloads information template into summary field of file ulpads
* and adds preview functionality to [[Special:Upload]]
*
* Code by [[de:Benutzer:Schnark]] on German Wikipedia
* Ported to English Wikipedia by [[User:Patrick87]]
* <nowiki>
*/
mw.loader.using(['mediawiki.util'], function() { $(function() {
var $editbox = $('#wpUploadDescription');
if ($editbox.length != 1) return; // exits silently if not exactly one #wpUploadDescription is found
var parseAsSummary; // distinguish between new upload and reupload for preview function
if (mw.util.getParamValue('wpForReUpload') != '1') { // upload of new file (e.g. no reupload)?
parseAsSummary = false; // upload description will be displayed on file page for new uploads
if (typeof wikEd != 'undefined' && wikEd.useWikEd) { // if WikEd is active
wikEd.UpdateTextarea(); // transfer WikEd to $editbox
}
if ($editbox.val() === '') {
$editbox.val('{{Information\n' +
'| description = \n' +
'| source = \n' +
'| date = \n' +
'| author = \n' +
'| permission = \n' +
'| other_versions = \n' +
'| additional_information = \n' +
'}}');
}
if (typeof wikEd != 'undefined' && wikEd.useWikEd) { // if WikEd is active
wikEd.UpdateFrame(); // transfer $editbox to WikEd
}
} else {
parseAsSummary = true; // upload description will only be displayed in file log for uploads of new file version
}
if (false) return;
var previewText = 'Preview';
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: 'File:' + ($('#wpDestFile').val() || 'Example.jpg'), // title, File:Example.jpg as default
prop: 'text',
pst: '',
text: '', // empty text field necessary even when parsed as summary, see bug 48319
format: 'json'};
param[ parseAsSummary ? 'summary' : 'text' ] = $editbox.val(); // use upload description either as summary or as page text
$.getJSON(mw.util.wikiScript('api'), param, function (json) {
var content = parseAsSummary ? 'parsedsummary' : 'text'; // set type of content to either parsedsummary or 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
$('#t-print a').removeAttr('accesskey'); // T58786
$('#t-print a, #wpPreview').updateTooltipAccessKeys();
});}); //ready
//</nowiki>