Introduce new option to link only the first occurrence of a title on a page.

This commit is contained in:
Daniel Kraus
2012-12-11 16:34:51 +01:00
parent 44c4315857
commit a2850bb318
4 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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
View File

@ -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.

Binary file not shown.