پرش به محتوا

مدیاویکی:Gadget-RedirectMaker.js: تفاوت میان نسخه‌ها

از دانشنامه علوم انسانی
imported>علیرضا
افزودن صفحهٔ کنونی به‌عنوان مقصد و واردنکردن پیشوند در فضاهای نام تعریف‌نشده مانند «ویژه»
imported>علیرضا
افزودن استایل به دکمه و bugfix
خط ۶۱: خط ۶۱:
         };
         };


         var text = "";
         var text = "@";
         for (var ns in namespaces) {
         if (typeof namespaces[mw.config.get("wgNamespaceNumber")] === "object")
            if (mw.config.get("wgNamespaceNumber") == ns) {
            text = namespaces[ns][0] + "@" + namespaces[ns][1] + mw.config.get("wgTitle");
                if (typeof namespaces[ns] === "object")
        else if (typeof namespaces[mw.config.get("wgNamespaceNumber")] === "string")
                    text = namespaces[ns][0] + "@" + namespaces[ns][1];
            text = namespaces[ns] + "@" + namespaces[ns] + mw.config.get("wgTitle");
                else
 
                    text = namespaces[ns] + "@" + namespaces[ns];
            }
            // On other namespaces (i.e. special pages)
            else
                text = "@";
        }
         return $("<button>", {
         return $("<button>", {
             text: text,
             text: text,
             style: "position: absolute; left: 1em;"
             style: "position: absolute; left: 1em;",
            class: "mw-ui-button mw-ui-constructive"
         }).click(function () {
         }).click(function () {
             var value = $("#redirectmakerinput").val().trim();
             var value = $("#redirectmakerinput").val().trim();
             if (value !== '')
             if (value !== '')
                 value = value + '\n';
                 value = value + '\n';
             value = value + text + mw.config.get("wgTitle");
             value = value + text;
             $("#redirectmakerinput").val(value).focus();
             $("#redirectmakerinput").val(value).focus();
         });
         });

نسخهٔ ۹ مارس ۲۰۱۵، ساعت ۲۰:۳۰

// <nowiki> // DO NOT REMOVE THIS LINE EVER
/*jslint browser: true, white: true*/
/*global mediaWiki, jQuery*/
/*!
 * @author User:Ebraminio, User:Yamaha5
 */
(function ($, mw) {
    'use strict';

    function createPage(title, text, summary, callback) {
        return new mw.Api().post({
            action: 'edit',
            title: title,
            text: text,
            summary: summary,
            createonly: '',
            minor: '',
            token: mw.user.tokens.get('editToken')
        }).then(
            function (data) {
                if (data.error && data.error.info) {
                    mw.notify(title + ' انجام نشد: ' + data.error.info);
                } else {
                    callback();
                }
                return data;
            },
            function (data) {
                mw.notify(title + ' انجام نشد: ' + data);
                return data;
            }
        );
    }

    function startRedirect(redirect, dest) {
        return createPage(
            redirect,
            '#تغییرمسیر [[' + dest + ']]',
            'ایجاد تغییرمسیر برای [[' + dest + ']] (ابزار تغییرمسیرساز)',
            function () {
                mw.notify('ایجاد ' + redirect + ' با موفقیت انجام شد.');
            }
        );
    }

    // Make button by namespace
    function makeButton() {
        var namespaces = {
            0: "",
            2: "کاربر:",
            4: ["وپ:", "ویکی\u200cپدیا:"],
            6: "پرونده:",
            8: "مدیاویکی:",
            10: "الگو:",
            12: "راهنما:",
            14: "رده:",
            100: "درگاه:",
            102: "کتاب:",
            446: "برنامه آموزشی:",
            828: "پودمان:"
        };

        var text = "@";
        if (typeof namespaces[mw.config.get("wgNamespaceNumber")] === "object")
            text = namespaces[ns][0] + "@" + namespaces[ns][1] + mw.config.get("wgTitle");
        else if (typeof namespaces[mw.config.get("wgNamespaceNumber")] === "string")
            text = namespaces[ns] + "@" + namespaces[ns] + mw.config.get("wgTitle");

        return $("<button>", {
            text: text,
            style: "position: absolute; left: 1em;",
            class: "mw-ui-button mw-ui-constructive"
        }).click(function () {
            var value = $("#redirectmakerinput").val().trim();
            if (value !== '')
                value = value + '\n';
            value = value + text;
            $("#redirectmakerinput").val(value).focus();
        });
    }

    function init(e) {
        e.preventDefault();
        $('<div>' +
            '<div style="width: 40em">تغییرمسیرها را در خط\u200cهای جداگانه در جعبهٔ زیر وارد کنید:</div>' +
            '<textarea style="width: 100%; background-color: white; resize:vertical; padding-left: 50px;" placeholder="مبدأ@مقصد" id="redirectmakerinput" rows="7"></textarea>' +
            '</div>'
        ).dialog({
            title: "ابزار ایجاد تغییرمسیر",
            modal: true,
            width: 700,
            open: function () {
                $("#redirectmakerinput").before(makeButton());
            },
            buttons: [{
                id: 'redirectmaker-button-import',
                text: 'ایجاد تغییرمسیر',
                click: function () {
                    var formInput = $('#redirectmakerinput').val();
                    if (formInput === '') {
                        mw.notify('لطفاً فرم درخواست را به درستی پر کنید');
                        return;
                    }
                    $.when.apply(null, $.map(formInput.split('\n'), function (x) {
                        var req = x.split('@');
                        if (req.length !== 2) {
                            return;
                        }
                        return startRedirect(req[0], req[1]);
                    })).then(function () {
                        mw.notify('ایجاد تغییرمسیرها\u200cها به پایان رسید، لطفاً بررسی کنید.');
                        window.location = '/wiki/Special:Contributions/' + mw.config.get('wgUserName');
                    });
                }
            }],
            close: function () {
                $(this).remove();
            }
        });
    }

    $(function () {
        //mw.util.addCSS('#t-redirectmaker { font-weight: bold; }');
        $(mw.util.addPortletLink('p-tb', '#', 'تغییرمسیر\u200cساز', 't-redirectmaker', 'ایجاد تغییرمسیر به صورت خودکار')).click(init);
    });
}(jQuery, mediaWiki));