Stop parsing urls and e-mail addresses.

This commit is contained in:
Daniel Kraus
2012-05-23 17:20:48 +02:00
parent 8d8c47356d
commit cc1dae2ad3
4 changed files with 16 additions and 3 deletions

View File

@ -80,8 +80,18 @@
$myTitle = $article->getTitle()->getText(); $myTitle = $article->getTitle()->getText();
( $wgLinkTitlesPreferShortTitles ) ? $sort_order = 'DESC' : $sort_order = ''; ( $wgLinkTitlesPreferShortTitles ) ? $sort_order = 'DESC' : $sort_order = '';
// Build a regular expression that will capture existing wiki links ("[[...]]"),
// wiki headings ("= ... =", "== ... ==" etc.),
// urls ("http://example.com", "[http://example.com]", "[http://example.com Description]",
// and email addresses ("mail@example.com").
// Since there is a user option to skip headings, we make this part of the expression
// optional. Note that in order to use preg_split(), it is important to have only one
// capturing subpattern (which precludes the use of conditional subpatterns).
( $wgLinkTitlesParseHeadings ) ? $delimiter = '' : $delimiter = '=+.+?=+|'; ( $wgLinkTitlesParseHeadings ) ? $delimiter = '' : $delimiter = '=+.+?=+|';
$delimiter = '/(' . $delimiter . '\[\[.*?\]\])/i'; $urlPattern = '[a-z]+?\:\/\/(?:\S+\.)+\S+(?:\/.*)?';
$delimiter = '/(' . $delimiter . '\[\[.*?\]\]|\[' .
$urlPattern . '\s.+?\]|'. $urlPattern . '(?=\s|$)|(?<=\b)\S+\@(?:\S+\.)+\S+(?=\b))/i';
// Build an SQL query and fetch all page titles ordered // Build an SQL query and fetch all page titles ordered
// by length from shortest to longest. // by length from shortest to longest.
@ -111,7 +121,7 @@
$safeTitle = str_replace( '/', '\/', $title ); $safeTitle = str_replace( '/', '\/', $title );
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( '/\b(' . $safeTitle . ')\b/i', '[[$1]]', $arr[$i] ); $arr[$i] = preg_replace( '/(?<![\:\.\@\/\?\&])\b(' . $safeTitle . ')\b/i', '[[$1]]', $arr[$i] );
}; };
$text = implode( '', $arr ); $text = implode( '', $arr );
}; // if $title != $myTitle }; // if $title != $myTitle

View File

@ -43,7 +43,7 @@
'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.0.0', 'version' => '1.1.0',
'descriptionmsg' => 'linktitles-desc' 'descriptionmsg' => 'linktitles-desc'
); );

3
NEWS
View File

@ -1,3 +1,6 @@
LinkTitles 1.1.0: 2012-05-24
* No longer parses urls and email addresses.
LinkTitles 1.0.0: 2012-05-22 LinkTitles 1.0.0: 2012-05-22
* Added new option to parse or not parse headings * Added new option to parse or not parse headings
* Added new option to parse pages on saving edits * Added new option to parse pages on saving edits

Binary file not shown.