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

Revision: 89050
Author:   jeroendedauw
Date:     2011-05-28 17:52:02 +0000 (Sat, 28 May 2011)
Log Message:
-----------
work on spark tag

Modified Paths:
--------------
    trunk/extensions/Spark/Spark.class.php
    trunk/extensions/Spark/Spark.hooks.php

Modified: trunk/extensions/Spark/Spark.class.php
===================================================================
--- trunk/extensions/Spark/Spark.class.php      2011-05-28 17:51:33 UTC (rev 
89049)
+++ trunk/extensions/Spark/Spark.class.php      2011-05-28 17:52:02 UTC (rev 
89050)
@@ -1,11 +1,11 @@
 <?php
 
 /**
- * Static class for hooks handled by the Spark extension.
+ * Class to render spark tags.
  * 
  * @since 0.1
  * 
- * @file Spark.hooks.php
+ * @file Spark.class.php
  * @ingroup Spark
  * 
  * @licence GNU GPL v3+
@@ -13,12 +13,63 @@
  */
 final class SparkTag {
        
-       public function __construct( array $args, $input ) {
-               // TODO
+       /**
+        * List of spark parameters.
+        * 
+        * @since 0.1
+        * 
+        * @var array
+        */
+       protected $parameters;
+       
+       /**
+        * Constructor.
+        * 
+        * @since 0.1
+        * 
+        * @var string or null
+        */
+       protected $contents;
+       
+       public function __construct( array $args, $contents ) {
+               $this->parameters = $this->getSparkParameters( $args );
+               $this->contents = $contents;
        }
        
+       /**
+        * Renrder the spark div.
+        * 
+        * @since 0.1
+        * 
+        * @return string
+        */
        public function render() {
-               return ''; // TODO
+               return Html::element(
+                       'div',
+                       array_merge( array( 'class' => 'spark' ), 
$this->parameters ),
+                       $this->contents
+               );
        }
        
+       /**
+        * Get the spark parameters from a list of key value pairs.
+        * 
+        * @since 0.1
+        * 
+        * @param array $args
+        * 
+        * @return array
+        */
+       protected function getSparkParameters( array $args ) {
+               $parameters = array();
+               
+               foreach ( $args as $name => $value ) {
+                       if ( strpos( $name, 'data-spark-' ) === 0 ) {
+                               $parameters[$name] = $value;
+                       }
+               }
+               
+               return $parameters;
+       }
+       
 }
\ No newline at end of file

Modified: trunk/extensions/Spark/Spark.hooks.php
===================================================================
--- trunk/extensions/Spark/Spark.hooks.php      2011-05-28 17:51:33 UTC (rev 
89049)
+++ trunk/extensions/Spark/Spark.hooks.php      2011-05-28 17:52:02 UTC (rev 
89050)
@@ -36,6 +36,13 @@
         * @param PPFrame $frame
         */
        public static function onSparkRender( $input, array $args, Parser 
$parser, PPFrame $frame ) {
+               static $loadedJs = false;
+               
+               if ( !$loadedJs ) {
+                       $parser->getOutput()->addModules( 'ext.spark' );
+                       $loadedJs = true;
+               }
+               
                $tag = new SparkTag( $args, $input );
                return $tag->render();
        }


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

Reply via email to