MediaWiki:OnPageForms.js

/** * @name   OnPageForms * @desc   Loads file history forms directly on page. * @author KhangND */ (function {   if(mw.config.get('wgNamespaceNumber') !== 6 // not File namespace || mw.config.get('wgUserName') === null // not user || window.OnPageFormsLoaded) {       return;    } window.OnPageFormsLoaded = true;

var $upload = $('#mw-imagepage-reupload-link a'), $delete = $('a:contains(delete)'), $revert = $('a:contains(revert)'), i18n = { text: 'on page', title: 'Performs this action without leaving page' },       props = { text: i18n.text, title: i18n.title, css: { cursor: 'pointer' } };

function init { $upload.after([           ' | ',            $('', $.extend({ click: loadUpload }, props))        ]); $delete.after([           ' | ',            $('', $.extend({ click: loadDelete }, props))        ]); $revert.after([           ' | ',            $('', $.extend({ click: loadRevert }, props))        ]); }

function loadForm(id, context) { var $form = $('#' + id);

if($form.length) { if(id === 'uploadForm') { toggle($form); return; } else { $form.slideUp(function {                   $form.remove;                }); }       }

$('[data-tab-body="history"]').append(           $(' ', { id: id, css: { display: 'none' }, }).load( $(context).prev.attr('href') + ' #mw-content-text > form', function { toggle('#' + id); } )       );    }

function loadUpload { loadForm('uploadForm', this); }

function loadDelete { loadForm('deleteForm', this); }

function loadRevert { loadForm('revertForm', this); }

function toggle($elem) { if(!($elem instanceof jQuery)) $elem = $($elem); // convert to jQuery object if not

if( $elem.css('display') === 'none') $elem.slideDown; else $elem.slideUp; }   init; });