مدیاویکی:Common.js: تفاوت میان نسخهها
محتوای حذفشده محتوای افزودهشده
repeated code |
testing. https://bugzilla.wikimedia.org/show_bug.cgi?id=48038 |
||
خط ۱۰۷: | خط ۱۰۷: | ||
/** |
/** |
||
* for adding "feature article", "good article" and "feature list" icon in interwiki list |
* for adding "feature article", "good article" and "feature list" icon in interwiki list |
||
⚫ | |||
$( function(){ |
$( function(){ |
||
$("span.FA").each(function(){ // feature article |
$("span.FA").each(function(){ // feature article |
||
خط ۱۲۲: | خط ۱۲۲: | ||
}); |
}); |
||
} ); |
} ); |
||
⚫ | |||
/*</pre> |
/*</pre> |
||
===Collapsible tables === |
===Collapsible tables === |
نسخهٔ ۳ مهٔ ۲۰۱۳، ساعت ۱۱:۴۶
//<syntaxhighlight lang="javascript">
/*</pre>
=== links in commons.js ===
<pre>*/
if ((wgNamespaceNumber == 2 || wgNamespaceNumber == 8) && wgTitle.lastIndexOf('.js') != -1 && wgAction == 'view') {
importScript('MediaWiki:JavascriptHeadings.js');
}
/*</pre>
=== Toggle direction of Bot Flag Request window ===
<pre>*/
if (wgNamespaceNumber == 4) {
if (wgAction == 'edit'){
var a='سیاست_ربات\u200cرانی/درخواست_مجوز/انگلیسی'
if (wgPageName.search(a)>0) {
mw.util.addCSS(".diff-addedline, .diff-deletedline, .diff-context { direction: ltr; }" +
".diff-addedline > div, .diff-deletedline > div, .diff-context > div { white-space: pre; }" +
"#wpTextbox1 { direction: ltr; }" );
}
}
}
/*</pre>
=== Magic editintros ===
<pre>*/
/** Magic editintros ****************************************************
*
* Description: Adds editintros on disambiguation pages and BLP pages.
* Maintainers: [[User:RockMFR]]
*/
function addEditIntro(name) {
var el = document.getElementById('ca-edit');
if (!el) return;
el = el.getElementsByTagName('a')[0];
if (el) el.href += '&editintro=' + name;
}
if (wgNamespaceNumber == 0) {
$( function () {
if (document.getElementById('disambig') || document.getElementById('disambigbox')) addEditIntro('Template:Disambig_editintro');
} );
$( function () {
var cats = document.getElementById('mw-normal-catlinks');
if (!cats) return;
cats = cats.getElementsByTagName('a');
for (var i = 0; i < cats.length; i++) {
if (cats[i].title == 'رده:افراد زنده') {
addEditIntro('Template:BLP_editintro');
break;
}
}
} );
}
/*</pre>
=== Sysop Javascript ===
<pre> */
/** Sysop Javascript *******************************************************
*
* Description: Allows for sysop-specific Javascript at [[MediaWiki:Sysop.js]].
*/
function sysopFunctions() {
if (wgUserGroups && !window.disableSysopJS) {
for (var g = 0; g < wgUserGroups.length; ++g) {
if (wgUserGroups[g] == "sysop") {
importScript("MediaWiki:Sysop.js");
break;
}
}
}
}
$( sysopFunctions );
if (navigator.appName == "Microsoft Internet Explorer") {
var oldWidth;
var docEl = document.documentElement;
function fixIEScroll() {
if (!oldWidth || docEl.clientWidth > oldWidth) doFixIEScroll();
else setTimeout(doFixIEScroll, 1);
oldWidth = docEl.clientWidth;
}
function doFixIEScroll() {
docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
}
document.attachEvent("onreadystatechange", fixIEScroll);
attachEvent("onresize", fixIEScroll);
}
function addLoadEvent(func) {
if (window.addEventListener) window.addEventListener("load", func, false);
else if (window.attachEvent) window.attachEvent("onload", func);
}
/*</pre>
=== FA interwiki ===
<pre> */
/**
* for adding "feature article", "good article" and "feature list" icon in interwiki list
$( function(){
$("span.FA").each(function(){ // feature article
$("li.interwiki-" + this.id).addClass("FA")
.attr("title", "این مقاله، یک مقاله برگزیده است");
});
$("span.GA").each(function(){ // good article
$("li.interwiki-" + this.id).addClass("GA")
.attr("title", "این مقاله، یک مقاله خوب است");
});
$("span.FL").each(function(){ // feature list
$("li.interwiki-" + this.id).addClass("FL")
.attr("title", "این یک فهرست برگزیده است");
});
} );
*/
/*</pre>
===Collapsible tables ===
<pre> */
/** Collapsible tables *********************************************************
*
* Description: Allows tables to be collapsed, showing only the header. See
* [[Wikipedia:NavFrame]].
* Maintainers: [[User:R. Koot]]
*/
var autoCollapse = 2;
var collapseCaption = "نهفتن";
var expandCaption = "نمایش";
function collapseTable( tableIndex )
{
var Button = document.getElementById( "collapseButton" + tableIndex );
var Table = document.getElementById( "collapsibleTable" + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
if ( Button.firstChild.data == collapseCaption ) {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = "none";
}
Button.firstChild.data = expandCaption;
} else {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
}
function createCollapseButtons()
{
var tableIndex = 0;
var NavigationBoxes = new Object();
var Tables = document.getElementsByTagName( "table" );
for ( var i = 0; i < Tables.length; i++ ) {
if ( hasClass( Tables[i], "collapsible" ) ) {
/* only add button and increment count if there is a header row to work with */
var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
if (!HeaderRow) continue;
var Header = HeaderRow.getElementsByTagName( "th" )[0];
if (!Header) continue;
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
var Button = document.createElement( "span" );
var ButtonLink = document.createElement( "a" );
var ButtonText = document.createTextNode( collapseCaption );
Button.className = "collapseButton"; //Styles are declared in Common.css
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
ButtonLink.setAttribute( "href", "#" );
addHandler( ButtonLink, "click", new Function( "evt", "collapseTable(" + tableIndex + " ); return killEvt( evt );") );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( "[" ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( "]" ) );
Header.insertBefore( Button, Header.childNodes[0] );
tableIndex++;
}
}
for ( var i = 0; i < tableIndex; i++ ) {
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
collapseTable( i );
}
else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {
var element = NavigationBoxes[i];
while (element = element.parentNode) {
if ( hasClass( element, "outercollapse" ) ) {
collapseTable ( i );
break;
}
}
}
}
}
$( createCollapseButtons );
/*</pre>
===Dynamic Navigation Bars ===
<pre> */
/** Dynamic Navigation Bars (experimental) *************************************
*
* Description: See [[Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/
// set up the words in your language
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
// shows and hides content and picture (if available) of navigation bars
// Parameters:
// indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar(indexNavigationBar)
{
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
if (!NavFrame || !NavToggle) {
return false;
}
// if shown now
if (NavToggle.firstChild.data == NavigationBarHide) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
// if hidden now
} else if (NavToggle.firstChild.data == NavigationBarShow) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton()
{
var indexNavigationBar = 0;
// iterate over all < div >-elements
var divs = document.getElementsByTagName("div");
for (var i = 0; NavFrame = divs[i]; i++) {
// if found a navigation bar
if (hasClass(NavFrame, "NavFrame")) {
indexNavigationBar++;
var NavToggle = document.createElement("a");
NavToggle.className = 'NavToggle';
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
var isCollapsed = hasClass( NavFrame, "collapsed" );
/*
* Check if any children are already hidden. This loop is here for backwards compatibility:
* the old way of making NavFrames start out collapsed was to manually add style="display:none"
* to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make
* the content visible without JavaScript support), the new recommended way is to add the class
* "collapsed" to the NavFrame itself, just like with collapsible tables.
*/
for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
if ( NavChild.style.display == 'none' ) {
isCollapsed = true;
}
}
}
if (isCollapsed) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
NavChild.style.display = 'none';
}
}
}
var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide);
NavToggle.appendChild(NavToggleText);
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
for(var j=0; j < NavFrame.childNodes.length; j++) {
if (hasClass(NavFrame.childNodes[j], "NavHead")) {
NavToggle.style.color = NavFrame.childNodes[j].style.color;
NavFrame.childNodes[j].appendChild(NavToggle);
}
}
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
}
}
}
$( createNavigationBarToggleButton );
/*</pre>
===Test if an element has a certain class ===
<pre> */
/* Test if an element has a certain class **************************************
*
* Description: Uses regular expressions and caching for better performance.
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
*/
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
/*</pre>
===Force IP to preview before saving changes ===
<pre> */
// ==============================
// Force IP to preview before saving changes.
// Copyright Marc Mongenet, 2006
function forcePreview() {
if (wgUserName != null) return;
if (document.getElementById('editpage-copywarn')) {
var saveButton = document.getElementById("wpSave");
var oldHTML = document.getElementById('editpage-copywarn').innerHTML;
var newHTML = oldHTML + '<p style="width:100%;background-color:#FFE4E1;border:2px solid #700050; color:#000000; font-size:90%; padding:2px;"> با <a href="//fa.wikipedia.org/w/index.php?title=وپ:نام">نام کاربری </a> وارد شوید یا برای فعال شدن دکمه «صفحه ذخیره شود»، ابتدا از دکمه «پیش نمایش» استفاده کنید.</p>';
if (!saveButton) return;
if (location.search.search(/&action=edit/) == -1) return;
document.getElementById('editpage-copywarn').innerHTML = newHTML;
saveButton.disabled = true;
saveButton.style.fontWeight = "normal";
document.getElementById("wpPreview").style.fontWeight = "bold";
}
}
addLoadEvent(forcePreview);
//For Change [[Special:Upload]] to [[Project:Upload]]
function SpecialUploadToProjectUpload() {
$("#t-upload a").attr("href", "//fa.wikipedia.org/wiki/%D9%88%DB%8C%DA%A9%DB%8C%E2%80%8C%D9%BE%D8%AF%DB%8C%D8%A7:%D8%A8%D8%A7%D8%B1%DA%AF%D8%B0%D8%A7%D8%B1%DB%8C");
}
$( SpecialUploadToProjectUpload );
/* Scripts specific to Internet Explorer */
if (navigator.appName == "Microsoft Internet Explorer") {
/** Internet Explorer bug fix **************************************************
*
* Description: Fixes IE horizontal scrollbar bug
* Maintainers: [[User:Tom-]]?
*/
var oldWidth;
var docEl = document.documentElement;
function fixIEScroll() {
if (!oldWidth || docEl.clientWidth > oldWidth) doFixIEScroll();
else setTimeout(doFixIEScroll, 1);
oldWidth = docEl.clientWidth;
}
function doFixIEScroll() {
docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
}
document.attachEvent("onreadystatechange", fixIEScroll);
document.attachEvent("onresize", fixIEScroll);
// In print IE (7?) does not like line-height
appendCSS('@media print { sup, sub, p, .documentDescription { line-height: normal; }}');
// IE overflow bug
appendCSS('div.overflowbugx { overflow-x: scroll !important; overflow-y: hidden !important; } div.overflowbugy { overflow-y: scroll !important; overflow-x: hidden !important; }');
// IE zoomfix
//Use to fix right floating div/table inside tables.
appendCSS('.iezoomfix div, .iezoomfix table { zoom: 1;}');
//Import scripts specific to Internet Explorer 6
if (navigator.appVersion.substr(22, 1) == "6") {
importScript("MediaWiki:Common.js/IE60Fixes.js");
}
}
/* Fixes for Windows font rendering */
if ($.client.profile().platform == 'win') {
mw.util.addCSS('.IPA, .Unicode { font-family: "Arial Unicode MS", "Lucida Sans Unicode"; }');
}
/*</pre>
===Main Page layout fixes ===
<pre> */
/** Main Page layout fixes *********************************************************
*
* Description: Adds an additional link to the complete list of languages available.
* Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
*/
if (wgPageName == 'صفحهٔ_اصلی' || wgPageName == 'بحث:صفحه_اصلی')
$( function () {
addPortletLink('p-lang', '//meta.wikimedia.org/wiki/فهرست ویکیپدیاها', 'فهرست کامل', 'interwiki-completelist', 'فهرست کامل');
var nstab = document.getElementById('ca-nstab-main');
if (nstab && wgUserLanguage == 'fa')
nstab.firstChild.firstChild.nodeValue = 'صفحهٔ اصلی';
} )
/*
* Description: Stay on the secure server as much as possible
* Maintainers: [[User:TheDJ]]
*/
if (wgServer == 'https://secure.wikimedia.org') {
importScript('MediaWiki:Common.js/secure.js');
}
/*</pre>
===uploadwizard_newusers ===
<pre> */
/***** uploadwizard_newusers ********
* Switches in a message for non-autoconfirmed users at [[Wikipedia:Upload]]
*
* Maintainers: [[User:Krimpet]]
****/
function uploadwizard_newusers() {
if (wgNamespaceNumber == 4 && wgTitle == "Upload" && wgAction == "view") {
var oldDiv = document.getElementById("autoconfirmedusers"),
newDiv = document.getElementById("newusers");
if (oldDiv && newDiv) {
if (typeof wgUserGroups == "object" && wgUserGroups) {
for (i = 0; i < wgUserGroups.length; i++) {
if (wgUserGroups[i] == "autoconfirmed") {
oldDiv.style.display = "block";
newDiv.style.display = "none";
return;
}
}
}
oldDiv.style.display = "none";
newDiv.style.display = "block";
return;
}
}
}
$( uploadwizard_newusers );
/*</pre>
=== SVG images ===
<pre> */
/***** SVG images ********
*
****/
if(wgTitle.match(/\.svg$/i)){
importScript("MediaWiki:Gadget-SVGImages.js");
}
/*</pre>
===WikiMiniAtlas ===
<pre> */
/** WikiMiniAtlas *******************************************************
*
* Description: WikiMiniAtlas is a popup click and drag world map.
* This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
* The script itself is located on meta because it is used by many projects.
* See [[Meta:WikiMiniAtlas]] for more information.
* Maintainers: [[User:Dschwen]]
*/
mw.loader.load("//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400")
// OSM
var osm_proj_map='نقشه'; //"map" in project language
var osm_proj_lang='fa'; //project language
var metaBase = "//meta.wikimedia.org";
importScriptURI(metaBase+'/w/index.php?title=MediaWiki:OSM.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400');
/*</pre>
===redirect redlinks for not autoconfirmed users===
<pre>*/
/**
* redirect redlinks for not autoconfirmed users
* and hides "new article wizard" edit buttons for them
* +
* two CSS class for show and hide something
* from autoconfirmed users and not autoconfirmed users
* +
* don't allow page creation for with nonstandard characters (for persian)
*/
if(typeof iamsure === "undefined")
iamsure = false; // is a global variable and users can modify it on their vector.js or monobook.js
// to prevent from redirect from not correct title
function importantFunction() {
if( !/(secure\.wikimedia\.org|fa\.wikipedia\.org)/.test(window.location.href)){
return; // prevent to executed on other wikis
}
function extpar(par) {
var href = window.location.href;
return href.replace(RegExp(".*?[&?]" + par + "=([^&]*).*"), "$1").replace(href,"");
}
var isautoconfirmed = false, issysop = false, passednewarticlewizard = false;
if (typeof(wgUserGroups) == "object" && wgUserGroups) {
for (i = 0; i < wgUserGroups.length; i++) {
if (wgUserGroups[i] == "autoconfirmed") {
isautoconfirmed = true;
}
if (wgUserGroups[i] == "sysop") {
issysop = true;
}
}
}
if (!isautoconfirmed) {
var myQuery = ".new";
if ($(".noarticletext").length !== 0) {
myQuery = "#ca-edit a"; // if we are on new page, do that function to fix create button instead redlinks
}
$(myQuery).each(function() {
if(!(/\/wiki\//.test(this.href) || /title=.*\:/.test(this.href)))
this.href = this.href + encodeURI("&preload=الگو:ایجاد+مقاله/استخوانبندی&editintro=الگو:ایجاد+مقاله/ادیتنوتیس&summary=ایجاد+یک+مقاله+نو+از+طریق+ایجادگر&nosummary=&prefix=&minor=&create=درست+کردن+مقاله+جدید");
});
$(".isautoconfirmed").hide();
$(".notautoconfirmed").show();
importScript("MediaWiki:Gadget-signit.js");
}
else { // if was autoconfirmed
$(".isautoconfirmed").show();
$(".notautoconfirmed").hide();
}
if (extpar("iamsure")!=="")
iamsure = true;
if (extpar("redlink") === "1" && wgAction == "edit" && wgNamespaceNumber === 0
/*&& (isautoconfirmed || passednewarticlewizard) && (!iamsure)
&& extpar("redirected") === ""*/) {
function fixarticletitle(instr){ // a simple text cleaner, can improved by gadget-extraeditbutton codes later
for (i=0;i<10;i++) {
instr = instr.replace(RegExp("(" + "٠١٢٣٤٥٦٧٨٩"[i] + "|" + i + ")", "g"), "۰۱۲۳۴۵۶۷۸۹"[i]); // arabic and latin numbers
}
return instr.replace(/[ىي]/g, "ی")
.replace(/ك/g, "ک")
.replace(/:(?=[^\s])/g, ": ")
.replace(/([^\s])\(/, "$1 (") // look behind is not supported by javascript
.replace(/([\.،«»\:؛\sزرذدواژؤإأآءةa-zA-Z])\u200c/g, "$1")
.replace(/\u200c /g, " ")
.replace(/(\u200c*$|^\u200c*)/g, "")
.replace(/[\u200dـ]/g, "")
.replace(/\(\s(.*?)\s\)/g, "($1)")
.replace(/(ۀ|هٓ)/g, "هٔ")
.replace(/ابهام ؟زدایی/,/*n*/ "ابهامزدایی");
}
fixedtitle = fixarticletitle(wgTitle);
if (fixedtitle !== wgTitle) {
window.location.href = window.location.href.replace(
encodeURI(wgTitle.replace(/\s/g,"_")),
encodeURI(fixedtitle.replace(/\s/g,"_"))
)+"&redirected=1";
}
}
if(!issysop && wgTitle == "تابلوی اعلانات مدیران"){
$("#ca-edit a").attr("href", $("#thismonthlink > a").attr("href").replace("§ion=new", ""));
}
}
$( importantFunction );
/*</pre>
===Toggle direction of math formulas to LTR===
<pre>*/
/**
* قرار دادن فرمولهای ریاضی در سمت چپ مناسب برای ویکیهای راست به چپ
*/
$(function(){
$("img.tex, span.texhtml").each(function () {
if($(this).parent().text().trim() == $(this).text() && $(this).parent().is("p,dd"))
$(this).parent().css({direction: "ltr", padding: "1em 0"});
});
});
/*</pre>
===Source codes pages direction and and pre white-space ===
<pre> */
/**
* Source codes pages direction and and pre white-space
*/
if (wgNamespaceNumber == 2 || wgNamespaceNumber == 8 || wgNamespaceNumber == 4) {
if(/\.(js|css|py)$/.test(wgPageName)) {
mw.util.addCSS(".diff-addedline, .diff-deletedline, .diff-context { direction: ltr; }" +
".diff-addedline > div, .diff-deletedline > div, .diff-context > div { white-space: pre; }" +
"#wpTextbox1 { direction: ltr; }" );
}
}
/*</pre>
===Fix Persian sorting===
<pre> */
/** Bug fixed for persian sorting, see: [[m:Help:Sorting#Text]]
* and [[bugzilla:31137]]
*/
mw.config.set('tableSorterCollation', {'پ':'بي', 'چ' : 'جي', 'ژ': 'زي', 'ک':'قي', 'گ':'کي', 'ی':'وي'});
//</syntaxhighlight>
/*</pre>
=== Adding combo box to edittools.js===
<pre> */
//activating Extension:CharInsert
var load_edittools = true;
// extra drop down menu on editing for adding special characters
importScript( 'MediaWiki:Edittools.js' );
/*</pre>
=== External Search Engines ===
<pre> */
//***********************
//افزودن موتورهای جستجو بهجستجو پیشرفته
//***********************
function externalSearchEngines() {
if (typeof SpecialSearchEnhanced2Disabled != 'undefined') return;
if ( mw.config.get('wgCanonicalSpecialPageName') != "Search") return;
var mainNode = document.getElementById("powersearch");
if (!mainNode) mainNode = document.getElementById("search");
if (!mainNode) return;
var beforeNode = document.getElementById("mw-search-top-table");
if (!beforeNode) return;
beforeNode = beforeNode.nextSibling;
if (!beforeNode) return;
var firstEngine = "mediawiki";
var choices = document.createElement("div");
choices.setAttribute("id","searchengineChoices");
choices.style.textAlign = "center";
var lsearchbox = document.getElementById("searchText");
if (!lsearchbox) return;
var initValue = lsearchbox.value;
var space = "";
for (var id in searchEngines) {
var engine = searchEngines[id];
if(engine.ShortName)
{
if (space) choices.appendChild(space);
space = document.createTextNode(" ");
var attr = {
type: "radio",
name: "searchengineselect",
value: id,
onFocus: "changeSearchEngine(this.value)",
id: "searchengineRadio-"+id
};
var html = "<input";
for (var a in attr) html += " " + a + "='" + attr[a] + "'";
html += " />";
var span = document.createElement("span");
span.innerHTML = html;
choices.appendChild( span );
var label = document.createElement("label");
label.htmlFor = "searchengineRadio-"+id;
if (engine.Template.indexOf('http') == 0) {
var lienMoteur = document.createElement("a");
lienMoteur.href = engine.Template.replace("{searchTerms}", initValue).replace("{language}", "fa");
lienMoteur.appendChild( document.createTextNode( engine.ShortName ) );
label.appendChild(lienMoteur);
} else {
label.appendChild( document.createTextNode( engine.ShortName ) );
}
choices.appendChild( label );
}
}
mainNode.insertBefore(choices, beforeNode);
var input = document.createElement("input");
input.id = "searchengineextraparam";
input.type = "hidden";
mainNode.insertBefore(input, beforeNode);
changeSearchEngine(firstEngine, initValue);
}
function changeSearchEngine(selectedId, searchTerms) {
var currentId = document.getElementById("searchengineChoices").currentChoice;
if (selectedId == currentId) return;
document.getElementById("searchengineChoices").currentChoice = selectedId;
var radio = document.getElementById('searchengineRadio-' + selectedId);
radio.checked = "checked";
var engine = searchEngines[selectedId];
var p = engine.Template.indexOf('?');
var params = engine.Template.substr(p+1);
var form;
if (document.forms["search"]) {
form = document.forms["search"];
} else {
form = document.getElementById("powersearch");
}
form.setAttribute("action", engine.Template.substr(0,p));
var l = ("" + params).split("&");
for (var idx = 0;idx < l.length;idx++) {
var p = l[idx].split("=");
var pValue = p[1];
if (pValue == "{language}") {
} else if (pValue == "{searchTerms}") {
var input;
input = document.getElementById("searchText");
input.name = p[0];
} else {
var input = document.getElementById("searchengineextraparam");
input.name = p[0];
input.value = pValue;
}
}
}
if ( mw.config.get('wgCanonicalSpecialPageName') == "Search") {
var searchEngines = {
mediawiki: {
ShortName: "جستجو در اینترنت",
Template: mw.config.get('wgScript') + "?search={searchTerms}"
},
google: {
ShortName: "گوگل",
Template: "http://www.google.com/search?as_sitesearch=fa.wikipedia.org&hl={language}&q={searchTerms}"
},
wikiwix: {
ShortName: "ویکیویکس",
Template: "http://fa.wikiwix.com/index.php?action={searchTerms}&lang={language}"
},
wlive: {
ShortName: "بینگ",
Template: "http://www.bing.com/search?q={searchTerms}&q1=site:http://fa.wikipedia.org"
},
yahoo: {
ShortName: "یاهو!",
Template: "http://search.yahoo.com/search?p={searchTerms}&vs=fa.wikipedia.org"
},
globalwpsearch: {
ShortName: "همهٔ پروژههای ویکیپدیا",
Template: "http://vs.aka-online.de/cgi-bin/globalwpsearch.pl?timeout=120&search={searchTerms}"
}
};
addOnloadHook(externalSearchEngines);
}
/**
* Redirect User:Name/skin.js and skin.css to the current skin's pages
* (unless the 'skin' page really exists)
* @source: http://www.mediawiki.org/wiki/Snippets/Redirect_skin.js
* @rev: 2
*/
if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) == 2 ) {
var titleParts = mw.config.get( 'wgPageName' ).split( '/' );
// Make sure there was a part before and after the slash
// And that the latter is 'skin.js' or 'skin.css'
if ( titleParts.length == 2 ) {
var userSkinPage = titleParts.shift() + '/' + mw.config.get( 'skin' );
if ( titleParts.slice(-1) == 'skin.js' ) {
window.location.href = mw.util.wikiGetlink( userSkinPage + '.js' );
} else if ( titleParts.slice(-1) == 'skin.css' ) {
window.location.href = mw.util.wikiGetlink( userSkinPage + '.css' );
}
}
}
/*</pre>
=== ToggleImage ===
<pre>*/
// Adapted from French Wikipedia
function toggleImage (group, remindex, shwindex) {
jQuery("#ImageGroupsGr" + group + "Im" + remindex).hide();
jQuery("#ImageGroupsGr" + group + "Im" + shwindex).show();
}
function ImageGroup() {
jQuery('div.ImageGroup').each(function(i, group) {
var unitnode = jQuery('div.ImageGroupUnits', group).get(0);
if (unitnode == undefined) {
return 1;
}
var units = jQuery(unitnode).children('.center');
var count = units.get().length;
if (count <= 1) {
return 1;
}
units.each(function(j, currentimage) {
jQuery(currentimage).attr('id', "ImageGroupsGr" + i + "Im" + j);
var leftlink = jQuery('<a href="#" style="text-decoration:none" />');
var rightlink = jQuery('<a href="#" style="text-decoration:none" />');
if (j != 0) {
leftlink.text('▶').click(function() {
toggleImage(i, j, j - 1); return false;
});
}
if (j != count - 1) {
rightlink.text('◀').click(function() {
toggleImage(i, j, j + 1); return false;
});
}
jQuery('<div/>').css({ 'font-size' : '110%', 'font-weight' : 'bold' })
.append(leftlink)
.append('<tt>(' + String(j+1).replace(/1/g, "۱").replace(/2/g, "۲").replace(/3/g, "۳").replace(/4/g, "۴").replace(/5/g, "۵").replace(/6/g, "۶").replace(/7/g, "۷").replace(/8/g, "۸").replace(/9/g, "۹").replace(/0/g, "۰") + ' از ' + String(count).replace(/1/g, "۱").replace(/2/g, "۲").replace(/3/g, "۳").replace(/4/g, "۴").replace(/5/g, "۵").replace(/6/g, "۶").replace(/7/g, "۷").replace(/8/g, "۸").replace(/9/g, "۹").replace(/0/g, "۰") + ')</tt>')
.append(rightlink)
.prependTo(jQuery(currentimage));
if (j != 0) {
jQuery(currentimage).hide().addClass('noprint');
}
});
});
}
jQuery(document).ready(ImageGroup);
importScript("MediaWiki:Gadget-election.js");