User:Krd/DeleteLink.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
/*
* Install a link to request speedy deletion as uploader request.
*/
$( function () {
	'use strict';

	var ext, $fileinfo, i18n,
		title = new mw.Title( mw.config.get( 'wgPageName' ) );

	if (
		!title ||
		// Only logged in users
		mw.user.isAnon() ||
		// Only File pages
		title.getNamespaceId() !== mw.config.get( 'wgNamespaceIds' ).file ||
		// Own uploads only
		!$( '#mw-imagepage-section-filehistory tr:last > td:last' )
			.prev( 'td' ).find( 'a' ).eq( 0 ).text().startsWith(mw.config.get( 'wgUserName' ))
		// uploaded recently
		// ...
		// not in use
		// ...
	) {
        return;
    }

	$fileinfo = $( '#mw-content-text .fileInfo' );
	if ( !$fileinfo.length ) { return; }

	i18n = {
		en: 'request speedy deletion',
	};
	ext = mw.config.get( 'wgUserLanguage' );
	$fileinfo.append(
		'; ',
		$( '<a>' ).attr( {
			href: '//commons.wikimedia.org/w/index.php?action=edit&section=new&preload=User:Krd/DeleteLink.js/text&nosummary=true&title='+title,
			style: 'white-space:nowrap; display:inline-block;',
			title: 'Request speedy deletion of own upload.'
		} ).append(
			'(',
			$( '<img>' ).prop( 'src', '//upload.wikimedia.org/wikipedia/commons/f/ff/Bin.png' ),
			i18n[ ext ] || i18n[ ext.split( '-' )[ 0 ] ] || i18n.en,
			')'
		)
	);
} );