FANDOM


//
/* Rollback Tool that I can actually use. */
mw.loader.using('mediawiki.api', function() {
// MamvikBud gets to use it. :3
if (wgServer === "http://vstf.wikia.com" && wgUserName !== "Mamvik"){
return;
}
    var main = {
        init: function() {
            if (mw.config.get('wgCanonicalSpecialPageName') == "Contributions") {
                $('#mw-content-text ul').find('li').each(function() {
                    if ($(this).find('.mw-uctop').length)
                        $(this).append(' <span class="mw-custom-revert-link">[<a style="cursor: pointer" title="&quot;Rollback&quot; reverts edit(s) to this page of the last contributor in one click" data-id="' + $(this).find('a:first').attr('title') + '">revert</a>]</span>');
                });
            } else if (($.getUrlVar('diff') || $.getUrlVar('oldid')) && $('#differences-nextlink').length === 0)
                $('.mw-usertoollinks:last').after('&nbsp;&nbsp;&nbsp;&nbsp;<span class="mw-custom-revert-link">[<a style="cursor: pointer" title="&quot;Rollback&quot; reverts edit(s) to this page of the last contributor in one click" data-id="' + mw.config.get('wgPageName') + '">revert</a>]</span>');
            $('.mw-custom-revert-link a').click(function() {
                main.getRevisionIdAndContent($(this).attr('data-id'));
                $(this).parent().remove();
            });
        },
        getRevisionIdAndContent: function(title) {
            var API = new mw.Api();
            API.get({
                action: 'query',
                prop: 'revisions',
                titles: title,
                rvprop: 'user|ids',
                rvlimit: 500,
                cb: new Date().getTime()
            }).done(function(d) {
                if (!d.error) {
                    var revisions;
                    for (var i in d.query.pages) {
                        revisions = d.query.pages[i].revisions;
                    }
                    var currentUser = revisions[0].user, //current user rollbacking from
                    lastUser, revId;
                    for (var i in revisions) {
                        if (revisions[i].user != currentUser) {
                            lastUser = revisions[i].user;
                            //remember last author
                            revId = revisions[i].revid;
                            //get revision to revert to
                            break;
                        }
                    }
                    if (lastUser) {
                        API.get({
                            action: 'query',
                            prop: 'revisions',
                            rvprop: 'content',
                            revids: revId,
                            cb: new Date().getTime()
                        }).done(function(d) {
                            if (!d.error) {
                                var content = "";
                                //can be no content on page so initialise empty as failsafe
                                for (var i in d.query.pages) {
                                    if (d.query.pages[i].revisions)
                                        content = d.query.pages[i].revisions[0]["*"];
                                }
                                main.performRollback(title, content, currentUser, lastUser);
                            } else
                                new BannerNotification('Unable to rollback (failed to get page content): ' + d.error.code,'error').show();
                        }).fail(function() {
                            new BannerNotification('Unable to rollback: failed to get page content!','error').show();
                        });
                    } else
                        new BannerNotification('Unable to rollback: no different editor found!','error').show();
                } else
                    new BannerNotification('Unable to rollback (failed to get revisions): ' + d.error.code,'error').show();
            }).fail(function() {
                new BannerNotification('Unable to rollback: failed to get revisions!','error').show();
            });
        },
        performRollback: function(page, text, user, user2) {
            var API = new mw.Api();
            API.get({
                action: 'query',
                prop: 'revisions',
                titles: page,
                rvprop: 'user|ids',
                rvlimit: 500,
                cb: new Date().getTime()
            }).done(function(undothing) {
                for (var i in undothing.query.pages) {
                    var something = undothing.query.pages[i].revisions;
                    var wowie = wgPageName.split("/");
                    var AlternateUser = $('td.diff-ntitle:nth-of-type(2) #mw-diff-ntitle2 .mw-userlink').html();
                    if (mw.config.get('wgCanonicalSpecialPageName') == "Contributions" && undothing.query.pages[i].revisions[0]["user"] == wowie[1].replace(/_/g, " ")) {
                            if (wgUserName === "Mamvik"  && wgServer !== "http://vstf.wikia.com"|| wgUserName === "Ditto Duck Penguin" && wgServer !== "http://vstf.wikia.com") {
                                mamvik = 'Un-did revisions by [[Special:Contributions/' + user + '|' + user + ']] ([[User_talk:' + user + '|talk]]) ([[w:c:botcentral:User:Ditto_Duck_Penguin/FixedRollback.javascript|Script]])';
                            } else {
                                mamvik = 'Un-did revisions by [[Special:Contributions/' + user + '|' + user + ']] ([[User_talk:' + user + '|talk]])';
                            }
                            var API = new mw.Api();
                            API.post({
                                action: 'edit',
                                title: page,
                                text: text,
                                summary: mamvik,
                                token: mw.user.tokens.values.editToken
                            })
                    } else if (undothing.query.pages[i].revisions[0]["user"] === AlternateUser) {
                            if (wgUserName === "Mamvik"  && wgServer !== "http://vstf.wikia.com"|| wgUserName === "Ditto Duck Penguin" && wgServer !== "http://vstf.wikia.com") {
                                mamvik = 'Un-did revisions by [[Special:Contributions/' + user + '|' + user + ']] ([[User_talk:' + user + '|talk]]) ([[w:c:botcentral:User:Ditto_Duck_Penguin/FixedRollback.javascript|Script]])';
                            } else {
                                mamvik = 'Un-did revisions by [[Special:Contributions/' + user + '|' + user + ']] ([[User_talk:' + user + '|talk]])';
                            }
                            var API = new mw.Api();
                            API.post({
                                action: 'edit',
                                title: page,
                                text: text,
                                summary: mamvik,
                                token: mw.user.tokens.values.editToken
                            })
                    }
                }
            }).done(function(d) {
                if (!d.error) {
                    new BannerNotification('Rollback successful!','confirm','',1000).show()
                } else
                    new BannerNotification('Unable to rollback (failed to publish edit): ' + d.error.code,'error').show();
            }).fail(function() {
                new BannerNotification('Unable to rollback: failed to publish edit!','error').show();
            });
        }
    };
    main.init();
});
function RCRevert() {
    mw.loader.using('mediawiki.api', function() {
 
        var main = {
            init: function() {
                if (mw.config.get('wgCanonicalSpecialPageName') == "Contributions") {
                    $('#mw-content-text ul').find('li').each(function() {
                        if ($(this).find('.mw-uctop').length)
                            $(this).append(' <span class="mw-custom-revert-link">[<a style="cursor: pointer" title="&quot;Rollback&quot; reverts edit(s) to this page of the last contributor in one click" data-id="' + $(this).find('a:first').attr('title') + '">revert</a>]</span>');
                    });
                } else if (($.getUrlVar('diff') || $.getUrlVar('oldid')) && $('#differences-nextlink').length === 0)
                    $('.mw-usertoollinks:last').after('&nbsp;&nbsp;&nbsp;&nbsp;<span class="mw-custom-revert-link">[<a style="cursor: pointer" title="&quot;Rollback&quot; reverts edit(s) to this page of the last contributor in one click" data-id="' + mw.config.get('wgPageName') + '">revert</a>]</span>');
 
                $('.mw-custom-revert-link a').click(function() {
                    main.getRevisionIdAndContent($(this).attr('data-id'));
                    $(this).parent().remove();
                });
            },
            getRevisionIdAndContent: function(title) {
                var API = new mw.Api();
                API.get({
                    action: 'query',
                    prop: 'revisions',
                    titles: title,
                    rvprop: 'user|ids',
                    rvlimit: 500,
                    cb: new Date().getTime()
                }).done(function(d) {
                    if (!d.error) {
                        var revisions;
 
                        for (var i in d.query.pages) {
                            revisions = d.query.pages[i].revisions;
                        }
 
                        var currentUser = revisions[0].user, //current user rollbacking from
                        lastUser, revId;
 
                        for (var i in revisions) {
                            if (revisions[i].user != currentUser) {
                                lastUser = revisions[i].user;
                                //remember last author
                                revId = revisions[i].revid;
                                //get revision to revert to
                                break;
                            }
                        }
 
                        if (lastUser) {
                            API.get({
                                action: 'query',
                                prop: 'revisions',
                                rvprop: 'content',
                                revids: revId,
                                cb: new Date().getTime()
                            }).done(function(d) {
                                if (!d.error) {
                                    var content = "";
                                    //can be no content on page so initialise empty as failsafe
                                    for (var i in d.query.pages) {
                                        if (d.query.pages[i].revisions)
                                            content = d.query.pages[i].revisions[0]["*"];
                                    }
                                    main.performRollback(title, content, currentUser, lastUser);
                                } else
                                    new BannerNotification('Unable to rollback (failed to get page content): ' + d.error.code,'error').show();
                            }).fail(function() {
                                new BannerNotification('Unable to rollback: failed to get page content!','error').show();
                            });
                        } else
                            new BannerNotification('Unable to rollback: no different editor found!','error').show();
                    } else
                        new BannerNotification('Unable to rollback (failed to get revisions): ' + d.error.code,'error').show();
                }).fail(function() {
                    new BannerNotification('Unable to rollback: failed to get revisions!','error').show();
                });
            },
            performRollback: function(page, text, user, user2) {
                var API = new mw.Api();
                API.get({
                    action: 'query',
                    prop: 'revisions',
                    titles: page,
                    rvprop: 'user|ids',
                    rvlimit: 500,
                    cb: new Date().getTime()
                }).done(function(undothing) {
                    for (var i in undothing.query.pages) {
                        var something = undothing.query.pages[i].revisions;
                        var wowie = wgPageName.split("/");
                        if (undothing.query.pages[i].revisions[0]["user"] == wowie[1].replace(/_/g, " ")) {
                            if (wgUserName === "Mamvik"  && wgServer !== "http://vstf.wikia.com"|| wgUserName === "Ditto Duck Penguin" && wgServer !== "http://vstf.wikia.com") {
                                mamvik = 'Un-did revisions by [[Special:Contributions/' + user + '|' + user + ']] ([[User_talk:' + user + '|talk]]) ([[w:c:botcentral:User:Ditto_Duck_Penguin/FixedRollback.javascript|Script]])';
                            } else {
                                mamvik = 'Un-did revisions by [[Special:Contributions/' + user + '|' + user + ']] ([[User_talk:' + user + '|talk]])';
                            }
                            var API = new mw.Api();
                            API.post({
                                action: 'edit',
                                title: page,
                                text: text,
                                summary: mamvik,
                                token: mw.user.tokens.values.editToken
                            })
                        }
                    }
                }).done(function(d) {
                    if (!d.error) {
                        new BannerNotification('Rollback successful!','confirm').show();
                    } else
                        new BannerNotification('Unable to rollback (failed to publish edit): ' + d.error.code,'error').show();
                }).fail(function() {
                    new BannerNotification('Unable to rollback: failed to publish edit!','error').show();
                });
            }
        };
 
        main.init();
 
    });
}
//
Community content is available under CC-BY-SA unless otherwise noted.