mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 00:13:36 +00:00
Remove oldid from URL when refreshing page
Code mostly copied from VE, but ported to native URL object. Change-Id: I3e780f33df548c59741b7ae3b5dfb33f657d24a3
This commit is contained in:
parent
776fca861f
commit
7364214ea6
|
@ -530,10 +530,28 @@ function updatePageContents( $container, data ) {
|
|||
// TODO: Upstream this to core/skins, triggered by a hook (wikipage.content?)
|
||||
// eslint-disable-next-line no-jquery/no-global-selector
|
||||
$( '#t-permalink a, #coll-download-as-rl a' ).each( function () {
|
||||
var url = new URL( this.href );
|
||||
url.searchParams.set( 'oldid', data.parse.revid );
|
||||
$( this ).attr( 'href', url.toString() );
|
||||
var permalinkUrl = new URL( this.href );
|
||||
permalinkUrl.searchParams.set( 'oldid', data.parse.revid );
|
||||
$( this ).attr( 'href', permalinkUrl.toString() );
|
||||
} );
|
||||
|
||||
var url = new URL( location.href );
|
||||
url.searchParams.delete( 'oldid' );
|
||||
|
||||
// If there are any other query parameters left, re-use that URL object.
|
||||
// Otherwise use the canonical style view url (T44553, T102363).
|
||||
var keys = [];
|
||||
url.searchParams.forEach( function ( val, key ) {
|
||||
keys.push( key );
|
||||
} );
|
||||
|
||||
if ( !keys.length || ( keys.length === 1 && keys[ 0 ] === 'title' ) ) {
|
||||
var viewUrl = new URL( mw.util.getUrl( mw.config.get( 'wgRelevantPageName' ) ), document.baseURI );
|
||||
viewUrl.hash = location.hash;
|
||||
history.pushState( null, '', viewUrl );
|
||||
} else {
|
||||
history.pushState( null, '', url );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue