Snippets/Main Page tab

From MediaWiki.org
Jump to: navigation, search
How to use Snippets
List of Snippets
Crystal Clear action run.png
Main Page tab
Language(s): javascript
Compatible with:

MediaWiki 1.17+ (Vector; Monobook)

Description[edit | edit source]

On the main page (and its associated namespaces and actions (Talk, edit, history etc.) this script will put "Main Page" instead of "Article" or "Page" in the first tab. Works in both Vector and Monobook.

Native[edit | edit source]

MediaWiki version: 1.18

If you are using 1.18 or higher, you can instead use the interface message "mainpage-nstab". You can do this by creating the page MediaWiki:mainpage-nstab on your wiki (requires administrator rights) with the desired label.

Code[edit | edit source]

MediaWiki version: 1.17
/**
 * MainPage tab
 *
 * @source mediawiki.org/wiki/Snippets/Main_Page_tab
 * @version 2014-07-30
 */
$( function() {
	var title = mw.config.get( 'wgTitle' ),
		hasMainPageTab = (title === 'Main Page'); // Title of the main page
	if ( hasMainPageTab ) {
		$( '#ca-nstab-main' ).find( 'a' ).text( title );
	}
} );

Alternative[edit | edit source]

The following requires $wgHtml5 to be set to true.

PageTab.js

/**
 * Page-tab
 * Replace "Article", "Page", or whatever in page/namespace tab with custom string
 *
 * @rev 1
 */
 
$( document ).ready( function () {
	var title = $.trim( $( '#mw-nstab' ).data( 'nstab' ) );
	if ( title !== '' ) {
		$('#ca-nstab-' + ( mw.config.get( 'wgCanonicalNamespace' ).toLowerCase() || 'main' ) ).find( 'a' ).text( title );
	}
} );

Template:Page_tab

<span id="mw-nstab" data-nstab="{{{1|}}}"></span>

Usage

{{Page tab|Awesome Tab}}