MediaWiki:Common.js
MediaWiki interface page
More actions
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. */
/* Fix VisualEditor button to use pretty URL with ?veaction=edit */
$(function() {
var $veTab = $('#ca-ve-edit a');
if ($veTab.length) {
var currentHref = $veTab.attr('href');
if (currentHref.includes('index.php') && currentHref.includes('veaction=edit')) {
var titleMatch = currentHref.match(/title=([^&]+)/);
if (titleMatch) {
var title = decodeURIComponent(titleMatch[1]).replace(/ /g, '_'); // Replace spaces with _, leave : and / literal
var prettyBase = '/' + title;
$veTab.attr('href', prettyBase + '?veaction=edit');
}
}
}
});
/* Fix diff and permanent links to use pretty URLs without /index.php */
function rewriteToPrettyUrl(href) {
var urlParams = new URLSearchParams(href.split('?')[1] || '');
var title = urlParams.get('title');
if (title) {
title = decodeURIComponent(title).replace(/ /g, '_');
urlParams.delete('title');
return '/' + title + (urlParams.toString() ? '?' + urlParams.toString() : '');
}
return href;
}
$(function() {
var $permalink = $('#t-permalink a');
if ($permalink.length && $permalink.attr('href').includes('index.php')) {
$permalink.attr('href', rewriteToPrettyUrl($permalink.attr('href')));
}
$('.mw-changeslist-date').each(function() {
var $this = $(this);
var href = $this.attr('href');
if (href && href.includes('index.php')) {
$this.attr('href', rewriteToPrettyUrl(href));
}
});
$('.mw-history-histlinks-current, .mw-history-histlinks-previous').each(function() {
var $this = $(this);
var href = $this.attr('href');
if (href && href.includes('index.php')) {
$this.attr('href', rewriteToPrettyUrl(href));
}
});
});