User:Enterprisey/ContribsTabVector.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Enterprisey/ContribsTabVector. |
/* This script adds Contributions and Statistics tabs to User and User talk pages. For Vector skin.
This script was originally written by [[User:Equazcion]] and rewritten mostly from scratch by [[User:HueSatLum]].
[[User:Enterprisey]] then added the ability to assign access keys to the tabs.
To use this script, place the following line in your vector.js page:
importScript('User:Equazcion/ContribsTabVector.js'); // Backlink: [[User:Equazcion/ContribsTabVector.js]]
Add any or all of these lines after the importScript line above to set various options (the default values are shown):
var contribsTab = true; // Turns the Contributions tab on or off (set to false; for off)
var contribsTabStats = true; // Turns the Statistics tab on or off (set to false; for off)
var contribsTabNumber = 50; // Number of contributions to display in the Contributions tab. Can be 1 to 5000.
var contribsTabName = "Contributions"; // Custom name for Contributions tab. Replace quoted text with your desired name.
var contribsTabStatsName = "Statistics"; // Custom name for Statistics tab. Replace quoted text with your desired name.
var contribsTabKey = null; // Access key for Contributions tab. See [[WP:K]] for more information.
var contribsTabStatsKey = null; // Access key for Statistics tab. See [[WP:K]] for more information.
-- End of documentation -- */
mw.loader.using( ['mediawiki.util', 'mediawiki.Uri'], function () {
"use strict";
var username, firstTab, contribsTabUrl, contribsTabStatsUrl, contribsTabKey, contribsTabStatsKey;
// Set default options for any that haven't been set
function setDefault( option, val ) {
if ( window[option] === undefined ) {
window[option] = val;
}
}
setDefault( 'contribsTabName', 'Contributions' );
setDefault( 'contribsTabNumber', 50 );
setDefault( 'contribsTabStats', true );
setDefault( 'contribsTab', true );
setDefault( 'contribsTabStatsName', 'Statistics' );
setDefault( 'contribsTabKey', null );
setDefault( 'contribsTabStatsKey', null );
username = mw.config.get( 'wgRelevantUserName' );
if ( !username ) {
return; // Don't do anything if we're not on a page with a relevant username (i.e. User or User talk)
}
firstTab = $( '#p-views ul li' ).eq( 0 ); // Tab to put the new tabs before (usually "Read")
// Release the current target of the given access key, if any
function releaseAccessKey( key ) {
if( !key ) return;
var existingKeyLink = document.querySelector( "*[accesskey=" + key + "]" );
if( existingKeyLink ) {
existingKeyLink.setAttribute( "accesskey", "" );
existingKeyLink.accesskey = existingKeyLink.accessKey = "";
existingKeyLink.title = existingKeyLink.title.replace( / \[[^\]]+?\]$/, "" );
}
}
if ( window.contribsTab ) { // Construct the contribs tab, if it's not turned off
// Construct contribs URL
contribsTabUrl = mw.util.getUrl( 'Special:Contributions', {
target: username,
limit: window.contribsTabNumber
} );
releaseAccessKey( window.contribsTabKey );
mw.util.addPortletLink(
'p-views',
contribsTabUrl,
window.contribsTabName,
'ca-contributions',
'Show this user\'s contributions',
window.contribsTabKey,
firstTab
);
}
if ( window.contribsTabStats ) { // Construct the stats tab, if it's not turned off
// Construct stats URL
contribsTabStatsUrl = new mw.Uri( '//tools.wmflabs.org/xtools-ec/' )
.extend( {
user: username,
project: mw.config.get( 'wgDBname' )
} )
.toString();
releaseAccessKey( window.contribsTabStatsKey );
mw.util.addPortletLink(
'p-views',
contribsTabStatsUrl,
window.contribsTabStatsName,
'ca-statistics',
'Show this user\'s editing statistics',
window.contribsTabStatsKey,
firstTab
);
}
} );