Do not mess up page content with leading slashes.

If a page title started with a slash, the algorithm to deal with leading
capitals would produce a faulty regexp by accessing $escapedTitle[0] and
substr($escapedTitle, 1), which would only capture the slash that escapes
the slash.

Also fix small bug in template detection (make expression non-greedy).
This commit is contained in:
Daniel Kraus
2013-08-27 20:55:06 +02:00
parent 9d414d0e5e
commit ad700ca7f4

View File

@ -107,7 +107,7 @@
if ( $wgLinkTitlesSkipTemplates ) if ( $wgLinkTitlesSkipTemplates )
{ {
$templatesDelimiter = '{{.+}}'; $templatesDelimiter = '{{.+?}}';
} else { } else {
$templatesDelimiter = '{{[^|]+?}}|{{.+\|'; $templatesDelimiter = '{{[^|]+?}}|{{.+\|';
}; };
@ -122,8 +122,8 @@
( $wgLinkTitlesParseHeadings ) ? $delimiter = '' : $delimiter = '=+.+?=+|'; ( $wgLinkTitlesParseHeadings ) ? $delimiter = '' : $delimiter = '=+.+?=+|';
$urlPattern = '[a-z]+?\:\/\/(?:\S+\.)+\S+(?:\/.*)?'; $urlPattern = '[a-z]+?\:\/\/(?:\S+\.)+\S+(?:\/.*)?';
$delimiter = '/(' . $delimiter . '\[\[.*?\]\]|' . $templatesDelimiter . $delimiter = '/(' . $delimiter . '\[\[.*?\]\]|' . $templatesDelimiter .
'|\[' . $urlPattern . '\s.+?\]|'. $urlPattern . '|\[' . $urlPattern . '\s.+?\]|'. $urlPattern . '(?=\s|$)' .
'(?=\s|$)|(?<=\b)\S+\@(?:\S+\.)+\S+(?=\b))/i'; '|(?<=\b)\S+\@(?:\S+\.)+\S+(?=\b))/i';
$black_list = str_replace( '_', ' ', $black_list = str_replace( '_', ' ',
'("' . implode( '", "',$wgLinkTitlesBlackList ) . '")' ); '("' . implode( '", "',$wgLinkTitlesBlackList ) . '")' );
@ -177,7 +177,7 @@
$title = str_replace('_', ' ', $row->page_title); $title = str_replace('_', ' ', $row->page_title);
if ( $title != $myTitle ) { if ( $title != $myTitle ) {
LinkTitles::$safeTitle = str_replace( '/', '\/', $title ); LinkTitles::$safeTitle = $title;
// split the string by [[...]] groups // split the string by [[...]] groups
// credits to inhan @ StackOverflow for suggesting preg_split // credits to inhan @ StackOverflow for suggesting preg_split
@ -192,7 +192,7 @@
// the title has to be searched for either in a strictly case-sensitive // the title has to be searched for either in a strictly case-sensitive
// way, or in a 'fuzzy' way where the first letter of the title may // way, or in a 'fuzzy' way where the first letter of the title may
// be either case. // be either case.
if ( $wgCapitalLinks ) { if ( $wgCapitalLinks && ( $escapedTitle[0] != '\\' )) {
$searchTerm = '((?i)' . $escapedTitle[0] . '(?-i)' . $searchTerm = '((?i)' . $escapedTitle[0] . '(?-i)' .
substr($escapedTitle, 1) . ')'; substr($escapedTitle, 1) . ')';
} else { } else {