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

بدون خلاصۀ ویرایش
(صفحه‌ای تازه حاوی «// <nowiki> // DON'T REMOVE THIS LINE EVER ←‏global jQuery, mediaWiki, persianWikiTools, persianTools: /** * UI code for Persian tools *...» ایجاد کرد)
 
بدون خلاصۀ ویرایش
 
(۵ نسخهٔ میانیِ ایجادشده توسط همین کاربر نشان داده نشد)
خط ۱۴: خط ۱۴:
'use strict';
'use strict';


//
// ابزار در حالت نمایش
// ابزار در حالت نمایش
/**
//
* Fetch a page
 
*/
function loadPage(title) {
function loadPage(title) {
return new mw.Api().get({
return new mw.Api().get({
خط ۲۶: خط ۲۶:
format: 'json'
format: 'json'
}).then(function (data) {
}).then(function (data) {
return data.query.pages[Object.keys(data.query.pages)[0]].revisions[0]['*'];
return Object.values(data.query.pages)[0].revisions[0]['*'];
});
});
}
}
 
function insertTags ( pre, post, peri ) {
function redirectPost(url, data) {
var current = $( '#wpTextbox1' );
var form = document.createElement('form');
if ( current && current.length ) {
document.body.appendChild(form);
current.textSelection(
form.method = 'post';
'encapsulateSelection', { pre: pre, peri: peri, post: post }
form.action = url;
);
for (var name in data) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = name;
input.value = data[name];
form.appendChild(input);
}
form.submit();
}
function addWatchthisParamIfAlreadyIsWatched(object) {
// if unwatch button exists it is in the user's watchlist right now
if ($('#ca-unwatch').length) {
object.wpWatchthis = '';
}
}
return object;
}
}
 
/**
function bringShowChanges(page, content, summary) {
* Save a page
redirectPost(new mw.Uri(mw.config.get('wgScript')).extend({
*/
title: page,
function savePage(title, text, summary) {
action: 'submit'
return new mw.Api().post({
}), addWatchthisParamIfAlreadyIsWatched({
action: 'edit',
wpTextbox1: content,
title: title,
wpDiff: '',
text: text,
wpSummary: summary,
summary: summary,
wpUltimateParam: 1
nocreate: '',
}));
minor: '',
token: mw.user.tokens.get('editToken')
});
}
}


