| Index: trunk/extensions/Spark/Spark.settings.php |
| — | — | @@ -19,3 +19,33 @@ |
| 20 | 20 | die( 'Not an entry point.' ); |
| 21 | 21 | } |
| 22 | 22 | |
| | 23 | +/* |
| | 24 | + * Example configuration modules |
| | 25 | + |
| | 26 | +$wgResourceModules['ext.spark.oatpivot'] = array( |
| | 27 | + 'localBasePath' => "$IP/extensions/Spark/", |
| | 28 | + 'remoteBasePath' => $egSparkScriptPath, |
| | 29 | + 'styles' => array('rdf-spark/lib/oat/styles/pivot.css'), |
| | 30 | + 'scripts' => array( 'rdf-spark/lib/oat/loader.js', 'rdf-spark/lib/oat/bootstrap.js', 'rdf-spark/lib/oat/animation.js', 'rdf-spark/lib/oat/barchart.js', 'rdf-spark/lib/oat/ghostdrag.js', 'rdf-spark/lib/oat/instant.js', 'rdf-spark/lib/oat/pivot.js', 'rdf-spark/lib/oat/statistics.js' ), |
| | 31 | + 'dependencies' => array(), |
| | 32 | + 'messages' => array() |
| | 33 | +); |
| | 34 | + |
| | 35 | +$wgResourceModules['ext.spark.datechart'] = array( |
| | 36 | + 'localBasePath' => "$IP/extensions/Spark/", |
| | 37 | + 'remoteBasePath' => $egSparkScriptPath, |
| | 38 | + 'styles' => array(), |
| | 39 | + 'scripts' => array( 'rdf-spark/lib/jquery.jqplot.js', 'rdf-spark/lib/jqplot.pieRenderer.js', 'rdf-spark/lib/jqplot.dateAxisRenderer.js', 'rdf-spark/lib/jqplot.categoryAxisRenderer.js' ), |
| | 40 | + 'dependencies' => array(), |
| | 41 | + 'messages' => array() |
| | 42 | +); |
| | 43 | + |
| | 44 | +$wgResourceModules['ext.spark.piechart'] = array( |
| | 45 | + 'localBasePath' => "$IP/extensions/Spark/", |
| | 46 | + 'remoteBasePath' => $egSparkScriptPath, |
| | 47 | + 'styles' => array(), |
| | 48 | + 'scripts' => array( 'rdf-spark/lib/jquery.jqplot.js', 'rdf-spark/lib/jqplot.pieRenderer.js', 'rdf-spark/lib/jqplot.dateAxisRenderer.js', 'rdf-spark/lib/jqplot.categoryAxisRenderer.js' ), |
| | 49 | + 'dependencies' => array(), |
| | 50 | + 'messages' => array() |
| | 51 | +); |
| | 52 | + */ |
| \ No newline at end of file |
| Index: trunk/extensions/Spark/Spark.hooks.php |
| — | — | @@ -44,7 +44,7 @@ |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | $tag = new SparkTag( $args, $input ); |
| 48 | | - return $tag->render( $parser ); |
| | 48 | + return $tag->render( $parser, $frame ); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | } |
| \ No newline at end of file |
| Index: trunk/extensions/Spark/Spark.class.php |
| — | — | @@ -2,87 +2,112 @@ |
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Class to render spark tags. |
| 6 | | - * |
| | 6 | + * |
| 7 | 7 | * @since 0.1 |
| 8 | | - * |
| | 8 | + * |
| 9 | 9 | * @file Spark.class.php |
| 10 | 10 | * @ingroup Spark |
| 11 | | - * |
| | 11 | + * |
| 12 | 12 | * @licence GNU GPL v3+ |
| 13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | 14 | */ |
| 15 | 15 | final class SparkTag { |
| 16 | | - |
| | 16 | + |
| 17 | 17 | /** |
| 18 | 18 | * List of spark parameters. |
| 19 | | - * |
| | 19 | + * |
| 20 | 20 | * @since 0.1 |
| 21 | | - * |
| | 21 | + * |
| 22 | 22 | * @var array |
| 23 | 23 | */ |
| 24 | 24 | protected $parameters; |
| 25 | | - |
| | 25 | + |
| 26 | 26 | /** |
| 27 | 27 | * Constructor. |
| 28 | | - * |
| | 28 | + * |
| 29 | 29 | * @since 0.1 |
| 30 | | - * |
| | 30 | + * |
| 31 | 31 | * @var string or null |
| 32 | 32 | */ |
| 33 | 33 | protected $contents; |
| 34 | | - |
| | 34 | + |
| 35 | 35 | public function __construct( array $args, $contents ) { |
| 36 | 36 | $this->parameters = $this->getSparkParameters( $args ); |
| 37 | 37 | $this->contents = $contents; |
| 38 | 38 | } |
| 39 | | - |
| | 39 | + |
| 40 | 40 | /** |
| 41 | 41 | * Renrder the spark div. |
| 42 | | - * |
| | 42 | + * |
| 43 | 43 | * @since 0.1 |
| 44 | | - * |
| | 44 | + * |
| 45 | 45 | * @param Parser $parser |
| 46 | | - * |
| | 46 | + * |
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | | - public function render( Parser $parser ) { |
| | 49 | + public function render( Parser $parser, PPFrame $frame ) { |
| | 50 | + global $wgResourceModules; |
| | 51 | + |
| 50 | 52 | if ( array_key_exists( 'data-spark-query', $this->parameters ) ) { |
| 51 | 53 | $query = htmlspecialchars( $this->parameters['data-spark-query'] ); |
| | 54 | + |
| | 55 | + // Before that, shall we allow internal parse, at least for the query? |
| | 56 | + // We replace variables, templates etc. |
| | 57 | + $query = $parser->replaceVariables($query, $frame); |
| | 58 | + |
| | 59 | + // Replace special characters |
| 52 | 60 | $query = str_replace( array( '<', '>' ), array( '<', '>' ), $query ); |
| | 61 | + |
| 53 | 62 | unset( $this->parameters['data-spark-query'] ); |
| | 63 | + |
| | 64 | + // Depending on the format, we possibly need to add modules |
| | 65 | + if ( array_key_exists( 'data-spark-format', $this->parameters ) ) { |
| | 66 | + $format = htmlspecialchars( $this->parameters['data-spark-format'] ); |
| | 67 | + // Remove everything before "spark.XXX" |
| | 68 | + $format = substr($format , strpos($format, "spark.")); |
| | 69 | + // Remove .js at the end |
| | 70 | + $format = str_replace( array( '.js' ), array( '' ), $format ); |
| | 71 | + $module = 'ext.'.$format; |
| | 72 | + if ( array_key_exists($module, $wgResourceModules)) { |
| | 73 | + // TODO: Do we need to check, whether module has been added already? |
| | 74 | + $parser->getOutput()->addModules( $module ); |
| 54 | 75 | |
| | 76 | + } |
| | 77 | + } |
| | 78 | + |
| 55 | 79 | $html = '<div class="spark" data-spark-query="' . $query . '" ' . Html::expandAttributes( $this->parameters ) . ' >' . |
| 56 | | - ( is_null( $this->contents ) ? '' : htmlspecialchars( $this->contents ) ) . |
| | 80 | + ( is_null( $this->contents ) ? '' : htmlspecialchars( $this->contents ) ) . |
| 57 | 81 | '</div>'; |
| 58 | 82 | |
| | 83 | + // In MW 1.17 there seems to be the problem that ? after an empty space is replaced by a non-breaking space ( ) Therefore we remove all spaces before ? which should still make the SPARQL query work |
| 59 | 84 | $html = preg_replace( '/[ \t]+(\?)/', '$1', $html ); |
| 60 | | - |
| | 85 | + |
| 61 | 86 | return array( $parser->insertStripItem( $html, $parser->mStripState ), 'noparse' => true, 'isHTML' => true ); |
| 62 | 87 | } |
| 63 | 88 | else { |
| 64 | 89 | return Html::element( 'i', array(), wfMsg( 'spark-missing-query' ) ); |
| 65 | 90 | } |
| 66 | 91 | } |
| 67 | | - |
| | 92 | + |
| 68 | 93 | /** |
| 69 | 94 | * Get the spark parameters from a list of key value pairs. |
| 70 | | - * |
| | 95 | + * |
| 71 | 96 | * @since 0.1 |
| 72 | | - * |
| | 97 | + * |
| 73 | 98 | * @param array $args |
| 74 | | - * |
| | 99 | + * |
| 75 | 100 | * @return array |
| 76 | 101 | */ |
| 77 | 102 | protected function getSparkParameters( array $args ) { |
| 78 | 103 | $parameters = array(); |
| 79 | | - |
| | 104 | + |
| 80 | 105 | foreach ( $args as $name => $value ) { |
| 81 | 106 | if ( strpos( $name, 'data-spark-' ) === 0 ) { |
| 82 | 107 | $parameters[$name] = $value; |
| 83 | 108 | } |
| 84 | 109 | } |
| 85 | | - |
| | 110 | + |
| 86 | 111 | return $parameters; |
| 87 | 112 | } |
| 88 | | - |
| | 113 | + |
| 89 | 114 | } |
| \ No newline at end of file |