diff --git a/LinkTitles.body.php b/LinkTitles.body.php index adaec5a..eb826a2 100755 --- a/LinkTitles.body.php +++ b/LinkTitles.body.php @@ -92,6 +92,7 @@ global $wgLinkTitlesWordEndOnly; // global $wgLinkTitlesIgnoreCase; global $wgLinkTitlesSmartMode; + global $wgCapitalLinks; ( $wgLinkTitlesWordStartOnly ) ? $wordStartDelim = '\b' : $wordStartDelim = ''; ( $wgLinkTitlesWordEndOnly ) ? $wordEndDelim = '\b' : $wordEndDelim = ''; @@ -127,6 +128,14 @@ $black_list = str_replace( '_', ' ', '("' . implode( '", "',$wgLinkTitlesBlackList ) . '")' ); + // Depending on the global setting $wgCapitalLinks, we need + // different callback functions further down. + if ( $wgCapitalLinks ) { + $callBack = "LinkTitles::CallBackCaseInsensitive"; + } else { + $callBack = "LinkTitles::CallBackCaseSensitive"; + } + // Build an SQL query and fetch all page titles ordered // by length from shortest to longest. // Only titles from 'normal' pages (namespace uid = 0) @@ -159,11 +168,21 @@ // see http://stackoverflow.com/questions/10672286 $arr = preg_split( $delimiter, $text, -1, PREG_SPLIT_DELIM_CAPTURE ); + // Depending on the global configuration setting $wgCapitalLinks, + // 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 + // be either case. + if ( $wgCapitalLinks ) { + $searchTerm = '((?i)' . LinkTitles::$safeTitle[0] . '(?-i)' . + substr(LinkTitles::$safeTitle, 1) . ')'; + } else { + $searchTerm = '(' . LinkTitles::$safeTitle . ')'; + } + for ( $i = 0; $i < count( $arr ); $i+=2 ) { // even indexes will point to text that is not enclosed by brackets $arr[$i] = preg_replace( '/(?= 0 ) && ( $count > 0 )) { break; @@ -171,6 +190,9 @@ }; $text = implode( '', $arr ); + // If smart mode is turned on, the extension will perform a second + // pass on the page and add links with aliases where the case does + // not match. if ($wgLinkTitlesSmartMode) { // split the string by [[...]] groups // credits to inhan @ StackOverflow for suggesting preg_split @@ -181,8 +203,7 @@ // even indexes will point to text that is not enclosed by brackets $arr[$i] = preg_replace_callback( '/(?= 0 ) && ( $count > 0 )) { break; }; @@ -194,7 +215,7 @@ return true; } - static function CallBack($matches) { + static function CallBackCaseInsensitive($matches) { if ( strcmp(substr(LinkTitles::$safeTitle, 1), substr($matches[0], 1)) == 0 ) { return '[[' . $matches[0] . ']]'; } else { @@ -202,6 +223,14 @@ } } + static function CallBackCaseSensitive($matches) { + if ( strcmp(substr(LinkTitles::$safeTitle, 0), substr($matches[0], 0)) == 0 ) { + return '[[' . $matches[0] . ']]'; + } else { + return '[[' . LinkTitles::$safeTitle . '|' . $matches[0] . ']]'; + } + } + static function removeMagicWord( &$parser, &$text ) { $mw = MagicWord::get('MAG_LINKTITLES_NOAUTOLINKS'); $mw -> matchAndRemove( $text ); diff --git a/LinkTitles.php b/LinkTitles.php index f118566..48e7053 100755 --- a/LinkTitles.php +++ b/LinkTitles.php @@ -49,7 +49,7 @@ 'name' => 'LinkTitles', 'author' => '[https://www.mediawiki.org/wiki/User:Bovender Daniel Kraus]', 'url' => 'https://www.mediawiki.org/wiki/Extension:LinkTitles', - 'version' => '2.1.1', + 'version' => '2.2.0', 'descriptionmsg' => 'linktitles-desc' ); diff --git a/NEWS b/NEWS index b576436..988ac56 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +LinkTitles 2.2.0: 2013-04-16 +* Fix case-sensitive linking when $wgCapitalLinks is false. + LinkTitles 2.1.1: 2013-03-06 * Fix crashing bugs that occurred with older PHP versions (prior to 5.3). diff --git a/release/LinkTitles-2.2.0.tar.gz b/release/LinkTitles-2.2.0.tar.gz new file mode 100644 index 0000000..a79e26f Binary files /dev/null and b/release/LinkTitles-2.2.0.tar.gz differ