From e850f3e3674d0b3c1b8371626db3c90cb9fc7fd6 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sat, 28 Feb 2015 14:24:12 +0100 Subject: [PATCH] Cache delimiters used in regular expressions. - CHANGE: Improve performance. --- LinkTitles.body.php | 132 +++++++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 58 deletions(-) diff --git a/LinkTitles.body.php b/LinkTitles.body.php index 93f0795..64744a4 100755 --- a/LinkTitles.body.php +++ b/LinkTitles.body.php @@ -44,6 +44,14 @@ /// as a string. private static $targetTitleText; + /// Delimiter used in a regexp split operation to seperate those parts + /// of the page that should be parsed from those that should not be + /// parsed (e.g. inside pre-existing links etc.). + private static $delimiter; + + private static $wordStartDelim; + private static $wordEndDelim; + /// Setup function, hooks the extension's functions to MediaWiki events. public static function setup() { global $wgLinkTitlesParseOnEdit; @@ -56,6 +64,7 @@ $wgHooks['InternalParseBeforeLinks'][] = 'LinkTitles::onInternalParseBeforeLinks'; }; $wgHooks['GetDoubleUnderscoreIDs'][] = 'LinkTitles::onGetDoubleUnderscoreIDs'; + self::BuildDelimiters(); } /// Event handler that is hooked to the PageContentSave event. @@ -95,69 +104,17 @@ // Configuration variables need to be defined here as globals. global $wgLinkTitlesPreferShortTitles; global $wgLinkTitlesMinimumTitleLength; - global $wgLinkTitlesParseHeadings; global $wgLinkTitlesBlackList; - global $wgLinkTitlesSkipTemplates; global $wgLinkTitlesFirstOnly; - global $wgLinkTitlesWordStartOnly; - global $wgLinkTitlesWordEndOnly; global $wgLinkTitlesSmartMode; global $wgCapitalLinks; - // Use unicode character properties rather than \b escape sequences - // to detect whole words containing non-ASCII characters as well. - // Note that this requires the use of the '/u' switch, and you need - // to have PHP with a PCRE library that was compiled with - // --enable-unicode-properties - ( $wgLinkTitlesWordStartOnly ) ? $wordStartDelim = '(?.*?<.nowiki>|.*?<\/code>|' . // nowiki/code - '
.*?<\/pre>|.*?<\/html>|' .      // pre/html
-				'