|
|
| (۱۹۵ نسخهٔ میانی ویرایش شده توسط ۴ کاربر نشان داده نشد) |
| خط ۱: |
خط ۱: |
| function savePage(title, text, summary, callback) { | | (function ($, mw) { |
| new mw.Api().post({
| | var isVector2022 = mw.config.get('skin') === 'vector-2022'; |
| action: 'edit',
| | var portlet = isVector2022 ? 'p-collaboration' : 'p-tb'; |
| title: title,
| | $(mw.util.addPortletLink( |
| text: text,
| | portlet, |
| summary: summary,
| | '//fa.wikipedia.org/wiki/%D9%88%DB%8C%DA%98%D9%87:%D8%B5%D9%81%D8%AD%D9%87%D9%94_%D8%AE%D8%A7%D9%84%DB%8C/tofawiki-conosle?withJS=MediaWiki:TofawikiConsole.js#catmaker', |
| minor: '',
| | 'رده\u200cساز', |
| token: mw.user.tokens.get('editToken')
| | 't-catmaker', |
| }).done(function (data) {
| | 'ساخت رده به صورت خودکار' |
| if (data.error && data.error.info) {
| | )).css('font-weight', 'bold').attr('target', '_blank'); |
| mw.notify(data.error.info);
| | }(jQuery, mediaWiki)); |
| } else {
| |
| callback();
| |
| }
| |
| }).fail(function (data) {
| |
| mw.notify(data);
| |
| });
| |
| }
| |
| | |
| function faWikiName(title) {
| |
| return $.ajax({
| |
| url: '//en.wikipedia.org/w/api.php',
| |
| data: { action: 'query', prop: 'langlinks', titles: title, redirects: 1, format: 'json', lllimit:500 },
| |
| dataType: 'jsonp'
| |
| }).then(function (data) {
| |
| return $.grep($.map(data.query.pages, function (x) { return x; })[0].langlinks, function (x) { return x.lang === 'fa'; })[0];
| |
| }).then(function (x) {
| |
| return x['*'];
| |
| });
| |
| }
| |
| | |
| function catParents(title) {
| |
| return $.ajax({
| |
| url: '//en.wikipedia.org/w/api.php',
| |
| data: { action: 'query', prop: 'categories', titles: title, clshow: '!hidden', cllimit: 500, format: 'json' },
| |
| dataType: 'jsonp'
| |
| }).then(function (data) {
| |
| return $.map($.map(data.query.pages, function (x) { return x; })[0].categories, function (x) { return x.title; });
| |
| });
| |
| }
| |
| | |
| $(function () {
| |
| if (wgNamespaceNumber !== 14 || $('.noarticletext').length === 0) {
| |
| return;
| |
| }
| |
| $(mw.util.addPortletLink('p-views', '#', 'ردهساز', 'ca-catmaker'))
| |
| .click(function (e) {
| |
| e.preventDefault();
| |
| var title = prompt('نام ردهٔ معادل انگلیسی؟');
| |
| catParents(title).done(function (x) {
| |
| $.when.apply(null, $.map(x, function (y) { return faWikiName(y); })).done(function () {
| |
| savePage(
| |
| wgPageName,
| |
| $.map(arguments, function (x) { return '[[' + x + ']]'; }).join('\n'),
| |
| 'ایجاد ردهٔ معادل به کمک ابزار ردهساز',
| |
| function () { location.href = location.href; }
| |
| );
| |
| });
| |
| });
| |
| });
| |
| });
| |
(function ($, mw) {
var isVector2022 = mw.config.get('skin') === 'vector-2022';
var portlet = isVector2022 ? 'p-collaboration' : 'p-tb';
$(mw.util.addPortletLink(
portlet,
'//fa.wikipedia.org/wiki/%D9%88%DB%8C%DA%98%D9%87:%D8%B5%D9%81%D8%AD%D9%87%D9%94_%D8%AE%D8%A7%D9%84%DB%8C/tofawiki-conosle?withJS=MediaWiki:TofawikiConsole.js#catmaker',
'رده\u200cساز',
't-catmaker',
'ساخت رده به صورت خودکار'
)).css('font-weight', 'bold').attr('target', '_blank');
}(jQuery, mediaWiki));