مدیاویکی:Common.js: تفاوت میان نسخه‌ها

از ویکی حج
بدون خلاصۀ ویرایش
(خنثی‌سازی نسخهٔ 55143 از Engineer (بحث))
برچسب: خنثی‌سازی
 
(۱۲ نسخهٔ میانیِ ایجادشده توسط همین کاربر نشان داده نشد)
خط ۶: خط ۶:
});
});


/* تنظیمات پاپ آپ ها */
/* تنظیمات پاپ آپ ها  
mw.loader.using( [ 'ext.popups' ], function() { // wait for popups to be loaded
mw.loader.using( [ 'ext.popups' ], function() { // wait for popups to be loaded


خط ۲۴: خط ۲۴:
var scrollto = offset.top - 100; // minus fixed header height
var scrollto = offset.top - 100; // minus fixed header height
$('html, body').animate({scrollTop:scrollto}, 0);
$('html, body').animate({scrollTop:scrollto}, 0);
*/
/* global mw, $ */
// Editing-related javascripts
if (mw.config.get("wgAction") === "edit" || mw.config.get("wgAction") === "submit" || mw.config.get("wgCanonicalSpecialPageName") === "Upload") {
  /* scripts specific to editing pages */
  importScript("مدیاویکی:Common.js/edit.js");
}
/** Magic editintros ****************************************************
*
*  Description: Adds editintros on disambiguation pages and BLP pages.
*  Maintainers: [[User:RockMFR]]
*/
function addEditIntro(name) {
  $(".mw-editsection, #ca-edit").find("a").each(function(i, el) {
    el.href = $(this).attr("href") + "&editintro=" + name;
  });
}


// wordcount
if (mw.config.get("wgNamespaceNumber") === 0) {
//<nowiki>
  $(function() {
// This code is based on https://en.wikipedia.org/wiki/User:Dr_pda/prosesize.js
    if (document.getElementById("disambigbox")) {
// but adds CJK support (http://stackoverflow.com/questions/2315488) and support
      addEditIntro("Template:Disambig_editintro");
// for references and other lists.
    }
//
  });
function getWordCount(html) {
var str = html.innerHTML.replace(/(<([^>]+)>)/ig,"").trim();
 
var wordCount = 0;
 
var arr = str.match(/[\u3040-\u309F]|[\u30A0-\u30FF]|[\u4E00-\u9FFF\uF900-\uFAFF\u3400-\u4DBF]|\S+/g);
 
if (arr) {
wordCount = arr.length;
}


return wordCount;
  $(function() {
    var cats = mw.config.get("wgCategories");
    if (!cats) {
      return;
    }
    if ($.inArray("افراد زنده", cats) !== -1) {
      addEditIntro("Template:BLP_editintro");
    }
  });
}
}


function getContentDiv() {
/**
var contentDiv;
* @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
* @revision 2020-04-04
*/
mw.loader.using( ['mediawiki.util'], function () {
var extraCSS = mw.util.getParamValue( 'withCSS' ),
extraJS = mw.util.getParamValue( 'withJS' );


if (mw.config.get('wgAction') == 'edit') {
if ( extraCSS ) {
contentDiv = document.getElementById('wikiPreview');
// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
}
if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
else {
mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraCSS ) + '&action=raw&ctype=text/css', 'text/css' );
contentDiv = document.getElementById('mw-content-text');
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
}
}
}


return contentDiv;
if ( extraJS ) {
}
// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
 
if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
function isValidListNode(node) {
mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' );
if (node.parentElement.id == "word-count-stats") {
} else {
return false;
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
}
}
}
});


if (node.className.indexOf("toclevel-") > -1 ||
/**
node.parentElement.parentElement.id == "toc") {
* Opening preload.js to add interactive training keys
*/
mw.loader.using(["mediawiki.util"], function() {
  if (mw.util.getParamValue("preload")) {
    importScript("MediaWiki:Preloaded.js");
  }
});


return false;
/**
}
* Collapsible tables; reimplemented with mw-collapsible
* Styling is also in place to avoid FOUC
*
* Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
* @version 3.0.0 (2018-05-20)
* @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
* @author [[User:R. Koot]]
* @author [[User:Krinkle]]
* @author [[User:TheDJ]]
* @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
* is supported in MediaWiki core. Shimmable since MediaWiki 1.32
*
* @param {jQuery} $content
*/
function makeCollapsibleMwCollapsible( $content ) {
var $tables = $content
.find( 'table.collapsible:not(.mw-collapsible)' )
.addClass( 'mw-collapsible' );


if (node.parentElement.parentElement.parentElement.className == "catlinks") {
$.each( $tables, function ( index, table ) {
return false;
// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
if ( $( table ).hasClass( 'collapsed' ) ) {
$( table ).addClass( 'mw-collapsed' );
// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
}
} );
if ( $tables.length > 0 ) {
mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
$tables.makeCollapsible();
} );
}
}
}
mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );


var bodyContent = getContentDiv();
/**
var curNode = node.parentElement.parentElement;
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
 
*
while (curNode && (curNode != bodyContent)) {
* Maintainers: TheDJ
if (curNode.className.indexOf("infobox") > -1) {
*/
return false;
function mwCollapsibleSetup( $collapsibleContent ) {
var $element,
$toggle,
autoCollapseThreshold = 2;
$.each( $collapsibleContent, function ( index, element ) {
$element = $( element );
if ( $element.hasClass( 'collapsible' ) ) {
$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
}
}
else if (curNode.className.indexOf("metadata") > -1) {
if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
return false;
$element.data( 'mw-collapsible' ).collapse();
} else if ( $element.hasClass( 'innercollapse' ) ) {
if ( $element.parents( '.outercollapse' ).length > 0 ) {
$element.data( 'mw-collapsible' ).collapse();
}
}
}
else if (curNode.className.indexOf("navbox") > -1) {
// because of colored backgrounds, style the link in the text color
return false;
// to ensure accessible contrast
$toggle = $element.find( '.mw-collapsible-toggle' );
if ( $toggle.length ) {
// Make the toggle inherit text color
if ( $toggle.parent()[ 0 ].style.color ) {
$toggle.find( 'a' ).css( 'color', 'inherit' );
}
}
}
else {
} );
curNode = curNode.parentElement;
}
}
 
return true;
}
}


function isValidParagraphNode(node) {
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );
if (node.parentNode.className == "mw-parser-output" ||
node.parentNode.parentNode.className == "mw-parser-output" ||
node.parentNode.nodeName == "BLOCKQUOTE") {


return true;
/**
}
* Dynamic Navigation Bars (experimental)
else {
*
return false;
* Description: See [[Wikipedia:NavFrame]].
}
* Maintainers: UNMAINTAINED
}
*/


function isValidReferenceNode(node) {
var collapseCaption = 'بسته';
var bodyContent = getContentDiv();
var expandCaption = 'باز';
var curNode = node.parentElement;


while (curNode && (curNode != bodyContent)) {
// Set up the words in your language
if (curNode.classList.contains("references") ||
var navigationBarHide = '[' + collapseCaption + ']';
curNode.classList.contains("reflist") ||
var navigationBarShow = '[' + expandCaption + ']';
curNode.classList.contains("refbegin")) {


return true;
/**
}
* Shows and hides content and picture (if available) of navigation bars.
*
* @param {number} indexNavigationBar The index of navigation bar to be toggled
* @param {jQuery.Event} event Event object
* @return {boolean}
*/
function toggleNavigationBar( indexNavigationBar, event ) {
var navToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
var navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
var navChild;


curNode = curNode.parentElement;
if ( !navFrame || !navToggle ) {
return false;
}
}


return false;
// If shown now
}
if ( navToggle.firstChild.data === navigationBarHide ) {
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
if ( $( navChild ).hasClass( 'NavContent' ) ) {
navChild.style.display = 'none';
}
}
navToggle.firstChild.data = navigationBarShow;


function toggleWordCount() {
// If hidden now
if (mw.config.get('wgAction') == 'edit') {
} else if ( navToggle.firstChild.data === navigationBarShow ) {
var wikiPreview = document.getElementById('wikiPreview');
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
 
if ( $( navChild ).hasClass( 'NavContent' ) ) {
var wikiPreviewStyle = window.getComputedStyle(wikiPreview);
navChild.style.display = 'block';
 
}
if (wikiPreviewStyle.display === 'none') {
alert("You need to preview the text for the word count script to work in edit mode.");
 
return;
}
}
navToggle.firstChild.data = navigationBarHide;
}
}


var bodyContent = getContentDiv();
event.preventDefault();
}


var output = document.getElementById("word-count-stats");
/**
* Adds show/hide-button to navigation bars.
*
* @param {jQuery} $content
*/
function createNavigationBarToggleButton( $content ) {
var j, navChild, navToggle, navToggleText, isCollapsed,
indexNavigationBar = 0;
// Iterate over all < div >-elements
var $divs = $content.find( 'div.NavFrame:not(.mw-collapsible)' );
$divs.each( function ( i, navFrame ) {
indexNavigationBar++;
navToggle = document.createElement( 'a' );
navToggle.className = 'NavToggle';
navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
navToggle.setAttribute( 'href', '#' );
$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );


if (output) {
isCollapsed = $( navFrame ).hasClass( 'collapsed' );
var oldStyle = output.className;
/**
 
* Check if any children are already hidden. This loop is here for backwards compatibility:
var i = 0;
* 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
// Cleanup background color
* the content visible without JavaScript support), the new recommended way is to add the class
var pList = bodyContent.getElementsByTagName("p");
* "collapsed" to the NavFrame itself, just like with collapsible tables.
 
*/
if (pList) {
for ( navChild = navFrame.firstChild; navChild !== null && !isCollapsed; navChild = navChild.nextSibling ) {
for (i=0; i < pList.length; i++){
if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
if (isValidParagraphNode(pList[i])) {
if ( navChild.style.display === 'none' ) {
pList[i].style.cssText = oldStyle;
isCollapsed = true;
}
}
}
}
}
}
 
if ( isCollapsed ) {
var listTypes = ["li", "dd"];
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
for (var j = 0; j < listTypes.length; j++) {
navChild.style.display = 'none';
var liList = bodyContent.getElementsByTagName(listTypes[j]);
 
if (liList) {
for (i=0; i < liList.length; i++) {
liList[i].style.cssText = oldStyle;
}
}
}
}
}
}
navToggleText = document.createTextNode( isCollapsed ? navigationBarShow : navigationBarHide );
navToggle.appendChild( navToggleText );


var hList = bodyContent.getElementsByClassName("mw-headline");
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
 
for ( j = 0; j < navFrame.childNodes.length; j++ ) {
if (hList) {
if ( $( navFrame.childNodes[ j ] ).hasClass( 'NavHead' ) ) {
for (i=0; i < hList.length; i++) {
navToggle.style.color = navFrame.childNodes[ j ].style.color;
hList[i].style.cssText = oldStyle;
navFrame.childNodes[ j ].appendChild( navToggle );
}
}
}
}
 
navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
// Remove nodes
} );
output.parentNode.removeChild(output);
 