if (mw.config.get('wgAction') === 'view' &&
if (mw.config.get('wgAction') === 'view' &&
mw.config.get('wgIsArticle') &&
mw.config.get('wgIsArticle') &&
mw.config.get('wgPageName') !== 'صفحهٔ_اصلی') {
mw.config.get('wgUserEditCount') > 100 &&
mw.config.get('wgPageName') !== 'صفحهٔ_اصلی' &&
$('#mw-imagepage-nofile, #noarticletext').length === 0 &&
mw.config.get('wgNamespaceNumber') !== 6 &&
mw.config.get('wgNamespaceNumber') !== 8) {
$('#ca-abar-abzar').remove();
$('#ca-abar-abzar').remove();
if ($('#mw-imagepage-nofile, #noarticletext').length !== 0 ||
var interwikiFix = !$('#t-wikibase').length &&
mw.config.get('wgNamespaceNumber') === 6 ||
$('.interlanguage-link').length &&
mw.config.get('wgNamespaceNumber') === 8) {
$('.wbc-editpage').length;
return;
$(mw.util.addPortletLink(
}
'p-views', '#',
var interwikiFix = false;
interwikiFix ? 'ابرابزار+انتقال میان‌ویکی' : 'ابرابزار',
if (!$('#t-wikibase').length && $('.interlanguage-link').length && $('.wbc-editpage').length) {
'ca-abar-abzar',
interwikiFix = true;
interwikiFix ?
}
'ابزار پیشرفتهٔ ویرایش متن + ابزار انتقال خودکار میان‌ویکی سنتی به ویکی‌داده' :
$(mw.util.addPortletLink('p-views', '#', interwikiFix ? 'ابرابزار+انتقال میان‌ویکی' : 'ابرابزار', 'ca-abar-abzar', interwikiFix ? 'ابزار پیشرفتهٔ ویرایش متن + ابزار انتقال خودکار میان‌ویکی سنتی به ویکی‌داده' : 'ابزار پیشرفتهٔ ویرایش متن')).click(function (e) {
'ابزار پیشرفتهٔ ویرایش متن'
)).click(function (e) {
e.preventDefault();
e.preventDefault();
mw.loader.using('oojs-ui').then(function () {
Promise.all([
OO.ui.confirm('اجرای ابرابزار بر این صفحه؟ مسئولیت ویرایش ابرابزار با شما خواهد بود').then(function (confirmed) {
// افزودن میان‌ویکی سنتی به ویکی‌داده به صورت خودکار
if (!confirmed) return;
interwikiFix ?
$.get('//dexbot.toolforge.org/interwikidata.php', {
return loadPage(mw.config.get('wgPageName')).then(function (text) {
page: mw.config.get('wgPageName')
return savePage(
}) : '',
mw.config.get('wgPageName'),
// اجرای کدهای ربات
persianWikiTools.superTool(text),
botworks.trigFillcat,
'ویرایش به‌وسیلهٔ [[' + (mw.config.get('wgServerName') !== 'fa.wikipedia.org' ? ':w:fa:' : '') + 'وپ:ابرابزار|ابرابزار]]: '
botworks.trigMissedFileUpload,
);
botworks.trigMissedRef
}).then(function (data) {
]).catch(function () {}).then(function () {
mw.notify('اجرای ابرابزار بر محتویات این صفحه…');
return loadPage(mw.config.get('wgPageName'));
// افزودن میان‌ویکی سنتی به ویکی‌داده به صورت خودکار
}).then(function (content) {
if (interwikiFix) {
bringShowChanges(
$.get('//tools.wmflabs.org/dexbot/interwikidata.php', { page: mw.config.get('wgPageName') })
mw.config.get('wgPageName'),
.then(function () {}, function () {});
persianWikiTools.superTool(content),
}
'ابرابزار'
// اجرای کدهای ربات
);
botworks.trigFillcat();
botworks.trigMissedFileUpload();
botworks.trigMissedRef();
if (data.error) {
mw.notify('ویرایش موفقیت‌آمیز نبود، دوباره تلاش کنید: ' + data.error.info);
} else if (data.edit && data.edit.result === 'Success') {
if (data.edit.nochange !== undefined) {
mw.notify('تغییری در صفحه ایجاد نشد.');
} else {
mw.notify('ویرایش با موفقیت انجام پذیرفت');
// Loading diff page
window.location = new mw.Uri(mw.config.get('wgScript')).extend({
title: mw.config.get('wgPageName'),
diff: data.edit.newrevid
});
}
} else {
mw.notify('ویرایش در صفحه موفقیت‌آمیز نبود.');
}
});
});
});
});
});
});
}
}


