The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
/**
 * Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
 * loaded for all users on every wiki page. If possible create a gadget that is
 * enabled by default instead of adding it here (since gadgets are fully
 * optimized ResourceLoader modules with possibility to add dependencies etc.)
 *
 * Since Common.js isn't a gadget, there is no place to declare its
 * dependencies, so we have to lazy load them with mw.loader.using on demand and
 * then execute the rest in the callback. In most cases these dependencies will
 * be loaded (or loading) already and the callback will not be delayed. In case a
 * dependency hasn't arrived yet it'll make sure those are loaded before this.
 */

/* global mw, $ */
/* jshint strict:false, browser:true */

mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
	/* Begin of mw.loader.using callback */

	/**
	 * 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 ( mw.config.get( 'wgPageName' ) === 'Main_Page' || mw.config.get( 'wgPageName' ) === 'Talk:Main_Page' ) {
		$( function () {
			mw.util.addPortletLink( 'p-lang', '//meta.bharatmedia.org/wiki/List_of_Bharatpedias',
				'Complete list', 'interwiki-completelist', 'Complete list of Bharatpedias' );
		} );
	}

	/**
	 * Map addPortletLink to mw.util
	 * @deprecated: Use mw.util.addPortletLink instead.
	 */
	mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );

	/**
	 * Extract a URL parameter from the current URL
	 * @deprecated: Use mw.util.getParamValue with proper escaping
	 */
	mw.log.deprecate( window, 'getURLParamValue', mw.util.getParamValue, 'Use mw.util.getParamValue instead' );

	/**
	 * Test if an element has a certain class
	 * @deprecated:  Use $(element).hasClass() instead.
	 */
	mw.log.deprecate( window, 'hasClass', function ( element, className ) {
		return $( element ).hasClass( className );
	}, 'Use jQuery.hasClass() instead' );

	/**
	 * @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
	 * @rev 6
	 */
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' );

	if ( extraCSS ) {
		if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
			mw.loader.load( '/index.php?title=' + 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 ) {
		if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
			mw.loader.load( '/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
		}
	}

	/**
	 * 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 = 'hide';
	var expandCaption = 'show';

	// 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 );

	/**
	 * Magic editintros ****************************************************
	 *
	 * Description: Adds editintros on disambiguation pages and BLP pages.
	 * Maintainers: [[User:RockMFR]]
	 *
	 * @param {string} name
	 */
	function addEditIntro( name ) {
		$( '.mw-editsection, #ca-edit, #ca-ve-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( 'Living people', cats ) !== -1 || $.inArray( 'Possibly living people', cats ) !== -1 ) {
				addEditIntro( 'Template:BLP_editintro' );
			}
		} );
	}

	/* Actions specific to the edit page */
	if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' ) {
		/**
		 * Fix edit summary prompt for undo
		 *
		 *  Fixes the fact that the undo function combined with the "no edit summary prompter"
		 *  complains about missing editsummary, if leaving the edit summary unchanged.
		 *  Added by [[User:Deskana]], code by [[User:Tra]].
		 *  See also [[phab:T10912]].
		 */
		$( function () {
			if ( document.location.search.indexOf( 'undo=' ) !== -1 && document.getElementsByName( 'wpAutoSummary' )[ 0 ] ) {
				document.getElementsByName( 'wpAutoSummary' )[ 0 ].value = '1';
			}
		} );
	}

	/* End of mw.loader.using callback */
} );

/**
 * Bharatpedia Vector main page — auto news, DYK, month events, recent deaths.
 * MediaWiki 1.43. Runs only if the main page has #bp-vector-news (or the other hooks).
 * BharatpediaNeo does not have those hooks, so this is a no-op there.
 */
mw.loader.using(['mediawiki.api', 'mediawiki.util']).then(function () {
    if (!mw.config.get('wgIsMainPage')) {
        return;
    }
    if (!document.getElementById('bp-vector-news') &&
        !document.getElementById('bp-vector-dyk') &&
        !document.getElementById('bp-vector-events') &&
        !document.getElementById('bp-vector-deaths')) {
        return;
    }

    var HOMEPAGECACHE_PAGE = 'User:WikiDwarf/sandbox';
    var api = new mw.Api();

    var $ = function (id) {
        return document.getElementById(id);
    };

    var localizeWikiLinks = function (html) {
        return String(html || '')
            .replace(/(?:https?:)?\/\/en\.wikipedia\.org\/wiki\//gi, '/wiki/')
            .replace(/(?:https?:)?\/\/en\.wikipedia\.org\/w\/index\.php\?title=/gi, '/wiki/')
            .replace(/href="\/w\/index\.php\?title=([^"&#]+)/gi, 'href="/wiki/$1');
    };

    var istNow = function () {
        return new Date(new Date().toLocaleString('en-US', { timeZone: 'Asia/Kolkata' }));
    };

    var wikiToHtml = function (text) {
        return String(text || '')
            .replace(/<ref[\s\S]*?<\/ref>/gi, '')
            .replace(/<ref[^>]*\/?>/gi, '')
            .replace(/\{\{[^{}]*\}\}/g, '')
            .replace(/\[\[([^|\]]+)\|([^\]]+)\]\]/g, function (_, t, l) {
                return '<a href="' + mw.util.getUrl(t) + '">' + l + '</a>';
            })
            .replace(/\[\[([^\]]+)\]\]/g, function (_, t) {
                return '<a href="' + mw.util.getUrl(t) + '">' + t + '</a>';
            })
            .replace(/'''(.*?)'''/g, '<b>$1</b>')
            .replace(/''(.*?)''/g, '<i>$1</i>')
            .replace(/\s+/g, ' ')
            .trim();
    };

    var splitNewsItems = function (html) {
        var tmp = document.createElement('div');
        tmp.innerHTML = html || '';
        var parts = Array.prototype.map.call(tmp.querySelectorAll('li'), function (n) {
            return n.innerHTML.trim();
        }).filter(Boolean);
        if (parts.length < 2) {
            parts = String(html || '')
                .replace(/<div class="homepagecache-meta"[^>]*>[\s\S]*$/i, '')
                .replace(/Source:[\s\S]*$/i, '')
                .split(/(?=\d{1,2}\s+(?:January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{4})/)
                .map(function (x) { return x.trim(); })
                .filter(function (x) { return x.length > 30; });
        }
        return parts;
    };

    var renderSlot = function (el, title, html, moreHref, moreLabel) {
        if (!el) {
            return;
        }
        if (!html) {
            el.innerHTML = '<p class="bp-vec-empty">Nothing cached yet.</p>';
            return;
        }
        var wrap = document.createElement('div');
        wrap.innerHTML = html;
        var metaEl = wrap.querySelector('.homepagecache-footer, .homepagecache-meta');
        var stamp = '';
        if (metaEl) {
            var m = metaEl.textContent.match(/Last updated:\s*(\S+)/i);
            stamp = m ? m[1] : '';
            metaEl.remove();
        }
        var items = title === 'News' ? splitNewsItems(wrap.innerHTML) : [];
        var body;
        if (title === 'News' && items.length) {
            body = '<ul class="bp-vec-list">' + items.map(function (p) {
                return '<li>' + p + '</li>';
            }).join('') + '</ul>';
        } else {
            body = '<div class="bp-vec-body">' + wrap.innerHTML + '</div>';
        }
        el.innerHTML =
            body +
            '<div class="bp-vec-foot">' +
            (moreHref ? '<a href="' + moreHref + '">' + moreLabel + '</a>' : '') +
            (stamp ? '<span>Updated ' + stamp + '</span>' : '') +
            '</div>';
    };

    var loadHomepageCache = function () {
        return api.get({
            action: 'parse',
            page: HOMEPAGECACHE_PAGE,
            prop: 'text',
            disablelimitreport: 1,
            disableeditsection: 1,
            formatversion: 2
        }).then(function (res) {
            var tmp = document.createElement('div');
            tmp.innerHTML = (res.parse && res.parse.text) || '';
            return {
                news: localizeWikiLinks(tmp.querySelector('.homepagecache-india-news') && tmp.querySelector('.homepagecache-india-news').innerHTML),
                dyk: localizeWikiLinks(tmp.querySelector('.homepagecache-india-dyk') && tmp.querySelector('.homepagecache-india-dyk').innerHTML)
            };
        });
    };

    var monthNames = [
        'January', 'February', 'March', 'April', 'May', 'June',
        'July', 'August', 'September', 'October', 'November', 'December'
    ];

    var getYearPage = function (y) {
        return api.get({
            action: 'parse',
            page: y + ' in India',
            prop: 'wikitext',
            formatversion: 2
        }).then(function (res) {
            return (res.parse && res.parse.wikitext) || '';
        }).catch(function () {
            return '';
        });
    };

    var extractChapter = function (wikitext, name) {
        var re = new RegExp(
            '^==\\s*' + name + '\\s*==\\s*$([\\s\\S]*?)(?=^==\\s*[^=\\n]+\\s*==\\s*$)',
            'im'
        );
        var match = wikitext.match(re);
        return match ? match[1] : '';
    };

    var extractMonthSection = function (source, monthName, y) {
        var escaped = monthName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
        var headingRegex = new RegExp(
            '^={2,4}\\s*' + escaped + '(?:\\s+' + y + ')?\\s*={2,4}\\s*$',
            'im'
        );
        var headingMatch = headingRegex.exec(source);
        if (!headingMatch) {
            return '';
        }
        var remaining = source.substring(headingMatch.index + headingMatch[0].length);
        var nextHeading = remaining.search(/^={2,4}\s*[^=\n]+\s*={2,4}\s*$/m);
        return nextHeading >= 0 ? remaining.substring(0, nextHeading) : remaining;
    };

    var parseMonthEvents = function (wikitext, monthIndex, y) {
        var section = extractMonthSection(extractChapter(wikitext, 'Events') || wikitext, monthNames[monthIndex], y);
        if (!section) {
            return [];
        }
        var events = [];
        var currentDay = null;
        section.split(/\r?\n/).forEach(function (line) {
            var dateOnly = line.match(/^\s*\*\s*(\d{1,2})\s+(January|February|March|April|May|June|July|August|September|October|November|December)\s*(?:–|-|—)\s*$/i);
            var dateWithText = line.match(/^\s*\*\s*(\d{1,2})\s+(January|February|March|April|May|June|July|August|September|October|November|December)\s*(?:–|-|—)\s+(.+)$/i);
            if (dateOnly) {
                currentDay = parseInt(dateOnly[1], 10);
                return;
            }
            if (dateWithText) {
                currentDay = parseInt(dateWithText[1], 10);
                events.push({ day: currentDay, month: monthIndex, year: y, title: dateWithText[3] });
                return;
            }
            if (currentDay && /^\s*\*{2,}\s*\S/.test(line)) {
                events.push({
                    day: currentDay,
                    month: monthIndex,
                    year: y,
                    title: line.replace(/^\s*\*+\s*/, '')
                });
            }
        });
        return events;
    };

    var firstLink = function (text) {
        var raw = String(text || '');
        var match = raw.match(/\[\[([^\[\]]+)\]\]/);
        if (!match) {
            return { title: '', text: '', after: raw };
        }
        var parts = match[1].split('|');
        return {
            title: (parts[0] || '').trim(),
            text: (parts[1] || parts[0] || '').trim()
        };
    };

    var cleanPlain = function (text) {
        return String(text || '')
            .replace(/\[\[([^|\]]+)\|([^\]]+)\]\]/g, '$2')
            .replace(/\[\[([^\]]+)\]\]/g, '$1')
            .replace(/\{\{[^{}]*\}\}/g, '')
            .replace(/<ref[\s\S]*?<\/ref>/gi, '')
            .replace(/<ref[^>]*\/?>/gi, '')
            .replace(/'''|''/g, '')
            .replace(/<[^>]+>/g, '')
            .replace(/\s+/g, ' ')
            .replace(/\.+$/, '')
            .trim();
    };

    var parseDeaths = function (wikitext, year) {
        var section = extractChapter(wikitext, 'Deaths');
        if (!section) {
            return [];
        }
        var deaths = [];
        var current = null;
        section.split(/\r?\n/).forEach(function (line) {
            var dateOnly = line.match(/^\s*\*\s*(\d{1,2})\s+(January|February|March|April|May|June|July|August|September|October|November|December)\s*(?:–|-|—)\s*$/i);
            var dateWithText = line.match(/^\s*\*\s*(\d{1,2})\s+(January|February|March|April|May|June|July|August|September|October|November|December)\s*(?:–|-|—)\s+(.+)$/i);
            if (dateOnly) {
                current = { day: parseInt(dateOnly[1], 10), month: monthNames.findIndex(function (m) { return m.toLowerCase() === dateOnly[2].toLowerCase(); }) };
                return;
            }
            if (dateWithText) {
                current = { day: parseInt(dateWithText[1], 10), month: monthNames.findIndex(function (m) { return m.toLowerCase() === dateWithText[2].toLowerCase(); }) };
                deaths.push({ day: current.day, month: current.month, year: year, raw: dateWithText[3] });
                return;
            }
            if (current && /^\s*\*{2,}\s*\[\[/.test(line)) {
                deaths.push({ day: current.day, month: current.month, year: year, raw: line.replace(/^\s*\*+\s*/, '') });
            }
        });
        return deaths.map(function (item) {
            var link = firstLink(item.raw);
            var plain = cleanPlain(item.raw);
            var bits = plain.split(',');
            return {
                day: item.day,
                month: item.month,
                year: item.year,
                name: link.text || (bits[0] || '').trim(),
                detail: bits.slice(1).join(',').trim(),
                url: link.title ? mw.util.getUrl(link.title) : mw.util.getUrl(year + ' in India') + '#Deaths'
            };
        }).filter(function (item) { return item.name; });
    };

    var injectStyles = function () {
        if ($('bp-vector-home-style')) {
            return;
        }
        var st = document.createElement('style');
        st.id = 'bp-vector-home-style';
        st.textContent = [
            '.bp-vec-list, .bp-vec-events { margin: .4em 0 0; padding-left: 1.2em; }',
            '.bp-vec-list li, .bp-vec-events li { margin: .45em 0; line-height: 1.45; }',
            '.bp-vec-body { line-height: 1.45; }',
            '.bp-vec-body li { margin: .35em 0; }',
            '.bp-vec-foot { display: flex; justify-content: space-between; gap: 12px; margin-top: .8em; font-size: 90%; }',
            '.bp-vec-foot span { color: #54595d; }',
            '.bp-vec-empty, .bp-vec-loading { color: #54595d; font-size: 90%; }',
            '.bp-vec-death { display: block; margin: .35em 0; text-decoration: none; }',
            '.bp-vec-death small { display: block; color: #54595d; }',
            '.bp-vec-date { font-weight: 700; margin-right: .35em; }'
        ].join('\n');
        document.head.appendChild(st);
    };

    var fillNewsDyk = function () {
        var newsEl = $('bp-vector-news');
        var dykEl = $('bp-vector-dyk');
        if (!newsEl && !dykEl) {
            return;
        }
        loadHomepageCache().then(function (slots) {
            renderSlot(newsEl, 'News', slots.news, mw.util.getUrl('Portal:India/News'), 'All news');
            renderSlot(dykEl, 'Did you know', slots.dyk, mw.util.getUrl('Portal:India/DYK'), 'All did you know');
        }).catch(function (e) {
            console.error('Vector homepage cache failed', e);
            if (newsEl) {
                newsEl.innerHTML = '<p class="bp-vec-empty">News could not be loaded.</p>';
            }
            if (dykEl) {
                dykEl.innerHTML = '<p class="bp-vec-empty">Did you know could not be loaded.</p>';
            }
        });
    };

    var fillEvents = function () {
        var el = $('bp-vector-events');
        if (!el) {
            return;
        }
        var today = istNow();
        var year = today.getFullYear();
        var month = today.getMonth();
        var todayDay = today.getDate();

        getYearPage(year).then(function (wikitext) {
            var events = parseMonthEvents(wikitext, month, year).filter(function (ev) {
                return ev.day <= todayDay;
            });
            events.sort(function (a, b) {
                return (b.year * 10000 + (b.month + 1) * 100 + b.day) - (a.year * 10000 + (a.month + 1) * 100 + a.day);
            });

            var finish = function (finalEvents) {
                finalEvents = finalEvents.slice(0, 5);
                if (!finalEvents.length) {
                    el.innerHTML = '<p class="bp-vec-empty">No recent events listed on ' + year + ' in India.</p>';
                    return;
                }
                el.innerHTML =
                    '<ul class="bp-vec-events">' +
                    finalEvents.map(function (ev) {
                        return '<li><span class="bp-vec-date">' + String(ev.day).padStart(2, '0') + ' ' + monthNames[ev.month] + '</span> ' + wikiToHtml(ev.title) + '</li>';
                    }).join('') +
                    '</ul>' +
                    '<div class="bp-vec-foot"><a href="' + mw.util.getUrl(year + ' in India') + '#Events">All events</a><span>From ' + year + ' in India</span></div>';
            };

            if (events.length < 5) {
                var prevMonth = month - 1;
                var prevYear = year;
                if (prevMonth < 0) {
                    prevMonth = 11;
                    prevYear -= 1;
                    getYearPage(prevYear).then(function (prevText) {
                        events = events.concat(parseMonthEvents(prevText, prevMonth, prevYear));
                        events.sort(function (a, b) {
                            return (b.year * 10000 + (b.month + 1) * 100 + b.day) - (a.year * 10000 + (a.month + 1) * 100 + a.day);
                        });
                        finish(events);
                    });
                } else {
                    events = events.concat(parseMonthEvents(wikitext, prevMonth, prevYear));
                    events.sort(function (a, b) {
                        return (b.year * 10000 + (b.month + 1) * 100 + b.day) - (a.year * 10000 + (a.month + 1) * 100 + a.day);
                    });
                    finish(events);
                }
            } else {
                finish(events);
            }
        }).catch(function (e) {
            console.error(e);
            el.innerHTML = '<p class="bp-vec-empty">Events could not be loaded.</p>';
        });
    };

    var fillDeaths = function () {
        var el = $('bp-vector-deaths');
        if (!el) {
            return;
        }
        var today = istNow();
        var year = today.getFullYear();

        getYearPage(year).then(function (wikitext) {
            var todayStamp = year * 10000 + (today.getMonth() + 1) * 100 + today.getDate();
            var recent = parseDeaths(wikitext, year).filter(function (item) {
                return item.year * 10000 + (item.month + 1) * 100 + item.day <= todayStamp;
            }).sort(function (a, b) {
                return (b.year * 10000 + (b.month + 1) * 100 + b.day) - (a.year * 10000 + (a.month + 1) * 100 + a.day);
            }).slice(0, 5);
            if (!recent.length) {
                el.innerHTML = '<p class="bp-vec-empty">No recent deaths listed.</p>';
                return;
            }
            el.innerHTML = recent.map(function (item) {
                var mon = (monthNames[item.month] || '').substring(0, 3);
                return '<a class="bp-vec-death" href="' + item.url + '"><span class="bp-vec-date">' + String(item.day).padStart(2, '0') + ' ' + mon + '</span> <b>' + item.name + '</b>' +
                    (item.detail ? '<small>' + item.detail + '</small>' : '') + '</a>';
            }).join('') +
                '<div class="bp-vec-foot"><a href="' + mw.util.getUrl(year + ' in India') + '#Deaths">All deaths</a></div>';
        }).catch(function (e) {
            console.error(e);
            el.innerHTML = '<p class="bp-vec-empty">Deaths could not be loaded.</p>';
        });
    };

    var boot = function () {
        injectStyles();
        fillNewsDyk();
        fillEvents();
        fillDeaths();
    };

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', boot);
    } else {
        boot();
    }
});

/* DO NOT ADD CODE BELOW THIS LINE */