var header = document.getElementById("word-count-header");
 
header.parentNode.removeChild(header);
}
else {
getStatistics(bodyContent);
}
}
}


//
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
// Main counting function
//
function getStatistics(bodyContent) {


// Statistics
/** Dynamic Navigation Bars (experimental) *************************************
var output = document.createElement("ul");
*
output.id = "word-count-stats";
*  Description: See [[Wikipedia:NavFrame]].
*  Maintainers: UNMAINTAINED
*/


var main_body_value = document.createElement("li");
// set up the words in your language
main_body_value.id = "main-body-stat";
var NavigationBarHide = "[" + collapseCaption + "]";
output.appendChild(main_body_value);
var NavigationBarShow = "[" + expandCaption + "]";
output.className = bodyContent.getElementsByTagName("p").item(0).style.cssText;


var ref_value = document.createElement("li");
// shows and hides content and picture (if available) of navigation bars
ref_value.id = "ref-stat";
// Parameters:
output.appendChild(ref_value);
//    indexNavigationBar: the index of navigation bar to be toggled
window.toggleNavigationBar = function(indexNavigationBar, event) {
  var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
  var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
  var NavChild;


var total_value = document.createElement("li");
  if (!NavFrame || !NavToggle) {
total_value.id = "total-stat";
    return false;
output.appendChild(total_value);
  }


bodyContent.insertBefore(output, bodyContent.firstChild);
  /* if shown now */
  if (NavToggle.firstChild.data === NavigationBarHide) {
    for (NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
      if ($(NavChild).hasClass("NavContent") || $(NavChild).hasClass("NavPic")) {
        NavChild.style.display = "none";
      }
    }
    NavToggle.firstChild.data = NavigationBarShow;


// Header
    /* if hidden now */
var header = document.createElement("span");
  } else if (NavToggle.firstChild.data === NavigationBarShow) {
header.id = "word-count-header";
    for (NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
header.innerHTML = "<br/><b>Word counts</b> (<a href='https://en.wikipedia.org/wiki/User:Caorongjin/wordcount'>doc</a>)<b>:</b>";
      if ($(NavChild).hasClass("NavContent") || $(NavChild).hasClass("NavPic")) {
bodyContent.insertBefore(header,output);
        NavChild.style.display = "block";
      }
    }
    NavToggle.firstChild.data = NavigationBarHide;
  }


// Create counters
  event.preventDefault();
var main_body_count = 0;
};
var ref_count = 0;


var i = 0;
/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton() {
  var indexNavigationBar = 0;
  var NavFrame;
  var NavChild;
  /* iterate over all < div >-elements */
  var divs = document.getElementsByTagName("div");
  for (var i = 0;
    (NavFrame = divs[i]); i++) {
    /* if found a navigation bar */
    if ($(NavFrame).hasClass("NavFrame")) {


// Count within paragraphs
      indexNavigationBar++;
var pList = bodyContent.getElementsByTagName("p");
      var NavToggle = document.createElement("a");
      NavToggle.className = "NavToggle";
      NavToggle.setAttribute("id", "NavToggle" + indexNavigationBar);
      NavToggle.setAttribute("href", "#");
      $(NavToggle).on("click", $.proxy(window.toggleNavigationBar, window, indexNavigationBar));


if (pList) {
      var isCollapsed = $(NavFrame).hasClass("collapsed");
for (i=0; i < pList.length; i++) {
      /**
var para = pList[i];
      * 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 (NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
        if ($(NavChild).hasClass("NavPic") || $(NavChild).hasClass("NavContent")) {
          if (NavChild.style.display === "none") {
            isCollapsed = true;
          }
        }
      }
      if (isCollapsed) {
        for (NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
          if ($(NavChild).hasClass("NavPic") || $(NavChild).hasClass("NavContent")) {
            NavChild.style.display = "none";
          }
        }
      }
      var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide);
      NavToggle.appendChild(NavToggleText);


if (isValidParagraphNode(para)) {
      /* Find the NavHead and attach the toggle link (Must be this complicated because Moz"s firstChild handling is borked) */
var paraCount = getWordCount(para);
      for (var j = 0; j < NavFrame.childNodes.length; j++) {
 
        if ($(NavFrame.childNodes[j]).hasClass("NavHead")) {
if (paraCount > 0) {
          NavToggle.style.color = NavFrame.childNodes[j].style.color;
main_body_count += paraCount;
          NavFrame.childNodes[j].appendChild(NavToggle);
para.style.cssText = "background-color:yellow";
        }
}
      }
}
      NavFrame.setAttribute("id", "NavFrame" + indexNavigationBar);
}
    }
}
  }
}


