On Thu, Aug 26, 2010 at 4:44 AM, Tgr <gtisza(a)gmail.com> wrote:
in Firefox, and I'm pretty sure it works the same
way on other browsers.
(encodeURI is almost the same, but leaves more characters unencoded, which in
this case is a bad thing.)
Then you need to replace %20 with _, % with ., unencoded characters ~!*()' with
their proper utf-8 sequence, and you have the section title fragment.
(It might be a good idea to include a function doing that in wikibits.js, if
there isn't one yet.)
This isn't reliable. In particular, it will fail when the section
name has any wikitext or HTML in it. The section text is parsed
first, then the parsed text has HTML stripped from it, and the anchor
is generated from that. This is a mess, since it makes it impossible
to create section links reliably even within MediaWiki from any place
other than the TOC, but that's the status quo. See bug 5019 and
related (111, 2346, 2831). Bug 18700 is also related, although
conceptually somewhat different.
So in other words, something like this is reliable enough for internal
use in MediaWiki in some places (return to section after edit and
history page links), so it will probably work most of the time. I
guess a JS function for it might be useful, but it would probably fall
out of sync with the core code.