r89050 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89049‎ | r89050 | r89051 >
Date:17:52, 28 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on spark tag
Modified paths:
  • /trunk/extensions/Spark/Spark.class.php (modified) (history)
  • /trunk/extensions/Spark/Spark.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Spark/Spark.hooks.php
@@ -36,6 +36,13 @@
3737 * @param PPFrame $frame
3838 */
3939 public static function onSparkRender( $input, array $args, Parser $parser, PPFrame $frame ) {
 40+ static $loadedJs = false;
 41+
 42+ if ( !$loadedJs ) {
 43+ $parser->getOutput()->addModules( 'ext.spark' );
 44+ $loadedJs = true;
 45+ }
 46+
4047 $tag = new SparkTag( $args, $input );
4148 return $tag->render();
4249 }
Index: trunk/extensions/Spark/Spark.class.php
@@ -1,11 +1,11 @@
22 <?php
33
44 /**
5 - * Static class for hooks handled by the Spark extension.
 5+ * Class to render spark tags.
66 *
77 * @since 0.1
88 *
9 - * @file Spark.hooks.php
 9+ * @file Spark.class.php
1010 * @ingroup Spark
1111 *
1212 * @licence GNU GPL v3+
@@ -13,12 +13,63 @@
1414 */
1515 final class SparkTag {
1616
17 - public function __construct( array $args, $input ) {
18 - // TODO
 17+ /**
 18+ * List of spark parameters.
 19+ *
 20+ * @since 0.1
 21+ *
 22+ * @var array
 23+ */
 24+ protected $parameters;
 25+
 26+ /**
 27+ * Constructor.
 28+ *
 29+ * @since 0.1
 30+ *
 31+ * @var string or null
 32+ */
 33+ protected $contents;
 34+
 35+ public function __construct( array $args, $contents ) {
 36+ $this->parameters = $this->getSparkParameters( $args );
 37+ $this->contents = $contents;
1938 }
2039
 40+ /**
 41+ * Renrder the spark div.
 42+ *
 43+ * @since 0.1
 44+ *
 45+ * @return string
 46+ */
2147 public function render() {
22 - return ''; // TODO
 48+ return Html::element(
 49+ 'div',
 50+ array_merge( array( 'class' => 'spark' ), $this->parameters ),
 51+ $this->contents
 52+ );
2353 }
2454
 55+ /**
 56+ * Get the spark parameters from a list of key value pairs.
 57+ *
 58+ * @since 0.1
 59+ *
 60+ * @param array $args
 61+ *
 62+ * @return array
 63+ */
 64+ protected function getSparkParameters( array $args ) {
 65+ $parameters = array();
 66+
 67+ foreach ( $args as $name => $value ) {
 68+ if ( strpos( $name, 'data-spark-' ) === 0 ) {
 69+ $parameters[$name] = $value;
 70+ }
 71+ }
 72+
 73+ return $parameters;
 74+ }
 75+
2576 }
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r89053follow up to r89050jeroendedauw18:30, 28 May 2011

Status & tagging log