From: Arne Heizmann Date: Mon, 12 Jul 2004 22:57:13 +0000 (+0000) Subject: This fixes the issue that something like [http://url/ link]s (i.e. text directly... X-Git-Tag: 1.5.0alpha1~2689 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=92fded9b95fcc017a88349a3c697b3e7e8b7e1c6;p=lhc%2Fweb%2Fwiklou.git This fixes the issue that something like [url/ link]s (i.e. text directly following the closing square bracket) would produce something ugly in printing: link (http://url/)s Now it finishes the word first: links (http://url/) The given example seems pointless, but in languages other than English this happens more frequently. --- diff --git a/includes/Parser.php b/includes/Parser.php index f4d87e6192..204dc695e5 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -953,23 +953,37 @@ class Parser $s = array_shift( $a ); $s = substr( $s, 1 ); - $e1 = "/^([{$uc}"."{$sep}]+)](.*)\$/sD"; - $e2 = "/^([{$uc}"."{$sep}]+)\\s+([^\\]]+)](.*)\$/sD"; + # Regexp for URL in square brackets + $e1 = "/^([{$uc}{$sep}]+)\\](.*)\$/sD"; + # Regexp for URL with link text in square brackets + $e2 = "/^([{$uc}{$sep}]+)\\s+([^\\]]+)\\](\\S*)(.*)\$/sD"; foreach ( $a as $line ) { + + # CASE 1: Link in square brackets, e.g. + # some text [http://domain.tld/some.link] more text if ( preg_match( $e1, $line, $m ) ) { $link = "{$protocol}:{$m[1]}"; $trail = $m[2]; if ( $autonumber ) { $text = "[" . ++$this->mAutonumber . "]"; } else { $text = wfEscapeHTML( $link ); } - } else if ( preg_match( $e2, $line, $m ) ) { + } + + # CASE 2: Link with link text and text directly following it, e.g. + # This is a collection of [http://domain.tld/some.link link]s + else if ( preg_match( $e2, $line, $m ) ) { $link = "{$protocol}:{$m[1]}"; $text = $m[2]; - $trail = $m[3]; - } else { + $dtrail = $m[3]; + $trail = $m[4]; + } + + # CASE 3: Nothing matches, just output the source text + else { $s .= "[{$protocol}:" . $line; continue; } + if( $link == $text || preg_match( "!$protocol://" . preg_quote( $text, "/" ) . "/?$!", $link ) ) { $paren = ''; } else { @@ -977,7 +991,7 @@ class Parser $paren = " (" . htmlspecialchars ( $link ) . ")"; } $la = $sk->getExternalLinkAttributes( $link, $text ); - $s .= "{$text}{$paren}{$trail}"; + $s .= "{$text}{$dtrail}{$paren}{$trail}"; } return $s;