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

بدون خلاصۀ ویرایش
بدون خلاصۀ ویرایش
خط ۱۴: خط ۱۴:
'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) {
redirectPost(new mw.Uri(mw.config.get('wgScript')).extend({
title: page,
action: 'submit'
}), addWatchthisParamIfAlreadyIsWatched({
wpTextbox1: content,
wpDiff: '',
wpSummary: summary,
wpUltimateParam: 1
}));
}
}


/**
* Save a page
*/
   
function goToEdit() {
        window.location="//"+mw.config.get('wgServerName')+"/w/index.php?title="+mw.config.get('wgPageName')+"&action=submit#continueAbar";
}
    if (window.location.hash=='#continueAbar'){
            var text=$('#wpTextbox1').val()
            setTimeout(function() {
                var newText=persianWikiTools.superTool(text)
                $('#wpTextbox1').val(newText)
                $('#wpSummary').val('ابرابزار')
                setTimeout(function() {
                    document.getElementById('wpDiff').click();
                }, 500);
            }, 2000);
    };
if (mw.config.get('wgAction') === 'view' &&
if (mw.config.get('wgAction') === 'view' &&
mw.config.get('wgIsArticle') &&
mw.config.get('wgIsArticle') &&
mw.config.get('wgUserEditCount')>100&&
mw.config.get('wgUserEditCount') > 100 &&
mw.config.get('wgPageName') !== 'صفحهٔ_اصلی') {
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-cactions', '#', 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 (data) {
page: mw.config.get('wgPageName')
// افزودن میان‌ویکی سنتی به ویکی‌داده به صورت خودکار
}) : '',
if (interwikiFix) {
// اجرای کدهای ربات
$.get('//dexbot.toolforge.org/interwikidata.php', { page: mw.config.get('wgPageName') })
botworks.trigFillcat,
.then(function () {}, function () {});
botworks.trigMissedFileUpload,
}
botworks.trigMissedRef
// اجرای کدهای ربات
]).catch(function () {}).then(function () {
botworks.trigFillcat();
return loadPage(mw.config.get('wgPageName'));
botworks.trigMissedFileUpload();
}).then(function (content) {
botworks.trigMissedRef();
bringShowChanges(
}).then(function (text) {
mw.config.get('wgPageName'),
return goToEdit();
persianWikiTools.superTool(content),
})
'ابرابزار'
});
);
});
});
});
});
}
}


//
// ابزار در حالت ویرایش
// ابزار در حالت ویرایش
//
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);
}
}
خط ۱۹۵: خط ۲۱۳:
}
}
}
}
}
/*
* اجازه می‌دهد که برخی کاربران از دسترسی به ابرابزار محروم شوند
*/
function superToolAllowed() {
return $.inArray(
mw.config.get('wgUserId'),
[
707839 // Viera iran
]
) == -1;
}
}


خط ۳۲۴: خط ۳۳۰:
tools.superTool = buttonGenerator(
tools.superTool = buttonGenerator(
function () {
function () {
if ( superToolAllowed() ) {
applyOnSelection(persianWikiTools.superTool);
applyOnSelection(persianWikiTools.superTool);
} else {
mw.notify('شما اجازهٔ استفاده از ابرابزار را ندارید!');
}
},
},
'ابرابزار',
'ابرابزار',
خط ۳۳۸: خط ۳۴۰:
);
);


/* ابزار املا */
/* ابزار املا  
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.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'