MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More actions
Content deleted Content added
Updated VisualEdit button link fix |
No edit summary Tag: Reverted |
||
| Line 15: | Line 15: | ||
} |
} |
||
} |
} |
||
}); |
|||
/* 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)); |
|||
} |
|||
}); |
|||
}); |
}); |
||
Revision as of 22:04, 22 February 2026
/* 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));
}
});
});