User:Nikki/TalkPageHeader.js
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.
/**
* This is a script which aims to replace [[MediaWiki:Talkpageheader]], so that
* the talk page header is shown for languages other than English. If it works
* well enough, it could be turned into a gadget which is enabled by default.
*
* To help test it, add the follow to your common.js:
* mw.loader.load("//www.wikidata.org/w/index.php?title=User:Nikki/TalkPageHeader.js&action=raw&ctype=text/javascript");
*
* @license CC0-1.0
*/
( function () {
'use strict';
if ( mw.config.get( 'wgNamespaceNumber' ) !== 1 ) {
// Only show on item talk pages
return;
}
function init() {
var div = document.querySelector( '.mw-talkpageheader' );
if ( !div ) {
div = document.createElement( 'div' );
div.className = 'mw-talkpageheader';
document.getElementById( 'mw-content-text' ).prepend( div );
}
var args = {
'action': 'parse',
'contentmodel': 'wikitext',
'disablelimitreport': 1,
'formatversion': 2,
'prop': 'text',
'text': '{{Item documentation|' + mw.config.get( 'wgTitle' ) + '}}',
'uselang': mw.config.get( 'wgUserLanguage' ),
};
var api = new mw.Api().get( args ).done( function ( data ) {
div.innerHTML = data.parse.text;
} );
}
mw.loader.using( [ 'mediawiki.api' ] ).then( function () {
init();
} );
} )();