میڈیا وکی:Gadget-zumraband.js

آزاد انسائیکلوپیڈیا، وکیپیڈیا توں

نوٹ: بچان مگروں توانوں اپنے براؤزر دے کاشے توں بار جانا پوے گا تبدیلیاں ویکھن لئی۔

  • Firefox / Safari: Shift پھڑی رکھو ریلوڈ تے کلکنگ کردیاں ہویاںCtrl-F5 or Ctrl-R (Command-R میک تے)
  • گوکل کروم: دباؤ Ctrl-Shift-R (Command-Shift-R میک تے)

Internet Explorer: hold Ctrl کلک کردیاں Refresh, یا دباؤ Ctrl-F5 Konqueror:کلک ریلوڈ یا F5 دباؤ۔ Opera: کاشے نوں صاف کرو آوزار → تانگاں

$(function() {
    function loadPage(title, callback) {
        new mw.Api().get({
            action: 'query',
            prop: 'revisions',
            titles: title,
            rvprop: 'content',
            format: 'json'
        }).done(function(data) {
            try {
                callback($.map(data.query.pages, function(value) {
                    return value;
                })[0].revisions[0]['*']);
            } catch (exception) {
                callback('');
            }
        }).fail(function(data) {
            callback($.map(data.query.pages, function(value) {
                return value;
            })[0].revisions[0]);
        });
    }

    function savePage(title, text, summary, callback) {
        new mw.Api().post({
            action: 'edit',
            title: title,
            text: text,
            summary: summary,
            minor: '',
            token: mw.user.options.get('csrfToken')
        }).done(function(data) {
            if (data.error && data.error.info) {
                mw.notify(data.error.info);
            } else {
                callback();
            }
        }).fail(function(data) {
            mw.notify(data);
        });
    }

    function CloseTalkPage(text) {
        text = text.replace("ج" + mw.config.get('wgTitle') + "}}");
        mw.notify('!');
        return text;
    }

    function loadSavePageRefresh(page, replaceCallback, summary) {
        loadPage(page, function(text) {
            savePage(page, replaceCallback(text), summary, function() {
                //window.location = mw.util.getUrl(page) + '?action=purge';
            });
        });
    }

    function addBotLink2(botName, id, tooltip, note, botUrl, imageUrl) {
        $(mw.util.addPortletLink(
            'p-cactions',
            '#',
            botName,
            id,
            tooltip
        )).click(function(e) {
            e.preventDefault();
            mw.notify(note, {
                autoHide: false
            });
            $.get(new mw.Uri(botUrl).extend({
                enwiki: mw.config.get('wgTitle'),
            }).toString()).then(function(result) {
                mw.notify(result.msg, {
                    autoHide: false
                });
                loadSavePageRefresh("وپ",
                    function(text) {
                        return CloseTalkPage(text)
                    }, '/' + '*اضافہ*' + '/');
                var uri = new mw.Uri();
                uri.query = {
                    title: "وپ/" + mw.config.get('wgTitle'),
                    action: 'edit',
                    redlink: 1,
                    withJS: 'MediaWiki:',
                    summary: '',
                    text: result.page_content,
                };
                uri.path = mw.config.get('wgScriptPath') + '/index.php';
                window.location = uri.toString();
            })
        }).find('a').prepend(imageUrl ? [$('<img>', {
            src: imageUrl,
            height: 20,
            width: 20
        }), ' '] : '');
    }

    function addBotLink(botName, id, tooltip, note, botUrl, imageUrl) {
        $(mw.util.addPortletLink(
            'p-cactions',
            '#',
            botName,
            id,
            tooltip
        )).click(function(e) {
            e.preventDefault();
            mw.notify(note, {
                autoHide: false
            });
            var pageTitle=mw.config.get('wgTitle')
            if (id === 'ca-r-replace') {//ج
                alert('!')
                var link1 = prompt("!");
                var link2 = prompt("!");
                if (link1.length > 1 && link2.length > 1){
                    var reResion = prompt("!");
                    if (reResion.length <= 1){
                        alert('!')
                        var reResion = prompt("!");
                        if (reResion.length <= 1){return;}
                    }
                    pageTitle=link1+'---'+link2+'---'+reResion
                }else{
                    alert('!')
                }
            }
            $.get(new mw.Uri(botUrl).extend({
                title: pageTitle,
                fawiki: mw.config.get('wgTitle').replace(/ /g,'_'),
                user: 'صارف:' + mw.config.get('wgUserName'),
                namespace: mw.config.get('wgNamespaceNumber')
            }).toString()).then(function(result) {
                mw.notify(result.msg, {
                    autoHide: false
                });
                var resultmsg = result.msg;
                
                var uri = new mw.Uri(),
                    pageTitle;
                if (id === 'ca-eval' && mw.config.get('wgNamespaceNumber') === 0) {
                    pageTitle = 'تبادلۂ خیال:' + mw.config.get('wgPageName')
                } else if (id === 'ca-articleneeded') {
                    pageTitle = resultmsg;
                } else {
                    pageTitle = mw.config.get('wgPageName')
                }
                uri.query = {
                    'title': pageTitle,
                    'diff': 'cur',
                    'oldid': 'prev'
                };
                uri.path = mw.config.get('wgScriptPath') + '/index.php';
                if (id !== 'ca-zumraband' && id !== 'ca-filling'&& id !== 'ca-navebox' && id !== 'ca-pipe'){
                    window.location = uri.toString();
                }else if (id !== 'ca-r-replace'){
                    mw.notify('روبہ شروع ہو گیا ہے۔');
                }else{
                    setTimeout(function() {
                        var uri = new mw.Uri()
                        uri.query = {
                            'title': pageTitle
                        };
                        uri.path = mw.config.get('wgScriptPath') + '/index.php';
                        window.location = uri.toString();
                    }, 8000);
                }
            });
        }).find('a').prepend(imageUrl ? [$('<img>', {
            src: imageUrl,
            height: 20,
            width: 20
        }), ' '] : '');
    }
    
    if (mw.config.get('wgNamespaceNumber') === 0) {
        // اضافہ زمرہ
        addBotLink(
            'اضافہ زمرہ جات',
            'ca-zumraband',
            'خودکار اضافہ زمرہ جات',
            'اضافہ جاری ہے، براہ کرم کچھ دیر بعد صفحہ تازہ کر لیں؛ اگر زمرے شامل کیے گئے ہونگے تو دکھائی دینے لگیں گے۔',
            '//tools.wmflabs.org/zumraband/zumra.php',
        );
    }
});