Last modified: 2008-12-18 19:54:07 UTC
This does not seem to affect ordinary MediaWiki operation. Steps to reproduce: $sk =&$wgUser->getSkin(); $ret = $sk->makeKnownLink('Wikipedia:Main Page#Anchor'); (Any interwiki link will do) $ret contains: <a href="http://en.wikipedia.org/wiki/Main_Page#anchor#anchor" title="wikipedia:Main Page">wikipedia:Main Page</a> This is because Linker::makeKnownLinkObj uses Title::escapeLocalURL which is documented to *not* add a fragment. However, after Title checks if $this->isExternal(), it calls getFullURL(). Unlike getLocalURL(), getFullURL() includes the fragment. Then Linker::makeKnownLinkObj adds a second anchor before returning. Patch in the next comment.
Created attachment 1872 [details] Patches one line of Linker.php Patches one line of Linker.php May be better to use escapeFullURL() instead? I cannot predict the reprocussions of that.
Note that makeKnownLink (non-obj) is deprecated.
I did not realize that. This should still produce the bug: $sk =&$wgUser->getSkin(); echo $sk->makeKnownLinkObj(Title::newFromText('Wikipedia:Main Page#anchor')); I take back the suggestion to use "escapeFullURL" *instead*. That would make absolute URLs when shorter ones would do. Adding keyword 'patch'
It's marked as "deprecated - do not use" in the code.
(In reply to comment #3) > I did not realize that. This should still produce the bug: > $sk =&$wgUser->getSkin(); > echo $sk->makeKnownLinkObj(Title::newFromText('Wikipedia:Main Page#anchor')); "#" isn't a valid character in page titles, so that would produce a very interesting error, since Title::newFromText() would choke and return NULL.
# is the separator between primary title and fragment ID, which will be parsed by the title object.
This is working ok for me in current 1.14 dev trunk: > return $wgUser->getSkin()->makeKnownLink('Project:Main Page#Anchor'); <a href="/trunk/index.php/ShortWiki:Main_Page#Anchor" title="ShortWiki:Main Page">ShortWiki:Main Page</a> I believe that makeKnownLink() and friends have been redone to run through the more modern funcs using the title objs, and everything is now parsed correctly.