From: Aryeh Gregor Date: Fri, 1 Aug 2008 01:47:02 +0000 (+0000) Subject: (bug 14995 again) Fix behavior of link() when it's provided with Titles that have... X-Git-Tag: 1.31.0-rc.0~46232 X-Git-Url: https://git.cyclocoop.org//%22?a=commitdiff_plain;h=7450051289922994a40c82f211c2e05d06d8e486;p=lhc%2Fweb%2Fwiklou.git (bug 14995 again) Fix behavior of link() when it's provided with Titles that have no text, only a fragment. getLocalURL() doesn't work here either. Can we have a function that actually means "generate a link to whatever this Title points at"? Also remove, as Tim so eloquently terms it, "that crap in the release notes", which I also think is unnecessary and crufty. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 1bc66ecdb2..3a660559ee 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -48,8 +48,6 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Recursion loop check added to Categoryfinder class * Fixed few performance troubles of large job queue processing * Not setting various parameters in Foreign Repos now fails more gracefully -* (bug 14995) Some link fragments in the interface stopped appearing -* (bug 14997) Rollback links now work again === API changes in 1.14 === diff --git a/includes/Linker.php b/includes/Linker.php index afeabf150c..5a820d4cc8 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -221,11 +221,19 @@ class Linker { $query['action'] = 'edit'; $query['redlink'] = '1'; } - $ret = $target->getLocalURL( $query ); - if( $target->getFragment() !== '' ) { - $ret .= '#'.$target->getFragment(); + # A couple of things to be concerned about here. First of all, + # getLocalURL() ignores fragments. Second of all, if the Title is + # *only* a fragment, it returns something like "/". + if( $target->getFragment() === '' and $target->getPrefixedText() !== '' ) { + return $target->getLocalURL( $query ); } - return $ret; + if( $target->getPrefixedText() === '' ) { + # Just a fragment. There had better be one, anyway, or this is a + # pretty silly Title. + return '#'.$target->getFragment(); + } + # Then we must have a fragment *and* some Title text. + return $target->getLocalURL( $query ).'#'.$target->getFragment(); } private function linkAttribs( $target, $attribs, $options ) { @@ -1203,7 +1211,7 @@ class Linker { * * @todo Document the $local parameter. */ - private function formatAutocomments( $comment, $title = NULL, $local = false ) { + private function formatAutocomments( $comment, $title = null, $local = false ) { $match = array(); while (preg_match('!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment,$match)) { $pre=$match[1]; @@ -1222,7 +1230,7 @@ class Linker { $section = str_replace( '[[', '', $section ); $section = str_replace( ']]', '', $section ); if ( $local ) { - $sectionTitle = Title::newFromText( '#' . $section); + $sectionTitle = Title::newFromText( '#' . $section ); } else { $sectionTitle = wfClone( $title ); $sectionTitle->setFragment( $section );