Index: trunk/phase3/includes/Linker.php |
— | — | @@ -988,42 +988,49 @@ |
989 | 989 | * Formats wiki links and media links in text; all other wiki formatting |
990 | 990 | * is ignored |
991 | 991 | * |
| 992 | + * @fixme doesn't handle sub-links as in image thumb texts like the main parser |
992 | 993 | * @param string $comment Text to format links in |
993 | 994 | * @return string |
994 | 995 | */ |
995 | 996 | public function formatLinksInComment( $comment ) { |
| 997 | + return preg_replace_callback( |
| 998 | + '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/', |
| 999 | + array( $this, 'formatLinksInCommentCallback' ), |
| 1000 | + $comment ); |
| 1001 | + } |
| 1002 | + |
| 1003 | + protected function formatLinksInCommentCallback( $match ) { |
996 | 1004 | global $wgContLang; |
997 | 1005 | |
998 | 1006 | $medians = '(?:' . preg_quote( Namespace::getCanonicalName( NS_MEDIA ), '/' ) . '|'; |
999 | 1007 | $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):'; |
| 1008 | + |
| 1009 | + $comment = $match[0]; |
1000 | 1010 | |
1001 | | - $match = array(); |
1002 | | - while(preg_match('/\[\[:?(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) { |
1003 | | - # Handle link renaming [[foo|text]] will show link as "text" |
1004 | | - if( "" != $match[3] ) { |
1005 | | - $text = $match[3]; |
| 1011 | + # Handle link renaming [[foo|text]] will show link as "text" |
| 1012 | + if( "" != $match[3] ) { |
| 1013 | + $text = $match[3]; |
| 1014 | + } else { |
| 1015 | + $text = $match[1]; |
| 1016 | + } |
| 1017 | + $submatch = array(); |
| 1018 | + if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) { |
| 1019 | + # Media link; trail not supported. |
| 1020 | + $linkRegexp = '/\[\[(.*?)\]\]/'; |
| 1021 | + $thelink = $this->makeMediaLink( $submatch[1], "", $text ); |
| 1022 | + } else { |
| 1023 | + # Other kind of link |
| 1024 | + if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) { |
| 1025 | + $trail = $submatch[1]; |
1006 | 1026 | } else { |
1007 | | - $text = $match[1]; |
| 1027 | + $trail = ""; |
1008 | 1028 | } |
1009 | | - $submatch = array(); |
1010 | | - if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) { |
1011 | | - # Media link; trail not supported. |
1012 | | - $linkRegexp = '/\[\[(.*?)\]\]/'; |
1013 | | - $thelink = $this->makeMediaLink( $submatch[1], "", $text ); |
1014 | | - } else { |
1015 | | - # Other kind of link |
1016 | | - if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) { |
1017 | | - $trail = $submatch[1]; |
1018 | | - } else { |
1019 | | - $trail = ""; |
1020 | | - } |
1021 | | - $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/'; |
1022 | | - if (isset($match[1][0]) && $match[1][0] == ':') |
1023 | | - $match[1] = substr($match[1], 1); |
1024 | | - $thelink = $this->makeLink( $match[1], $text, "", $trail ); |
1025 | | - } |
1026 | | - $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 ); |
| 1029 | + $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/'; |
| 1030 | + if (isset($match[1][0]) && $match[1][0] == ':') |
| 1031 | + $match[1] = substr($match[1], 1); |
| 1032 | + $thelink = $this->makeLink( $match[1], $text, "", $trail ); |
1027 | 1033 | } |
| 1034 | + $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 ); |
1028 | 1035 | |
1029 | 1036 | return $comment; |
1030 | 1037 | } |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -84,6 +84,9 @@ |
85 | 85 | * (bug 11478) Fix undefined method call in file deletion interface |
86 | 86 | * (bug 278) Search results no longer highlight incorrect partial word matches |
87 | 87 | * Compatibility with incorrectly detected old-style DJVU mime types |
| 88 | +* (bug 11560) Fix broken HTML output from weird link nesting in edit comments. |
| 89 | + Nested links (as in image caption text) still don't work _right_ but they're |
| 90 | + less wrong. |
88 | 91 | |
89 | 92 | |
90 | 93 | === API changes in 1.12 === |