// Count within lists
// $(createNavigationBarToggleButton);
var listTypes = ["li", "dd"];


for (var j = 0; j < listTypes.length; j++) {
/** Main Page layout fixes *********************************************************
var liList = bodyContent.getElementsByTagName(listTypes[j]);
*
*  Description: Adds an additional link to the complete list of languages available.
*  Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
*/
mw.loader.using(["mediawiki.util"], function() {
/**
  * Extract a URL parameter from the current URL
  * @deprecated: Use mw.util.getParamValue with proper escaping
  */
  mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );
  if (["صفحهٔ_اصلی", "بحث:صفحه_اصلی"].indexOf(mw.config.get("wgPageName")) !== -1) {
    $(function() {
      mw.util.addPortletLink("p-lang", "//meta.wikimedia.org/wiki/List_of_Wikipedias/fa", "فهرست کامل", "interwiki-completelist", "فهرست کامل");
    });
  }
});


if (liList) {
/**
for (i=0; i < liList.length; i++) {
* WikiMiniAtlas
var li = liList[i];
*
* 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]]
*/
(function() {
  var require_wikiminiatlas = false;
  var coord_filter = /geohack/;
  $(function() {
    $("a.external.text").each(function(key, link) {
      if (link.href && coord_filter.exec(link.href)) {
        require_wikiminiatlas = true;
        // break from loop
        return false;
      }
    });
    if ($("div.kmldata").length) {
      require_wikiminiatlas = true;
    }
    if (require_wikiminiatlas) {
      mw.loader.load("//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript");
    }
  });
})();


if (isValidReferenceNode(li)) {
/**
ref_count += getWordCount(li);
* Source codes pages direction and and pre white-space
li.style.cssText = "background-color:cyan";
*/
}
mw.loader.using(["mediawiki.util"], function() {
else if (isValidListNode(li)) {
  if ([2, 4, 8].indexOf(mw.config.get("wgNamespaceNumber")) !== -1) {
main_body_count += getWordCount(li);
    if (/\.(js|css|py)$/.test(mw.config.get("wgPageName"))) {
li.style.cssText = "background-color:yellow";
      mw.util.addCSS(".diff-addedline, .diff-deletedline, .diff-context { direction: ltr; } " +
}
        "#wpTextbox1 { direction: ltr; }");
}
    }
}
  }
}


// Count within headings
  // Newbies are misusing wikilove instead using talk pages add new section
var hList = bodyContent.getElementsByClassName("mw-headline");
  // hiding WikiLove from not autoconfirmed users or without more than 100 edits
  if ($.inArray("autoconfirmed", mw.config.get("wgUserGroups")) === -1 || mw.config.get("wgUserEditCount") < 100) {
    mw.util.addCSS("#ca-wikilove { display: none; }");
  }
});
/**
* قراردادن فرمول‌های ریاضی در سمت چپ مناسب برای ویکی‌های راست به چپ
*/
$(function() {
  $("span.mwe-math-mathml-inline").each(function() {
    if ($(this).parent().parent().text().trim() === $(this).parent().text().trim() && $(this).parent().parent().is("p, dd")) {
      $(this).parent().parent().css({
        direction: "ltr",
        padding: "1em 0"
      });
    }
  });
});


if (hList) {
// هشدار به کاربرها در مورد عنوان ایمیل
for (i=0; i < hList.length; i++) {
$(function() {
var h = hList[i];
  if ( $('#mw-input-wpSubject').parents('tr').length > 0 ) {
    $('#mw-input-wpSubject').parents('tr').before('<tr><td></td><td style="color: red; font-weight: bold">لطفاً عبارت Wikipedia e-mail ‌را با یک عنوان مناسب جایگزین کنید!</td><tr>');
  }
});


if (h.id == "Contents") {
// Make refrence number that you clicked on bold for proper navigation
continue;
// Author: User:Ladsgroup
}
$( 'sup.reference' ).click( function () {
    var citeId = $( this ).attr( 'id' );
    $( 'sup > a[href="#' + citeId + '"]').css('color', '#2a4b8d').css('font-weight', 'bold');
    $( 'sup > a[href="#' + citeId + '"]').click( function() {
        $( this ).css('color', '').css('font-weight', '');
    } );
} );


main_body_count += getWordCount(h);
// Hide the FileExporter portlet link if the file is not free content
h.style.cssText = "background-color:yellow";
$(function() {
}
  if ($('#ca-fileExporter').length == 1 & $(mw.config.get('wgCategories')).filter(['محتویات غیر آزاد', 'تصویرهای با منبع نامعلوم', 'تصویرهای با پدیدآور نامشخص', 'پرونده‌های بدون مجوز قابل خواندن برای ماشین']).length > 0) {
}
  $('#ca-fileExporter').find('a').css('color', 'grey').attr('title', 'غیرفعال برای محتوای غیر آزاد');
  }
});


main_body_value.innerHTML = "Main body: " + main_body_count + " words";
function updateUserScriptWarning( msg, newMsg ) {
ref_value.innerHTML = "References: " + ref_count + " words";
return function () {
total_value.innerHTML = "Total: " + (main_body_count + ref_count) + " words";
var userScript = '/wiki/Special:MyPage/' + mw.config.get('skin') + '.js';
var commonScript = '/wiki/Special:MyPage/common.js';
mw.notify(
$('<div>').html(
// please translate to Farsi
'One of the scripts you are running is broken and using a deprecated function <strong>' + msg + '</strong>. Please check your <a href="' + userScript + '">skin scripts</a> and <a href="' + commonScript + '">common scripts</a>, to update the reference to' + newMsg + 'to restore your script.'
),
{ type: 'error' }
);
};
}
}
jQuery(function () {
mw.loader.using( ['mediawiki.util'], function () {
if($.inArray(mw.config.get('wgAction'), ['edit', 'view' , 'submit' , 'historysubmit' , 'purge']) !== -1) {
$( mw.util.addPortletLink('p-tb', '#', 'Word count', 't-word-count', 'Calculate word count') )
.click( toggleWordCount );
}
});
});
//</nowiki>

نسخهٔ کنونی تا ‏۱ نوامبر ۲۰۲۳، ساعت ۱۰:۰۴

/* اضافه کردن تیتر برای یادداشت ها */
$( function() {
    if($('#reflist-notes .reflist').text().length>10) {
        $('#reflist-notes').before('<h2>یادداشت‌ها</h2>');
    }
});

