Index: trunk/phase3/maintenance/parserTests.txt |
— | — | @@ -7433,7 +7433,29 @@ |
7434 | 7434 | Poked at a <a href="https://www.mediawiki.org/index.php?title=/subpage&action=edit&redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> here... |
7435 | 7435 | !!end |
7436 | 7436 | |
| 7437 | +!! test |
| 7438 | +Edit comment with bare anchor link (local, as on diff) |
| 7439 | +!! options |
| 7440 | +comment |
| 7441 | +local |
| 7442 | +title=[[Main Page]] |
| 7443 | +!!input |
| 7444 | +[[#section]] |
| 7445 | +!! result |
| 7446 | +<a href="#section">#section</a> |
| 7447 | +!! end |
7437 | 7448 | |
| 7449 | +!! test |
| 7450 | +Edit comment with bare anchor link (non-local, as on history) |
| 7451 | +!! options |
| 7452 | +comment |
| 7453 | +title=[[Main Page]] |
| 7454 | +!!input |
| 7455 | +[[#section]] |
| 7456 | +!! result |
| 7457 | +<a href="https://www.mediawiki.org/wiki/Main_Page#section" title="Main Page">#section</a> |
| 7458 | +!! end |
| 7459 | + |
7438 | 7460 | TODO: |
7439 | 7461 | more images |
7440 | 7462 | more tables |
Index: trunk/phase3/includes/Linker.php |
— | — | @@ -922,7 +922,7 @@ |
923 | 923 | |
924 | 924 | # Render autocomments and make links: |
925 | 925 | $comment = $this->formatAutoComments( $comment, $title, $local ); |
926 | | - $comment = $this->formatLinksInComment( $comment, $title ); |
| 926 | + $comment = $this->formatLinksInComment( $comment, $title, $local ); |
927 | 927 | |
928 | 928 | wfProfileOut( __METHOD__ ); |
929 | 929 | return $comment; |
— | — | @@ -1009,13 +1009,15 @@ |
1010 | 1010 | * @param string $comment Text to format links in |
1011 | 1011 | * @return string |
1012 | 1012 | */ |
1013 | | - public function formatLinksInComment( $comment, $title = null ) { |
| 1013 | + public function formatLinksInComment( $comment, $title = null, $local = false ) { |
1014 | 1014 | $this->commentContextTitle = $title; |
| 1015 | + $this->commentLocal = $local; |
1015 | 1016 | $html = preg_replace_callback( |
1016 | 1017 | '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/', |
1017 | 1018 | array( $this, 'formatLinksInCommentCallback' ), |
1018 | 1019 | $comment ); |
1019 | 1020 | unset( $this->commentContextTitle ); |
| 1021 | + unset( $this->commentLocal ); |
1020 | 1022 | return $html; |
1021 | 1023 | } |
1022 | 1024 | |
— | — | @@ -1060,10 +1062,18 @@ |
1061 | 1063 | $linkTarget = Linker::normalizeSubpageLink( $this->commentContextTitle, |
1062 | 1064 | $match[1], $linkText ); |
1063 | 1065 | |
1064 | | - $thelink = $this->link( |
1065 | | - Title::newFromText( $linkTarget ), |
1066 | | - $linkText . $inside |
1067 | | - ) . $trail; |
| 1066 | + $target = Title::newFromText( $linkTarget ); |
| 1067 | + if( $target ) { |
| 1068 | + if( $target->getText() == '' && !$this->commentLocal && $this->commentContextTitle ) { |
| 1069 | + $newTarget = clone( $this->commentContextTitle ); |
| 1070 | + $newTarget->setFragment( '#' . $target->getFragment() ); |
| 1071 | + $target = $newTarget; |
| 1072 | + } |
| 1073 | + $thelink = $this->link( |
| 1074 | + $target, |
| 1075 | + $linkText . $inside |
| 1076 | + ) . $trail; |
| 1077 | + } |
1068 | 1078 | } |
1069 | 1079 | $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 ); |
1070 | 1080 | |