From: Brion Vibber Date: Mon, 20 Jul 2009 02:26:37 +0000 (+0000) Subject: Also treat [[#section]] links as expected with the 'local' param for diff view vs... X-Git-Tag: 1.31.0-rc.0~40811 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=a7218307629f23dd276a6679b4cd58dbd6266968;p=lhc%2Fweb%2Fwiklou.git Also treat [[#section]] links as expected with the 'local' param for diff view vs RC/history view. --- diff --git a/includes/Linker.php b/includes/Linker.php index 7e2f13169e..d059d76c45 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -922,7 +922,7 @@ class Linker { # Render autocomments and make links: $comment = $this->formatAutoComments( $comment, $title, $local ); - $comment = $this->formatLinksInComment( $comment, $title ); + $comment = $this->formatLinksInComment( $comment, $title, $local ); wfProfileOut( __METHOD__ ); return $comment; @@ -1009,13 +1009,15 @@ class Linker { * @param string $comment Text to format links in * @return string */ - public function formatLinksInComment( $comment, $title = null ) { + public function formatLinksInComment( $comment, $title = null, $local = false ) { $this->commentContextTitle = $title; + $this->commentLocal = $local; $html = preg_replace_callback( '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/', array( $this, 'formatLinksInCommentCallback' ), $comment ); unset( $this->commentContextTitle ); + unset( $this->commentLocal ); return $html; } @@ -1060,10 +1062,18 @@ class Linker { $linkTarget = Linker::normalizeSubpageLink( $this->commentContextTitle, $match[1], $linkText ); - $thelink = $this->link( - Title::newFromText( $linkTarget ), - $linkText . $inside - ) . $trail; + $target = Title::newFromText( $linkTarget ); + if( $target ) { + if( $target->getText() == '' && !$this->commentLocal && $this->commentContextTitle ) { + $newTarget = clone( $this->commentContextTitle ); + $newTarget->setFragment( '#' . $target->getFragment() ); + $target = $newTarget; + } + $thelink = $this->link( + $target, + $linkText . $inside + ) . $trail; + } } $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 ); diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt index 898c4011ff..2b2d2a21bf 100644 --- a/maintenance/parserTests.txt +++ b/maintenance/parserTests.txt @@ -7433,6 +7433,28 @@ Poked at a [[/subpage]] here... Poked at a /subpage here... !!end +!! test +Edit comment with bare anchor link (local, as on diff) +!! options +comment +local +title=[[Main Page]] +!!input +[[#section]] +!! result +#section +!! end + +!! test +Edit comment with bare anchor link (non-local, as on history) +!! options +comment +title=[[Main Page]] +!!input +[[#section]] +!! result +#section +!! end TODO: more images