/* تنظیمات پاپ آپ ها 
mw.loader.using( [ 'ext.popups' ], function() { // wait for popups to be loaded

// Time to wait in ms before showing a popup on hover. Default is 500.
mw.popups.render.POPUP_DELAY = 500;

// Time to wait in ms before closing a popup on de-hover. Default is 300.
mw.popups.render.POPUP_CLOSE_DELAY = 300;

// Time to wait in ms before starting the API queries on hover, must be <= POPUP_DELAY. Default is 50.
// Don't change this unless you know what you're doing.
mw.popups.render.API_DELAY = 50;

});

var offset = $(':target').offset();
var scrollto = offset.top - 100; // minus fixed header height
$('html, body').animate({scrollTop:scrollto}, 0);
*/
/* global mw, $ */
// Editing-related javascripts
if (mw.config.get("wgAction") === "edit" || mw.config.get("wgAction") === "submit" || mw.config.get("wgCanonicalSpecialPageName") === "Upload") {
  /* scripts specific to editing pages */
  importScript("مدیاویکی:Common.js/edit.js");
}
/** Magic editintros ****************************************************
 *
 *  Description: Adds editintros on disambiguation pages and BLP pages.
 *  Maintainers: [[User:RockMFR]]
 */
function addEditIntro(name) {
  $(".mw-editsection, #ca-edit").find("a").each(function(i, el) {
    el.href = $(this).attr("href") + "&editintro=" + name;
  });
}

if (mw.config.get("wgNamespaceNumber") === 0) {
  $(function() {
    if (document.getElementById("disambigbox")) {
      addEditIntro("Template:Disambig_editintro");
    }
  });

  $(function() {
    var cats = mw.config.get("wgCategories");
    if (!cats) {
      return;
    }
    if ($.inArray("افراد زنده", cats) !== -1) {
      addEditIntro("Template:BLP_editintro");
    }
  });
}

/**
 * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 * @revision 2020-04-04
 */
mw.loader.using( ['mediawiki.util'], function () {
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' );

	if ( extraCSS ) {
		// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
		if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraCSS ) + '&action=raw&ctype=text/css', 'text/css' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
		}
	}

	if ( extraJS ) {
		// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
		if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
		}
	}
});

/**
 * Opening preload.js to add interactive training keys
 */
mw.loader.using(["mediawiki.util"], function() {
  if (mw.util.getParamValue("preload")) {
    importScript("MediaWiki:Preloaded.js");
  }
});

/**
 * Collapsible tables; reimplemented with mw-collapsible
 * Styling is also in place to avoid FOUC
 *
 * Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
 * @version 3.0.0 (2018-05-20)
 * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
 * @author [[User:R. Koot]]
 * @author [[User:Krinkle]]
 * @author [[User:TheDJ]]
 * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
 * is supported in MediaWiki core. Shimmable since MediaWiki 1.32
 *
 * @param {jQuery} $content
 */
function makeCollapsibleMwCollapsible( $content ) {
	var $tables = $content
		.find( 'table.collapsible:not(.mw-collapsible)' )
		.addClass( 'mw-collapsible' );

	$.each( $tables, function ( index, table ) {
		// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
		if ( $( table ).hasClass( 'collapsed' ) ) {
			$( table ).addClass( 'mw-collapsed' );
			// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
		}
	} );
	if ( $tables.length > 0 ) {
		mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
			$tables.makeCollapsible();
		} );
	}
}
mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );

/**
 * Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
 *
 * Maintainers: TheDJ
 */
function mwCollapsibleSetup( $collapsibleContent ) {
	var $element,
		$toggle,
		autoCollapseThreshold = 2;
	$.each( $collapsibleContent, function ( index, element ) {
		$element = $( element );
		if ( $element.hasClass( 'collapsible' ) ) {
			$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
		}
		if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
			$element.data( 'mw-collapsible' ).collapse();
		} else if ( $element.hasClass( 'innercollapse' ) ) {
			if ( $element.parents( '.outercollapse' ).length > 0 ) {
				$element.data( 'mw-collapsible' ).collapse();
			}
		}
		// because of colored backgrounds, style the link in the text color
		// to ensure accessible contrast
		$toggle = $element.find( '.mw-collapsible-toggle' );
		if ( $toggle.length ) {
			// Make the toggle inherit text color
			if ( $toggle.parent()[ 0 ].style.color ) {
				$toggle.find( 'a' ).css( 'color', 'inherit' );
			}
		}
	} );
}

mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );

/**
 * Dynamic Navigation Bars (experimental)
 *
 * Description: See [[Wikipedia:NavFrame]].
 * Maintainers: UNMAINTAINED
 */

var collapseCaption = 'بسته';
var expandCaption = 'باز';

// Set up the words in your language
var navigationBarHide = '[' + collapseCaption + ']';
var navigationBarShow = '[' + expandCaption + ']';

/**
 * Shows and hides content and picture (if available) of navigation bars.
 *
 * @param {number} indexNavigationBar The index of navigation bar to be toggled
 * @param {jQuery.Event} event Event object
 * @return {boolean}
 */
