http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72383

Revision: 72383
Author:   jeroendedauw
Date:     2010-09-04 16:21:08 +0000 (Sat, 04 Sep 2010)

Log Message:
-----------
Evil code inspired by MaxSem

Modified Paths:
--------------
    trunk/extensions/Validator/includes/ParserHook.php

Modified: trunk/extensions/Validator/includes/ParserHook.php
===================================================================
--- trunk/extensions/Validator/includes/ParserHook.php  2010-09-04 15:09:08 UTC 
(rev 72382)
+++ trunk/extensions/Validator/includes/ParserHook.php  2010-09-04 16:21:08 UTC 
(rev 72383)
@@ -66,9 +66,10 @@
         * @return true
         */
        public function init( Parser &$wgParser ) {
-               $wgParser->setHook( $this->getName(), array( $this, 'renderTag' 
) );
-               $wgParser->setFunctionHook( $this->getName(), array( $this, 
'renderFunction' ) );
-               
+               $name = get_class( $this );
+               $wgParser->setHook( $this->getName(), array( new 
ParserHookCaller( $name, 'renderTag' ), 'runHook' ) );
+               $wgParser->setFunctionHook( $this->getName(), array( new 
ParserHookCaller( $name, 'renderFunction' ), 'runHook' ) );
+
                return true;
        }
        
@@ -86,7 +87,7 @@
                $magicWords[$this->getName()] = array( 0, $this->getName() );
                
                return true;
-       }       
+       }
        
        /**
         * Handler for rendering the tag hook.
@@ -194,4 +195,29 @@
                return array();
        }       
        
+}
+
+/**
+ * Completely evil class to create a new instance of the handling ParserHook 
when the actual hook gets called.
+ * 
+ * @evillness >9000 - to be replaced when a better solution (LSB?) is possible.
+ * 
+ * @since 0.4
+ * 
+ * @author Jeroen De Dauw
+ */
+class ParserHookCaller {
+       
+       protected $class;
+       protected $method;
+       
+       function __construct( $class, $method ) {
+               $this->class = $class;
+               $this->method = $method;
+       }
+        
+       public function runHook() {
+               return call_user_func_array( array( new $this->class(), 
$this->method ), func_get_args() );
+       }
+       
 }
\ No newline at end of file



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to