mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 01:39:30 +02:00
Implement option to not parse headings
This commit is contained in:
24
HISTORY
24
HISTORY
@ -1,24 +0,0 @@
|
||||
Extension:LinkTitles
|
||||
|
||||
0.0.7: 2012-05-20
|
||||
* Fix version information
|
||||
|
||||
0.0.6: 2012-05-20
|
||||
* Fix bug: Minimum length title
|
||||
|
||||
0.0.5: 2012-05-20
|
||||
* Add $wgLinkTitlesMinimumTitleLength configuration variable.
|
||||
|
||||
0.0.4: 2012-05-20
|
||||
* Add $wgLinkTitlesPreferShortTitles configuration variable.
|
||||
|
||||
0.0.3: 2012-05-20
|
||||
* Only look for page titles from 'normal' pages (namespace = 0).
|
||||
|
||||
0.0.2: 2012-05-20
|
||||
* Prevent generation of self-references.
|
||||
* Escape slashes in page titles before using them in a regexp.
|
||||
|
||||
0.0.1: 2012-05-20
|
||||
* Initial release.
|
||||
|
@ -51,7 +51,7 @@
|
||||
// To prevent time-consuming parsing of the page whenever
|
||||
// it is edited and saved, we only parse it if the flag
|
||||
// 'minor edits' is not set.
|
||||
return $minor or self::parseContent( $article, $content );
|
||||
return $minor or self::parseContent( $article, $text );
|
||||
}
|
||||
|
||||
/// Called when an ArticleAfterFetchContent event occurs; this requires the
|
||||
@ -80,7 +80,8 @@
|
||||
$myTitle = $article->getTitle()->getText();
|
||||
|
||||
( $wgLinkTitlesPreferShortTitles ) ? $sort_order = 'DESC' : $sort_order = '';
|
||||
|
||||
( $wgLinkTitlesParseHeadings ) ? $delimiter = '' : $delimiter = '=+.+?=+|';
|
||||
$delimiter = '/(' . $delimiter . '\[\[.*?\]\])/i';
|
||||
|
||||
// Build an SQL query and fetch all page titles ordered
|
||||
// by length from shortest to longest.
|
||||
@ -95,7 +96,6 @@
|
||||
array( 'ORDER BY' => 'CHAR_LENGTH(page_title) ' . $sort_order ));
|
||||
|
||||
// Iterate through the page titles
|
||||
$newText = $text;
|
||||
foreach( $res as $row ) {
|
||||
// Page titles are stored in the database with spaces
|
||||
// replaced by underscores. Therefore we now convert
|
||||
@ -104,38 +104,20 @@
|
||||
|
||||
if ( $title != $myTitle ) {
|
||||
// split the string by [[...]] groups
|
||||
$arr = preg_split( '/(\[\[.*?\]\])/', $newText, -1, PREG_SPLIT_DELIM_CAPTURE );
|
||||
// credits to inhan @ StackOverflow for suggesting preg_split
|
||||
// see http://stackoverflow.com/questions/10672286
|
||||
$arr = preg_split( $delimiter, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
|
||||
// dump( $arr );
|
||||
$safeTitle = str_replace( '/', '\/', $title );
|
||||
for ( $i = 0; $i < count( $arr ); $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] );
|
||||
};
|
||||
$newText = implode( '', $arr );
|
||||
$text = implode( '', $arr );
|
||||
}; // if $title != $myTitle
|
||||
}; // foreach $res as $row
|
||||
if ( $newText != '' ) {
|
||||
$text = $newText;
|
||||
};
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The following function was initially used, but it does not replace
|
||||
* every occurrence of the title words in the page text.
|
||||
*
|
||||
public static function parse1( &$newText ) {
|
||||
// Now look for every occurrence of $title in the
|
||||
// page $text and enclose it in double square brackets,
|
||||
// unless it is already enclosed in brackets (directly
|
||||
// adjacent or remotely, see http://stackoverflow.com/questions/10672286
|
||||
// Regex built with the help from Eugene @ Stackoverflow
|
||||
// http://stackoverflow.com/a/10672440/270712
|
||||
$newText = preg_replace(
|
||||
'/(\b' . str_replace('/', '\/', $title) . '\b)([^\]]+(\[|$))/ium',
|
||||
'[[$1]]$2',
|
||||
$newText );
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
}
|
||||
// vim: ts=2:sw=2:noet
|
||||
|
@ -23,11 +23,13 @@
|
||||
die( 'Not an entry point.' );
|
||||
}
|
||||
|
||||
/*
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 'Off');
|
||||
ini_set('error_log', 'php://stderr');
|
||||
$wgMainCacheType = CACHE_NONE;
|
||||
$wgCacheDirectory = false;
|
||||
*/
|
||||
|
||||
// Configuration variables
|
||||
$wgLinkTitlesPreferShortTitles = false;
|
||||
@ -41,7 +43,7 @@
|
||||
'name' => 'LinkTitles',
|
||||
'author' => '[http://www.mediawiki.org/wiki/User:Bovender Daniel Kraus]',
|
||||
'url' => 'http://www.mediawiki.org/wiki/Extension:LinkTitles',
|
||||
'version' => '0.0.7',
|
||||
'version' => '1.0.0',
|
||||
'descriptionmsg' => 'linktitles-desc'
|
||||
);
|
||||
|
||||
|
29
NEWS
Normal file
29
NEWS
Normal file
@ -0,0 +1,29 @@
|
||||
LinkTitles 1.0.0: 2012-05-22
|
||||
* 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 viewing (unless the page is retrieved
|
||||
from cache)
|
||||
* Minor performance improvement
|
||||
|
||||
LinkTitles 0.0.7: 2012-05-20
|
||||
* Fix version information
|
||||
|
||||
LinkTitles 0.0.6: 2012-05-20
|
||||
* Fix bug: Minimum length title
|
||||
|
||||
LinkTitles 0.0.5: 2012-05-20
|
||||
* Add $wgLinkTitlesMinimumTitleLength configuration variable.
|
||||
|
||||
LinkTitles 0.0.4: 2012-05-20
|
||||
* Add $wgLinkTitlesPreferShortTitles configuration variable.
|
||||
|
||||
LinkTitles 0.0.3: 2012-05-20
|
||||
* Only look for page titles from 'normal' pages (namespace = 0).
|
||||
|
||||
LinkTitles 0.0.2: 2012-05-20
|
||||
* Prevent generation of self-references.
|
||||
* Escape slashes in page titles before using them in a regexp.
|
||||
|
||||
LinkTitles 0.0.1: 2012-05-20
|
||||
* Initial release.
|
||||
|
Reference in New Issue
Block a user