User:Encrypt0r/common.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
The accompanying .css page for this skin can be added at User:Encrypt0r/common.css. |
// mw.loader.load("//fa.wikipedia.org/w/index.php?title=MediaWiki:Tofawiki.js&action=raw&ctype=text/javascript");
(function () {
'use strict';
// افزودن ابزار ترجمه
importScript("User:Ebrahim/ArticleTranslator.js");
if (mw.config.get('wgAction') !== 'view' ||
(mw.config.get('wgNamespaceNumber') !== 0 &&
mw.config.get('wgNamespaceNumber') !== 4 &&
mw.config.get('wgNamespaceNumber') !== 6 &&
mw.config.get('wgNamespaceNumber') !== 10 &&
mw.config.get('wgNamespaceNumber') !== 14 &&
mw.config.get('wgNamespaceNumber') !== 108)) {
return;
}
var GENERAL_BOT = 'Wikipedia: Request to create an article (Robotics)';
var CITIES_BOT = 'Wikipedia: Wikipedia Creating articles for cities with robots / Robotics Request';
var PEOPLE_BOT = 'Wikipedia: Article Creation (Robotics) / Human';
var OTHER_REQUESTS = 'Wikipedia: Requested Articles';
var CATEGORIES_BOT = 'Wikipedia: Category Request (Robotics)';
var FAIRUSE_IMAGES = 'Fair Use Images';
var TEMPLATE_BOOK_TRANSLATOR = 'Template and book translator';
var DISAMBIGUATION_BOT = 'Disambiguation page';
var WIKIPEDIA_TRANSLATOR='Wikipedia name space translator';
var requestingPages = {
'Arrays, movies, music, rivers, buildings and video games': GENERAL_BOT,
'Cities and Residences': CITIES_BOT,
'People & People': PEOPLE_BOT,
'Disambiguation page': DISAMBIGUATION_BOT,
'General Content': OTHER_REQUESTS,
'Categories': CATEGORIES_BOT,
'Fair pictures': FAIRUSE_IMAGES,
'Templates and Books': TEMPLATE_BOOK_TRANSLATOR,
'Wikipedia name space': WIKIPEDIA_TRANSLATOR
};
function suggestRequestPlace() {
if ($('.infobox.geography').length !== 0 && ($('#catlinks a[href^="/wiki/Category:Rivers"]').length === 0)&& mw.config.get('wgNamespaceNumber') === 0) {
return CITIES_BOT;
} else if (($('.infobox.biota, .infobox.haudio, .description a[href="/wiki/Single_(music)"]').length !== 0) ||
($('#coordinates').length !== 0 && $('.infobox.vcard .fn').length !== 0) ||
($('#catlinks a[href^="/wiki/Category:Rivers"]').length !== 0) ||
($('#catlinks a[href^="/wiki/Category:Songs"]').length !== 0) ||
($('#catlinks a[href^="/wiki/Category:Films"]').length !== 0) ||
($('#catlinks a[href$="films"]').length !== 0) ||
($('#catlinks a[href*="video_games"], #catlinks a[href*="Video_game"]').length !== 0)&& mw.config.get('wgNamespaceNumber') === 0) {
return GENERAL_BOT;
} else if (( $('#catlinks a[href^="/wiki/Category:All_article_disambiguation_pages"]').length !== 0 || $('#catlinks a[href^="/wiki/Category:All_set_index_articles"]').length !== 0) && mw.config.get('wgNamespaceNumber') === 0) {
return DISAMBIGUATION_BOT;
} else if ($('#catlinks a[href^="/wiki/Category:Island"]').length !== 0&& mw.config.get('wgNamespaceNumber') === 0) {
return CITIES_BOT;
} else if (mw.config.get('wgNamespaceNumber') === 4) {
return WIKIPEDIA_TRANSLATOR;
} else if (mw.config.get('wgNamespaceNumber') === 14) {
return CATEGORIES_BOT;
} else if (mw.config.get('wgNamespaceNumber') === 10 || mw.config.get('wgNamespaceNumber') === 108) {
return TEMPLATE_BOOK_TRANSLATOR;
} else if (mw.config.get('wgNamespaceNumber') === 6) {
return FAIRUSE_IMAGES;
} else if (($('.infobox.vcard .fn, #catlinks a[href^="people"]').length !== 0&& mw.config.get('wgNamespaceNumber') === 0) &&
($('#catlinks a[href*="Ethnic_groups"]').length === 0)) {
return PEOPLE_BOT;
}
return OTHER_REQUESTS;
}
function pageExists(page) {
return new mw.Api({ ajax: { url: '//ckb.wikipedia.org/w/api.php' } }).get({
action: 'query',
titles: page,
format: 'json',
origin: location.protocol + '//' + location.hostname
}).then(function (data) { return data.query.pages['-1'] === undefined; });
}
function isAllowedToUseTofawikiConsole() {
return new mw.Api({ ajax: { url: '//ckb.wikipedia.org/w/api.php' } }).get({
action: 'query',
list: 'users',
ususers: mw.config.get('wgUserName'),
usprop: 'groups',
origin: location.protocol + '//' + location.hostname
}).then(function (res) {
return res.query.users[0].groups.some(function (x) {
return ['bot', 'autopatrolled', 'patroller', 'sysop', 'eliminator'].indexOf(x) !== -1;
});
});
}
var passedHtml = '<span style="color: #00af89; font-size: 140%">✓</span>';
var failedHtml = '<span style="color: #d33; font-size: 140%">✗</span>';
function validityCheck() {
var origValue = $('#tofawiki-name').val(), page = origValue;
if (page === '') { $('#tofawiki-status').html(''); return; }
if (mw.config.get('wgNamespaceNumber') === 14) { page = 'رده:' + page.replace(/^رده:/, ''); }
if (mw.config.get('wgNamespaceNumber') === 10) { page = 'الگو:' + page.replace(/^الگو:/, ''); }
if (mw.config.get('wgNamespaceNumber') === 108) { page = 'کتاب:' + page.replace(/^کتاب:/, ''); }
if (mw.config.get('wgNamespaceNumber') === 6) { page = 'پرونده:' + page.replace(/^پرونده:/, ''); }
pageExists(page).then(function (exists) {
if ($('#tofawiki-name').val() !== origValue) { // that request is no longer relevant
return;
}
if (!exists) {
$('#tofawiki-status').empty().append(passedHtml + ' صفحهای با نام «' + page + '» ' +
'It does not exist in Kurdish Wikipedia, so we will continue the creation process!');
} else {
$('#tofawiki-status').empty().append(failedHtml, ' Title «', $('<a>', {
target: '_blank',
href: '//ckb.wikipedia.org' + mw.util.getUrl(page),
text: page
}), '»Exists in Kurdish Wikipedia. Make sure the page is not duplicate! ');
if ($('#tofawiki-select').val() === DISAMBIGUATION_BOT) {
$('#tofawiki-status').append('<br><br>', $('<a>', {
text: 'Click to add (disambiguation) as',
href: '#'
}).click(function (e) {
e.preventDefault();
$('#tofawiki-name').val($('#tofawiki-name').val() + ' (disambiguation)');
validityCheck();
}));
}
}
});
}
$.when($.ready, mw.loader.using('jquery.ui')).then(function () {
if ($('.interlanguage-link.interwiki-fa').length !== 0) { return; }
// if is commons image, give up
if ($('#ca-view-foreign').length !== 0) { return; }
$('#ca-tofawiki').remove();
if ($('#mw-imagepage-nofile, #noarticletext').length !== 0) {
return;
}
// if it is a free image, bring TransferToCommons instead
if (mw.config.get('wgNamespaceNumber') === 6 && $('#catlinks a[href="/wiki/Category:GFDL_files"], ' +
'#catlinks a[href^="/wiki/Category:Creative_Commons_Attribution"], ' +
'#catlinks a[href="/wiki/Category:Move_to_Commons_Priority_Candidates"],' +
'#catlinks a[href="/wiki/Category:Convert_to_SVG_and_copy_to_Wikimedia_Commons"], ' +
'#catlinks a[href^="/wiki/Category:Copy_to_Wikimedia_Commons"]').length !== 0 &&
$('#catlinks a[href^="/wiki/Category:Wikipedia_files_not_suitable_for_Commons"]').length === 0) {
$(mw.util.addPortletLink(
'p-views',
new mw.Uri('//commonshelper.toolforge.org/').extend({
lang: mw.config.get('wgContentLanguage'),
image: mw.config.get('wgTitle'),
interface: mw.config.get('wgContentLanguage')
}),
'Transfer to Wikinews'
)).find('a').prop('target', '_blank').prepend($('<img>', {
src: '//upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/14px-Commons-logo.svg.png'
}), ' ');
return;
}
mw.util.addCSS(
"#tofawiki-form * { font-family: 'Segoe UI', Tahoma, 'Iranian Sans', 'DejaVu Sans', 'Noto Sans', 'Droid Arabic Kufi', sans-serif !important; } " +
"#tofawiki-form .ui-dialog-buttonset { float: left; } " +
"#tofawiki-form .ui-dialog-titlebar-close { right: initial; left: .75em; } " +
"#tofawiki-form .ui-dialog-title { float: right; }"
);
$(mw.util.addPortletLink($('#p-views').length !== 0 ? 'p-views' : 'p-cactions', '#', 'tofawiki!', 'ca-tofawiki', null, null, '#ca-view')).click(function (e) {
mw.loader.load('//ckb.wikipedia.org/w/index.php?title=MediaWiki:Gadget-Extra-Editbuttons-persiantools.js&action=raw&ctype=text/javascript');
mw.loader.load('//ckb.wikipedia.org/w/index.php?title=MediaWiki:Gadget-Extra-Editbuttons-persianwikitools.js&action=raw&ctype=text/javascript');
mw.loader.load('//ckb.wikipedia.org/w/index.php?title=MediaWiki:Gadget-Extra-Editbuttons-dictionary.js&action=raw&ctype=text/javascript');
e.preventDefault();
$('#tofawiki-form').remove();
$('<div>', {
dir: 'rtl',
style: "position: relative;"
}).append($('<div>', { style: 'font-size: 90%; float: left' }).append($('<a>', {
id: 'tofawiki-consolelink',
html: 'Mass creation tool',
tabindex: '-1',
title: 'Mass creation tool',
target: '_blank',
href: '//ckb.wikipedia.org' + mw.util.getUrl('ویژه:صفحهٔ_خالی/tofawiki-conosle') + '?withJS=MediaWiki:TofawikiConsole.js'
}).hide()), '<br style="clear: both">', $('<div>', {
style: 'margin-top: 0.4em;',
text: 'Created by:'
}).append($('<a>', {
text: 'Guide',
tabindex: '-1',
title: 'Tools guide',
target: '_blank',
style: 'float: left; font-size: smaller;',
href: '//ckb.wikipedia.org' + mw.util.getUrl('راهنما:ابزار/به_ویکیفا')
}), $('<select>', {
id: 'tofawiki-select',
style: 'padding: 1px; vertical-align: baseline; font-family: inherit;'
}).append(
$.map(requestingPages, function (item, description) {
var disabled =
mw.config.get('wgNamespaceNumber') === 14 && item !== CATEGORIES_BOT ||
mw.config.get('wgNamespaceNumber') === 0 && item === CATEGORIES_BOT ||
mw.config.get('wgNamespaceNumber') === 4 && item !== WIKIPEDIA_TRANSLATOR ||
mw.config.get('wgNamespaceNumber') === 0 && item === WIKIPEDIA_TRANSLATOR ||
mw.config.get('wgNamespaceNumber') === 6 && item !== FAIRUSE_IMAGES ||
mw.config.get('wgNamespaceNumber') === 0 && item === FAIRUSE_IMAGES ||
(mw.config.get('wgNamespaceNumber') === 10 || mw.config.get('wgNamespaceNumber') === 108) && item !== TEMPLATE_BOOK_TRANSLATOR ||
mw.config.get('wgNamespaceNumber') === 0 && item === TEMPLATE_BOOK_TRANSLATOR;
return $('<option>', { value: item, text: description, disabled: disabled });
})
)), $('<div>', {
style: 'padding-top: 1em',
text: 'Title: '
}).append($('<input>', {
dir: 'rtl',
id: 'tofawiki-name',
style: 'font-family: inherit; width: 50%'
}).on('input', validityCheck), ' ', $('<img>', { src: '//upload.wikimedia.org/wikipedia/fa/f/fc/Button_super_tool.png' }).click(function () {
$('#tofawiki-name').val(persianWikiTools.superToolMove($('#tofawiki-name').val()));
}), ' ', mw.config.get('wgNamespaceNumber') === 0
? $('<button>', {
id: 'tofawiki-transliteration-suggestion',
style: 'font-size: 70%',
text: 'Preview',
title: 'Receive Suggested Title via Robotic Characterization'
}).click(function () {
var button = $(this).prop('disabled', 'disabled').text('لطفاً منتظر بمانید…');
$.get('https://rezabot.toolforge.org/TileTransliteration.php', { page: mw.config.get('wgTitle') }).then(function (response) {
button.replaceWith($('<div>', { style: 'font-size: 90%; color: #d33', text: 'نویسهگردانی عنوان با موفقیت وارد شد. احتمال خطا وجود دارد، لطفاً به دقت بازبینی کنید!' }));
$('#tofawiki-name').val(response.result);
}, function () {
button.replaceWith($('<span>', { style: 'font-size: 70%', text: 'The transcript request failed'}));
});
})
: ''
), $('<div>', {
id: 'tofawiki-status'
})).dialog({
width: 500,
title: 'Create in Persian Wikipedia',
open: function () {
$('#tofawiki-select').val(suggestRequestPlace());
if (mw.config.get('wgNamespaceNumber') === 10) {
$('#tofawiki-name').val(mw.config.get('wgTitle'));
validityCheck();
}
if (mw.config.get('wgNamespaceNumber') === 6) {
$('#tofawiki-name').val(mw.config.get('wgTitle')).prop('dir', 'ltr').css('width', '80%');
validityCheck();
}
},
buttons: [mw.config.get('wgNamespaceNumber') === 0 ? {
text: 'Content-assisted translation',
title:'In this case a translation tool is used, it is recommended for general text and long translations',
class: 'ui-button-green',
style: 'direction: rtl',
click: function () {
window.open(new mw.Uri('//ckb.wikipedia.org/w/index.php')
.extend({
title: 'Special:CX',
page: mw.config.get('wgPageName'),
from: 'en',
to: 'ckb',
targettitle: $('#tofawiki-name').val().replace(/_/g, '+').replace(/ي/g, 'ی').replace(/ك/g, 'ک'),
withJS: 'MediaWiki:EnableCX.js'
}).toString());
$(this).dialog('close');
}
} : { style: 'display: none;' }, {
text: mw.config.get('wgNamespaceNumber') === 6 ? 'Upload': 'Create via Tofaviki tool',
title:'In this case you can monitor the request',
class: 'ui-button-blue',
click: function () {
var faName = $('#tofawiki-name').val().replace(/ي/g, 'ی').replace(/ك/g, 'ک');
var requestingPage = $('#tofawiki-select').val();
var uri = new mw.Uri('//ckb.wikipedia.org/w/index.php');
if (!faName || !requestingPage) {
$('#tofawiki-status').text('Enter a name first!');
return;
}
if (requestingPage === FAIRUSE_IMAGES) {
uri.query = {
title: 'ویژه:بارگذاری_پرونده',
wpDestFile: faName,
enName: mw.config.get('wgRelevantPageName'),
withJS: 'MediaWiki:TofawikiUpload.js',
wpUploadDescription: '----'
};
} else {
if (requestingPage === CATEGORIES_BOT) { faName = "رده:" + faName.replace(/^رده:/, ''); }
if (mw.config.get('wgNamespaceNumber') === 10) { faName = "الگو:" + faName.replace(/^الگو:/, ''); }
if (mw.config.get('wgNamespaceNumber') === 108) { faName = "کتاب:" + faName.replace(/^کتاب:/, ''); }
if (requestingPage === WIKIPEDIA_TRANSLATOR) { faName = "ویکیپدیا:" + faName.replace(/^ویکیپدیا:/, ''); }
uri.query = {
title: faName,
enName: mw.config.get('wgRelevantPageName'),
enOldid: mw.config.get('wgRevisionId'),
redlink: 1,
action: 'edit',
withJS: 'MediaWiki:TofawikiHelper.js',
requestingPage: requestingPage,
editintro: 'الگو:به ویکیفا/ادیتنوتیس'
};
}
window.open(uri.toString());
$(this).dialog('close');
}
}],
close: function () {
$(this).remove();
$('#tofawiki-name').remove();
}
}).parent().prop('id', 'tofawiki-form');
isAllowedToUseTofawikiConsole().then(function (allowed) {
if (allowed) {
$('#tofawiki-consolelink').show();
}
});
});
});
}());