مدیاویکی:Gadget-CatMaker.js: تفاوت میان نسخهها
ظاهر
imported>Yamaha5 بدون خلاصۀ ویرایش |
imported>Yamaha5 بدون خلاصۀ ویرایش |
||
| خط ۵۰: | خط ۵۰: | ||
//-------------translation------------------ | //-------------translation------------------ | ||
function | 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(c.query.pages, function (x) { return x; })[0].langlinks, function (x) { return x.lang === 'fa'; })[0]; | |||
}); | |||
}). | |||
} | } | ||
function | function catParents(title) { | ||
$.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(c.query.pages, function (x) { return x; })[0].categories, function (x) { return x.title; }) | |||
}); | |||
// | |||
// | |||
function | |||
} | } | ||
نسخهٔ ۲۸ مارس ۲۰۱۴، ساعت ۱۴:۵۳
//-------------------Load and save----------------
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.tokens.get('editToken')
}).done(function (data) {
if (data.error && data.error.info) {
mw.notify(data.error.info);
} else {
callback();
}
}).fail(function (data) {
mw.notify(data);
});
}
function loadSavePageRefresh(page, replaceCallback, summary) {
loadPage(page, function (text) {
savePage(page, replaceCallback(text), summary, function () {
//window.location = mw.util.wikiGetlink(page) + '?action=purge';
});
});
}
//-------------translation------------------
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(c.query.pages, function (x) { return x; })[0].langlinks, function (x) { return x.lang === 'fa'; })[0];
});
}
function catParents(title) {
$.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(c.query.pages, function (x) { return x; })[0].categories, function (x) { return x.title; })
});
}
//var test=GetCategory('ایران')
//--------------------------------------------
$(function () {
if (wgNamespaceNumber !== 14 || $('.noarticletext').length === 0) {
return;
}
$(mw.util.addPortletLink('p-views', '#', 'ردهساز', 'ca-catmaker'))
.click(function (e) {
alert(prompt('نام ردهٔ معادل انگلیسی؟'));
e.preventDefault();
});
});