Jump to content

Wikipedia:WikiProject User scripts/Scripts/Upload Preview

From Wikipedia, the free encyclopedia
/* On [[Special:Upload|Upload]] page this script allows you to preview Summary field using [[AJAX]]. 

Without the script you have to first upload image and then check how your description look like. See why: [[:mediazilla:2537]], comment #6. The script is using [{{SERVER}}/skins-1.5/common/preview.js preview.js] which is a part of  [[:mw:Manual:Live preview|Live preview]] which is not currently used by Mediawiki.

Installation: add to [[Special:Mypage/monobook.js|your monobook.js]]
* either <code>importScript('{{FULLPAGENAME}}')</code>
* or the code below:
<syntaxhighlight lang=javascript>*/

if (mw.config.get('wgCanonicalNamespace') == 'Special' && mw.config.get('wgCanonicalSpecialPageName') == 'Upload'){
 addOnloadHook(uploadPreviewInit)
 //prepare Mediawiki Live Preview
 wgLivepreviewMessageLoading = 'Wait...'
 wgLivepreviewMessageReady = 'Done'
 document.write('<script type= "text/javascript" src="/skins-1.5/common/preview.js"></script>')
}

function uploadPreviewInit(){
 wpUploadDescription = document.getElementById('wpUploadDescription') //global var
 var but = document.createElement('input')
 but.type = 'button'
 but.value='Preview' 
 but.onclick=uploadPreviewDo
 wpUploadDescription.parentNode.insertBefore(but, wpUploadDescription.nextSibling)
}

function uploadPreviewDo(){
 if (!window.wikiPreview) //create preview div
    wikiPreview = document.createElement('div')
    wikiPreview.id = 'wikiPreview' 
    wpUploadDescription.parentNode.insertBefore(wikiPreview, wpUploadDescription.nextSibling.nextSibling)
 lpDoPreview(wpUploadDescription.value, '/w/index.php?action=submit&live')
}
//</syntaxhighlight>