Difference between revisions 779464 and 780809 on knwiki

importScript('User:Ucucha/duplinks.js'); // [[User:Ucucha/duplinks]]
importScript('User:JeremyMcCracken/contribstab.js');
importScript('User:Dipankan001/Edit Count.js')
importScript('User:Amalthea/userhighlighter.js')
importScript('User:Anomie/ajaxpreview.js'); // Linkback: [[User:Anomie/ajaxpreview.js]]
importScript("User:PleaseStand/userinfo.js");
importScript('User:Cameltrader/Advisor.js');

/*
 * Redirect Management
 * @description Delete broken redirects and fix double redirects automatically.
 * @author Ozuzanna
 * @author KockaAdmiralac
 * <nowiki>
 */
(function() {
    var config = mw.config.get([
        'wgCanonicalSpecialPageName',
        'wgContentLanguage',
        'wgUserGroups',
        'wgUserLanguage'
    ]);
    if (
           !(/DoubleRedirects|BrokenRedirects/g.test(config.wgCanonicalSpecialPageName))
        || $('#btn-resolve-broken').length
        || $('#btn-resolve-double').length
        || ( // ew
                  !(/sysop|vstf|staff|helper|content-moderator/.test(config.wgUserGroups))
               && config.wgCanonicalSpecialPageName === 'BrokenRedirects'
           )
    ) {
        return;
    }
    var i18n = {
        en: {
            button: 'Resolve redirects',
            editSummary: 'Resolving [[Special:DoubleRedirects|double redirect]] (automatic)',
            deleteReason: 'Resolving [[Special:BrokenRedirects|broken redirect]] (automatic)',
            successDouble: 'Resolving double redirect for $1 successful!',
            errorDouble: 'Failed to resolve double redirect for $1',
            successBroken: 'Deletion of $1 successful!',
            errorBroken: 'Failed to delete $1'
        },
        kn: {
            button: 'ಪುನರ್ನಿರ್ದೇಶನಗಳ ಪರಿಹರಿಸಿ',
            editSummary: '[[Special:DoubleRedirect|ಡಬಲ್ ಮರುನಿರ್ದೇಶನ ಪರಿಹರಿಸಲಾಗುತ್ತಿದೆ  (ಸ್ವಯಂಚಾಲಿತ)]]',
            deleteReason: '[[Special:BrokenRedirect|ಮುರಿದು ಮರುನಿರ್ದೇಶಿಸು ಪರಿಹರಿಸಲಾಗುತ್ತಿದೆ (ಸ್ವಯಂಚಾಲಿತ)]]',
            successDouble: 'ಪರಿಹರಿಸಲಾಗುತ್ತಿದೆ ಡಬಲ್ $1 ಯಶಸ್ವಿ ಮರುನಿರ್ದೇಶಿಸುತ್ತದೆ!',
            errorDouble: '$1 ಡಬಲ್ ಮರುನಿರ್ದೇಶಿಸುತ್ತದೆ ಪರಿಹರಿಸುವಲ್ಲಿ ವಿಫಲಗೊಂಡಿದೆ ',
            successBroken: '$1 ಅಳಿಸುವಿಕೆ ಯಶಸ್ವಿ!',
            errorBroken: '$1 ಅಳಿಸಲು ವಿಫಲವಾಗಿದೆ'
        }
     };
    var RedirectManagement = {
        init: function() {
            this.api = new mw.Api();
            this.double = config.wgCanonicalSpecialPageName === 'DoubleRedirects';
            // ;-;
            var i18nc1 = $.extend(true, {}, i18n),
                i18nc2 = $.extend(true, {}, i18n);
            this.i18nu = $.extend(i18nc1.en, i18nc1[config.wgUserLanguage.split('-')[0]], i18nc1[config.wgUserLanguage]);
            this.i18nc = $.extend(i18nc2.en, i18nc2[config.wgContentLanguage.split('-')[0]], i18nc2[config.wgContentLanguage]);
            $('.mw-spcontent p')
                .first()
                .append(
                    $('<p>')
                        .append(
                            $('<a>')
                                .attr({
                                    class: 'button',
                                    style: 'cursor: pointer;',
                                    id: 'btn-resolve-redirects'
                                })
                                .text(this.i18nu.button)
                        )
                );
            $('#btn-resolve-redirects').click($.proxy(this.onClick, this));
        },
        onClick: function() {
            $('.special > li').each($.proxy(function(_, el) {
                var children = $(el).children();
                if(children.length !== 4) {
                    // Already resolved
                    return;
                }
                var page = $(children[0]).text();
                this.api.post($.extend({
                    title: page,
                    watchlist: 'nochange',
                    token: mw.user.tokens.get('editToken')
                }, this.double ? {
                    action: 'edit',
                    text: '#REDIRECT [[' + $(children[3]).text() + ']]',
                    summary: this.i18nc.editSummary
                } : {
                    action: 'delete',
                    reason: this.i18nc.deleteReason
                }))
                .done($.proxy(function(d) {
                    if(d.error) {
                        console.error(this.i18nPrefix('error', page) + ': ' + d.error.code);
                    } else {
                        console.info(this.i18nPrefix('success', page));
                    }
                }, this))
                .fail($.proxy(function() {
                    console.error(this.i18nPrefix('error', page));
                }, this));
            }, this));
            setTimeout(function() {
                location.reload();
            }, 15000);
        },
        i18nPrefix: function(k, param) {
            return this.i18nu[k + (this.double ? 'Double' : 'Broken')].replace('$1', param);
        }
    };
    mw.loader.using('mediawiki.api', $.proxy(RedirectManagement.init, RedirectManagement));
})(mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Ucucha/duplinks.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:JeremyMcCracken/contribstab.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Dipankan001/Edit Count.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Amalthea/userhighlighter.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Anomie/ajaxpreview.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:PleaseStand/userinfo.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Cameltrader/Advisor.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Kephir/gadgets/sagittarius.js&action=raw&ctype=text/javascript');