mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 01:39:30 +02:00
Introduce new option to link only the first occurrence of a title on a page.
This commit is contained in:
@ -76,12 +76,14 @@
|
||||
global $wgLinkTitlesParseHeadings;
|
||||
global $wgLinkTitlesBlackList;
|
||||
global $wgLinkTitlesSkipTemplates;
|
||||
global $wgLinkTitlesFirstOnly;
|
||||
|
||||
// To prevent adding self-references, we now
|
||||
// extract the current page's title.
|
||||
$myTitle = $article->getTitle()->getText();
|
||||
|
||||
( $wgLinkTitlesPreferShortTitles ) ? $sort_order = 'ASC' : $sort_order = 'DESC';
|
||||
( $wgLinkTitlesFirstOnly ) ? $limit = 1 : $limit = -1;
|
||||
|
||||
if ( $wgLinkTitlesSkipTemplates )
|
||||
{
|
||||
@ -137,9 +139,11 @@
|
||||
$arr = preg_split( $delimiter, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
|
||||
// dump( $arr );
|
||||
$safeTitle = str_replace( '/', '\/', $title );
|
||||
for ( $i = 0; $i < count( $arr ); $i+=2 ) {
|
||||
( $wgLinkTitlesFirstOnly ) ? $loopLimit = 1 : $loopLimit = count( $arr );
|
||||
for ( $i = 0; $i < $loopLimit; $i+=2 ) {
|
||||
// even indexes will point to text that is not enclosed by brackets
|
||||
$arr[$i] = preg_replace( '/(?<![\:\.\@\/\?\&])\b(' . $safeTitle . ')\b/i', '[[$1]]', $arr[$i] );
|
||||
$arr[$i] = preg_replace( '/(?<![\:\.\@\/\?\&])\b(' . $safeTitle . ')\b/i',
|
||||
'[[$1]]', $arr[$i], $limit );
|
||||
};
|
||||
$text = implode( '', $arr );
|
||||
}; // if $title != $myTitle
|
||||
|
@ -39,13 +39,14 @@
|
||||
$wgLinkTitlesParseOnRender = false;
|
||||
$wgLinkTitlesSkipTemplates = false;
|
||||
$wgLinkTitlesBlackList = array();
|
||||
$wgLinkTitlesFirstOnly = false;
|
||||
|
||||
$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.4.0',
|
||||
'version' => '1.5.0',
|
||||
'descriptionmsg' => 'linktitles-desc'
|
||||
);
|
||||
|
||||
|
3
NEWS
3
NEWS
@ -1,3 +1,6 @@
|
||||
LinkTitles 1.5.0: 2012-12-11
|
||||
* Added new option to link only the first occurrence of a page title.
|
||||
|
||||
LinkTitles 1.4.0: 2012-10-09
|
||||
* Added new option to skip template variables.
|
||||
|
||||
|
BIN
release/LinkTitles-1.5.0.tar.gz
Normal file
BIN
release/LinkTitles-1.5.0.tar.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user