function toggleNavigationBar( indexNavigationBar, event ) {
	var navToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
	var navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
	var navChild;

	if ( !navFrame || !navToggle ) {
		return false;
	}

	// If shown now
	if ( navToggle.firstChild.data === navigationBarHide ) {
		for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
			if ( $( navChild ).hasClass( 'NavContent' ) ) {
				navChild.style.display = 'none';
			}
		}
		navToggle.firstChild.data = navigationBarShow;

	// If hidden now
	} else if ( navToggle.firstChild.data === navigationBarShow ) {
		for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
			if ( $( navChild ).hasClass( 'NavContent' ) ) {
				navChild.style.display = 'block';
			}
		}
		navToggle.firstChild.data = navigationBarHide;
	}

	event.preventDefault();
}

/**
 * Adds show/hide-button to navigation bars.
 *
 * @param {jQuery} $content
 */
function createNavigationBarToggleButton( $content ) {
	var j, navChild, navToggle, navToggleText, isCollapsed,
		indexNavigationBar = 0;
	// Iterate over all < div >-elements
	var $divs = $content.find( 'div.NavFrame:not(.mw-collapsible)' );
	$divs.each( function ( i, navFrame ) {
		indexNavigationBar++;
		navToggle = document.createElement( 'a' );
		navToggle.className = 'NavToggle';
		navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
		navToggle.setAttribute( 'href', '#' );
		$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );

		isCollapsed = $( navFrame ).hasClass( '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 ( navChild = navFrame.firstChild; navChild !== null && !isCollapsed; navChild = navChild.nextSibling ) {
			if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
				if ( navChild.style.display === 'none' ) {
					isCollapsed = true;
				}
			}
		}
		if ( isCollapsed ) {
			for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
				if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
					navChild.style.display = 'none';
				}
			}
		}
		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 ( j = 0; j < navFrame.childNodes.length; j++ ) {
			if ( $( navFrame.childNodes[ j ] ).hasClass( 'NavHead' ) ) {
				navToggle.style.color = navFrame.childNodes[ j ].style.color;
				navFrame.childNodes[ j ].appendChild( navToggle );
			}
		}
		navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
	} );
}

mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );

/** 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
window.toggleNavigationBar = function(indexNavigationBar, event) {
  var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
  var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
  var NavChild;

  if (!NavFrame || !NavToggle) {
    return false;
  }

  /* if shown now */
  if (NavToggle.firstChild.data === NavigationBarHide) {
    for (NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
      if ($(NavChild).hasClass("NavContent") || $(NavChild).hasClass("NavPic")) {
        NavChild.style.display = "none";
      }
    }
    NavToggle.firstChild.data = NavigationBarShow;

    /* if hidden now */
  } else if (NavToggle.firstChild.data === NavigationBarShow) {
    for (NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
      if ($(NavChild).hasClass("NavContent") || $(NavChild).hasClass("NavPic")) {
        NavChild.style.display = "block";
      }
    }
    NavToggle.firstChild.data = NavigationBarHide;
  }

  event.preventDefault();
};

