User:BZPN/RfD.js

From Test Wiki
Revision as of 12:55, 1 November 2024 by BZPN (talk | contribs) (Created page with "// Simple English Wikipedia Deletion Gadget // This gadget helps users nominate pages for deletion according to Simple English Wikipedia's policy. (function() { if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgIsArticle') === false) return; // Check if page is already tagged for deletion if (document.getElementById('delete-tag')) { alert('This page is already nominated for deletion.'); return; } // Create deletion proc...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// Simple English Wikipedia Deletion Gadget
// This gadget helps users nominate pages for deletion according to Simple English Wikipedia's policy.

(function() {
    if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgIsArticle') === false) return;

    // Check if page is already tagged for deletion
    if (document.getElementById('delete-tag')) {
        alert('This page is already nominated for deletion.');
        return;
    }

    // Create deletion process UI elements
    const deletionBtn = document.createElement('button');
    deletionBtn.textContent = 'Nominate for deletion';
    deletionBtn.style.margin = '10px';
    deletionBtn.onclick = initiateDeletionProcess;

    // Append button to page
    document.getElementById('mw-content-text').prepend(deletionBtn);

    // Function to initiate deletion process
    function initiateDeletionProcess() {
        const reason = prompt('Please provide a reason for deletion:', 'Not a notable topic');
        
        if (!reason) {
            alert('Deletion process canceled.');
            return;
        }

        // Step 1: Tagging the article with deletion notice
        tagPageForDeletion(reason);

        // Step 2: Creating the deletion discussion page
        createDiscussionPage(reason);

        // Step 3: Adding the discussion link to the deletion list
        addToDeletionList();
    }

    // Function to tag page with deletion notice
    function tagPageForDeletion(reason) {
        const tag = `{{rfd|${reason}}}`;
        const editSummary = 'Nominating for deletion';

        new mw.Api().postWithToken('csrf', {
            action: 'edit',
            title: mw.config.get('wgPageName'),
            prependtext: tag + '\n',
            summary: editSummary,
            watchlist: 'watch',
        }).done(function() {
            alert('Page tagged for deletion.');
        }).fail(function() {
            alert('Failed to tag the page for deletion. Please try again.');
        });
    }

    // Function to create deletion discussion page
    function createDiscussionPage(reason) {
        const discussionPageTitle = `Wikipedia:Requests for deletion/Requests/${mw.config.get('wgPageName')}`;
        const discussionContent = `{{RfD/Preload/Template|reason=${reason}}}\n\n==Deletion discussion==\nMore detailed reason why this page should be deleted:\n* ${reason}`;

        new mw.Api().postWithToken('csrf', {
            action: 'edit',
            title: discussionPageTitle,
            text: discussionContent,
            summary: 'Starting deletion discussion',
            watchlist: 'watch',
        }).done(function() {
            alert('Deletion discussion page created.');
        }).fail(function() {
            alert('Failed to create deletion discussion page. Please try again.');
        });
    }

    // Function to add deletion discussion to the list
    function addToDeletionList() {
        const deletionListTitle = 'Wikipedia:Requests for deletion/Current discussions';
        const discussionLink = `{{Wikipedia:Requests for deletion/Requests/${mw.config.get('wgPageName')}}}`;

        new mw.Api().edit(deletionListTitle, function(revision) {
            return {
                text: discussionLink + '\n' + revision.content,
                summary: 'Adding new deletion discussion',
                watchlist: 'watch',
            };
        }).done(function() {
            alert('Deletion discussion added to the list.');
        }).fail(function() {
            alert('Failed to add the discussion to the deletion list. Please try again.');
        });
    }
})();