* Export the return value of wfUrlProtocols() to JS for use in the EditToolbar extension
authorRoan Kattouw <catrope@users.mediawiki.org>
Wed, 21 Oct 2009 17:35:57 +0000 (17:35 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Wed, 21 Oct 2009 17:35:57 +0000 (17:35 +0000)
* 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
includes/Skin.php

index c23a64c..b92e48f 100644 (file)
@@ -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;
 }
 
 /**
index 81dd0bf..17da161 100644 (file)
@@ -384,6 +384,7 @@ class Skin extends Linker {
                $vars = array(
                        'skin' => $skinName,
                        'stylepath' => $wgStylePath,
+                       'urlprotocols' => wfUrlProtocols(),
                        'wgArticlePath' => $wgArticlePath,
                        'wgScriptPath' => $wgScriptPath,
                        'wgScriptExtension' => $wgScriptExtension,