"मीडियाविकि:Common.js" इत्यस्य संस्करणे भेदः

विकिस्रोतः तः
Content deleted Content added
updating for new Google OCR tool
try to fix up mw.util references that don't wait for mediawiki.util loading, see meta:Tech
पङ्क्तिः ४: पङ्क्तिः ४:
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:InterWikiTransclusion.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:InterWikiTransclusion.js&action=raw&ctype=text/javascript');


/* Deprecated functions now in the central mw software */

window.getParamValue = mw.util.getParamValue;


/**
/**
पङ्क्तिः ४५५: पङ्क्तिः ४५०:
* Maintainer: [[User:Platonides]], [[User:Lupo]]
* Maintainer: [[User:Platonides]], [[User:Lupo]]
*/
*/
mw.loader.using('mediawiki.util', function () {
var extraJS = mw.util.getParamValue('withJS');
var extraJS = mw.util.getParamValue('withJS');
// Leave here for backwards compatibility
// Leave here for backwards compatibility
(function (extraJS) {
if (!extraJS) {
if (extraJS) {
if (extraJS.match(/^MediaWiki:[^&<>=%#]*\.js$/)) {
return;
// Disallow some characters in file name
}
importScript(extraJS);
if (extraJS.match(/^MediaWiki:[^&<>=%#]*\.js$/)) {
} else {
// Disallow some characters in file name
// Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready.
importScript(extraJS);
$(function () {
} else {
// Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready.
jsMsg(extraJS + ' javascript not allowed to be loaded.', 'error');
});
$(function () {
}
jsMsg(extraJS + ' javascript not allowed to be loaded.', 'error');
});
}
}
});
})(extraJS);



/**
/**

१२:३३, १८ मे २०१८ इत्यस्य संस्करणं

/* यहां लिखी गई जावास्क्रीप्ट सभी सदस्योंके लिये इस्तेमाल में लाई जायेगी। */

// import scripts for Interwiki Transclusion from http://wikisource.org/wiki/Wikisource:Shared_Scripts
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:InterWikiTransclusion.js&action=raw&ctype=text/javascript');

/**
 * Scripts imported from wikisource.org
 */

// Messages are configurable here
self.ws_messages = { 
	'optlist':'Display options',
	'hide_page_numbers':'Hide page links',
	'show_page_numbers':'Show page links',
	'layout':'Layout',
	'author':'Author',
	'translator':'Translator', 
	'editor':'Editor', 
	'publisher':'Publisher', 
	'place':'Place', 
	'volume':'Volume', 
	'school':'School', 
	'book':'Book', 
	'collection':'Collection', 
	'journal':'Journal or magazine', 
	'phdthesis':'Thesis, report', 
	'dictionary':'Dictionary', 
	'progress':'Progress', 
	'progress_T':'Done', 
	'progress_V':'To be validated', 
	'progress_C':'To be proofread', 
	'progress_MS':'Ready for Match & Split', 
	'progress_OCR':'Needs an OCR text layer', 
	'progress_L':'Source file is incorrect (missing pages, unordered pages, etc)', 
	'▲':'Return to the top of the page.',
	
	'corr_list':"List of corrections performed on this page" , 
	'corr_link':"Corrections" , 
	'corr_one':"One typo </a> has been corrected." , 
	'corr_many':" typos</a> have been corrected." , 
	'corr_close':"Close." , 

	'iwtrans':'Its text comes from', 
	'iwtrans2':'Its text comes from other Wikisource subdomains.'
};

// Dynamic layouts
if ( !self.ws_layouts ) {
 self.ws_layouts = {};
}
self.ws_layouts['Layout 1'] = {
   '#text-wrap':"", 
   '#text-container':"" , 
   '#text':"", 
   '.sidenote-right':"float:right;margin:0.5em;padding:3px;border:solid 1px gray;max-width:9em;text-indent:0em;text-align:left;",
   '.sidenote-left':"float:left;margin:0.5em;padding:3px;border:solid 1px gray;max-width:9em;text-indent:0em;text-align:left;",
   '.editsection':"display:none",
   '#headertemplate':"" 
};
self.ws_layouts['Layout 2'] = {
   '#text-wrap':"position:relative;margin-left:3em;margin-right:3em;", 
   '#text-container':"width:36em;margin:0px auto;font-family:Georgia,serif;" , 
   '#text':"text-align:justify;", 
   '.sidenote-right':"position:absolute; left:37em;width:16em;text-indent:0em;text-align:left;",
   '.sidenote-left':"position:absolute; right:37em;width:16em;text-indent:0em;text-align:right;",
   '.editsection':"display:none",
   '#headertemplate':"" 
};
self.ws_layouts['Layout 3'] = {
   '#text-wrap':"margin-left:3em",
   '#text-container':"position:relative; min-width:60em; float:left; width:100%; margin-right:-23em;" , 
   '#text':"text-align:justify;margin-right:23em; text-indent:0em; padding-left:0px; padding-right:0px;width:auto; position:relative;",
   '.sidenote-right':"position:absolute; right:-10em; width:9em; background-color:#eeeeee;text-indent:0em;text-align:left;",
   '.sidenote-left':"position:absolute; right:-10em; width:9em; background-color:#eeeeee;text-indent:0em;text-align:left;",
   '.editsection':"display:none",
   '#headertemplate':"position:absolute; top:0em; right:-23em; width:21em;float:right; text-align:left;" 
};

self.proofreadpage_add_container = true;

mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:GoogleOCR.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:DisplayFooter.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:PageNumbers.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:Corrections.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:IndexForm.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:Dictionary.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:InterWikiTransclusion.js&action=raw&ctype=text/javascript');

// Mouse wheel zoom should work now for most browsers.
// If it does not work for you, set this to true in your javascript.
self.proofreadpage_disable_wheelzoom = false;


/**
 * Allow descriptive labels next to sidebar language links using {{interwiki-info}}
 * by [[user:ThomasV]]
 */
function interwikiExtra() {
	// iterate over all <span>-elements
	for(var i=0; a=document.getElementsByTagName('span')[i]; i++) {
		// if found a linkInfo span
		if(a.className == 'interwiki-info') {
			// iterate over all <li>-elements
			var count=0;
			for(var j=0; b=document.getElementsByTagName('li')[j]; j++) {
				if(b.className == 'interwiki-' + a.id) {
					b.innerHTML = b.innerHTML + ' ' + a.title;
					if(a.title == '(vo)') {
						b.title = 'Original Version';
					}
				}
				else if(b.className == 'interwiki-' + a.id.substr(0, a.id.length-1)) {
					count++;
					if(a.id.charAt(a.id.length-1) == count) {
						b.innerHTML = b.innerHTML + ' ' + a.title;
					}
				}
			}
		}
	}
}
$(interwikiExtra);


/**
 * Quality indicators on "article" tab
 * by [[user:ThomasV]]
 */
// Return src for icon given percentage
function icon_src(t){
	var src='//upload.wikimedia.org/wikipedia/commons/';
	switch(t){
		case '0%': src+='8/8f/00'; break;
		case '25%': src+='5/5b/25'; break;
		case '50%': src+='3/3a/50'; break;
		case '75%': src+='c/cd/75'; break;
		case '100%': src+='6/64/100'; break;
	} 
	return src + '%25.png';
}

// add indicator
function pageQuality() {
	var a = document.getElementById('ca-nstab-main');
	if(!a) return;

	var pr_index = document.getElementById('pr_index');
	if(pr_index) return;

	var q = document.getElementById('textquality');
	var new_img;
	if(q) {
		new_img = document.createElement('img');
		new_img.setAttribute('src', icon_src(q.className));
		a.firstChild.appendChild(new_img);
	}

	for(var i=0; spanElem = document.getElementsByTagName('span')[i]; i++) {
		if (spanElem.className == 'pagequality') {
			new_img = document.createElement('img');
			new_img.setAttribute('src', icon_src(spanElem.title));
	
			if(mw.config.get('wgCanonicalNamespace') == 'Page') {
				a.firstChild.appendChild(new_img);
			}
			else {
				s1 = spanElem.parentNode.previousSibling;
				opttext = s1.firstChild.firstChild;
				img = opttext.firstChild.nextSibling.nextSibling.nextSibling;
				next = img.nextSibling;
				opttext.removeChild(img);
				opttext.insertBefore(new_img,next);
			}
		}
	}
}
$(pageQuality);

// Add link to the extension [[user:sanbeg]]
function pr_add_quality_buttons_link(){ 
    if(typeof proofreadPageMessageStatus == 'undefined') return;
	if( self.proofreadpage_no_quality_buttons ) return;
	var ig = document.getElementById("wpWatchthis");
	if( !ig ) return;
	var f = document.createElement("span");
	f.innerHTML = ' (<a href="/wiki/Help:Page Status">help</a>)';

    ig.parentNode.insertBefore(f,ig.nextSibling.nextSibling.nextSibling.nextSibling);
}
$(pr_add_quality_buttons_link);


/**
 * Add arrows on sidebar to compare current page to interlanguage link'd page
 * by [[user:Pathoschild]], based on older script by unknown
 */
function BilingualLink() {
	if ( document.getElementById('p-lang') ) {
		// get list of links
		var biboxes = document.getElementById('p-lang').getElementsByTagName('li');

		// iterate over links
		for(var i=0; i<biboxes.length; i++) {
			// get link
			var bilink = biboxes[i].getElementsByTagName('a')[0];

			// create new URL
			var bilang = bilink.getAttribute('href').match(/\/\/([^\.]+)\.wikisource/)[1];
			var bilanglink = mw.util.getUrl( mw.config.get('wgPageName') ) + '?match=' + bilang;

			// create link
			var bianchor = document.createElement('a');
			bianchor.setAttribute('href',bilanglink);
			bianchor.setAttribute('title','Compare this page with the '+bilang+' version.');
			bianchor.appendChild(document.createTextNode(' ⇔'));

			// add link
			biboxes[i].appendChild(bianchor);
		}
	}
}
//$(BilingualLink);

/**
 * Allows extra script to run in Special:Watchlist — addition of announcements
 * script allows users to dismiss Mediawiki:watchlist-announcements, as per sitenotice 
 * user:billinghurst 20100522, as hacked from WP script
 */
/*if ( mw.config.get('wgCanonicalSpecialPageName') == 'Watchlist' ) {
  importScript('MediaWiki:Common.js/watchlist.js');
}*/

// (should be redundant with the implementation of protocol relative urls (201101004); if not reactivated can be cleansed by end of 2011
// Script to rewrite external links to other Wikimedia projects to
// use the secure server when already browsing from https://secure.wikimedia.org
//
//if ( mw.config.get('wgServer') == 'https://secure.wikimedia.org' ) {
//  mw.loader.load('//en.wikipedia.org/w/index.php?title=MediaWiki:Common.js/secure.js&action=raw&ctype=text/javascript');
//}

/** Collapsible tables *********************************************************
 *
 *  Description: Allows tables to be collapsed, showing only the header. See
 *               [[w:Wikipedia:NavFrame]].
 *  Maintainers: [[w:User:R. Koot]]
 */

var autoCollapse = 1;
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 ( $(Tables[i]).hasClass( "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 false;") );
            ButtonLink.appendChild( ButtonText );

            Button.appendChild( document.createTextNode( "[" ) );
            Button.appendChild( ButtonLink );
            Button.appendChild( document.createTextNode( "]" ) );

            Header.insertBefore( Button, Header.firstChild );
            tableIndex++;
        }
    }

    for ( var i = 0;  i < tableIndex; i++ ) {
        if ( $(NavigationBoxes[i]).hasClass( "collapsed" ) || ( tableIndex >= autoCollapse &&  $(NavigationBoxes[i]).hasClass( "autocollapse" ) ) ) {
            collapseTable( i );
        } 
        else if (  $(NavigationBoxes[i]).hasClass( "innercollapse" ) ) {
            var element = NavigationBoxes[i];
            while (element = element.parentNode) {
                if ( $(element).hasClass( "outercollapse" ) ) {
                    collapseTable ( i );
                    break;
                }
            }
        }
    }
}
$( createCollapseButtons );


/** Dynamic Navigation Bars (experimental) *************************************
 *
 *  Description: See [[w: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 ($(NavChild).hasClass( 'NavContent') || $(NavChild).hasClass( '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 ($(NavChild).hasClass( 'NavContent') || $(NavChild).hasClass( '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 ($(NavFrame).hasClass( "NavFrame")) {

            indexNavigationBar++;
            var NavToggle = document.createElement("a");
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
            NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + 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 (var 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 (var 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 );

/*
 * port from [[:he:mediawiki:common.js]] for [[mediawiki:edittools]] -Steve
 */
/* פונקציה שמשמשת לאיפשור ניקוד ב[[מדיה ויקי:edittools]] */
function nikud(){
 if (document.getElementById('edit-templates')!=null){
  for(var i=0; a = document.getElementsByTagName("span")[i]; i++) {
  if(a.className == "nikud") {
   a.onclick=function(){insertTags('', this.title, '');return false;};
   }
  }
 }
}
$(nikud);


/**
 * withJS
 *
 * Allow to load custom scripts from the MediaWiki namespace without
 * editing [[Special:Mypage/common.js]]
 *
 * Maintainer: [[User:Platonides]], [[User:Lupo]]
 */
mw.loader.using('mediawiki.util', function () {
	var extraJS = mw.util.getParamValue('withJS');
	// Leave here for backwards compatibility
	 if (extraJS) {
		 if (extraJS.match(/^MediaWiki:[^&<>=%#]*\.js$/)) {
		     // Disallow some characters in file name
		     importScript(extraJS);
		 } else {
		     // Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready.
		     $(function () {
		         jsMsg(extraJS + ' javascript not allowed to be loaded.', 'error');
		     });
		 }
	 }
});

/**
 * Icons on the top right of the article.
 * See also CSS
 *
 * @source: http://www.mediawiki.org/wiki/Snippets/Top_icons
 * @rev: 2
 */
jQuery( document ).ready( function( $ ) {
        $( '.Top_icon_raw' )
                .removeClass( 'Top_icon_raw' )
                .addClass( 'Top_icon_dynamic' )
                .prependTo( '#firstHeading' );
} );

/*Script to allow language links to Old Wikisource (http://wikisource.org) */
mw.loader.load('//en.wikisource.org/w/index.php?title=User:Doug/Multilingual-link.js&action=raw&ctype=text/javascript');
"https://sa.wikisource.org/w/index.php?title=मीडियाविकि:Common.js&oldid=144632" इत्यस्माद् प्रतिप्राप्तम्