mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 01:39:30 +02:00
Generate aliases for case-mismatched page titles.
If a page title does has a different case than an occurrence of the same word(s) on the page that is being edited, the extension will now automatically generate 'piped' links such as [[Linking titles|Linking Titles]].
This commit is contained in:
@ -25,10 +25,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dump($var) {
|
function dump($var) {
|
||||||
error_log(print_r($var, TRUE), 3, 'php://stderr');
|
error_log(print_r($var, TRUE) . "\n", 3, 'php://stderr');
|
||||||
};
|
};
|
||||||
|
|
||||||
class LinkTitles {
|
class LinkTitles {
|
||||||
|
static $st;
|
||||||
|
|
||||||
/// 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() {
|
||||||
global $wgLinkTitlesParseOnEdit;
|
global $wgLinkTitlesParseOnEdit;
|
||||||
@ -79,11 +81,11 @@
|
|||||||
global $wgLinkTitlesFirstOnly;
|
global $wgLinkTitlesFirstOnly;
|
||||||
global $wgLinkTitlesWordStartOnly;
|
global $wgLinkTitlesWordStartOnly;
|
||||||
global $wgLinkTitlesWordEndOnly;
|
global $wgLinkTitlesWordEndOnly;
|
||||||
global $wgLinkTitlesIgnoreCase;
|
// global $wgLinkTitlesIgnoreCase;
|
||||||
|
|
||||||
( $wgLinkTitlesWordStartOnly ) ? $wordStartDelim = '\b' : $wordStartDelim = '';
|
( $wgLinkTitlesWordStartOnly ) ? $wordStartDelim = '\b' : $wordStartDelim = '';
|
||||||
( $wgLinkTitlesWordEndOnly ) ? $wordEndDelim = '\b' : $wordEndDelim = '';
|
( $wgLinkTitlesWordEndOnly ) ? $wordEndDelim = '\b' : $wordEndDelim = '';
|
||||||
( $wgLinkTitlesIgnoreCase ) ? $regexModifier = 'i' : $regexModifier = '';
|
// ( $wgLinkTitlesIgnoreCase ) ? $regexModifier = 'i' : $regexModifier = '';
|
||||||
|
|
||||||
// To prevent adding self-references, we now
|
// To prevent adding self-references, we now
|
||||||
// extract the current page's title.
|
// extract the current page's title.
|
||||||
@ -146,11 +148,13 @@
|
|||||||
$arr = preg_split( $delimiter, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
|
$arr = preg_split( $delimiter, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
|
||||||
// dump( $arr );
|
// dump( $arr );
|
||||||
$safeTitle = str_replace( '/', '\/', $title );
|
$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( '/(?<![\:\.\@\/\?\&])' .
|
$arr[$i] = preg_replace_callback( '/(?<![\:\.\@\/\?\&])' .
|
||||||
$wordStartDelim . '(' . $safeTitle . ')' .
|
$wordStartDelim . '(' . $safeTitle . ')' .
|
||||||
$wordEndDelim . '/' . $regexModifier , '[[$1]]', $arr[$i], $limit, $count );
|
$wordEndDelim . '/i',
|
||||||
|
"LinkTitles::CallBack", $arr[$i], $limit, $count );
|
||||||
if (( $limit >= 0 ) && ( $count > 0 )) {
|
if (( $limit >= 0 ) && ( $count > 0 )) {
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
@ -160,6 +164,14 @@
|
|||||||
}; // foreach $res as $row
|
}; // foreach $res as $row
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function CallBack($matches) {
|
||||||
|
if ( strcmp(substr(LinkTitles::$st, 1), substr($matches[0], 1)) == 0 ) {
|
||||||
|
return '[[' . $matches[0] . ']]';
|
||||||
|
} else {
|
||||||
|
return '[[' . LinkTitles::$st . '|' . $matches[0] . ']]';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: ts=2:sw=2:noet
|
// vim: ts=2:sw=2:noet
|
||||||
|
@ -42,14 +42,14 @@
|
|||||||
$wgLinkTitlesFirstOnly = false;
|
$wgLinkTitlesFirstOnly = false;
|
||||||
$wgLinkTitlesWordStartOnly = true;
|
$wgLinkTitlesWordStartOnly = true;
|
||||||
$wgLinkTitlesWordEndOnly = true;
|
$wgLinkTitlesWordEndOnly = true;
|
||||||
$wgLinkTitlesIgnoreCase = true;
|
// $wgLinkTitlesIgnoreCase = 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.7.0',
|
'version' => '1.8.1',
|
||||||
'descriptionmsg' => 'linktitles-desc'
|
'descriptionmsg' => 'linktitles-desc'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
7
NEWS
7
NEWS
@ -1,3 +1,8 @@
|
|||||||
|
LinkTitles 1.8.1: 2013-01-26
|
||||||
|
* The extension will now automatically generate aliases for case-mismatched
|
||||||
|
page titles.
|
||||||
|
* Fix version number confusion (1.7.0 in the extension vs. 1.8.0 on GitHub).
|
||||||
|
|
||||||
LinkTitles 1.7.0: 2013-01-22
|
LinkTitles 1.7.0: 2013-01-22
|
||||||
* Added new option to do exact searches of page titles; the default is to
|
* Added new option to do exact searches of page titles; the default is to
|
||||||
do __case-insensitive__ searches as before ($wgLinkTitlesIgnoreCase).
|
do __case-insensitive__ searches as before ($wgLinkTitlesIgnoreCase).
|
||||||
@ -61,4 +66,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: flp=\*\s
|
# vim: fo=tqn:flp=\*\s
|
||||||
|
BIN
release/LinkTitles-1.8.1.tar.gz
Normal file
BIN
release/LinkTitles-1.8.1.tar.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user