mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 01:39:30 +02:00
Introduce smart mode ($wgLinkTitlesSmartmode).
Smart mode generates aliases for page titles if a case mismatch is detected.
This commit is contained in:
@ -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,17 +144,35 @@
|
||||
$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( '/(?<![\:\.\@\/\?\&])' .
|
||||
$wordStartDelim . '((?i)' . LinkTitles::$safeTitle[0] . '(?-i)' .
|
||||
substr(LinkTitles::$safeTitle, 1) . ')' . $wordEndDelim . '/',
|
||||
'[[$1]]', $arr[$i], $limit, $count );
|
||||
if (( $limit >= 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( '/(?<![\:\.\@\/\?\&])' .
|
||||
$wordStartDelim . '(' . $safeTitle . ')' .
|
||||
$wordStartDelim . '(' . LinkTitles::$safeTitle . ')' .
|
||||
$wordEndDelim . '/i',
|
||||
"LinkTitles::CallBack", $arr[$i], $limit, $count );
|
||||
if (( $limit >= 0 ) && ( $count > 0 )) {
|
||||
@ -160,16 +180,17 @@
|
||||
};
|
||||
};
|
||||
$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] . ']]';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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'
|
||||
);
|
||||
|
||||
|
7
NEWS
7
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
|
||||
|
Binary file not shown.
BIN
release/LinkTitles-2.0.0.tar.gz
Normal file
BIN
release/LinkTitles-2.0.0.tar.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user