Community Central
Community Central
mNo edit summary
mNo edit summary
Line 326: Line 326:
 
$button = $('<li><a id="mark-template" style="cursor: pointer;">Prefix Information</a></li>');
 
$button = $('<li><a id="mark-template" style="cursor: pointer;">Prefix Information</a></li>');
 
$button.click(function deleteNoticeButtonClickHandler() {
 
$button.click(function deleteNoticeButtonClickHandler() {
var promptedDeleteReason = "subst:User:343 TheGuiltyProphet/prefix_information";
+
var promptedDeleteReason = "subst:User:343TheGuiltyProphet/prefix_information";
 
if (typeof window.c === "object" && window.Template !== null && typeof window.Template.promptedDeleteReason === "string") {
 
if (typeof window.c === "object" && window.Template !== null && typeof window.Template.promptedDeleteReason === "string") {
 
promptedDeleteReason = window.Template.promptedDeleteReason;
 
promptedDeleteReason = window.Template.promptedDeleteReason;

Revision as of 17:35, 1 May 2020

importArticles({
    type: 'script',
    articles: [
        'u:a:MediaWiki:Gadget-HotCat.js',
        'u:dev:MediaWiki:AjaxBatchDelete.js',
        'u:dev:MediaWiki:AjaxUndo/code.js',
        'u:dev:MediaWiki:DiscussionsFeed.js',
        'u:dev:MediaWiki:MarkForDeletion/code.js',
        'u:dev:MediaWiki:QuickCreateUserPage/code.js',
        'u:dev:MediaWiki:WHAM/code.2.js',
        'u:mlp:User:Jr Mime/MarkForTemplate/General.js',
        'u:dev:MediaWiki:LastEdited/code.js',
        'u:dev:MediaWiki:QuickDiff/code.js'
    ]
});
$('ul.tools > li:first-child').after(
    $('<li>').append(
        $('<a>', {
            href: mw.util.getUrl('Special:DiscussionsFeed'),
            text: 'Discussions Feed'
        })
    )
);
$('#my-tools-menu').prepend(
    $('<li>', {
        'class': 'custom'
    }).append(
        $('<a>', {
            href: mw.util.getUrl('Special:ListAdmins'),
            text: 'List Admins'
        })
    )
);
AjaxRCRefreshText = 'Auto-refresh';
AjaxRCRefreshHoverText = 'Automatically refresh the page';
// Signature button
if (window.mwCustomEditButtons) {
    mwCustomEditButtons.push(
        {
            imageFile: 'https://images.wikia.nocookie.net/mlp/images/a/a6/Pictogram_voting_comment.svg',
            speedTip: 'Local Signature',
            tagOpen: '{' + '{User:343TheGuiltyProphet/Sig}}',
            tagClose: '~~' + '~~' + '~',
            sampleText: ' '
        },
        {
            imageFile: 'https://images.wikia.nocookie.net/mlp/images/a/a6/Pictogram_voting_comment.svg',
            speedTip: 'Global Signature',
            tagOpen: '{' + '{w:User:343TheGuiltyProphet/Sig}}',
            tagClose: '~~' + '~~' + '~',
            sampleText: ' '
        }
    );
}

/*
 * @name:               Rollback
 * @description:        Perform rollbacks without needing to be in the usergroup
 * @author:             Ozank Cx <dev.fandom.com/wiki/User:Ozank_Cx>
 *                      Cleanup/+i18n by Count of Howard <dev.fandom.com/wiki/User:Count_of_Howard>
 */

(function() {
    if ($('.mw-rollback-link').length || $('.mw-custom-rollback-link').length || window.RollbackWikiDisable) {
        return;
    }

    var config = mw.config.get([
        'wgAction',
        'wgPageName',
        'wgContentLanguage',
        'wgCanonicalSpecialPageName'
    ]),
    i18n = {
        'en': {
            title: '"Rollback" reverts edit(s) to this page of the last contributor in one click',
            failGeneral: 'Unable to rollback',
            failRevisions: 'Failed to get revisions',
            failContent: 'Failed to get page content',
            failEditor: 'No different editor found',
            failPublish: 'Failed to publish edit',
            success: 'Rollback successful',
            rollback: 'rollback',
            summary1: 'Reverted edits by',
            summary2: 'to last version by',
            script: 'script',
            talk: 'talk',
            block: 'block'
       
        }
    },
    lang = i18n[config.wgContentLanguage] || i18n[config.wgContentLanguage.split('-')[0]] || i18n.en;

    function init() {
        var rollbackLinkParams = {
            style: 'cursor: pointer',
            title: lang.title
        };

        if (
            config.wgAction === 'history' &&
            $('#pagehistory li').length > 1
        ) {
            rollbackLinkParams['data-id'] = config.wgPageName;
            $('#pagehistory li:first .mw-history-undo a').before(
                $('<span/>', {
                    class: 'mw-custom-rollback-link'
                }).html(
                    buildElement('a', lang.rollback, rollbackLinkParams) + ' | '
                )
            );
        } else if (
            config.wgCanonicalSpecialPageName === 'Contributions'
        ) {
            rollbackLinkParams['data-id'] = $('#mw-content-text ul').find('a:first').attr('title');
            $('#mw-content-text ul').find('li').each(
                function() {
                    if ($(this).find('.mw-uctop').length) {
                        $(this).append(
                            $('<span/>', {
                                class: 'mw-custom-rollback-link'
                            }).html(
                                '[' + buildElement('a', lang.rollback, rollbackLinkParams) + ']'
                            )
                        );
                    }
                }
            );
        } else if (
            $('#differences-nextlink').length === 0 &&
            (
                $.getUrlVar('diff') || 
                $.getUrlVar('oldid')
            )
        ) {
            rollbackLinkParams['data-id'] = config.wgPageName;
            $('.mw-usertoollinks:last').after(
                '&nbsp;&nbsp;&nbsp;&nbsp;<span class="mw-custom-rollback-link">' +
                '[' + buildElement('a', lang.rollback, rollbackLinkParams) + ']</span>'
            );
        }

        $('.mw-custom-rollback-link a').click(
            function() {
                getRevisionIdAndContent($(this).attr('data-id'), handleData);
                $(this).parent().remove();
            }
        );
    }

    function buildElement(tag, html, attrs) {
        if (typeof(html) !== 'string') {
            attrs = html;
            html = null;
        }

        var h = '<' + tag;
        for (var attr in attrs) {
            if (attrs[attr] === false) {
                continue;
            }

            h += ' ' + attr + '="' + mw.html.escape(attrs[attr]) + '"';
        }
        return h += html ? ">" + mw.html.escape(html) + "</" + tag + ">" : "/>";
    }

    function getRevisionIdAndContent(title, callback) {
        new mw.Api().get({
            action: 'query',
            prop: 'revisions',
            titles: title,
            rvprop: 'user|ids',
            rvlimit: 500,
            cb: new Date().getTime()
        }).done(
            function(d) {
                if (!d.error) {
                    callback(title, d);
                } else {
                    new BannerNotification(
                        lang.failGeneral + ' (' + lang.failRevisions + '): ' + d.error.code, 'error'
                    ).show();
                }
            }
        ).fail(
            function() {
                new BannerNotification(
                    lang.failGeneral + ' (' + lang.failRevisions + ')', 'error'
                ).show();
            }
        );
    }

    function handleData(title, data) {
        var revisions;

        for (var i in data.query.pages) {
            revisions = data.query.pages[i].revisions;
        }

        var currentUser = revisions[0].user,
            lastUser,
            revId;

        for (var i in revisions) {
            if (revisions[i].user != currentUser) {
                lastUser = revisions[i].user;
                revId = revisions[i].revid;
                break;
            }
        }

        if (lastUser) {
            new mw.Api().get({
                action: 'query',
                prop: 'revisions',
                rvprop: 'content',
                revids: revId,
                cb: new Date().getTime()
            }).done(
                function(d) {
                    if (!d.error) {
                        var content = "";
                        for (var i in d.query.pages) {
                            if (d.query.pages[i].revisions) {
                                content = d.query.pages[i].revisions[0]["*"];
                            }
                        }
                        performRollback(title, content, currentUser, lastUser);
                    } else {
                        new BannerNotification(
                            lang.failGeneral + ' (' + lang.failContent + '): ' + d.error.code,'error'
                        ).show();
                    }
                }
            ).fail(
                function() {
                    new BannerNotification(
                        lang.failGeneral + ' (' + lang.failContent + ')','error'
                    ).show();
                }
            );
        } else {
            new BannerNotification(
                lang.failGeneral + ' (' + lang.failEditor + ')','error'
            ).show();
        }
    }

    function performRollback(page, text, user, user2) {
        var summary = lang.summary1 + ' [[Special:Contributions/' + user + '|' + user + ']] ([[User_talk:' + user + '|' + lang.talk +
                ']] | [[Special:Block/' + user + '|' + lang.block + ']]) ' + lang.summary2 + user2 + ' ([[w:c:dev:Rollback|' + lang.script + ']])';

        if (summary.length > 150) {
            summary = lang.summary1 + ' ' + user ;
        }

        new mw.Api().post({
            action: 'edit',
            title: page,
            text: text,
            summary: summary,
            token: mw.user.tokens.values.editToken
        }).done(
            function(d) {
                if (!d.error) {
                    new BannerNotification(
                        lang.success + '!', 'confirm'
                    ).show();
                } else {
                    new BannerNotification(
                        lang.failGeneral + ' (' + lang.failPublish + '): ' + d.error.code,'error'
                    ).show();
                }
            }
        ).fail(
            function() {
                new BannerNotification(
                    lang.failGeneral + ' (' + lang.failPublish + ')', 'error'
                ).show();
            }
        );
    }

    init();
})();

 /*!
     * Original script: http://dev.wikia.com/wiki/MarkForDeletion
     */
 
    /*jshint forin:true, noempty:true, eqeqeq:true, bitwise:true, strict:true, undef:true, unused:true, curly:true, browser:true, jquery:true */
    /*global mediaWiki */
 
    if (mediaWiki.config.get("wgAction") === "view" && mediaWiki.config.get("wgNamespaceNumber") !== -1 && mediaWiki.config.get("wgUserName") !== null) {
            (function ($, mw, window, document) {
                    "use strict";
 
                    var wgServer = mw.config.get("wgServer"),
                            wgPageNameEncoded = window.encodeURIComponent(mw.config.get("wgPageName"));
 
                    // uses MW API to automatically edit the page and insert the delete template at the top
                    function setDeleteNotice(deleteReason) {
                            var xhr = new XMLHttpRequest(),
                                    summary = "Adding template: {" + "{" + deleteReason + "}}",
                                    content = "{" + "{" + deleteReason + "}}",
                                    editToken = mw.user.tokens.get("editToken"),
                                    url = wgServer + "/api.php?action=edit&title=" + wgPageNameEncoded + "&summary=" + window.encodeURIComponent(summary) + "&format=json&appendtext=" + window.encodeURIComponent(content) + "&token=" + window.encodeURIComponent(editToken);
 
                            xhr.open("POST", url);
                            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                            xhr.onreadystatechange = function () {
                                    if (this.readyState === 4) {
                                            window.location.reload();
                                    }
                            };
                            xhr.send();
                    }
 
                    // adds a "Mark for deletion" button to the user's toolbar
                    function initDeleteNoticeButton() {
                            var $button, toolbar, $mytoolsLI, $customizeLI;
 
                            // create button
                            $button = $('<li><a id="mark-template" style="cursor: pointer;">Prefix Information</a></li>');
                            $button.click(function deleteNoticeButtonClickHandler() {
                                    var promptedDeleteReason = "subst:User:343TheGuiltyProphet/prefix_information";
                                    if (typeof window.c === "object" && window.Template !== null && typeof window.Template.promptedDeleteReason === "string") {
                                            promptedDeleteReason = window.Template.promptedDeleteReason;
                                    }
 
                                    var deleteReason = window.prompt("Enter template name here - Signature must already be in the template - Don't add extra {{}}", promptedDeleteReason);
 
                                    if (typeof deleteReason === "string" && deleteReason.length > 0) {
                                            setDeleteNotice(deleteReason);
                                    }
                            });
 
                            // add button to toolbar
                            toolbar = document.getElementById("WikiaBarWrapper");
                            if (toolbar !== null) {
                                    // oasis
                                    $mytoolsLI = $(toolbar).find("li.mytools");
                                    if ($mytoolsLI.length > 0) {
                                            // insert link before My Tools
                                            $mytoolsLI.before($button);
                                    } else {
                                            // try to insert link before Customize
                                            $customizeLI = $(toolbar).find("a.tools-customize").parent();
                                            $customizeLI.before($button);
                                    }
                            } else {
                                    // monobook
                                    toolbar = document.getElementById("p-tb");
                                    if (toolbar !== null) {
                                            $(toolbar).find("ul").append($button);
                                    }
                            }
                    }
 
                    // add button on DOMReady
                    $(initDeleteNoticeButton);
            }(jQuery, mediaWiki, window, document));
    }