# 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;
* @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;
}
$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 );
Poked at a <a href="/index.php?title=/subpage&action=edit&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