مدیاویکی:Gadget-Extra-Editbuttons.js: تفاوت میان نسخهها
ظاهر
imported>علیرضا حذف کدهای مربوط به خوشآمدگویی؛ زیرا خوشآمدگویی با ربات انجام میشود و در ابزار تذکر هم وجود دارد. |
imported>علیرضا reindent + virtual space replaced with '\ u200c' (to prevent from silently removed by one or more browsers) |
||
| خط ۱۲: | خط ۱۲: | ||
* * [[مدیاویکی:Gadget-Extra-Editbuttons-autoed.js]] | * * [[مدیاویکی:Gadget-Extra-Editbuttons-autoed.js]] | ||
*/ | */ | ||
(function ($, mw) { | (function($, mw) { | ||
'use strict'; | 'use strict'; | ||
| خط ۲۶: | خط ۲۶: | ||
rvprop: 'content', | rvprop: 'content', | ||
format: 'json' | format: 'json' | ||
}).then(function (data) { | }).then(function(data) { | ||
return $.map(data.query.pages, function (value) { return value; })[0].revisions[0]['*']; | return $.map(data.query.pages, function(value) { | ||
return value; | |||
})[0].revisions[0]['*']; | |||
}); | }); | ||
} | } | ||
| خط ۴۷: | خط ۴۹: | ||
/** | /** | ||
* Load and save a page | * Load and save a page | ||
*/ | */ | ||
function loadSavePage(editorDelegate, summary) { | function loadSavePage(editorDelegate, summary) { | ||
return loadPage(mw.config.get('wgPageName')).then(function (text) { | return loadPage(mw.config.get('wgPageName')).then(function(text) { | ||
return savePage(mw.config.get('wgPageName'), editorDelegate(text), summary); | return savePage(mw.config.get('wgPageName'), editorDelegate(text), summary); | ||
}); | }); | ||
| خط ۵۶: | خط ۵۸: | ||
if (mw.config.get('wgAction') === 'view' && | if (mw.config.get('wgAction') === 'view' && | ||
mw.config.get('wgIsArticle') && | |||
mw.config.get('wgPageName') !== 'صفحهٔ_اصلی') { | |||
$.when($.ready, mw.loader.using('jquery.ui.dialog')).then(function () { | $.when($.ready, mw.loader.using('jquery.ui.dialog')).then(function() { | ||
$('#ca-abar-abzar').remove(); | $('#ca-abar-abzar').remove(); | ||
if ($('#mw-imagepage-nofile, #noarticletext').length !== 0 || | if ($('#mw-imagepage-nofile, #noarticletext').length !== 0 || | ||
mw.config.get('wgNamespaceNumber') === 6 || | |||
mw.config.get('wgNamespaceNumber') === 8) { | |||
return; | return; | ||
} | } | ||
$(mw.util.addPortletLink('p-views', '#', 'ابرابزار', 'ca-abar-abzar')).click(function (e) { | $(mw.util.addPortletLink('p-views', '#', 'ابرابزار', 'ca-abar-abzar')).click(function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
$( | $( | ||
'<div><div>مطمئنید می\u200cخواهید ویرایشی خودکار جهت اصلاح متن این صفحه به کمک ابرابزار داشته باشید؟</h6><br><br>بعد از انجام ویرایش باید ویرایش | '<div><div>مطمئنید می\u200cخواهید ویرایشی خودکار جهت اصلاح متن این صفحه به کمک ابرابزار داشته باشید؟</h6><br><br>بعد از انجام ویرایش باید ویرایش انجام\u200cشده را از نظر درستی بررسی کنید <b>زیرا مسئولیت تغییرات ابرابزار با شماست!</b></div>' | ||
).dialog({ | ).dialog({ | ||
modal: true, | modal: true, | ||
| خط ۷۴: | خط ۷۶: | ||
resizable: false, | resizable: false, | ||
buttons: { | buttons: { | ||
'بله': function () { | 'بله': function() { | ||
loadSavePage( | loadSavePage( | ||
persianWikiTools.superTool, | persianWikiTools.superTool, | ||
'/' + '* ویرایش به وسیلهٔ [[' + (mw.config.get('wgServerName') !== 'fa.wikipedia.org' ? ':w:fa:' : '') + 'وپ:ابرابزار|ابرابزار]] *' + '/' | '/' + '* ویرایش به وسیلهٔ [[' + (mw.config.get('wgServerName') !== 'fa.wikipedia.org' ? ':w:fa:' : '') + 'وپ:ابرابزار|ابرابزار]] *' + '/' | ||
).then(function (data) { | ).then(function(data) { | ||
if (data.error) { | if (data.error) { | ||
mw.notify('ویرایش موفقیت آمیز نبود: ' + data.error.info); | mw.notify('ویرایش موفقیت آمیز نبود: ' + data.error.info); | ||
| خط ۹۳: | خط ۹۵: | ||
} | } | ||
} else { | } else { | ||
mw.notify('ویرایش در صفحه | mw.notify('ویرایش در صفحه موفقیت\u200cآمیر نبود.'); | ||
} | } | ||
}, function (error) { | }, function(error) { | ||
mw.notify(error); | mw.notify(error); | ||
}); | }); | ||
$(this).dialog("close"); | $(this).dialog("close"); | ||
}, | }, | ||
'خیر': function () { | 'خیر': function() { | ||
$(this).dialog("close"); | $(this).dialog("close"); | ||
} | } | ||
}, | }, | ||
close: function () { | close: function() { | ||
$(this).remove(); | $(this).remove(); | ||
} | } | ||
| خط ۱۲۱: | خط ۱۲۳: | ||
return; | return; | ||
} | } | ||
var summary = $('.editOptions #wpSummary'), summaryPrefix = '', pos; | var summary = $('.editOptions #wpSummary'), | ||
summaryPrefix = '', | |||
pos; | |||
if (summary.length === 0) { | if (summary.length === 0) { | ||
return; | return; | ||
| خط ۱۵۱: | خط ۱۵۵: | ||
addEditSummary(summaryText, replaceSummary); | addEditSummary(summaryText, replaceSummary); | ||
} | } | ||
var button = $('<span>', { id: 'persian-wiki-tools-' + idSuffix }).click(clickCallback).append( | var button = $('<span>', { | ||
id: 'persian-wiki-tools-' + idSuffix | |||
}).click(clickCallback).append( | |||
$('<img>').attr({ | $('<img>').attr({ | ||
src: image, | src: image, | ||
title: title, | title: title, | ||
alt: alt | alt: alt | ||
}).on("error", function () { | }).on("error", function() { | ||
button.replaceWith($('<button>', { text: alt }).click(clickCallback)); | button.replaceWith($('<button>', { | ||
text: alt | |||
}).click(clickCallback)); | |||
}) | }) | ||
); | ); | ||
| خط ۲۱۰: | خط ۲۱۸: | ||
/* ی ک */ | /* ی ک */ | ||
tools.ykArabic = buttonGenerator( | tools.ykArabic = buttonGenerator( | ||
function () { applyOnSelection(persianTools.toStandardPersianCharacters); }, | function() { | ||
applyOnSelection(persianTools.toStandardPersianCharacters); | |||
}, | |||
'اصلاح نویسه\u200cهای عربی', | 'اصلاح نویسه\u200cهای عربی', | ||
false, | false, | ||
| خط ۲۲۱: | خط ۲۳۱: | ||
/* فاصلهٔ مجازی */ | /* فاصلهٔ مجازی */ | ||
tools.zwnj = buttonGenerator( | tools.zwnj = buttonGenerator( | ||
function () { applyOnSelection(persianWikiTools.wikiApplyZwnj); }, | function() { | ||
applyOnSelection(persianWikiTools.wikiApplyZwnj); | |||
}, | |||
'اصلاح فاصلهٔ مجازی', | 'اصلاح فاصلهٔ مجازی', | ||
false, | false, | ||
| خط ۲۳۰: | خط ۲۴۲: | ||
); | ); | ||
/* اصلاح | /* اصلاح نویسه\u200cها و حالت\u200cهای غیراستاندارد */ | ||
tools.applyOrthography = buttonGenerator( | tools.applyOrthography = buttonGenerator( | ||
function () { applyOnSelection(persianWikiTools.wikiApplyOrthography); }, | function() { | ||
applyOnSelection(persianWikiTools.wikiApplyOrthography); | |||
}, | |||
'اصلاح نویسه', | 'اصلاح نویسه', | ||
false, | false, | ||
'//upload.wikimedia.org/wikipedia/fa/9/94/Button_non_standard.png', | '//upload.wikimedia.org/wikipedia/fa/9/94/Button_non_standard.png', | ||
'اصلاح | 'اصلاح نویسه\u200cها و حالت\u200cهای غیراستاندارد', | ||
'اصلاح | 'اصلاح نویسه\u200cها و حالت\u200cهای غیراستاندارد', | ||
'apply-orthography' | 'apply-orthography' | ||
); | ); | ||
| خط ۲۴۳: | خط ۲۵۷: | ||
/* اصلاح ارقام */ | /* اصلاح ارقام */ | ||
tools.dig = buttonGenerator( | tools.dig = buttonGenerator( | ||
function () { applyOnSelection(persianWikiTools.wikiTextDigitsToPersian); }, | function() { | ||
applyOnSelection(persianWikiTools.wikiTextDigitsToPersian); | |||
}, | |||
'اصلاح ارقام', | 'اصلاح ارقام', | ||
false, | false, | ||
| خط ۲۵۴: | خط ۲۷۰: | ||
/* اصلاح ارقام مخصوص صفحه انتقال */ | /* اصلاح ارقام مخصوص صفحه انتقال */ | ||
tools.digMove = buttonGenerator( | tools.digMove = buttonGenerator( | ||
function () { applyOnSelection(persianWikiTools.wikiConvertToPersianCharacters); }, | function() { | ||
applyOnSelection(persianWikiTools.wikiConvertToPersianCharacters); | |||
}, | |||
'اصلاح ارقام', | 'اصلاح ارقام', | ||
false, | false, | ||
| خط ۲۶۵: | خط ۲۸۳: | ||
/* یونیکد نشانی وب */ | /* یونیکد نشانی وب */ | ||
tools.urlFix = buttonGenerator( | tools.urlFix = buttonGenerator( | ||
function () { applyOnSelection(persianWikiTools.wikiUrlMinifier); }, | function() { | ||
applyOnSelection(persianWikiTools.wikiUrlMinifier); | |||
}, | |||
'اصلاح نشانی وب', | 'اصلاح نشانی وب', | ||
false, | false, | ||
| خط ۲۷۶: | خط ۲۹۶: | ||
/* اصلاح علامت @ */ | /* اصلاح علامت @ */ | ||
tools.atSignFix = buttonGenerator( | tools.atSignFix = buttonGenerator( | ||
function () { | function() { | ||
applyOnSelection(function (text) { | applyOnSelection(function(text) { | ||
return text.replace(/(\S+?)@(\S+?)/g, '$1{{at}}$2'); | return text.replace(/(\S+?)@(\S+?)/g, '$1{{at}}$2'); | ||
}); | }); | ||
| خط ۲۹۱: | خط ۳۱۱: | ||
/* ابرابزار */ | /* ابرابزار */ | ||
tools.superTool = buttonGenerator( | tools.superTool = buttonGenerator( | ||
function () { | function() { | ||
applyOnSelection(persianWikiTools.superTool); | applyOnSelection(persianWikiTools.superTool); | ||
}, | }, | ||
| خط ۳۰۴: | خط ۳۲۴: | ||
/* ابزار املا */ | /* ابزار املا */ | ||
tools.dictation = buttonGenerator( | tools.dictation = buttonGenerator( | ||
function () { applyOnSelection(persianWikiTools.wikiDictation); }, | function() { | ||
applyOnSelection(persianWikiTools.wikiDictation); | |||
}, | |||
'اصلاح املا', | 'اصلاح املا', | ||
false, | false, | ||
| خط ۳۱۵: | خط ۳۳۷: | ||
/* ابرابزار مخصوص صفحه انتقال */ | /* ابرابزار مخصوص صفحه انتقال */ | ||
tools.superToolMove = buttonGenerator( | tools.superToolMove = buttonGenerator( | ||
function () { | function() { | ||
applyOnSelection(persianWikiTools.superToolMove); | applyOnSelection(persianWikiTools.superToolMove); | ||
}, | }, | ||
| خط ۳۲۸: | خط ۳۵۰: | ||
/* اصلاحات قراردادن نقطه */ | /* اصلاحات قراردادن نقطه */ | ||
tools.punc = buttonGenerator( | tools.punc = buttonGenerator( | ||
function () { applyOnSelection(persianWikiTools.wikiPunctuation); }, | function() { | ||
applyOnSelection(persianWikiTools.wikiPunctuation); | |||
}, | |||
'اصلاح سجاوندی', | 'اصلاح سجاوندی', | ||
false, | false, | ||
| خط ۳۴۰: | خط ۳۶۴: | ||
/* برچسب ویکی\u200cسازی */ | /* برچسب ویکی\u200cسازی */ | ||
tools.wikify = buttonGenerator( | tools.wikify = buttonGenerator( | ||
function () { | function() { | ||
$('#wpTextbox1').val('{{ویکی\u200cسازی}}\n' + $('#wpTextbox1').val()); | $('#wpTextbox1').val('{{ویکی\u200cسازی}}\n' + $('#wpTextbox1').val()); | ||
}, | }, | ||
| خط ۳۵۳: | خط ۳۷۷: | ||
/* بدون منبع */ | /* بدون منبع */ | ||
tools.noSource = buttonGenerator( | tools.noSource = buttonGenerator( | ||
function () { | function() { | ||
$('#wpTextbox1').val('{{بدون منبع}}\n' + $('#wpTextbox1').val()); | $('#wpTextbox1').val('{{بدون منبع}}\n' + $('#wpTextbox1').val()); | ||
}, | }, | ||
| خط ۳۶۶: | خط ۳۹۰: | ||
/* حذف سریع */ | /* حذف سریع */ | ||
tools.speedyDel = buttonGenerator( | tools.speedyDel = buttonGenerator( | ||
function () { | function() { | ||
var temp = $('#wpTextbox1').val(); | var temp = $('#wpTextbox1').val(); | ||
$('#wpTextbox1').val(''); | $('#wpTextbox1').val(''); | ||
| خط ۳۸۱: | خط ۴۰۵: | ||
/* حذف زماندار */ | /* حذف زماندار */ | ||
tools.prod = buttonGenerator( | tools.prod = buttonGenerator( | ||
function () { | function() { | ||
var temp = $('#wpTextbox1').val(); | var temp = $('#wpTextbox1').val(); | ||
$('#wpTextbox1').val(''); | $('#wpTextbox1').val(''); | ||
| خط ۳۹۶: | خط ۴۲۰: | ||
/* منبع تصویر نامعلوم */ | /* منبع تصویر نامعلوم */ | ||
tools.picSource = buttonGenerator( | tools.picSource = buttonGenerator( | ||
function () { | function() { | ||
$('#wpTextbox1').val('{{منبع تصویر نامعلوم}}\n' + $('#wpTextbox1').val()); | $('#wpTextbox1').val('{{منبع تصویر نامعلوم}}\n' + $('#wpTextbox1').val()); | ||
}, | }, | ||
| خط ۴۰۹: | خط ۴۳۳: | ||
/* حق تکثیر تصویر نامعلوم */ | /* حق تکثیر تصویر نامعلوم */ | ||
tools.picCopy = buttonGenerator( | tools.picCopy = buttonGenerator( | ||
function () { | function() { | ||
$('#wpTextbox1').val('{{جا:حق تکثیر تصویر نامعلوم}}\n' + $('#wpTextbox1').val()); | $('#wpTextbox1').val('{{جا:حق تکثیر تصویر نامعلوم}}\n' + $('#wpTextbox1').val()); | ||
}, | }, | ||
| خط ۴۲۲: | خط ۴۴۶: | ||
/* تمیزکاری */ | /* تمیزکاری */ | ||
tools.cleanup = buttonGenerator( | tools.cleanup = buttonGenerator( | ||
function () { | function() { | ||
$('#wpTextbox1').val('{{تمیزکاری}}\n' + $('#wpTextbox1').val()); | $('#wpTextbox1').val('{{تمیزکاری}}\n' + $('#wpTextbox1').val()); | ||
}, | }, | ||
| خط ۴۳۵: | خط ۴۵۹: | ||
/* اخطار نگاره */ | /* اخطار نگاره */ | ||
tools.imgWarn = buttonGenerator( | tools.imgWarn = buttonGenerator( | ||
function () { | function() { | ||
$('#wpTextbox1').val(''); | $('#wpTextbox1').val(''); | ||
mw.toolbar.insertTags( | mw.toolbar.insertTags( | ||
| خط ۴۵۳: | خط ۴۷۷: | ||
/* حق تکثیر مشکوک */ | /* حق تکثیر مشکوک */ | ||
tools.sus = buttonGenerator( | tools.sus = buttonGenerator( | ||
function () { | function() { | ||
$('#wpTextbox1').val('{{حق تکثیر مشکوک}}\n' + $('#wpTextbox1').val()); | $('#wpTextbox1').val('{{حق تکثیر مشکوک}}\n' + $('#wpTextbox1').val()); | ||
}, | }, | ||
| خط ۴۶۶: | خط ۴۹۰: | ||
/* نقض حق تکثیر */ | /* نقض حق تکثیر */ | ||
tools.copyR = buttonGenerator( | tools.copyR = buttonGenerator( | ||
function () { | function() { | ||
$('#wpTextbox1').val(''); | $('#wpTextbox1').val(''); | ||
mw.toolbar.insertTags( | mw.toolbar.insertTags( | ||
| خط ۴۸۴: | خط ۵۰۸: | ||
/* لحن نامناسب */ | /* لحن نامناسب */ | ||
tools.tone = buttonGenerator( | tools.tone = buttonGenerator( | ||
function () { | function() { | ||
$('#wpTextbox1').val('{{لحن نامناسب}}\n' + $('#wpTextbox1').val()); | $('#wpTextbox1').val('{{لحن نامناسب}}\n' + $('#wpTextbox1').val()); | ||
}, | }, | ||
| خط ۴۹۸: | خط ۵۲۲: | ||
/* تغییر جهت */ | /* تغییر جهت */ | ||
tools.toggleDirection = buttonGenerator( | tools.toggleDirection = buttonGenerator( | ||
function () { | function() { | ||
$('#wpTextbox1, #wpNewTitleMain, .ace_editor').css({ | $('#wpTextbox1, #wpNewTitleMain, .ace_editor').css({ | ||
'text-align': 'start', | 'text-align': 'start', | ||
| خط ۵۱۴: | خط ۵۳۸: | ||
/* پیوند درونی */ | /* پیوند درونی */ | ||
tools.wikiLink = buttonGenerator( | tools.wikiLink = buttonGenerator( | ||
function () { | function() { | ||
mw.toolbar.insertTags('[[', ']]', 'مقاله'); | mw.toolbar.insertTags('[[', ']]', 'مقاله'); | ||
}, | }, | ||
| خط ۵۲۷: | خط ۵۵۱: | ||
/* متن خطخورده */ | /* متن خطخورده */ | ||
tools.strikeTextButton = buttonGenerator( | tools.strikeTextButton = buttonGenerator( | ||
function () { | function() { | ||
mw.toolbar.insertTags('<s>', '</s>', 'متن خط خورده'); | mw.toolbar.insertTags('<s>', '</s>', 'متن خط خورده'); | ||
}, | }, | ||
| خط ۵۴۰: | خط ۵۶۴: | ||
/* توضیح */ | /* توضیح */ | ||
tools.commentButton = buttonGenerator( | tools.commentButton = buttonGenerator( | ||
function () { | function() { | ||
mw.toolbar.insertTags('<!--', '-->', 'توضیح'); | mw.toolbar.insertTags('<!--', '-->', 'توضیح'); | ||
}, | }, | ||
| خط ۵۵۳: | خط ۵۷۷: | ||
/* ملزومات مقاله */ | /* ملزومات مقاله */ | ||
tools.addEssentialThings = buttonGenerator( | tools.addEssentialThings = buttonGenerator( | ||
function () { | function() { | ||
mw.toolbar.insertTags('== جستارهای وابسته ==\n\n== منابع ==\n{{پانویس}}', '', ''); | mw.toolbar.insertTags('== جستارهای وابسته ==\n\n== منابع ==\n{{پانویس}}', '', ''); | ||
}, | }, | ||
| خط ۵۶۶: | خط ۵۹۰: | ||
/* چپچین */ | /* چپچین */ | ||
tools.chapChin = buttonGenerator( | tools.chapChin = buttonGenerator( | ||
function () { | function() { | ||
mw.toolbar.insertTags( | mw.toolbar.insertTags( | ||
'{{چپ\u200cچین}}\n', | '{{چپ\u200cچین}}\n', | ||
| خط ۵۸۳: | خط ۶۰۷: | ||
/* اندیس بالا */ | /* اندیس بالا */ | ||
tools.upperText = buttonGenerator( | tools.upperText = buttonGenerator( | ||
function () { | function() { | ||
mw.toolbar.insertTags('<sup>', '</sup>', 'اندیس'); | mw.toolbar.insertTags('<sup>', '</sup>', 'اندیس'); | ||
}, | }, | ||
| خط ۵۹۶: | خط ۶۲۰: | ||
/* اندیس پایین */ | /* اندیس پایین */ | ||
tools.lowerText = buttonGenerator( | tools.lowerText = buttonGenerator( | ||
function () { | function() { | ||
mw.toolbar.insertTags('<sub>', '</sub>', 'اندیس'); | mw.toolbar.insertTags('<sub>', '</sub>', 'اندیس'); | ||
}, | }, | ||
| خط ۶۰۹: | خط ۶۳۳: | ||
/* تغییرمسیر */ | /* تغییرمسیر */ | ||
tools.redirectButton = buttonGenerator( | tools.redirectButton = buttonGenerator( | ||
function () { | function() { | ||
$('#wpTextbox1').val(''); | $('#wpTextbox1').val(''); | ||
mw.toolbar.insertTags( | mw.toolbar.insertTags( | ||
| خط ۶۲۷: | خط ۶۵۱: | ||
/* سال میلادی */ | /* سال میلادی */ | ||
tools.gregYear = buttonGenerator( | tools.gregYear = buttonGenerator( | ||
function () { | function() { | ||
mw.toolbar.insertTags( | mw.toolbar.insertTags( | ||
'[[', | '[[', | ||
| خط ۶۴۴: | خط ۶۶۸: | ||
/* مرتبسازی */ | /* مرتبسازی */ | ||
tools.sortText = buttonGenerator( | tools.sortText = buttonGenerator( | ||
function () { | function() { | ||
applyOnSelection(persianTools.persianSortText); | applyOnSelection(persianTools.persianSortText); | ||
}, | }, | ||
| خط ۶۵۷: | خط ۶۸۱: | ||
/* شد! */ | /* شد! */ | ||
tools.shod = buttonGenerator( | tools.shod = buttonGenerator( | ||
function () { | function() { | ||
$('#wpTextbox1').val($('#wpTextbox1').val() + '\n:{{شد}} ~~~~'); | $('#wpTextbox1').val($('#wpTextbox1').val() + '\n:{{شد}} ~~~~'); | ||
}, | }, | ||
| خط ۶۶۸: | خط ۶۹۲: | ||
); | ); | ||
$(function () { | $(function() { | ||
var extraEditButtons = [], extraMoveButtons = [], space = ' '; | var extraEditButtons = [], | ||
extraMoveButtons = [], | |||
space = ' '; | |||
extraEditButtons = extraEditButtons.concat(tools.toggleDirection, space, tools.ykArabic, tools.zwnj, tools.applyOrthography, | extraEditButtons = extraEditButtons.concat(tools.toggleDirection, space, tools.ykArabic, tools.zwnj, tools.applyOrthography, | ||
| خط ۶۸۴: | خط ۷۱۰: | ||
$('#persian-wiki-tools').remove(); | $('#persian-wiki-tools').remove(); | ||
if ($('#wpTextbox1').length !== 0) { | if ($('#wpTextbox1').length !== 0) { | ||
$('<div>', { id: 'persian-wiki-tools', dir: 'rtl', style: 'float:right;' }).append(extraEditButtons).insertBefore('#wpTextbox1'); | $('<div>', { | ||
id: 'persian-wiki-tools', | |||
dir: 'rtl', | |||
style: 'float:right;' | |||
}).append(extraEditButtons).insertBefore('#wpTextbox1'); | |||
} | } | ||
if ($('#movepage').length !== 0) { | if ($('#movepage').length !== 0) { | ||
$('<span>', { id: 'persian-wiki-tools' }).append(extraMoveButtons).insertAfter('#wpNewTitleMain'); | $('<span>', { | ||
id: 'persian-wiki-tools' | |||
}).append(extraMoveButtons).insertAfter('#wpNewTitleMain'); | |||
} | } | ||
}); | }); | ||
}(jQuery, mediaWiki)); | }(jQuery, mediaWiki)); | ||
نسخهٔ ۹ مارس ۲۰۱۵، ساعت ۱۲:۲۹
// <nowiki> // DON'T REMOVE THIS LINE EVER
/*jslint indent: 2, browser: true, white: true*/
/*global jQuery, mediaWiki, persianWikiTools, autoEd*/
/* above functions are coming from [[MediaWiki:Gadget-Extra-Editbuttons-autoed.js]] */
/**
* UI code for Persian tools
* Tests: [[مدیاویکی:Gadget-Extra-Editbuttons-tests.js]] [[وپ:تست]]
* See also:
* * [[مدیاویکی:Gadget-Extra-Editbuttons-persiantools.js]]
* * [[مدیاویکی:Gadget-Extra-Editbuttons-persianwikitools.js]]
* * [[مدیاویکی:Gadget-Extra-Editbuttons-dictionary.js]]
* * [[مدیاویکی:Gadget-Extra-Editbuttons-autoed.js]]
*/
(function($, mw) {
'use strict';
// ابزار در حالت نمایش
/**
* Fetch a page
*/
function loadPage(title) {
return new mw.Api().get({
action: 'query',
prop: 'revisions',
titles: title,
rvprop: 'content',
format: 'json'
}).then(function(data) {
return $.map(data.query.pages, function(value) {
return value;
})[0].revisions[0]['*'];
});
}
/**
* Save a page
*/
function savePage(title, text, summary) {
return new mw.Api().post({
action: 'edit',
title: title,
text: text,
summary: summary,
nocreate: '',
minor: '',
token: mw.user.tokens.get('editToken')
});
}
/**
* Load and save a page
*/
function loadSavePage(editorDelegate, summary) {
return loadPage(mw.config.get('wgPageName')).then(function(text) {
return savePage(mw.config.get('wgPageName'), editorDelegate(text), summary);
});
}
if (mw.config.get('wgAction') === 'view' &&
mw.config.get('wgIsArticle') &&
mw.config.get('wgPageName') !== 'صفحهٔ_اصلی') {
$.when($.ready, mw.loader.using('jquery.ui.dialog')).then(function() {
$('#ca-abar-abzar').remove();
if ($('#mw-imagepage-nofile, #noarticletext').length !== 0 ||
mw.config.get('wgNamespaceNumber') === 6 ||
mw.config.get('wgNamespaceNumber') === 8) {
return;
}
$(mw.util.addPortletLink('p-views', '#', 'ابرابزار', 'ca-abar-abzar')).click(function(e) {
e.preventDefault();
$(
'<div><div>مطمئنید می\u200cخواهید ویرایشی خودکار جهت اصلاح متن این صفحه به کمک ابرابزار داشته باشید؟</h6><br><br>بعد از انجام ویرایش باید ویرایش انجام\u200cشده را از نظر درستی بررسی کنید <b>زیرا مسئولیت تغییرات ابرابزار با شماست!</b></div>'
).dialog({
modal: true,
title: 'ابرابزار',
resizable: false,
buttons: {
'بله': function() {
loadSavePage(
persianWikiTools.superTool,
'/' + '* ویرایش به وسیلهٔ [[' + (mw.config.get('wgServerName') !== 'fa.wikipedia.org' ? ':w:fa:' : '') + 'وپ:ابرابزار|ابرابزار]] *' + '/'
).then(function(data) {
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('ویرایش در صفحه موفقیت\u200cآمیر نبود.');
}
}, function(error) {
mw.notify(error);
});
$(this).dialog("close");
},
'خیر': function() {
$(this).dialog("close");
}
},
close: function() {
$(this).remove();
}
});
});
});
}
// ابزار در حالت ویرایش
/**
* Adds edit summary
*/
function addEditSummary(summaryText, replaceSummary) {
if (summaryText === '') {
return;
}
var summary = $('.editOptions #wpSummary'),
summaryPrefix = '',
pos;
if (summary.length === 0) {
return;
}
if (summary.val().indexOf('*/ ') > -1) {
pos = summary.val().indexOf('*/ ');
summaryPrefix = summary.val().substr(0, pos + 3);
}
if (replaceSummary) {
summary.val(summaryPrefix + summaryText);
} else {
if (summary.val() === summaryPrefix) {
summary.val(summary.val() + summaryText);
} else {
if (summary.val().indexOf(summaryText) === -1) { // do not repeat in edit summary
summary.val(summary.val() + '، ' + summaryText);
}
}
}
}
/**
* Makes a simple button from parameters
*/
function buttonGenerator(callback, summaryText, replaceSummary, image, title, alt, idSuffix) {
function clickCallback(e) {
e.preventDefault();
callback();
addEditSummary(summaryText, replaceSummary);
}
var button = $('<span>', {
id: 'persian-wiki-tools-' + idSuffix
}).click(clickCallback).append(
$('<img>').attr({
src: image,
title: title,
alt: alt
}).on("error", function() {
button.replaceWith($('<button>', {
text: alt
}).click(clickCallback));
})
);
return button[0];
}
/**
* Applies the string functions defined below to the
* selected text in the edit box. If no text is selected, applies
* the function to the whole contents of edit box.
*/
function applyOnSelection(callback) {
var txtarea, range, startPos, endPos, selText;
if (document.getElementById('editform')) {
txtarea = document.getElementById('wpTextbox1');
} else if (document.getElementById('wpNewTitleMain')) {
txtarea = document.getElementById('wpNewTitleMain');
} else {
return;
}
if (document.selection && document.selection.createRange) { // IE/Opera
// get current selection
txtarea.focus();
range = document.selection.createRange();
selText = range.text;
if (selText) {
range.text = callback(selText);
range.select();
} else {
txtarea.value = callback(txtarea.value);
}
} else if (txtarea.selectionStart || txtarea.selectionStart === 0) { // Mozilla
// get current selection
txtarea.focus();
startPos = txtarea.selectionStart;
endPos = txtarea.selectionEnd;
selText = txtarea.value.substring(startPos, endPos);
// insert tags
if (selText) {
txtarea.value = txtarea.value.substring(0, startPos) + callback(selText) + txtarea.value.substring(endPos, txtarea.value.length);
txtarea.selectionStart = startPos + selText.length;
txtarea.selectionEnd = txtarea.selectionStart;
} else {
txtarea.value = callback(txtarea.value);
}
}
}
var tools = {};
// Buttons that FIX wikitext
/* ی ک */
tools.ykArabic = buttonGenerator(
function() {
applyOnSelection(persianTools.toStandardPersianCharacters);
},
'اصلاح نویسه\u200cهای عربی',
false,
'//upload.wikimedia.org/wikipedia/commons/8/88/Button_YehKeh.png',
'اصلاح ی و ک',
'ی و ک',
'YehKeh'
);
/* فاصلهٔ مجازی */
tools.zwnj = buttonGenerator(
function() {
applyOnSelection(persianWikiTools.wikiApplyZwnj);
},
'اصلاح فاصلهٔ مجازی',
false,
'//upload.wikimedia.org/wikipedia/fa/d/d0/Button_ZWNJ.png',
'فاصلهٔ مجازی',
'فاصلهٔ مجازی',
'ZWNJ'
);
/* اصلاح نویسه\u200cها و حالت\u200cهای غیراستاندارد */
tools.applyOrthography = buttonGenerator(
function() {
applyOnSelection(persianWikiTools.wikiApplyOrthography);
},
'اصلاح نویسه',
false,
'//upload.wikimedia.org/wikipedia/fa/9/94/Button_non_standard.png',
'اصلاح نویسه\u200cها و حالت\u200cهای غیراستاندارد',
'اصلاح نویسه\u200cها و حالت\u200cهای غیراستاندارد',
'apply-orthography'
);
/* اصلاح ارقام */
tools.dig = buttonGenerator(
function() {
applyOnSelection(persianWikiTools.wikiTextDigitsToPersian);
},
'اصلاح ارقام',
false,
'//upload.wikimedia.org/wikipedia/fa/4/4a/Button_numbers.png',
'اصلاح ارقام',
'ارقام',
'numbers'
);
/* اصلاح ارقام مخصوص صفحه انتقال */
tools.digMove = buttonGenerator(
function() {
applyOnSelection(persianWikiTools.wikiConvertToPersianCharacters);
},
'اصلاح ارقام',
false,
'//upload.wikimedia.org/wikipedia/fa/4/4a/Button_numbers.png',
'اصلاح ارقام',
'ارقام',
'numbers'
);
/* یونیکد نشانی وب */
tools.urlFix = buttonGenerator(
function() {
applyOnSelection(persianWikiTools.wikiUrlMinifier);
},
'اصلاح نشانی وب',
false,
'//upload.wikimedia.org/wikipedia/fa/b/ba/Button_decode_URI.png',
'یونی\u200cکدسازی نشانی\u200cها',
'یونی\u200cکدسازی',
'decode-URI'
);
/* اصلاح علامت @ */
tools.atSignFix = buttonGenerator(
function() {
applyOnSelection(function(text) {
return text.replace(/(\S+?)@(\S+?)/g, '$1{{at}}$2');
});
},
'اصلاح @',
false,
'//upload.wikimedia.org/wikipedia/fa/7/7f/Button_at_sign.png',
'اصلاح علامت @',
'@',
'at-sign'
);
/* ابرابزار */
tools.superTool = buttonGenerator(
function() {
applyOnSelection(persianWikiTools.superTool);
},
'ابرابزار',
false,
'//upload.wikimedia.org/wikipedia/fa/f/fc/Button_super_tool.png',
'ابرابزار',
'ابرابزار',
'super-tool'
);
/* ابزار املا */
tools.dictation = buttonGenerator(
function() {
applyOnSelection(persianWikiTools.wikiDictation);
},
'اصلاح املا',
false,
'//upload.wikimedia.org/wikipedia/commons/a/a3/Button_Dictation-fa.png',
'املا',
'املا',
'dictation'
);
/* ابرابزار مخصوص صفحه انتقال */
tools.superToolMove = buttonGenerator(
function() {
applyOnSelection(persianWikiTools.superToolMove);
},
'ابرابزار',
false,
'//upload.wikimedia.org/wikipedia/fa/f/fc/Button_super_tool.png',
'ابرابزار',
'ابرابزار',
'super-tool'
);
/* اصلاحات قراردادن نقطه */
tools.punc = buttonGenerator(
function() {
applyOnSelection(persianWikiTools.wikiPunctuation);
},
'اصلاح سجاوندی',
false,
'//upload.wikimedia.org/wikipedia/fa/e/ed/Button_punctuation.png',
'نقطه\u200cگذاری',
'نقطه\u200cگذاری',
'punctuation'
);
// Buttons that add tags
/* برچسب ویکی\u200cسازی */
tools.wikify = buttonGenerator(
function() {
$('#wpTextbox1').val('{{ویکی\u200cسازی}}\n' + $('#wpTextbox1').val());
},
'برچسب ویکی\u200cسازی',
false,
'//upload.wikimedia.org/wikipedia/fa/3/38/Button_wikify.png',
'برچسب ویکی\u200cسازی',
'ویکی\u200cسازی',
'wikify'
);
/* بدون منبع */
tools.noSource = buttonGenerator(
function() {
$('#wpTextbox1').val('{{بدون منبع}}\n' + $('#wpTextbox1').val());
},
'برچسب منبع',
false,
'//upload.wikimedia.org/wikipedia/fa/8/8a/Button_no_source_fa.png',
'برچسب بدون منبع',
'بدون منبع',
'no-source'
);
/* حذف سریع */
tools.speedyDel = buttonGenerator(
function() {
var temp = $('#wpTextbox1').val();
$('#wpTextbox1').val('');
mw.toolbar.insertTags('{{حذف سریع|', '}}\n' + temp, 'معیار');
},
'حذف سریع',
true,
'//upload.wikimedia.org/wikipedia/fa/c/c1/Button_delete_vote.png',
'برچسب حذف سریع',
'حذف سریع',
'delete-vote'
);
/* حذف زماندار */
tools.prod = buttonGenerator(
function() {
var temp = $('#wpTextbox1').val();
$('#wpTextbox1').val('');
mw.toolbar.insertTags('{{جا:حذف زمان\u200cدار|', '}}\n' + temp, 'معیار');
},
'حذف زمان\u200cدار',
true,
'//upload.wikimedia.org/wikipedia/commons/3/3f/Button_attendre.png',
'برچسب حذف زمان\u200cدار',
'حذف زمان\u200cدار',
'attendre'
);
/* منبع تصویر نامعلوم */
tools.picSource = buttonGenerator(
function() {
$('#wpTextbox1').val('{{منبع تصویر نامعلوم}}\n' + $('#wpTextbox1').val());
},
'برچسب منبع',
false,
'//upload.wikimedia.org/wikipedia/fa/5/59/Button_image_source.png',
'برچسب منبع تصویر نامعلوم',
'منبع تصویر نامعلوم',
'image-source'
);
/* حق تکثیر تصویر نامعلوم */
tools.picCopy = buttonGenerator(
function() {
$('#wpTextbox1').val('{{جا:حق تکثیر تصویر نامعلوم}}\n' + $('#wpTextbox1').val());
},
'برچسب حق تکثیر',
false,
'//upload.wikimedia.org/wikipedia/fa/7/7e/Button_image_copyright.png',
'برچسب حق تکثیر تصویر نامعلوم',
'حق تکثیر تصویر نامعلوم',
'image-copyright'
);
/* تمیزکاری */
tools.cleanup = buttonGenerator(
function() {
$('#wpTextbox1').val('{{تمیزکاری}}\n' + $('#wpTextbox1').val());
},
'برچسب تمیزکاری',
false,
'//upload.wikimedia.org/wikipedia/commons/2/2e/Button_broom.png',
'برچسب تمیزکاری',
'تمیزکاری',
'broom'
);
/* اخطار نگاره */
tools.imgWarn = buttonGenerator(
function() {
$('#wpTextbox1').val('');
mw.toolbar.insertTags(
'{{جا:اخطار نگاره|',
'}}',
'نگاره'
);
},
'برچسب نگاره',
false,
'//upload.wikimedia.org/wikipedia/commons/e/ec/Button_aviso.png',
'اخطار نگاره',
'اخطار نگاره',
'aviso'
);
/* حق تکثیر مشکوک */
tools.sus = buttonGenerator(
function() {
$('#wpTextbox1').val('{{حق تکثیر مشکوک}}\n' + $('#wpTextbox1').val());
},
'برچسب حق تکثیر',
false,
'//upload.wikimedia.org/wikipedia/fa/c/c7/Button_Sus.png',
'برچسب حق تکثیر مشکوک',
'حق تکثیر مشکوک',
'sus'
);
/* نقض حق تکثیر */
tools.copyR = buttonGenerator(
function() {
$('#wpTextbox1').val('');
mw.toolbar.insertTags(
'{{جا:نقض حق تکثیر|url=',
'}}',
'نشانی ایرنتنتی'
);
},
'برچسب حق تکثیر',
false,
'//upload.wikimedia.org/wikipedia/fa/6/6f/Button_CopyR.png',
'برچسب نقض حق تکثیر',
'نقض حق تکثیر',
'copyr'
);
/* لحن نامناسب */
tools.tone = buttonGenerator(
function() {
$('#wpTextbox1').val('{{لحن نامناسب}}\n' + $('#wpTextbox1').val());
},
'برچسب لحن',
false,
'//upload.wikimedia.org/wikipedia/fa/f/fc/Button_Tone.png',
'برچسب لحن نامناسب',
'لحن',
'tone'
);
// Buttons that help with wiki writing
/* تغییر جهت */
tools.toggleDirection = buttonGenerator(
function() {
$('#wpTextbox1, #wpNewTitleMain, .ace_editor').css({
'text-align': 'start',
'direction': $('#wpTextbox1, #wpNewTitleMain').css('direction') === 'rtl' ? 'ltr' : 'rtl'
});
},
'',
true,
'//upload.wikimedia.org/wikipedia/fa/d/d0/Button_toggle_dir.png',
'تغییر جهت جعبهٔ ویرایش',
'تغییرجهت',
'toggle-dir'
);
/* پیوند درونی */
tools.wikiLink = buttonGenerator(
function() {
mw.toolbar.insertTags('[[', ']]', 'مقاله');
},
'',
true,
'//upload.wikimedia.org/wikipedia/fa/d/d0/Button_in_wikify.png',
'پیوند',
'پیوند',
'wikify'
);
/* متن خطخورده */
tools.strikeTextButton = buttonGenerator(
function() {
mw.toolbar.insertTags('<s>', '</s>', 'متن خط خورده');
},
'',
true,
'//upload.wikimedia.org/wikipedia/commons/c/c9/Button_strike.png',
'متن خط\u200cخورده',
'متن خط\u200cخورده',
'strike'
);
/* توضیح */
tools.commentButton = buttonGenerator(
function() {
mw.toolbar.insertTags('<!--', '-->', 'توضیح');
},
'',
true,
'//upload.wikimedia.org/wikipedia/commons/3/34/Button_hide_comment.png',
'توضیح',
'توضیح',
'hide-comment'
);
/* ملزومات مقاله */
tools.addEssentialThings = buttonGenerator(
function() {
mw.toolbar.insertTags('== جستارهای وابسته ==\n\n== منابع ==\n{{پانویس}}', '', '');
},
'',
true,
'//upload.wikimedia.org/wikipedia/commons/e/ef/Add_note.jpg',
'ملزومات مقاله',
'ملزومات مقاله',
'add-note'
);
/* چپچین */
tools.chapChin = buttonGenerator(
function() {
mw.toolbar.insertTags(
'{{چپ\u200cچین}}\n',
'\n{{پایان چپ\u200cچین}}',
'متن چپ\u200cچین\u200cشده'
);
},
'',
true,
'//upload.wikimedia.org/wikipedia/en/e/ea/Button_align_left.png',
'چپ\u200cچین\u200cکردن متن',
'چپ\u200cچین',
'align-left'
);
/* اندیس بالا */
tools.upperText = buttonGenerator(
function() {
mw.toolbar.insertTags('<sup>', '</sup>', 'اندیس');
},
'',
true,
'//upload.wikimedia.org/wikipedia/en/8/80/Button_upper_letter.png',
'اندیس بالا',
'اندیس بالا',
'upper-letter'
);
/* اندیس پایین */
tools.lowerText = buttonGenerator(
function() {
mw.toolbar.insertTags('<sub>', '</sub>', 'اندیس');
},
'',
true,
'//upload.wikimedia.org/wikipedia/en/7/70/Button_lower_letter.png',
'اندیس پایین',
'اندیس پایین',
'lower-letter'
);
/* تغییرمسیر */
tools.redirectButton = buttonGenerator(
function() {
$('#wpTextbox1').val('');
mw.toolbar.insertTags(
'#تغییرمسیر [[',
']]',
'پیوند'
);
},
'',
true,
'//upload.wikimedia.org/wikipedia/en/c/c8/Button_redirect.png',
'تغییرمسیر',
'تغییرمسیر',
'redirect'
);
/* سال میلادی */
tools.gregYear = buttonGenerator(
function() {
mw.toolbar.insertTags(
'[[',
' (میلادی)|]]',
'سال'
);
},
'',
true,
'//upload.wikimedia.org/wikipedia/fa/a/a7/Button_cal.png',
'سال میلادی',
'میلادی',
'cal'
);
/* مرتبسازی */
tools.sortText = buttonGenerator(
function() {
applyOnSelection(persianTools.persianSortText);
},
'',
true,
'//upload.wikimedia.org/wikipedia/fa/3/33/Button_sort.png',
'مرتب\u200cسازی بر اساس الفبا',
'مرتب\u200cسازی',
'sort'
);
/* شد! */
tools.shod = buttonGenerator(
function() {
$('#wpTextbox1').val($('#wpTextbox1').val() + '\n:{{شد}} ~~~~');
},
'شد',
true,
'//upload.wikimedia.org/wikipedia/commons/5/5b/Button_check.png',
'شد',
'شد',
'check'
);
$(function() {
var extraEditButtons = [],
extraMoveButtons = [],
space = ' ';
extraEditButtons = extraEditButtons.concat(tools.toggleDirection, space, tools.ykArabic, tools.zwnj, tools.applyOrthography,
tools.dig, tools.punc, tools.dictation, tools.superTool, space, tools.urlFix, space,
tools.addEssentialThings, tools.noSource, tools.sus, tools.tone, tools.wikify,
tools.shod, tools.cleanup, tools.speedyDel, tools.prod, space, tools.redirectButton,
tools.gregYear, tools.strikeTextButton, tools.chapChin, tools.commentButton, space, tools.sortText);
extraEditButtons = extraEditButtons.concat(space).concat(window.userCustomEditButtons || []);
extraMoveButtons = extraMoveButtons.concat(tools.superToolMove, space, tools.toggleDirection, space,
tools.ykArabic, tools.zwnj, tools.applyOrthography, tools.digMove, tools.punc, space, tools.dictation);
$('#persian-wiki-tools').remove();
if ($('#wpTextbox1').length !== 0) {
$('<div>', {
id: 'persian-wiki-tools',
dir: 'rtl',
style: 'float:right;'
}).append(extraEditButtons).insertBefore('#wpTextbox1');
}
if ($('#movepage').length !== 0) {
$('<span>', {
id: 'persian-wiki-tools'
}).append(extraMoveButtons).insertAfter('#wpNewTitleMain');
}
});
}(jQuery, mediaWiki));