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 {
|
class LinkTitles {
|
||||||
static $st;
|
static $safeTitle;
|
||||||
|
|
||||||
/// Setup function, hooks the extension's functions to MediaWiki events.
|
/// Setup function, hooks the extension's functions to MediaWiki events.
|
||||||
public static function setup() {
|
public static function setup() {
|
||||||
@ -72,6 +72,7 @@
|
|||||||
|
|
||||||
/// This function performs the actual parsing of the content.
|
/// This function performs the actual parsing of the content.
|
||||||
static function parseContent( &$article, &$text ) {
|
static function parseContent( &$article, &$text ) {
|
||||||
|
|
||||||
// Configuration variables need to be defined here as globals.
|
// Configuration variables need to be defined here as globals.
|
||||||
global $wgLinkTitlesPreferShortTitles;
|
global $wgLinkTitlesPreferShortTitles;
|
||||||
global $wgLinkTitlesMinimumTitleLength;
|
global $wgLinkTitlesMinimumTitleLength;
|
||||||
@ -82,6 +83,7 @@
|
|||||||
global $wgLinkTitlesWordStartOnly;
|
global $wgLinkTitlesWordStartOnly;
|
||||||
global $wgLinkTitlesWordEndOnly;
|
global $wgLinkTitlesWordEndOnly;
|
||||||
// global $wgLinkTitlesIgnoreCase;
|
// global $wgLinkTitlesIgnoreCase;
|
||||||
|
global $wgLinkTitlesSmartMode;
|
||||||
|
|
||||||
( $wgLinkTitlesWordStartOnly ) ? $wordStartDelim = '\b' : $wordStartDelim = '';
|
( $wgLinkTitlesWordStartOnly ) ? $wordStartDelim = '\b' : $wordStartDelim = '';
|
||||||
( $wgLinkTitlesWordEndOnly ) ? $wordEndDelim = '\b' : $wordEndDelim = '';
|
( $wgLinkTitlesWordEndOnly ) ? $wordEndDelim = '\b' : $wordEndDelim = '';
|
||||||
@ -142,34 +144,53 @@
|
|||||||
$title = str_replace('_', ' ', $row->page_title);
|
$title = str_replace('_', ' ', $row->page_title);
|
||||||
|
|
||||||
if ( $title != $myTitle ) {
|
if ( $title != $myTitle ) {
|
||||||
|
LinkTitles::$safeTitle = str_replace( '/', '\/', $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
|
||||||
// see http://stackoverflow.com/questions/10672286
|
// see http://stackoverflow.com/questions/10672286
|
||||||
$arr = preg_split( $delimiter, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
|
$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 ) {
|
for ( $i = 0; $i < count( $arr ); $i+=2 ) {
|
||||||
// even indexes will point to text that is not enclosed by brackets
|
// even indexes will point to text that is not enclosed by brackets
|
||||||
$arr[$i] = preg_replace_callback( '/(?<![\:\.\@\/\?\&])' .
|
$arr[$i] = preg_replace( '/(?<![\:\.\@\/\?\&])' .
|
||||||
$wordStartDelim . '(' . $safeTitle . ')' .
|
$wordStartDelim . '((?i)' . LinkTitles::$safeTitle[0] . '(?-i)' .
|
||||||
$wordEndDelim . '/i',
|
substr(LinkTitles::$safeTitle, 1) . ')' . $wordEndDelim . '/',
|
||||||
"LinkTitles::CallBack", $arr[$i], $limit, $count );
|
'[[$1]]', $arr[$i], $limit, $count );
|
||||||
if (( $limit >= 0 ) && ( $count > 0 )) {
|
if (( $limit >= 0 ) && ( $count > 0 )) {
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
$text = implode( '', $arr );
|
$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 . '(' . LinkTitles::$safeTitle . ')' .
|
||||||
|
$wordEndDelim . '/i',
|
||||||
|
"LinkTitles::CallBack", $arr[$i], $limit, $count );
|
||||||
|
if (( $limit >= 0 ) && ( $count > 0 )) {
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
$text = implode( '', $arr );
|
||||||
|
}
|
||||||
}; // if $title != $myTitle
|
}; // if $title != $myTitle
|
||||||
}; // foreach $res as $row
|
}; // foreach $res as $row
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function CallBack($matches) {
|
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] . ']]';
|
return '[[' . $matches[0] . ']]';
|
||||||
} else {
|
} else {
|
||||||
return '[[' . LinkTitles::$st . '|' . $matches[0] . ']]';
|
return '[[' . LinkTitles::$safeTitle . '|' . $matches[0] . ']]';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,13 +43,14 @@
|
|||||||
$wgLinkTitlesWordStartOnly = true;
|
$wgLinkTitlesWordStartOnly = true;
|
||||||
$wgLinkTitlesWordEndOnly = true;
|
$wgLinkTitlesWordEndOnly = true;
|
||||||
// $wgLinkTitlesIgnoreCase = true;
|
// $wgLinkTitlesIgnoreCase = true;
|
||||||
|
$wgLinkTitlesSmartMode = true;
|
||||||
|
|
||||||
$wgExtensionCredits['parserhook'][] = array(
|
$wgExtensionCredits['parserhook'][] = array(
|
||||||
'path' => __FILE__,
|
'path' => __FILE__,
|
||||||
'name' => 'LinkTitles',
|
'name' => 'LinkTitles',
|
||||||
'author' => '[http://www.mediawiki.org/wiki/User:Bovender Daniel Kraus]',
|
'author' => '[http://www.mediawiki.org/wiki/User:Bovender Daniel Kraus]',
|
||||||
'url' => 'http://www.mediawiki.org/wiki/Extension:LinkTitles',
|
'url' => 'http://www.mediawiki.org/wiki/Extension:LinkTitles',
|
||||||
'version' => '1.8.1',
|
'version' => '2.0.0',
|
||||||
'descriptionmsg' => 'linktitles-desc'
|
'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
|
LinkTitles 1.8.1: 2013-01-26
|
||||||
* The extension will now automatically generate aliases for case-mismatched
|
* The extension will now automatically generate aliases for case-mismatched
|
||||||
page titles.
|
page titles.
|
||||||
@ -66,4 +71,4 @@ LinkTitles 0.0.2: 2012-05-20
|
|||||||
LinkTitles 0.0.1: 2012-05-20
|
LinkTitles 0.0.1: 2012-05-20
|
||||||
* Initial release.
|
* 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