Better extension function synonym cache
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 3 Jul 2006 03:29:57 +0000 (03:29 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 3 Jul 2006 03:29:57 +0000 (03:29 +0000)
includes/Parser.php

index 9a6278a..480a655 100644 (file)
@@ -128,7 +128,6 @@ class Parser
        function Parser() {
                $this->mTagHooks = array();
                $this->mFunctionHooks = array();
-               $this->mFunctionSynonymsValid = true;
                $this->mFunctionSynonyms = array();
                $this->clearState();
                $this->setHook( 'pre', array( $this, 'renderPreTag' ) );
@@ -178,10 +177,6 @@ class Parser
                $this->mShowToc = true;
                $this->mForceTocPosition = false;
 
-               # This doesn't actually clear anything, but it seemed like a nice place to put it
-               # Fill the function cache, if it needs filling
-               $this->refreshFunctionCache();
-
                wfRunHooks( 'ParserClearState', array( &$this ) );
        }
 
@@ -2859,8 +2854,6 @@ class Parser
                                $function = strtolower( substr( $part1, 1, $colonPos - 1 ) );
                                if ( isset( $this->mFunctionSynonyms[$function] ) ) {
                                        $function = $this->mFunctionSynonyms[$function];
-                               }
-                               if ( isset( $this->mFunctionHooks[$function] ) ) {
                                        $funcArgs = array_map( 'trim', $args );
                                        $funcArgs = array_merge( array( &$this, trim( substr( $part1, $colonPos + 1 ) ) ), $funcArgs );
                                        $result = call_user_func_array( $this->mFunctionHooks[$function], $funcArgs );
@@ -3909,28 +3902,14 @@ class Parser
                }
                $oldVal = @$this->mFunctionHooks[$id];
                $this->mFunctionHooks[$id] = $callback;
-               # Invalidate function synonym cache
-               $this->mFunctionSynonymsValid = false;
-               return $oldVal;
-       }
-
-       /**
-        * Make sure the function synonym cache is up to date
-        */
-       function refreshFunctionCache() {
-               if ( !$this->mFunctionSynonymsValid ) {
-                       $this->mFunctionSynonyms = array();
-                       foreach( $this->mFunctionHooks as $key => $value ) {
-                               if ( is_int( $key ) ) {
-                                       $mw = MagicWord::get( $key );
-                                       $synonyms = $mw->getSynonyms();
-                                       foreach( $synonyms as $synonym ) {
-                                               $this->mFunctionSynonyms[strtolower($synonym)] = $key;
-                                       }
-                               }
-                       }
-                       $this->mFunctionSynonymsValid = true;
+               # Add to function cache
+               if ( is_int( $id ) ) {
+                       $mw = MagicWord::get( $id );
+                       $mw->addToArray( $this->mFunctionSynonyms, $id );
+               } else {
+                       $this->mFunctionSynonyms[$id] = $id;
                }
+               return $oldVal;
        }
 
        /**