/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton() {
  var indexNavigationBar = 0;
  var NavFrame;
  var NavChild;
  /* iterate over all < div >-elements */
  var divs = document.getElementsByTagName("div");
  for (var i = 0;
    (NavFrame = divs[i]); i++) {
    /* if found a navigation bar */
    if ($(NavFrame).hasClass("NavFrame")) {

      indexNavigationBar++;
      var NavToggle = document.createElement("a");
      NavToggle.className = "NavToggle";
      NavToggle.setAttribute("id", "NavToggle" + indexNavigationBar);
      NavToggle.setAttribute("href", "#");
      $(NavToggle).on("click", $.proxy(window.toggleNavigationBar, window, indexNavigationBar));

      var isCollapsed = $(NavFrame).hasClass("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 (NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
        if ($(NavChild).hasClass("NavPic") || $(NavChild).hasClass("NavContent")) {
          if (NavChild.style.display === "none") {
            isCollapsed = true;
          }
        }
      }
      if (isCollapsed) {
        for (NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
          if ($(NavChild).hasClass("NavPic") || $(NavChild).hasClass("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 ($(NavFrame.childNodes[j]).hasClass("NavHead")) {
          NavToggle.style.color = NavFrame.childNodes[j].style.color;
          NavFrame.childNodes[j].appendChild(NavToggle);
        }
      }
      NavFrame.setAttribute("id", "NavFrame" + indexNavigationBar);
    }
  }
}

// $(createNavigationBarToggleButton);

/** 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]]
 */
mw.loader.using(["mediawiki.util"], function() {
 /**
  * Extract a URL parameter from the current URL
  * @deprecated: Use mw.util.getParamValue with proper escaping
  */
  mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );
  if (["صفحهٔ_اصلی", "بحث:صفحه_اصلی"].indexOf(mw.config.get("wgPageName")) !== -1) {
    $(function() {
      mw.util.addPortletLink("p-lang", "//meta.wikimedia.org/wiki/List_of_Wikipedias/fa", "فهرست کامل", "interwiki-completelist", "فهرست کامل");
    });
  }
});

/**
 * 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]]
 */
(function() {
  var require_wikiminiatlas = false;
  var coord_filter = /geohack/;
  $(function() {
    $("a.external.text").each(function(key, link) {
      if (link.href && coord_filter.exec(link.href)) {
        require_wikiminiatlas = true;
        // break from loop
        return false;
      }
    });
    if ($("div.kmldata").length) {
      require_wikiminiatlas = true;
    }
    if (require_wikiminiatlas) {
      mw.loader.load("//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript");
    }
  });
})();

/**
 * Source codes pages direction and and pre white-space 
 */
mw.loader.using(["mediawiki.util"], function() {
  if ([2, 4, 8].indexOf(mw.config.get("wgNamespaceNumber")) !== -1) {
    if (/\.(js|css|py)$/.test(mw.config.get("wgPageName"))) {
      mw.util.addCSS(".diff-addedline, .diff-deletedline, .diff-context { direction: ltr; } " +
        "#wpTextbox1 { direction: ltr; }");
    }
  }

  // Newbies are misusing wikilove instead using talk pages add new section
  // hiding WikiLove from not autoconfirmed users or without more than 100 edits
  if ($.inArray("autoconfirmed", mw.config.get("wgUserGroups")) === -1 || mw.config.get("wgUserEditCount") < 100) {
    mw.util.addCSS("#ca-wikilove { display: none; }");
  }
});
/**
 * قراردادن فرمول‌های ریاضی در سمت چپ مناسب برای ویکی‌های راست به چپ
 */
$(function() {
  $("span.mwe-math-mathml-inline").each(function() {
    if ($(this).parent().parent().text().trim() === $(this).parent().text().trim() && $(this).parent().parent().is("p, dd")) {
      $(this).parent().parent().css({
        direction: "ltr",
        padding: "1em 0"
      });
    }
  });
});

// هشدار به کاربرها در مورد عنوان ایمیل
$(function() {
  if ( $('#mw-input-wpSubject').parents('tr').length > 0 ) {
    $('#mw-input-wpSubject').parents('tr').before('<tr><td></td><td style="color: red; font-weight: bold">لطفاً عبارت Wikipedia e-mail ‌را با یک عنوان مناسب جایگزین کنید!</td><tr>');
  }
});

// Make refrence number that you clicked on bold for proper navigation
// Author: User:Ladsgroup
$( 'sup.reference' ).click( function () {
    var citeId = $( this ).attr( 'id' );
    $( 'sup > a[href="#' + citeId + '"]').css('color', '#2a4b8d').css('font-weight', 'bold');
    $( 'sup > a[href="#' + citeId + '"]').click( function() {
        $( this ).css('color', '').css('font-weight', '');
    } );
} );

// Hide the FileExporter portlet link if the file is not free content
$(function() {
  if ($('#ca-fileExporter').length == 1 & $(mw.config.get('wgCategories')).filter(['محتویات غیر آزاد', 'تصویرهای با منبع نامعلوم', 'تصویرهای با پدیدآور نامشخص', 'پرونده‌های بدون مجوز قابل خواندن برای ماشین']).length > 0) {
  	$('#ca-fileExporter').find('a').css('color', 'grey').attr('title', 'غیرفعال برای محتوای غیر آزاد');
  }
});

function updateUserScriptWarning( msg, newMsg ) {
	return function () {
		var userScript = '/wiki/Special:MyPage/' + mw.config.get('skin') + '.js';
		var commonScript = '/wiki/Special:MyPage/common.js';
		mw.notify(
			$('<div>').html(
				// please translate to Farsi
				'One of the scripts you are running is broken and using a deprecated function <strong>' + msg + '</strong>. Please check your <a href="' + userScript + '">skin scripts</a> and <a href="' + commonScript + '">common scripts</a>, to update the reference to' + newMsg + 'to restore your script.'
			),
			{ type: 'error' }
		); 
	};
}