From b128fd1b0536e1553a3a2254ecdc23e986ab5361 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Wed, 21 Oct 2009 17:35:57 +0000 Subject: [PATCH] * Export the return value of wfUrlProtocols() to JS for use in the EditToolbar extension * Also cache this value (in a static var for now, maybe put it in memcached?): when parsing pages with many external links, we'd end up calling implode() once and preg_quote() 11 times for every link --- includes/GlobalFunctions.php | 12 ++++++++++-- includes/Skin.php | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index c23a64c860..b92e48f70a 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2236,6 +2236,12 @@ function wfSpecialList( $page, $details ) { */ function wfUrlProtocols() { global $wgUrlProtocols; + + // This function is called a lot, cache its return value + // TODO: Cache this in memcached instead? + static $retval = null; + if ( !is_null( $retval ) ) + return $retval; // Support old-style $wgUrlProtocols strings, for backwards compatibility // with LocalSettings files from 1.5 @@ -2244,10 +2250,12 @@ function wfUrlProtocols() { foreach ($wgUrlProtocols as $protocol) $protocols[] = preg_quote( $protocol, '/' ); - return implode( '|', $protocols ); + $retval = implode( '|', $protocols ); } else { - return $wgUrlProtocols; + $retval = $wgUrlProtocols; } + + return $retval; } /** diff --git a/includes/Skin.php b/includes/Skin.php index 81dd0bf0d0..17da161abe 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -384,6 +384,7 @@ class Skin extends Linker { $vars = array( 'skin' => $skinName, 'stylepath' => $wgStylePath, + 'urlprotocols' => wfUrlProtocols(), 'wgArticlePath' => $wgArticlePath, 'wgScriptPath' => $wgScriptPath, 'wgScriptExtension' => $wgScriptExtension, -- 2.20.1