MediaWiki:Gadget-pseudodelete.js

From Wikinews, the free news source you can write!
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins

try { // containerize gadget, to protect other gadgets if this one goes wrong

/**
 * Based on [[w:en:User:Twinzor]]'s Wikimarks script
 * Also uses Bawolff's awesome API.
 *
 * This script adds a "QD" link near the usual view/edit/history buttons,
 * allowing a user to semi-automatically add [[Template:Delete]] to pages;
 * essentially mimicking the delete button for non-sysops.
 *
 * You can enable this gadget by selecting the relevant checkbox in
 * [[Special:Preferences]].
 */

function initQD() {
    mw.util.addPortletLink( 'p-cactions', 'javascript:showQD()', 'QD', 'ca-addQD', 'QD this page', '', '' );
}
$( initQD );

function addQD( qdreason ) {
    var QDNewpage = mw.config.get('wgPageName').replace( "_", " " );
    api( QDNewpage ).setDefaultSummary( 'Tagging for deletion with [[MediaWiki:Gadget-pseudodelete.js|js assistance]]' ).getPage().lift( function ( pageText ) {
        return '{{del' + 'ete|' + qdreason + '}}\n' + pageText;
    } ).savePage().exec();
    jsMsg( 'Page tagged for deletion! An administrator will be along shortly to consider your request.' );
}
function showQD() {
    var reasons = {
        "content": "A1: Nonsense",
        "test": "A2: Test page",
        "vand": "A3: Vandalism",
        "short": "A4: No context",
        //"rename": "A5: Cleanup after copy/paste move";
        "spam": "A6: Spam",
        "author": "A7: Author request",
        "hoax": "A8: Hoax",
        "undelete": "A9: Recreation of deleted content",
        "foreign": "A10: Not English",
        "scope": "A11: Out of project scope",
        "broken": "R1: Broken redirect",
        "namespace": "R2: Cross namespace redirect",
        "typo": "R3: Typo redirect",
        "r4": "R4: Result of page-move vandalism",
        "fairuse": "I1: Violation of fair use policy",
        "redundant": "I2: Redundant image",
        "unused": "I3: Unused image",
        //"userpage": "G1: Userpage deletion request by author",
        "disassociated": "G2: Disassociated talk/comments page",
        //"IP": "G3: Old IP talk page",
        "empty": "G4: Empty category",
        //"retired": "G5: User page of retired user",
        //"unpublished": "G6: Comments page of unpublished article"
    };

    var msg = '<ul>';
    for ( var reason in reasons ) {
        msg += '<li><a href="javascript:addQD(\'' + reason + '\');">' + reasons[reason] + '</a></li>\n';
    }
    jsMsg( msg );
}

} catch (e) { // containerize gadget, to protect other gadgets if this one goes wrong
  // ignore
}