Index: trunk/phase3/maintenance/parserTests.txt |
— | — | @@ -7456,6 +7456,17 @@ |
7457 | 7457 | <a href="https://www.mediawiki.org/wiki/Main_Page#section" title="Main Page">#section</a> |
7458 | 7458 | !! end |
7459 | 7459 | |
| 7460 | +!! test |
| 7461 | +Edit comment with mismatched brackets (bug 15745) |
| 7462 | +!! options |
| 7463 | +comment |
| 7464 | +title=[[Main Page]] |
| 7465 | +!!input |
| 7466 | +Some text, a [[broken link|bad and a [[good link|good]] |
| 7467 | +!! result |
| 7468 | +Some text, a [[broken link|bad and a <a href="https://www.mediawiki.org/index.php?title=Good_link&action=edit&redlink=1" class="new" title="Good link (page does not exist)">good</a> |
| 7469 | +!! end |
| 7470 | + |
7460 | 7471 | TODO: |
7461 | 7472 | more images |
7462 | 7473 | more tables |
Index: trunk/phase3/includes/Linker.php |
— | — | @@ -1012,10 +1012,22 @@ |
1013 | 1013 | public function formatLinksInComment( $comment, $title = null, $local = false ) { |
1014 | 1014 | $this->commentContextTitle = $title; |
1015 | 1015 | $this->commentLocal = $local; |
1016 | | - $html = preg_replace_callback( |
1017 | | - '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/', |
1018 | | - array( $this, 'formatLinksInCommentCallback' ), |
1019 | | - $comment ); |
| 1016 | + # Borrowed from Parser::replaceInternalLinks2 |
| 1017 | + $parts = StringUtils::explode( '[[', ' ' . $comment ); |
| 1018 | + $start = $parts->current(); |
| 1019 | + $parts->next(); |
| 1020 | + $line = $parts->current(); |
| 1021 | + $html = substr( $start, 1 ); |
| 1022 | + for ( ; $line !== false && $line !== null ; $parts->next(), $line = $parts->current() ) { |
| 1023 | + $linked = preg_replace_callback( |
| 1024 | + '/^:?(.*?)(\|(.*?))*\]\]([^[]*)/', |
| 1025 | + array( $this, 'formatLinksInCommentCallback' ), |
| 1026 | + $line, -1, $count ); |
| 1027 | + if( !$count ) { // No valid link found, put the brackets back |
| 1028 | + $linked = '[[' . $linked; |
| 1029 | + } |
| 1030 | + $html .= $linked; |
| 1031 | + } |
1020 | 1032 | unset( $this->commentContextTitle ); |
1021 | 1033 | unset( $this->commentLocal ); |
1022 | 1034 | return $html; |
— | — | @@ -1043,7 +1055,7 @@ |
1044 | 1056 | $submatch = array(); |
1045 | 1057 | if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) { |
1046 | 1058 | # Media link; trail not supported. |
1047 | | - $linkRegexp = '/\[\[(.*?)\]\]/'; |
| 1059 | + $linkRegexp = '/^(.*?)\]\]/'; |
1048 | 1060 | $title = Title::makeTitleSafe( NS_FILE, $submatch[1] ); |
1049 | 1061 | $thelink = $this->makeMediaLinkObj( $title, $text ); |
1050 | 1062 | } else { |
— | — | @@ -1053,7 +1065,7 @@ |
1054 | 1066 | } else { |
1055 | 1067 | $trail = ""; |
1056 | 1068 | } |
1057 | | - $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/'; |
| 1069 | + $linkRegexp = '/^(.*?)\]\]' . preg_quote( $trail, '/' ) . '/'; |
1058 | 1070 | if (isset($match[1][0]) && $match[1][0] == ':') |
1059 | 1071 | $match[1] = substr($match[1], 1); |
1060 | 1072 | list( $inside, $trail ) = Linker::splitTrail( $trail ); |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -304,6 +304,8 @@ |
305 | 305 | * (bug 17374) Special:Export no longer exports multiple copies of pages |
306 | 306 | * (bug 19818) Edits to user CSS/JS subpages can now be marked as patrolled by |
307 | 307 | users who can't edit them |
| 308 | +* (bug 15745) The edit summary link parser now handles mismatched brackets |
| 309 | + better |
308 | 310 | |
309 | 311 | == API changes in 1.16 == |
310 | 312 | |