پرش به محتوا

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

از دانشنامه علوم انسانی
imported>Ebrahim
انجام پشت سر هم
imported>Ebrahim
تبدیل فاصله با آنچه که ویرایشگر ویکی قرار می‌دهد
خط ۶: خط ۶:
  */
  */
(function ($, mw) {
(function ($, mw) {
    'use strict';
'use strict';


    function createPage(title, text, summary, callback) {
function createPage(title, text, summary, callback) {
        return new mw.Api().post({
return new mw.Api().post({
            action: 'edit',
action: 'edit',
            title: title,
title: title,
            text: text,
text: text,
            summary: summary,
summary: summary,
            createonly: '',
createonly: '',
            bot: '',
bot: '',
            token: mw.user.tokens.get('editToken')
token: mw.user.tokens.get('editToken')
        });
});
    }
}


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


        var append = "@";
var append = "@";
        var buttonText = "@";
var buttonText = "@";
        var ns = mw.config.get("wgNamespaceNumber");
var ns = mw.config.get("wgNamespaceNumber");
        if (typeof namespaces[ns] === "object") {
if (typeof namespaces[ns] === "object") {
            append = namespaces[ns][0] + "@" + namespaces[ns][1] + mw.config.get("wgTitle");
append = namespaces[ns][0] + "@" + namespaces[ns][1] + mw.config.get("wgTitle");
            buttonText = namespaces[ns][0] + "@اینجا";
buttonText = namespaces[ns][0] + "@اینجا";
        } else if (typeof namespaces[ns] === "string") {
} else if (typeof namespaces[ns] === "string") {
            append = namespaces[ns] + "@" + namespaces[ns] + mw.config.get("wgTitle");
append = namespaces[ns] + "@" + namespaces[ns] + mw.config.get("wgTitle");
            buttonText = namespaces[ns] + "@اینجا";
buttonText = namespaces[ns] + "@اینجا";
        }
}


        return $("<button>", {
return $("<button>", {
            text: buttonText,
text: buttonText,
            style: "position: absolute; left: 1em;",
style: "position: absolute; left: 1em;",
            class: "mw-ui-button mw-ui-constructive"
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 + append;
value = value + append;
            $("#redirectmakerinput").val(value).focus();
$("#redirectmakerinput").val(value).focus();
        });
});
    }
}


    function init(e) {
function init(e) {
        e.preventDefault();
e.preventDefault();
        $('<div>' +
$('<div>' +
            '<div style="width: 40em">تغییرمسیرها را در خط\u200cهای جداگانه در جعبهٔ زیر وارد کنید:</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>' +
'<textarea style="width: 100%; background-color: white; resize:vertical; padding-left: 50px;" placeholder="مبدأ@مقصد" id="redirectmakerinput" rows="7"></textarea>' +
            '</div>'
'</div>'
        ).dialog({
).dialog({
            title: "ابزار ایجاد تغییرمسیر",
title: "ابزار ایجاد تغییرمسیر",
            modal: true,
modal: true,
            width: 700,
width: 700,
            open: function () {
open: function () {
                $("#redirectmakerinput").before(makeButton());
$("#redirectmakerinput").before(makeButton());
            },
},
            buttons: [{
buttons: [{
                id: 'redirectmaker-button-import',
id: 'redirectmaker-button-import',
                text: 'ایجاد تغییرمسیر',
text: 'ایجاد تغییرمسیر',
                click: function () {
click: function () {
                    var requests = $('#redirectmakerinput').val();
var requests = $('#redirectmakerinput').val();
                    if (requests === '') {
if (requests === '') {
                        mw.notify('لطفاً فرم درخواست را به درستی پر کنید');
mw.notify('لطفاً فرم درخواست را به درستی پر کنید');
                        return;
return;
                    }
}


requests.split('\n').map(function (x) {
requests.split('\n').map(function (x) {
خط ۱۰۳: خط ۱۰۳:
});
});
};
};
                    }).reduce(function (defer, job) {
}).reduce(function (defer, job) {
return defer.then(job);
return defer.then(job);
}, $.Deferred().resolve()).then(function () {
}, $.Deferred().resolve()).then(function () {
                        mw.notify('ایجاد تغییرمسیرها\u200cها به پایان رسید، لطفاً بررسی کنید.');
mw.notify('ایجاد تغییرمسیرها\u200cها به پایان رسید، لطفاً بررسی کنید.');
                        window.location = '/wiki/Special:Contributions/' + mw.config.get('wgUserName');
window.location = '/wiki/Special:Contributions/' + mw.config.get('wgUserName');
                    });
});
                }
}
            }],
}],
            close: function () {
close: function () {
                $(this).remove();
$(this).remove();
            }
}
        });
});
    }
}


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

نسخهٔ ۱۶ مارس ۲۰۱۷، ساعت ۱۰:۴۶

// <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: '',
			bot: '',
			token: mw.user.tokens.get('editToken')
		});
	}

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

		var append = "@";
		var buttonText = "@";
		var ns = mw.config.get("wgNamespaceNumber");
		if (typeof namespaces[ns] === "object") {
			append = namespaces[ns][0] + "@" + namespaces[ns][1] + mw.config.get("wgTitle");
			buttonText = namespaces[ns][0] + "@اینجا";
		} else if (typeof namespaces[ns] === "string") {
			append = namespaces[ns] + "@" + namespaces[ns] + mw.config.get("wgTitle");
			buttonText = namespaces[ns] + "@اینجا";
		}

		return $("<button>", {
			text: buttonText,
			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 + append;
			$("#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 requests = $('#redirectmakerinput').val();
					if (requests === '') {
						mw.notify('لطفاً فرم درخواست را به درستی پر کنید');
						return;
					}

					requests.split('\n').map(function (x) {
						return function () {
							var req = x.split('@');
							if (req.length !== 2) {
								return;
							}
							var from = req[0].trim();
							var to = req[1].trim();
							return createPage(
								from,
								'#تغییرمسیر [[' + to + ']]',
								'ایجاد تغییرمسیر برای [[' + to + ']] (ابزار تغییرمسیرساز)',
							).then(function () {
								mw.notify('ایجاد ' + to + ' با موفقیت انجام شد.');
							}, function () {
								// revive the chain
								return $.Deferred().resolve();
							});
						};
					}).reduce(function (defer, job) {
						return defer.then(job);
					}, $.Deferred().resolve()).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));