Also treat [[#section]] links as expected with the 'local' param for diff view vs...
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 20 Jul 2009 02:26:37 +0000 (02:26 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 20 Jul 2009 02:26:37 +0000 (02:26 +0000)
includes/Linker.php
maintenance/parserTests.txt

index 7e2f131..d059d76 100644 (file)
@@ -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 );
 
index 898c401..2b2d2a2 100644 (file)
@@ -7433,6 +7433,28 @@ Poked at a [[/subpage]] here...
 Poked at a <a href="/index.php?title=/subpage&amp;action=edit&amp;redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> here...
 !!end
 
+!! test
+Edit comment with bare anchor link (local, as on diff)
+!! options
+comment
+local
+title=[[Main Page]]
+!!input
+[[#section]]
+!! result
+<a href="#section">#section</a>
+!! end
+
+!! test
+Edit comment with bare anchor link (non-local, as on history)
+!! options
+comment
+title=[[Main Page]]
+!!input
+[[#section]]
+!! result
+<a href="/wiki/Main_Page#section" title="Main Page">#section</a>
+!! end
 
 TODO:
 more images