۷٬۰۸۸
ویرایش
Nazarzadeh (بحث | مشارکتها) (صفحهای تازه حاوی «// <nowiki> // DON'T REMOVE THIS LINE EVER ←global jQuery, mediaWiki, persianWikiTools, persianTools: /** * UI code for Persian tools *...» ایجاد کرد) |
Nazarzadeh (بحث | مشارکتها) بدون خلاصۀ ویرایش |
||
(۵ نسخهٔ میانیِ ایجادشده توسط همین کاربر نشان داده نشد) | |||
خط ۱۴: | خط ۱۴: | ||
'use strict'; | 'use strict'; | ||
// | |||
// ابزار در حالت نمایش | // ابزار در حالت نمایش | ||
/ | // | ||
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 | return Object.values(data.query.pages)[0].revisions[0]['*']; | ||
}); | }); | ||
} | } | ||
function | function redirectPost(url, data) { | ||
var | var form = document.createElement('form'); | ||
document.body.appendChild(form); | |||
form.method = '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, | |||
function | action: 'submit' | ||
}), addWatchthisParamIfAlreadyIsWatched({ | |||
wpTextbox1: content, | |||
wpDiff: '', | |||
wpSummary: summary, | |||
wpUltimateParam: 1 | |||
})); | |||
}); | |||
} | } | ||
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(); | ||
var interwikiFix = !$('#t-wikibase').length && | |||
$('.interlanguage-link').length && | |||
$('.wbc-editpage').length; | |||
$(mw.util.addPortletLink( | |||
'p-views', '#', | |||
var interwikiFix = | interwikiFix ? 'ابرابزار+انتقال میانویکی' : 'ابرابزار', | ||
'ca-abar-abzar', | |||
interwikiFix ? | |||
'ابزار پیشرفتهٔ ویرایش متن + ابزار انتقال خودکار میانویکی سنتی به ویکیداده' : | |||
$(mw.util.addPortletLink('p-views', '#', interwikiFix ? 'ابرابزار+انتقال میانویکی' : 'ابرابزار', 'ca-abar-abzar', interwikiFix ? 'ابزار پیشرفتهٔ ویرایش متن + ابزار انتقال خودکار میانویکی سنتی به ویکیداده' : 'ابزار پیشرفتهٔ ویرایش متن')).click(function (e) { | 'ابزار پیشرفتهٔ ویرایش متن' | ||
)).click(function (e) { | |||
e.preventDefault(); | e.preventDefault(); | ||
Promise.all([ | |||
// افزودن میانویکی سنتی به ویکیداده به صورت خودکار | |||
interwikiFix ? | |||
$.get('//dexbot.toolforge.org/interwikidata.php', { | |||
page: mw.config.get('wgPageName') | |||
}) : '', | |||
// اجرای کدهای ربات | |||
botworks.trigFillcat, | |||
botworks.trigMissedFileUpload, | |||
botworks.trigMissedRef | |||
]).catch(function () {}).then(function () { | |||
return loadPage(mw.config.get('wgPageName')); | |||
}).then(function (content) { | |||
bringShowChanges( | |||
mw.config.get('wgPageName'), | |||
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) { | ||
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(). | 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(). | 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( | |||
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. | 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 ( | // ابزار حذف الگوهای ناموجود | ||
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 | 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) { | ||
$('<span>', { | $('<span>', { | ||
id: 'persian-wiki-tools' | id: 'persian-wiki-tools' |