مدیاویکی:Gadget-close.js: تفاوت میان نسخهها
ظاهر
imported>Yamaha5 بدون خلاصۀ ویرایش |
imported>Ebrahim به روزرسانی |
||
| خط ۱: | خط ۱: | ||
$(function () { | |||
function answered(sectionId, type){ | 'use strict'; | ||
function answered(sectionId, type) { | |||
$('#answerIcon' + sectionId).hide(); | |||
new mw.Api().get({ | |||
format: 'json', | |||
action: 'query', | |||
titles: mw.config.get('wgPageName'), | |||
prop: 'revisions', | |||
rvprop: 'content', | |||
rvsection: sectionId | |||
}).then(function (data) { | |||
var str = data.query.pages[Object.keys(data.query.pages)[0]].revisions[0]['*']; | |||
var title = (str.match(/^(=+)[^=]*?(\1)$/m) || [''])[0]; | |||
var the_reason = prompt("توضیح در مورد بستن بحث؟"); | |||
if (the_reason.length <= 1) { the_reason = ""; } | |||
if (type === 'request') { | |||
var requestStatus = confirm('آیا درخواست انجام شده است؟ یا ناموفق بود؟'); | |||
var the_reason2 = ""; | |||
if (!requestStatus) { | |||
the_reason2 = "|ناموفق=بله"; | |||
} | } | ||
the_reason = the_reason + ' ~~' + '~~'; | |||
str = str.replace(title, title + "\n{{بسته" + the_reason2 + "}}\n'''" + the_reason + "'''\n"); | |||
str = str + "\n{{پایان بسته}}"; | |||
} | |||
if (type === 'talk') { | |||
the_reason = "|" + the_reason; | |||
str = str.replace(title, title + "\n{{بحث بسته" + the_reason + "}}"); | |||
str = str + "\n{{پایان بسته}}"; | |||
} | |||
if (type === 'done1') { | |||
str = str + "\n:{{شد}} " + the_reason + ' ~~' + '~~'; | |||
} | |||
new mw.Api().post({ | |||
format: 'json', | |||
action: 'edit', | |||
title: mw.config.get('wgPageName'), | |||
section: sectionId, | |||
summary: 'جمعبندی به کمک [[مدیاویکی:Gadget-close.js|ابزار جمعبندی بحث]]', | |||
text: str, | |||
token: mw.user.tokens.get('editToken') | |||
}).then(function () { | |||
mw.notify('انجام شد'); | |||
location.reload(true); | |||
}); | }); | ||
}); | |||
} | |||
} ); | function addLink(sectionId, type, html, color, title) { | ||
} | $(this).before($('<a>', { | ||
id: 'answerIcon' + sectionId, | |||
href: '#', | |||
title: 'جمعبندی بحث', | |||
style: 'float: left; color: ' + color, | |||
html: html | |||
}).click(function (e) { | |||
e.preventDefault(); | |||
answered(sectionId, type); | |||
})); | |||
} | |||
if (wgNamespaceNumber === 3 && wgPageName.search(wgUserName) > 0) { | |||
if(wgNamespaceNumber == 3 && wgPageName.search(wgUserName) > 0){ | $('.mw-headline').each(function (data) { | ||
$('.mw-headline').each(function(data){ | addLink(data + 1, 'talk', '❐', '#090', 'جمعبندی بحث'); | ||
addLink(data + 1, 'done1', '✓', '#003A5C', '✓ شد'); | |||
}); | |||
}else if( | } else if (wgUserGroups.indexOf('sysop') > -1) { | ||
$('.mw-headline').each(function(data){ | $('.mw-headline').each(function (data) { | ||
addLink(data + 1, 'request', '❐', '#090', 'جمعبندی بحث'); | |||
addLink(data + 1, 'done1', '✓', '#003A5C', '✓ شد'); | |||
}); | |||
} | } | ||
}); | }); | ||
نسخهٔ ۲۱ ژانویهٔ ۲۰۱۵، ساعت ۱۷:۴۰
$(function () {
'use strict';
function answered(sectionId, type) {
$('#answerIcon' + sectionId).hide();
new mw.Api().get({
format: 'json',
action: 'query',
titles: mw.config.get('wgPageName'),
prop: 'revisions',
rvprop: 'content',
rvsection: sectionId
}).then(function (data) {
var str = data.query.pages[Object.keys(data.query.pages)[0]].revisions[0]['*'];
var title = (str.match(/^(=+)[^=]*?(\1)$/m) || [''])[0];
var the_reason = prompt("توضیح در مورد بستن بحث؟");
if (the_reason.length <= 1) { the_reason = ""; }
if (type === 'request') {
var requestStatus = confirm('آیا درخواست انجام شده است؟ یا ناموفق بود؟');
var the_reason2 = "";
if (!requestStatus) {
the_reason2 = "|ناموفق=بله";
}
the_reason = the_reason + ' ~~' + '~~';
str = str.replace(title, title + "\n{{بسته" + the_reason2 + "}}\n'''" + the_reason + "'''\n");
str = str + "\n{{پایان بسته}}";
}
if (type === 'talk') {
the_reason = "|" + the_reason;
str = str.replace(title, title + "\n{{بحث بسته" + the_reason + "}}");
str = str + "\n{{پایان بسته}}";
}
if (type === 'done1') {
str = str + "\n:{{شد}} " + the_reason + ' ~~' + '~~';
}
new mw.Api().post({
format: 'json',
action: 'edit',
title: mw.config.get('wgPageName'),
section: sectionId,
summary: 'جمعبندی به کمک [[مدیاویکی:Gadget-close.js|ابزار جمعبندی بحث]]',
text: str,
token: mw.user.tokens.get('editToken')
}).then(function () {
mw.notify('انجام شد');
location.reload(true);
});
});
}
function addLink(sectionId, type, html, color, title) {
$(this).before($('<a>', {
id: 'answerIcon' + sectionId,
href: '#',
title: 'جمعبندی بحث',
style: 'float: left; color: ' + color,
html: html
}).click(function (e) {
e.preventDefault();
answered(sectionId, type);
}));
}
if (wgNamespaceNumber === 3 && wgPageName.search(wgUserName) > 0) {
$('.mw-headline').each(function (data) {
addLink(data + 1, 'talk', '❐', '#090', 'جمعبندی بحث');
addLink(data + 1, 'done1', '✓', '#003A5C', '✓ شد');
});
} else if (wgUserGroups.indexOf('sysop') > -1) {
$('.mw-headline').each(function (data) {
addLink(data + 1, 'request', '❐', '#090', 'جمعبندی بحث');
addLink(data + 1, 'done1', '✓', '#003A5C', '✓ شد');
});
}
});