میڈیاویکی:Gadget-Extra-Editbuttons.js
یاددہانی: محفوظ کرنے کے بعد تازہ ترین تبدیلیوں کو دیکھنے کے لیے آپ کو اپنے براؤزر کا کیش صاف کرنا ہوگا۔
- فائرفاکس/ سفاری: جب Reload پر کلک کریں تو Shift دبا کر رکھیں، یا Ctrl-F5 یا Ctrl-R دبائیں (Mac پر R- )
- گوگل کروم: Ctrl-Shift-R دبائیں (Mac پر Shift-R-⌘)
- انٹرنیٹ ایکسپلورر: جب Refresh پر کلک کریں تو Ctrl یا Ctrl-F5 دبائیں
- اوپیرا: Tools → Preferences میں جائیں اور کیش صاف کریں
![]() | شاید اس اسکرپٹ کی دستاویزی تفصیلات میڈیاویکی:Gadget-Extra-Editbuttons پر، اور متعاقب .css صفحہ میڈیاویکی:Gadget-Extra-Editbuttons.css پر موجود ہیں۔ |
// <nowiki> // DON'T REMOVE THIS LINE EVER
/*jslint indent: 2, browser: true, white: true*/
/*global jQuery, mediaWiki, urduWikiTools, insertTags,
autoEdISBN, autoEdWhitespace, autoEdWikilinks, autoEdHTMLtoWikitext, autoEdHeadlines,
autoEdTemplates, autoEdTablestoWikitext, autoEdExtraBreaks, autoEdLinks*/
/* above functions are coming from [[MediaWiki:Gadget-Extra-Editbuttons-MoreFunctions.js]] */
/**
* UI code for Urdu tools
* Tests: [[میڈیاویکی:Gadget-Extra-Editbuttons-tests.js]] [[وپ:تست]]
* See also:
* * [[میڈیاویکی:Gadget-Extra-Editbuttons-urdutools.js]]
* * [[میڈیاویکی:Gadget-Extra-Editbuttons-urduwikitools.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('csrfToken')
}).then(function (data) {
if (data.error && data.error.info) {
mw.notify(data.error.info);
}
}, function (data) {
mw.notify(data);
});
}
/**
* 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('wgIsMainPage')) {
$.when($.ready, mw.loader.using('jquery.ui')).then(function () {
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 () {
$(
'<div><div>کیا آپ مطمئن ہیں\u200cخودکار ویکائی کرنے کے لیے یا آپ کومدد درکار ہے؟</h6><br><br>ترمیم کرنے پر اس کی درستی کو نمائش میں جانچ لینا چاہیے <b>دوسری صورت میں تبدیلیوں کی ذمہ داری آپ پر عائد ہوگی!</b></div>'
).dialog({
modal: true,
title: 'ویکائی',
resizable: false,
buttons: {
'ہاں': function () {
loadSavePage(
function (text) {
text = urduWikiTools.wikiConvertToUrduCharacters(text);
if (mw.config.get('wgNamespaceNumber') !== 10) {
text = urduWikiTools.wikiTextDigitsToUrdu(text);
}
text = urduWikiTools.wikiDictation(text);
text = urduWikiTools.wikiUrlMinifier(text);
return urduWikiTools.wikiPunctuation(text);
},
'/' + '* ترمیم بذریعہ [[' + (mw.config.get('wgServerName') !== 'ur.wiki.x.io' ? ':w:ur:' : '') + 'وپ:خودکار ترمیم|آلہ خودکار ترمیم]] *' + '/'
).then(function () {
// refresh and bring the diff after auto edit
mw.notify('ترمیم مکمل ہوئی');
// Loading diff page
var uri = new mw.Uri();
uri.query = {
'title': mw.config.get('wgPageName'),
'diff': 'cur',
'oldid': 'prev'
};
uri.path = mw.config.get('wgScriptPath') + '/index.php';
window.location = uri.toString();
});
$(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 = $('<a>', { id: 'urdu-wiki-tools-' + idSuffix }).click(clickCallback).append(
$('<img />').attr({
src: image,
title: title,
alt: alt
}).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.dig = buttonGenerator(
function () { applyOnSelection(urduWikiTools.wikiTextDigitsToUrdu); },
'درستی اعداد',
false,
'//up.wiki.x.io/wikipedia/fa/4/4a/Button_numbers.png',
'درستی اعداد',
'اعداد',
'numbers'
);
/* اصلاح ارقام مخصوص صفحه انتقال */
tools.digMove = buttonGenerator(
function () { applyOnSelection(urduWikiTools.convertDigitsToUrdu); },
'اصلاح ارقام',
false,
'//up.wiki.x.io/wikipedia/fa/4/4a/Button_numbers.png',
'درستی اعداد',
'اعداد',
'numbers'
);
/* یونیکوڈ علامت ویب */
tools.urlFix = buttonGenerator(
function () { applyOnSelection(urduWikiTools.wikiUrlMinifier); },
'درستی یوآرایل',
false,
'//up.wiki.x.io/wikipedia/fa/b/ba/Button_decode_URI.png',
'یوآرایل کی یونیکوڈ سازی',
'یونیکوڈ سازی',
'decode-URI'
);
/* اصلاح علامت @ */
tools.atSignFix = buttonGenerator(
function () {
applyOnSelection(function (text) {
return text.replace(/(\S+?)@(\S+?)/g, '$1{{at}}$2');
});
},
'درستی @',
false,
'//up.wiki.x.io/wikipedia/fa/7/7f/Button_at_sign.png',
'درستی علامت @',
'@',
'at-sign'
);
/* ابرابزار */
tools.superTool = buttonGenerator(
function () {
applyOnSelection(function (text) {
text = urduWikiTools.wikiConvertToUrduCharacters(text);
if (mw.config.get('wgNamespaceNumber') !== 10) {
text = urduWikiTools.wikiTextDigitsToUrdu(text);
}
text = urduWikiTools.wikiUrlMinifier(text);
text = urduWikiTools.wikiDictation(text);
return urduWikiTools.wikiPunctuation(text);
});
},
'ویکائی',
false,
'//up.wiki.x.io/wikipedia/fa/f/fc/Button_super_tool.png',
'ویکائی',
'ویکائی',
'super-tool'
);
/* ابزارهای بیشتر*/
tools.otherTools = buttonGenerator(
function () {
applyOnSelection(function (text) {
text = autoEdISBN(text);
text = autoEdWhitespace(text);
text = autoEdWikilinks(text);
text = autoEdHTMLtoWikitext(text);
text = autoEdHeadlines(text);
text = autoEdTemplates(text);
text = autoEdTablestoWikitext(text);
text = autoEdExtraBreaks(text);
return autoEdLinks(text);
});
},
'مزید آلات',
false,
'//up.wiki.x.io/wikipedia/commons/b/b3/Button_Other.png',
'مزید آلات',
'مزید',
'other-tools'
);
/* آلہ املا */
tools.dictation = buttonGenerator(
function () { applyOnSelection(urduWikiTools.wikiDictation); },
'درستی املا',
false,
'//up.wiki.x.io/wikipedia/commons/a/a3/Button_Dictation-fa.png',
'املا',
'املا',
'dictation'
);
/* اوپر آلہ خاص صفحہ منتقل */
tools.superToolMove = buttonGenerator(
function () {
applyOnSelection(function (text) {
text = urduWikiTools.wikiConvertToUrduCharacters(text);
text = urduWikiTools.wikiTextDigitsToUrdu(text);
text = urduWikiTools.wikiUrlMinifier(text);
text = urduWikiTools.wikiDictation(text);
return urduWikiTools.wikiPunctuation(text);
});
},
'ویکائی',
false,
'//up.wiki.x.io/wikipedia/fa/f/fc/Button_super_tool.png',
'ویکائی',
'ویکائی',
'super-tool'
);
/* درستی رموز اوقاف */
tools.punc = buttonGenerator(
function () { applyOnSelection(urduWikiTools.wikiPunctuation); },
'درستی رموز اوقاف',
false,
'//up.wiki.x.io/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,
'//up.wiki.x.io/wikipedia/fa/3/38/Button_wikify.png',
'ویکی ٹیگ\u200cسازی',
'ویکی\u200cسازی',
'wikify'
);
/* ناحوالہ*/
tools.noSource = buttonGenerator(
function () {
$('#wpTextbox1').val('{{ناحوالہ}}\n' + $('#wpTextbox1').val());
},
'ٹیگ حوالہ',
false,
'//up.wiki.x.io/wikipedia/fa/8/8a/Button_no_source_fa.png',
'ٹیگ ناحوالہ',
'ناحوالہ',
'no-source'
);
/* سریع حذف شدگی */
tools.speedyDel = buttonGenerator(
function () {
var temp = $('#wpTextbox1').val();
$('#wpTextbox1').val('');
insertTags('{{سریع حذف شدگی|', '}}\n' + temp, 'اصول');
},
'سریع حذف شدگی',
true,
'//up.wiki.x.io/wikipedia/fa/c/c1/Button_delete_vote.png',
'ٹیگ سریع حذف شدگی',
'سریع حذف شدگی',
'delete-vote'
);
/* مجوزہ حذف شدگی */
tools.prod = buttonGenerator(
function () {
var temp = $('#wpTextbox1').val();
$('#wpTextbox1').val('');
insertTags('{{نقل:مجوزہ حذف شدگی\u200c|', '}}\n' + temp, 'اصول');
},
'مجوزہ حذف شدگی\u200c',
true,
'//up.wiki.x.io/wikipedia/commons/3/3f/Button_attendre.png',
'ٹیگ مجوزہ حذف شدگی\u200c',
'مجوزہ حذف شدگی\u200c',
'attendre'
);
/* منبع تصویر نامعلوم */
tools.picSource = buttonGenerator(
function () {
$('#wpTextbox1').val('{{بدون حوالہ}}\n' + $('#wpTextbox1').val());
},
'ٹیگ حوالہ',
false,
'//up.wiki.x.io/wikipedia/fa/5/59/Button_image_source.png',
'ٹیگ بدون حوالہ تصویر',
'منبع تصویر نامعلوم',
'image-source'
);
/* صفائی */
tools.cleanup = buttonGenerator(
function () {
$('#wpTextbox1').val('{{صفائی}}\n' + $('#wpTextbox1').val());
},
'ٹیگ صفائی',
false,
'//up.wiki.x.io/wikipedia/commons/2/2e/Button_broom.png',
'ٹیگ صفائی',
'صفائی',
'broom'
);
/* اندیس بالا */
tools.upperText = buttonGenerator(
function () {
insertTags('<sup>', '</sup>', 'اندیس');
},
'',
true,
'//up.wiki.x.io/wikipedia/en/8/80/Button_upper_letter.png',
'اندیس بالا',
'اندیس بالا',
'upper-letter'
);
/* اندیس پایین */
tools.lowerText = buttonGenerator(
function () {
insertTags('<sub>', '</sub>', 'اندیس');
},
'',
true,
'//up.wiki.x.io/wikipedia/en/7/70/Button_lower_letter.png',
'اندیس پایین',
'اندیس پایین',
'lower-letter'
);
/* تغییرمسیر */
tools.redirectButton = buttonGenerator(
function () {
$('#wpTextbox1').val('');
insertTags(
'#رجوع_مکرر [[',
']]',
'ربط'
);
},
'',
true,
'//up.wiki.x.io/wikipedia/en/c/c8/Button_redirect.png',
'رجوع مکرر',
'رجوع مکرر',
'redirect'
);
/* سنہ عیسوی */
tools.gregYear = buttonGenerator(
function () {
insertTags(
'[[',
' (عیسوی)|]]',
'سنہ'
);
},
'',
true,
'//up.wiki.x.io/wikipedia/fa/a/a7/Button_cal.png',
'سال عیسوی',
'عیسوی',
'cal'
);
$(function () {
var extraEditButtons = [], extraMoveButtons = [], space = ' ';
extraEditButtons = extraEditButtons.concat(tools.toggleDirection, space, tools.zwnj,
tools.dig, tools.punc, tools.dictation, tools.superTool, tools.otherTools, space, tools.urlFix, space, tools.welcome,
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.commentButton, space);
extraEditButtons = extraEditButtons.concat(space).concat(window.userCustomEditButtons || []);
extraMoveButtons = extraMoveButtons.concat(tools.superToolMove, space, tools.toggleDirection, space,
tools.zwnj, tools.digMove, tools.punc, space, tools.dictation);
if ($('#wpTextbox1').length !== 0) {
$('<div>', { id: 'urdu-wiki-tools', dir: 'rtl' }).append(extraEditButtons).insertBefore('#wpTextbox1');
}
if ($('#movepage').length !== 0) {
$('<span>', { id: 'urdu-wiki-tools' }).append(extraMoveButtons).insertAfter('#wpNewTitleMain');
}
});
}(jQuery, mediaWiki));