Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/** * 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 foundvarparseAsSummary;// distinguish between new upload and reupload for preview functionif(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 uploadsif(typeofwikEd!='undefined'&&wikEd.useWikEd){// if WikEd is activewikEd.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(typeofwikEd!='undefined'&&wikEd.useWikEd){// if WikEd is activewikEd.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;varpreviewText='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(typeofwikEd!='undefined'&&wikEd.useWikEd){// if WikEd is activewikEd.UpdateTextarea();// transfer WikEd to $editbox}varparam={action:'parse',title:'File:'+($('#wpDestFile').val()||'Example.jpg'),// title, File:Example.jpg as defaultprop:'text',pst:'',text:'',// empty text field necessary even when parsed as summary, see bug 48319format:'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){varcontent=parseAsSummary?'parsedsummary':'text';// set type of content to either parsedsummary or textif(!json||!json.parse||!json.parse[content]||!json.parse[content]['*'])return;varhtml='<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>