Page MenuHomePhabricator

Retain section anchor in URL when clicking "Permanent link" link in the sidebar
Open, Needs TriagePublic

Description

It would be nice if the section anchor in a URL was retained when clicking the "Permanent link" link in the sidebar of a MediaWiki page.

Currently if I'm visiting a URL such as https://en.wikipedia.org/wiki/Wikipedia:Administrators%27_noticeboard#Winterysteppe in my Web browser and I click "Permanent link", I'll be taken to https://en.wikipedia.org/w/index.php?title=Wikipedia:Administrators%27_noticeboard&oldid=907478355. But I very often want the URL to be https://en.wikipedia.org/w/index.php?title=Wikipedia:Administrators%27_noticeboard&oldid=907478355#Winterysteppe instead. I end up needing to click the link in the table of contents box to get the anchor back after clicking "Permanent link". This is somewhat annoying behavior.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJul 23 2019, 7:43 AM

There is probably a bad work around, but if the url contains # (meaning that a section is linked to) copy that from the current url and append it to the permalink. I can make that as an on-wiki script in the meanwhile if there is a better way to do it in PHP

@MZMcBride on-wiki script:

PermaLinkSection.js
$(document).ready( function () {
    $('#t-permalink > a').each( 
        function() {
            this.href = 'javascript:window.permaLinkSection("' + this.href + '")';
        }
    );
} );
window.permaLinkSection= function( href ){
    var section = window.location.href.match(/#.*$/);
    if ( section && section[0] ) {
    	href = href + section[0];
    }
    location.href = href;
};

if (understandably) this ticket isn't actioned soon, I may propose this as a gadget