mediawiki

How to get MediaWiki sections to include a right-clickable link to the section?


In some places -- for example, this GitHub README, you have sections that automatically generate a little link/section icon that the user can right-click on to get a link to that particular section.

In MediaWiki syntax, I can do

=== My Section ===

and it will render with a [edit] bit on the right side, where I can click to edit -- but I don't want to edit, I just want to copy a hyperlink.

Is there a way in MediaWiki to get such right-clickable hyperlinks for section titles? Anything reasonable will work; if the above rendered as something like so:

🔗 My Section [edit]

or

§ My Section [edit]

with the left-side icons working like the GitHub example above, that would be very usable.

I've done a lot of searching through MediaWiki syntax documentation and haven't found anything.


Solution

  • You can have a header that refers to itself:

    === [[#Foobar|Foobar]] ===
    
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    

    Foobar

    Lorem ipsum dolor sit amet, consectetur adipiscing elit.

    You can also put a § before the header:

    === [[#Foobar|§]] Foobar ===
    
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    

    § Foobar

    Lorem ipsum dolor sit amet, consectetur adipiscing elit.

    A template would look something like this:

    <!-- Template:Linkable header -->[[#{{{1}}}|&sect;]] {{{1}}}
    
    === {{Linkable header|Foobar}} ===
    

    Alternatively, you can use JS to dynamically add links wherever you want them to be, but that depends on your skin and such.