Build the Sandbox menu item in the mobile menu markup so it renders there Tags: Mobile edit Mobile web edit Advanced mobile edit |
Give the Sandbox menu item a box icon Tags: Mobile edit Mobile web edit Advanced mobile edit |
||
| Line 779: | Line 779: | ||
} ); | } ); | ||
/* Sandbox link in the user menu: above Preferences on desktop skins, | /* Sandbox link in the user menu: above Preferences on desktop skins, | ||
above Log out in the mobile user menu, | above Log out in the mobile user menu, with a box icon drawn in code | ||
because an added item has no built-in icon. | |||
Village pump (proposals), "Sandbox Button" section. */ | Village pump (proposals), "Sandbox Button" section. */ | ||
$( function () { | $( function () { | ||
| Line 787: | Line 787: | ||
} | } | ||
var sandboxHref = mw.util.getUrl( 'Special:MyPage/sandbox' ); | var sandboxHref = mw.util.getUrl( 'Special:MyPage/sandbox' ); | ||
var sandboxSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"><path d="M12 3l8.5 4.5v9L12 21l-8.5-4.5v-9z"/><path d="M3.5 7.5L12 12l8.5-4.5"/><path d="M12 12v9"/></g></svg>'; | |||
if ( mw.config.get( 'skin' ) === 'minerva' ) { | if ( mw.config.get( 'skin' ) === 'minerva' ) { | ||
var personalList = document.getElementById( 'p-personal' ); | var personalList = document.getElementById( 'p-personal' ); | ||
| Line 798: | Line 799: | ||
sandboxLink.title = 'Your personal sandbox'; | sandboxLink.title = 'Your personal sandbox'; | ||
var sandboxIcon = document.createElement( 'span' ); | var sandboxIcon = document.createElement( 'span' ); | ||
sandboxIcon.className = 'minerva-icon | sandboxIcon.className = 'minerva-icon bp-sandbox-icon'; | ||
sandboxIcon.innerHTML = sandboxSvg; | |||
var sandboxLabel = document.createElement( 'span' ); | var sandboxLabel = document.createElement( 'span' ); | ||
sandboxLabel.className = 'toggle-list-item__label'; | sandboxLabel.className = 'toggle-list-item__label'; | ||
| Line 813: | Line 815: | ||
} | } | ||
} else { | } else { | ||
mw.util.addPortletLink( | var sandboxLi = mw.util.addPortletLink( | ||
'p-personal', | 'p-personal', | ||
sandboxHref, | sandboxHref, | ||
| Line 822: | Line 824: | ||
'#pt-preferences' | '#pt-preferences' | ||
); | ); | ||
if ( sandboxLi ) { | |||
sandboxLi.classList.add( 'user-links-collapsible-item' ); | |||
var sandboxAnchor = sandboxLi.querySelector( 'a' ); | |||
var vectorIcon = sandboxAnchor ? sandboxAnchor.querySelector( 'span.vector-icon' ) : null; | |||
if ( sandboxAnchor && !vectorIcon ) { | |||
vectorIcon = document.createElement( 'span' ); | |||
sandboxAnchor.insertBefore( vectorIcon, sandboxAnchor.firstChild ); | |||
} | |||
if ( vectorIcon ) { | |||
vectorIcon.className = 'vector-icon bp-sandbox-icon'; | |||
vectorIcon.innerHTML = sandboxSvg; | |||
} | |||
} | |||
} | } | ||
} ); | } ); | ||
/* DO NOT ADD CODE BELOW THIS LINE */ | /* DO NOT ADD CODE BELOW THIS LINE */ | ||
Revision as of 16:29, 17 November 2026
/* 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();
}
});
/* Infobox header colours (6 November 2026):
The BharatpediaNeo skin stylesheet forces a cream background on
.infobox th with !important, which overrides the background colour
each infobox template sets inline and leaves white header text
invisible. Promote any inline background colour on infobox cells
to !important so the template's own colour wins again. This block
can be removed if the skin rule ever loses its !important. */
$( function () {
$( '.infobox th, .infobox td' ).each( function () {
var bg = this.style.backgroundColor;
if ( bg ) {
this.style.setProperty( 'background-color', bg, 'important' );
}
} );
} );
/* Cache refresh touch, 6 November 2026. */
/* Open and closed discussion counter (15 November 2026):
On the Administrators' noticeboard and the Village pump section
pages, count the level 2 discussion sections and write the open,
closed and total numbers into the counter line in the page header.
A section counts as closed when its archive top box is present. */
mw.hook( 'wikipage.content' ).add( function () {
try {
var bpDiscPages = {
'Bharatpedia:Administrators\'_noticeboard': 1,
'Bharatpedia:Village_pump_(policy)': 1,
'Bharatpedia:Village_pump_(proposals)': 1,
'Bharatpedia:Village_pump_(technical)': 1,
'Bharatpedia:Village_pump_(idea_lab)': 1,
'Bharatpedia:Village_pump_(miscellaneous)': 1,
'Bharatpedia:Village_pump_(foundation)': 1
};
if ( !bpDiscPages[ mw.config.get( 'wgPageName' ) ] ) { return; }
function bpCountDiscussions() {
var openSlot = document.getElementById( 'bp-disc-open' );
var closedSlot = document.getElementById( 'bp-disc-closed' );
var totalSlot = document.getElementById( 'bp-disc-total' );
if ( !openSlot || !closedSlot || !totalSlot ) { return; }
var out = document.querySelector( '.mw-parser-output' );
if ( !out ) { return; }
var useWrappers = out.querySelectorAll( '.mw-heading2' ).length > 0;
var nodes = out.querySelectorAll( useWrappers ?
'.mw-heading2, .mw-archivedtalk' : 'h2, .mw-archivedtalk' );
var closed = [], idx = -1;
Array.prototype.forEach.call( nodes, function ( el ) {
var isHeading = useWrappers ?
el.classList.contains( 'mw-heading2' ) : el.tagName === 'H2';
if ( isHeading ) {
if ( !useWrappers && ( el.id === 'mw-toc-heading' ||
( el.closest && el.closest( '#toc, .toc, .vph' ) ) ) ) { return; }
idx++;
closed[ idx ] = false;
} else if ( idx >= 0 ) {
closed[ idx ] = true;
}
} );
if ( idx < 0 ) { return; }
var open = 0, shut = 0;
closed.forEach( function ( c ) { if ( c ) { shut++; } else { open++; } } );
openSlot.textContent = '[ ' + open + ' ]';
closedSlot.textContent = '[ ' + shut + ' ]';
totalSlot.textContent = '[ ' + ( open + shut ) + ' ]';
}
bpCountDiscussions();
setTimeout( bpCountDiscussions, 2500 );
} catch ( e ) {}
} );
/* Sandbox link in the user menu: above Preferences on desktop skins,
above Log out in the mobile user menu, with a box icon drawn in code
because an added item has no built-in icon.
Village pump (proposals), "Sandbox Button" section. */
$( function () {
if ( !mw.config.get( 'wgUserName' ) || document.getElementById( 'pt-sandbox' ) ) {
return;
}
var sandboxHref = mw.util.getUrl( 'Special:MyPage/sandbox' );
var sandboxSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"><path d="M12 3l8.5 4.5v9L12 21l-8.5-4.5v-9z"/><path d="M3.5 7.5L12 12l8.5-4.5"/><path d="M12 12v9"/></g></svg>';
if ( mw.config.get( 'skin' ) === 'minerva' ) {
var personalList = document.getElementById( 'p-personal' );
if ( !personalList ) { return; }
var sandboxItem = document.createElement( 'li' );
sandboxItem.id = 'pt-sandbox';
sandboxItem.className = 'toggle-list-item';
var sandboxLink = document.createElement( 'a' );
sandboxLink.className = 'toggle-list-item__anchor';
sandboxLink.href = sandboxHref;
sandboxLink.title = 'Your personal sandbox';
var sandboxIcon = document.createElement( 'span' );
sandboxIcon.className = 'minerva-icon bp-sandbox-icon';
sandboxIcon.innerHTML = sandboxSvg;
var sandboxLabel = document.createElement( 'span' );
sandboxLabel.className = 'toggle-list-item__label';
sandboxLabel.textContent = 'Sandbox';
sandboxLink.appendChild( sandboxIcon );
sandboxLink.appendChild( sandboxLabel );
sandboxItem.appendChild( sandboxLink );
var logoutLink = personalList.querySelector( 'a[href*="Special:UserLogout"]' );
var logoutItem = logoutLink ? logoutLink.closest( 'li' ) : null;
if ( logoutItem ) {
personalList.insertBefore( sandboxItem, logoutItem );
} else {
personalList.appendChild( sandboxItem );
}
} else {
var sandboxLi = mw.util.addPortletLink(
'p-personal',
sandboxHref,
'Sandbox',
'pt-sandbox',
'Your personal sandbox',
null,
'#pt-preferences'
);
if ( sandboxLi ) {
sandboxLi.classList.add( 'user-links-collapsible-item' );
var sandboxAnchor = sandboxLi.querySelector( 'a' );
var vectorIcon = sandboxAnchor ? sandboxAnchor.querySelector( 'span.vector-icon' ) : null;
if ( sandboxAnchor && !vectorIcon ) {
vectorIcon = document.createElement( 'span' );
sandboxAnchor.insertBefore( vectorIcon, sandboxAnchor.firstChild );
}
if ( vectorIcon ) {
vectorIcon.className = 'vector-icon bp-sandbox-icon';
vectorIcon.innerHTML = sandboxSvg;
}
}
}
} );
/* DO NOT ADD CODE BELOW THIS LINE */