User:Gary/show upload deletion logs.js
Appearance
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. |
Documentation for this user script can be added at User:Gary/show upload deletion logs. |
/*
SHOW UPLOAD DELETION LOGS
Description: After clicking on a link to a deleted file, this script shows links to a file's deletion logs for convenience.
*/
if (typeof(showUploadDeletionLogs) == 'undefined') showUploadDeletionLogs = {};
if (typeof(unsafeWindow) != 'undefined')
{
mw = unsafeWindow.mw;
}
function showUploadDeletionLogsFunction()
{
// Set default configuration
if (typeof(showUploadDeletionLogs) == 'undefined') showUploadDeletionLogs = {};
if (typeof(showUploadDeletionLogs.linkToFileEdit) == 'undefined') showUploadDeletionLogs.linkToFileEdit = false;
// Viewing an article, replace links to deleted images with links to file edit page, if preference is set.
if ((mw.config.get('wgAction') == 'view' || mw.config.get('wgAction') == 'edit' || mw.config.get('wgAction') == 'submit') && mw.config.get('wgPageName') != 'Special:Upload')
{
$('.new').each(function()
{
var a = $(this);
var href = a.attr('href');
if (href && href.indexOf('wpDestFile=') != -1)
{
if (showUploadDeletionLogs.linkToFileEdit) a.attr('href', generateFileEditLink(href))
else a.attr('href', generateFileUploadLink(href));
}
});
}
// Clicked on a link to a deleted image, from an article
else if (mw.config.get('wgPageName') == 'Special:Upload' && location.href.indexOf('wpDestFile=') != -1 && $('#contentSub2').length)
{
var editLink = $('<a class="external" href="' + generateFileEditLink(location.href) + '">Edit file</a>');
var sub = $('#contentSub2').children().last().append(' / ').append(editLink);
}
}
function generateFileEditLink(url)
{
var wpDestFileIndex = url.indexOf('wpDestFile=');
if (url.indexOf('&', wpDestFileIndex) != -1) var endIndex = url.indexOf('&', wpDestFileIndex);
else var endIndex = url.length;
return mw.config.get('wgScript') + '?title=File:' + url.substring(wpDestFileIndex + 'wpDestFile='.length, endIndex) + '&action=edit&redlink=1';
}
function generateFileUploadLink(url)
{
var wpDestFileIndex = url.indexOf('wpDestFile=');
if (url.indexOf('&', wpDestFileIndex) != -1) var endIndex = url.indexOf('&', wpDestFileIndex)
else var endIndex = url.length;
return mw.config.get('wgScript') + '?title=Special:Upload&wpDestFile=' + url.substring(wpDestFileIndex + 'wpDestFile='.length, endIndex);
}
$(document).ready(function()
{
showUploadDeletionLogsFunction();
});