//
// ابزار در حالت ویرایش
// ابزار در حالت ویرایش
//
function insertTags(pre, post, peri) {
if ($('#wpTextbox1').length) {
$('#wpTextbox1').textSelection(
'encapsulateSelection', { pre: pre, peri: peri, post: post }
);
}
}
/**
/**
* Adds edit summary
* Adds edit summary
*/
*/
function addEditSummary(summaryText, replaceSummary) {
function addEditSummary(summaryText, replaceSummary) {
                if (mw.util.getParamValue("section")==='new'){
return;
}
if (summaryText === '') {
return;
}
var summary = $('input#wpSummary, #wpSummary > input'),
var summary = $('input#wpSummary, #wpSummary > input'),
summaryPrefix = '',
summaryPrefix = '',
pos;
pos;
if (summary.length === 0) {
if (mw.util.getParamValue('section') === 'new' ||
summaryText === '' || summary.length === 0) {
return;
return;
}
}
if (summary.val().indexOf('*/ ') > -1) {
if (summary.val().includes('*/ ')) {
pos = summary.val().indexOf('*/ ');
pos = summary.val().indexOf('*/ ');
summaryPrefix = summary.val().substr(0, pos + 3);
summaryPrefix = summary.val().substr(0, pos + 3);
خط ۱۳۹: خط ۱۴۰:
summary.val(summary.val() + summaryText);
summary.val(summary.val() + summaryText);
} else {
} else {
if (summary.val().indexOf(summaryText) === -1) { // do not repeat in edit summary
if (!summary.val().includes(summaryText)) { // do not repeat in edit summary
summary.val(summary.val() + '، ' + summaryText);
summary.val(summary.val() + '، ' + summaryText);
}
}
خط ۲۸۳: خط ۲۸۴:
//عدم تغییر در متن بحث‌ها، سیاست‌ها در فضاهای نام دیگر
//عدم تغییر در متن بحث‌ها، سیاست‌ها در فضاهای نام دیگر
if (mw.config.get('wgNamespaceNumber') === 0) {
/*if (mw.config.get('wgNamespaceNumber') === 0) {
/* برداشتن پیوند تاریخ‌ها */
برداشتن پیوند تاریخ‌ها  
tools.fixBadLinks = buttonGenerator(
tools.fixBadLinks = buttonGenerator(
function () {
function () {
خط ۲۹۶: خط ۲۹۷:
'datelinks'
'datelinks'
);
);
}
}*/


/* یونیکد نشانی وب */
/* یونیکد نشانی وب */
خط ۳۳۹: خط ۳۴۰:
);
);


/* ابزار املا */
/* ابزار املا  
tools.dictation = buttonGenerator(
tools.dictation = buttonGenerator(
function () {
function () {
خط ۳۵۱: خط ۳۵۲:
'dictation'
'dictation'
);
);
 
*/
/* ابرابزار مخصوص صفحه انتقال */
/* ابرابزار مخصوص صفحه انتقال */
tools.superToolMove = buttonGenerator(
tools.superToolMove = buttonGenerator(
خط ۳۷۹: خط ۳۸۰:


// Buttons that add tags
// Buttons that add tags
/* برچسب ویکی\u200cسازی *//*
/* برچسب ویکی\u200cسازی  
tools.wikify = buttonGenerator(
tools.wikify = buttonGenerator(
function () {
function () {
خط ۳۹۱: خط ۳۹۲:
'wikify'
'wikify'
);
);
 
*/
/* بدون منبع *//*
/* بدون منبع  
tools.noSource = buttonGenerator(
tools.noSource = buttonGenerator(
function () {
function () {
خط ۴۰۴: خط ۴۰۵:
'no-source'
'no-source'
);
);
 
*/
/* حذف سریع *//*
/* حذف سریع  
tools.speedyDel = buttonGenerator(
tools.speedyDel = buttonGenerator(
function () {
function () {
خط ۴۱۹: خط ۴۲۰:
'delete-vote'
'delete-vote'
);
);
 
*/
/* حذف زماندار *//*
/* حذف زماندار  
tools.prod = buttonGenerator(
tools.prod = buttonGenerator(
function () {
function () {
خط ۴۳۴: خط ۴۳۵:
'attendre'
'attendre'
);
);
 
*/
/* منبع تصویر نامعلوم *//*
/* منبع تصویر نامعلوم  
tools.picSource = buttonGenerator(
tools.picSource = buttonGenerator(
function () {
function () {
خط ۴۴۷: خط ۴۴۸:
'image-source'
'image-source'
);
);
 
*/
/* حق تکثیر تصویر نامعلوم *//*
/* حق تکثیر تصویر نامعلوم  
tools.picCopy = buttonGenerator(
tools.picCopy = buttonGenerator(
function () {
function () {
خط ۴۶۰: خط ۴۶۱:
'image-copyright'
'image-copyright'
);
);
 
*/
/* تمیزکاری *//*
/* تمیزکاری  
tools.cleanup = buttonGenerator(
tools.cleanup = buttonGenerator(
function () {
function () {
خط ۴۷۴: خط ۴۷۵:
);
);
*/
*/
/* اخطار نگاره *//*
/* اخطار نگاره  
tools.imgWarn = buttonGenerator(
tools.imgWarn = buttonGenerator(
function () {
function () {
خط ۴۹۲: خط ۴۹۳:
);
);
*/
*/
/* حق تکثیر مشکوک *//*
/* حق تکثیر مشکوک  
tools.sus = buttonGenerator(
tools.sus = buttonGenerator(
function () {
function () {
خط ۵۰۵: خط ۵۰۶:
);
);
*/
*/
/* نقض حق تکثیر *//*
/* نقض حق تکثیر  
tools.copyR = buttonGenerator(
tools.copyR = buttonGenerator(
function () {
function () {
خط ۵۲۳: خط ۵۲۴:
);
);
*/
*/
/* لحن نامناسب */
/* لحن نامناسب  
/*tools.tone = buttonGenerator(
tools.tone = buttonGenerator(
function () {
function () {
$('#wpTextbox1').val('{' + '{لحن نامناسب}}\n' + $('#wpTextbox1').val());
$('#wpTextbox1').val('{' + '{لحن نامناسب}}\n' + $('#wpTextbox1').val());
خط ۵۵۲: خط ۵۵۳:
'toggle-dir'
'toggle-dir'
);
);
tools.putSelectionInBDI = buttonGenerator(
function () {
applyOnSelection(persianWikiTools.putSelectionInBDI);
},
'جداسازی دوجهته',
false,
'//upload.wikimedia.org/wikipedia/commons/3/31/Button_bdi_tag.png',
'جداسازی دوجهته',
'دوجهته',
'put-in-bdi'
);


/* پیوند درونی */
/* پیوند درونی */
خط ۵۷۹: خط ۵۹۴:
);
);


/* توضیح */
/* توضیح  
tools.commentButton = buttonGenerator(
tools.commentButton = buttonGenerator(
function () {
function () {
خط ۵۹۱: خط ۶۰۶:
'hide-comment'
'hide-comment'
);
);
 
*/
/* ملزومات مقاله *//*
/* ملزومات مقاله  
tools.addEssentialThings = buttonGenerator(
tools.addEssentialThings = buttonGenerator(
function () {
function () {
خط ۶۰۳: خط ۶۱۸:
'ملزومات مقاله',
'ملزومات مقاله',
'add-note'
'add-note'
);
);*/
/* خوشامدید *//*
/* خوشامدید  
tools.welcome = buttonGenerator(
tools.welcome = buttonGenerator(
function () {
function () {
خط ۶۱۹: خط ۶۳۴:
'خوشامد',
'خوشامد',
'alien-cool'
'alien-cool'
);
);*/
/* چپچین */
/* چپچین */
tools.chapChin = buttonGenerator(
tools.chapChin = buttonGenerator(
خط ۶۳۷: خط ۶۵۲:
);
);


/* اندیس بالا */
/* اندیس بالا  
tools.upperText = buttonGenerator(
tools.upperText = buttonGenerator(
function () {
function () {
خط ۶۴۹: خط ۶۶۴:
'upper-letter'
'upper-letter'
);
);
 
*/
/* اندیس پایین */
/* اندیس پایین  
tools.lowerText = buttonGenerator(
tools.lowerText = buttonGenerator(
function () {
function () {
خط ۶۶۲: خط ۶۷۷:
'lower-letter'
'lower-letter'
);
);
 
*/
/* تغییرمسیر */
/* تغییرمسیر  
tools.redirectButton = buttonGenerator(
tools.redirectButton = buttonGenerator(
function () {
function () {
خط ۶۸۰: خط ۶۹۵:
'redirect'
'redirect'
);
);
 
*/
/* سال میلادی */
/* سال میلادی */
tools.gregYear = buttonGenerator(
tools.gregYear = buttonGenerator(
خط ۷۰۱: خط ۷۱۶:
tools.sortText = buttonGenerator(
tools.sortText = buttonGenerator(
function () {
function () {
applyOnSelection(persianTools.persianSortText);
applyOnSelection(function (text) {
return persianTools.persianSort(text.split('\n')).join('\n');
});
},
},
'',
'',
خط ۷۱۱: خط ۷۲۸:
);
);


/* شد! */
/* شد!  
tools.shod = buttonGenerator(
tools.shod = buttonGenerator(
function () {
function () {
خط ۷۲۲: خط ۷۳۹:
'شد',
'شد',
'check'
'check'
);
);*/
  /* عدد انگلیسی */
/* عدد انگلیسی */
tools.toEnNumRobust = buttonGenerator(
tools.toEnNumRobust = buttonGenerator(
function () {
function () {
خط ۷۳۵: خط ۷۵۲:
'ToEnNumberRobust'
'ToEnNumberRobust'
);
);
/* حذف ویکی‌سازی */
/* حذف ویکی‌سازی  
tools.removeWiki = buttonGenerator(
tools.removeWiki = buttonGenerator(
function () {
function () {
خط ۷۴۶: خط ۷۶۳:
'حذف ویکی‌سازی',
'حذف ویکی‌سازی',
'removeWiki'
'removeWiki'
);
);*/
$(function () {
$(function () {
if (typeof Array.prototype.includes !== 'function') {
mw.log.error('Script not supported by browser.');
return;
}
// کد مناسب ویرایشگر جدید متنی
// کد مناسب ویرایشگر جدید متنی
/*mw.hook('ve.activationComplete').add(function () {
/*mw.hook('ve.activationComplete').add(function () {
خط ۷۵۶: خط ۷۷۷:
x.innerText = persianWikiTools.superTool(x.innerText);
x.innerText = persianWikiTools.superTool(x.innerText);
});
});
            }));
}));
}
}
});*/
});*/
خط ۷۶۴: خط ۷۸۵:
space = ' ';
space = ' ';


extraEditButtons = extraEditButtons.concat(tools.toggleDirection, space, tools.ykArabic, tools.zwnj, tools.applyOrthography,
extraEditButtons = extraEditButtons.concat(tools.toggleDirection, tools.putSelectionInBDI, space, tools.ykArabic, tools.zwnj, tools.applyOrthography,
tools.dig, tools.punc, tools.dictation, tools.superTool, space, tools.urlFix, tools.fixBadLinks, space, tools.welcome,
tools.dig, tools.punc, tools.dictation, tools.superTool, space, tools.urlFix, tools.fixBadLinks, space, tools.welcome,
tools.addEssentialThings, tools.noSource, tools.sus, tools.tone, tools.wikify,
tools.addEssentialThings, tools.noSource, tools.sus, tools.tone, tools.wikify,
tools.shod, tools.cleanup, tools.speedyDel, tools.prod, space, tools.redirectButton,
tools.shod, tools.cleanup, tools.speedyDel, tools.prod, space, tools.redirectButton,
tools.gregYear, tools.strikeTextButton, tools.chapChin, tools.commentButton, space, tools.sortText, space, tools.picCopy, tools.picSource, space, tools.toEnNumRobust);
tools.gregYear, tools.strikeTextButton, tools.chapChin, tools.commentButton, space, tools.sortText, space, tools.picCopy, tools.picSource, space, tools.toEnNumRobust);
        // شرط برای کاربری که گشت خودکار دارد
var userGroups = mw.config.get('wgUserGroups', []);
        // ابزار حذف الگوهای ناموجود
// شرط برای کاربری که گشت خودکار دارد
if ((mw.config.get('wgUserGroups').indexOf('autopatrolled') > -1 ||mw.config.get('wgUserGroups').indexOf('eliminator') > -1 ||mw.config.get('wgUserGroups').indexOf('sysop') > -1)) {
// ابزار حذف الگوهای ناموجود
        extraEditButtons = extraEditButtons.concat(tools.removeWiki);
if (userGroups.includes('autopatrolled') ||
        };
userGroups.includes('eliminator') ||
userGroups.includes('sysop')) {
extraEditButtons = extraEditButtons.concat(tools.removeWiki);
}
extraEditButtons = extraEditButtons.concat(space).concat(window.userCustomEditButtons || []);
extraEditButtons = extraEditButtons.concat(space).concat(window.userCustomEditButtons || []);


خط ۷۸۰: خط ۸۰۴:


$('#persian-wiki-tools').remove();
$('#persian-wiki-tools').remove();
if ($('#wpTextbox1').length !== 0) {
if ($('#wpTextbox1').length) {
$('<div>', {
$('<div>', {
id: 'persian-wiki-tools',
id: 'persian-wiki-tools',
خط ۷۸۶: خط ۸۱۰:
style: 'float:right;'
style: 'float:right;'
}).append(extraEditButtons).insertBefore('#wpTextbox1');
}).append(extraEditButtons).insertBefore('#wpTextbox1');
}
} else if ($('#movepage').length) {
if ($('#movepage').length !== 0) {
$('<span>', {
$('<span>', {
id: 'persian-wiki-tools'
id: 'persian-wiki-tools'