diff --git a/LinkTitles.body.php b/LinkTitles.body.php index e99f4b8..ecba0d4 100755 --- a/LinkTitles.body.php +++ b/LinkTitles.body.php @@ -29,7 +29,7 @@ }; class LinkTitles { - static $st; + static $safeTitle; /// Setup function, hooks the extension's functions to MediaWiki events. public static function setup() { @@ -72,6 +72,7 @@ /// This function performs the actual parsing of the content. static function parseContent( &$article, &$text ) { + // Configuration variables need to be defined here as globals. global $wgLinkTitlesPreferShortTitles; global $wgLinkTitlesMinimumTitleLength; @@ -82,6 +83,7 @@ global $wgLinkTitlesWordStartOnly; global $wgLinkTitlesWordEndOnly; // global $wgLinkTitlesIgnoreCase; + global $wgLinkTitlesSmartMode; ( $wgLinkTitlesWordStartOnly ) ? $wordStartDelim = '\b' : $wordStartDelim = ''; ( $wgLinkTitlesWordEndOnly ) ? $wordEndDelim = '\b' : $wordEndDelim = ''; @@ -142,34 +144,53 @@ $title = str_replace('_', ' ', $row->page_title); if ( $title != $myTitle ) { + LinkTitles::$safeTitle = str_replace( '/', '\/', $title ); + // split the string by [[...]] groups // credits to inhan @ StackOverflow for suggesting preg_split // see http://stackoverflow.com/questions/10672286 $arr = preg_split( $delimiter, $text, -1, PREG_SPLIT_DELIM_CAPTURE ); - // dump( $arr ); - $safeTitle = str_replace( '/', '\/', $title ); - LinkTitles::$st = $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_callback( '/(?= 0 ) && ( $count > 0 )) { break; }; }; $text = implode( '', $arr ); + + if ($wgLinkTitlesSmartMode) { + // split the string by [[...]] groups + // credits to inhan @ StackOverflow for suggesting preg_split + // see http://stackoverflow.com/questions/10672286 + $arr = preg_split( $delimiter, $text, -1, PREG_SPLIT_DELIM_CAPTURE ); + + for ( $i = 0; $i < count( $arr ); $i+=2 ) { + // even indexes will point to text that is not enclosed by brackets + $arr[$i] = preg_replace_callback( '/(?= 0 ) && ( $count > 0 )) { + break; + }; + }; + $text = implode( '', $arr ); + } }; // if $title != $myTitle }; // foreach $res as $row return true; } static function CallBack($matches) { - if ( strcmp(substr(LinkTitles::$st, 1), substr($matches[0], 1)) == 0 ) { + if ( strcmp(substr(LinkTitles::$safeTitle, 1), substr($matches[0], 1)) == 0 ) { return '[[' . $matches[0] . ']]'; } else { - return '[[' . LinkTitles::$st . '|' . $matches[0] . ']]'; + return '[[' . LinkTitles::$safeTitle . '|' . $matches[0] . ']]'; } } } diff --git a/LinkTitles.php b/LinkTitles.php index 2900938..e86c94d 100755 --- a/LinkTitles.php +++ b/LinkTitles.php @@ -43,13 +43,14 @@ $wgLinkTitlesWordStartOnly = true; $wgLinkTitlesWordEndOnly = true; // $wgLinkTitlesIgnoreCase = true; + $wgLinkTitlesSmartMode = true; $wgExtensionCredits['parserhook'][] = array( 'path' => __FILE__, 'name' => 'LinkTitles', 'author' => '[http://www.mediawiki.org/wiki/User:Bovender Daniel Kraus]', 'url' => 'http://www.mediawiki.org/wiki/Extension:LinkTitles', - 'version' => '1.8.1', + 'version' => '2.0.0', 'descriptionmsg' => 'linktitles-desc' ); diff --git a/NEWS b/NEWS index 49eb0d2..7d5172f 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +LinkTitles 2.0.0: 2013-01-29 +* Introduced a new 'smart mode' ($wgLinkTitlesSmartMode) which is enabled by + default and will automatically generate aliased links if there is a case + mismatch. To increase performance, this smart mode can be disabled. + LinkTitles 1.8.1: 2013-01-26 * The extension will now automatically generate aliases for case-mismatched page titles. @@ -66,4 +71,4 @@ LinkTitles 0.0.2: 2012-05-20 LinkTitles 0.0.1: 2012-05-20 * Initial release. -# vim: fo=tqn:flp=\*\s +# vim: tw=76:fo=tqn:flp=^\*\s diff --git a/release/LinkTitles-1.3.2.tar.gz b/release/LinkTitles-1.3.2.tar.gz deleted file mode 100644 index 514b60d..0000000 Binary files a/release/LinkTitles-1.3.2.tar.gz and /dev/null differ diff --git a/release/LinkTitles-2.0.0.tar.gz b/release/LinkTitles-2.0.0.tar.gz new file mode 100644 index 0000000..1e8ad35 Binary files /dev/null and b/release/LinkTitles-2.0.0.tar.gz differ