Index: trunk/extensions/Spark/Spark.i18n.php |
— | — | @@ -77,22 +77,6 @@ |
78 | 78 | 'spark-missing-query' => 'Es necessari specificar un consulta usante le parametro "data-spark-query".', |
79 | 79 | ); |
80 | 80 | |
81 | | -/** Japanese (日本語) |
82 | | - * @author Schu |
83 | | - */ |
84 | | -$messages['ja'] = array( |
85 | | - 'spark-desc' => '[http://km.aifb.kit.edu/sites/spark/ Spark] マッシュアップを埋め込む事を可能にする <code><nowiki><spark /></nowiki></code> タグを追加します。Spark ライブラリは、Denny Vrandecic と Andreas Harth によって作成されました。', |
86 | | - 'spark-missing-query' => '「data-spark-query」パラメーターを用いてクエリを指定する必要があります。', |
87 | | -); |
88 | | - |
89 | | -/** Colognian (Ripoarisch) |
90 | | - * @author Purodha |
91 | | - */ |
92 | | -$messages['ksh'] = array( |
93 | | - 'spark-desc' => 'Deiht dä Befähl <code lang="en"><nowiki><spark /></nowiki></code> en et Wiki, dä et müjjelesh määt, <i lang="en">[http://km.aifb.kit.edu/sites/spark/ Spark] mash-ups</i> enzebenge. De <i lang="en">Spark</i>-Projramm-Sammlong wood vum <i lang="en">Denny Vrandecic</i> un vum <i lang="en">Andreas Harth</i> jemaat.', |
94 | | - 'spark-missing-query' => 'Mer moß och en Frooch övver dä Parrameeter <code lang="en">data-spark-query</code> aanjävve.', |
95 | | -); |
96 | | - |
97 | 81 | /** Macedonian (Македонски) |
98 | 82 | * @author Bjankuloski06 |
99 | 83 | */ |
Index: trunk/extensions/Spark/Spark.settings.php |
— | — | @@ -19,33 +19,37 @@ |
20 | 20 | die( 'Not an entry point.' ); |
21 | 21 | } |
22 | 22 | |
| 23 | +/// Parameters ///// |
| 24 | +define("egSparkQuery", "data-spark-query"); |
| 25 | +define("egSparkFormat", "data-spark-format"); |
| 26 | + |
23 | 27 | /* |
24 | 28 | * 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 | 29 | |
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 | | -); |
| 30 | + $wgResourceModules['ext.spark.oatpivot'] = array( |
| 31 | + 'localBasePath' => "$IP/extensions/Spark/", |
| 32 | + 'remoteBasePath' => $egSparkScriptPath, |
| 33 | + 'styles' => array('rdf-spark/lib/oat/styles/pivot.css'), |
| 34 | + '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' ), |
| 35 | + 'dependencies' => array(), |
| 36 | + 'messages' => array() |
| 37 | + ); |
43 | 38 | |
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 | | -); |
| 39 | + $wgResourceModules['ext.spark.datechart'] = array( |
| 40 | + 'localBasePath' => "$IP/extensions/Spark/", |
| 41 | + 'remoteBasePath' => $egSparkScriptPath, |
| 42 | + 'styles' => array(), |
| 43 | + 'scripts' => array( 'rdf-spark/lib/jquery.jqplot.js', 'rdf-spark/lib/jqplot.dateAxisRenderer.js', 'rdf-spark/lib/jqplot.categoryAxisRenderer.js' ), |
| 44 | + 'dependencies' => array(), |
| 45 | + 'messages' => array() |
| 46 | + ); |
| 47 | + |
| 48 | + $wgResourceModules['ext.spark.piechart'] = array( |
| 49 | + 'localBasePath' => "$IP/extensions/Spark/", |
| 50 | + 'remoteBasePath' => $egSparkScriptPath, |
| 51 | + 'styles' => array(), |
| 52 | + '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' ), |
| 53 | + 'dependencies' => array(), |
| 54 | + 'messages' => array() |
| 55 | + ); |
52 | 56 | */ |
\ No newline at end of file |
Index: trunk/extensions/Spark/Spark.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Initialization file for the Spark extension. |
6 | | - * |
| 6 | + * |
7 | 7 | * Documentation: http://www.mediawiki.org/wiki/Extension:Spark |
8 | 8 | * Support http://www.mediawiki.org/wiki/Extension_talk:Spark |
9 | 9 | * Source code: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Spark |
— | — | @@ -24,8 +24,9 @@ |
25 | 25 | die( 'Not an entry point.' ); |
26 | 26 | } |
27 | 27 | |
28 | | -if ( version_compare( $wgVersion, '1.17', '<' ) ) { |
29 | | - die( '<b>Error:</b> Spark requires MediaWiki 1.17 or above.' ); |
| 28 | +// We also want to support versions below 1.17 |
| 29 | +if ( version_compare( $wgVersion, '1.15', '<' ) ) { |
| 30 | + die( '<b>Error:</b> Spark requires MediaWiki 1.15 or above.' ); |
30 | 31 | } |
31 | 32 | |
32 | 33 | define( 'Spark_VERSION', '0.2 alpha' ); |
— | — | @@ -36,27 +37,36 @@ |
37 | 38 | 'version' => Spark_VERSION, |
38 | 39 | 'author' => array( |
39 | 40 | '[http://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]', |
40 | | - ), |
| 41 | +), |
41 | 42 | 'url' => 'http://www.mediawiki.org/wiki/Extension:Spark', |
42 | 43 | 'descriptionmsg' => 'spark-desc' |
43 | 44 | ); |
44 | 45 | |
45 | | -$egSparkScriptPath = ( $wgExtensionAssetsPath === false ? $wgScriptPath . '/extensions' : $wgExtensionAssetsPath ) . '/Spark'; |
| 46 | +// $wgExtensionAssetsPath does possibly not exist. |
| 47 | +$egSparkScriptPath = ( (!isset($wgExtensionAssetsPath) || $wgExtensionAssetsPath === false) ? $wgScriptPath . '/extensions' : $wgExtensionAssetsPath ) . '/Spark'; |
46 | 48 | |
47 | 49 | $wgExtensionMessagesFiles['Spark'] = dirname( __FILE__ ) . '/Spark.i18n.php'; |
48 | 50 | |
49 | 51 | $wgAutoloadClasses['SparkHooks'] = dirname( __FILE__ ) . '/Spark.hooks.php'; |
50 | 52 | $wgAutoloadClasses['SparkTag'] = dirname( __FILE__ ) . '/Spark.class.php'; |
51 | 53 | |
52 | | -$wgResourceModules['ext.spark'] = array( |
| 54 | +if ( version_compare( $wgVersion, '1.17', '<' ) ) { |
| 55 | + // We do not have resource loader |
| 56 | + $egSparkScriptJquery = $egSparkScriptPath.'/rdf-spark/lib/jquery-1.4.4.js'; |
| 57 | + $egSparkScriptJquerySpark = $egSparkScriptPath.'/rdf-spark/jquery.spark.js'; |
| 58 | +} else { |
| 59 | + // We have resource loader |
| 60 | + $wgResourceModules['ext.spark'] = array( |
53 | 61 | 'localBasePath' => dirname( __FILE__ ), |
54 | 62 | 'remoteBasePath' => $egSparkScriptPath, |
55 | 63 | 'styles' => array(), |
56 | 64 | 'scripts' => array( 'rdf-spark/jquery.spark.js' ), |
57 | 65 | 'dependencies' => array(), |
58 | 66 | 'messages' => array() |
59 | | -); |
| 67 | + ); |
| 68 | +} |
60 | 69 | |
| 70 | + |
61 | 71 | $wgHooks['ParserFirstCallInit'][] = 'SparkHooks::onParserFirstCallInit'; |
62 | 72 | |
63 | 73 | require_once 'Spark.settings.php'; |
\ No newline at end of file |
Index: trunk/extensions/Spark/CHANGELOG |
— | — | @@ -7,3 +7,4 @@ |
8 | 8 | * Added support for older versions of MW that do not have a resource loader
|
9 | 9 | * Spark sometimes needs additional JavaScript. IT can be given in LocalSettings.php using the variable $wgResourceModules
|
10 | 10 |
|
| 11 | +
|
Index: trunk/extensions/Spark/Spark.hooks.php |
— | — | @@ -2,49 +2,72 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Static class for hooks handled by the Spark extension. |
6 | | - * |
| 6 | + * |
7 | 7 | * @since 0.1 |
8 | | - * |
| 8 | + * |
9 | 9 | * @file Spark.hooks.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 SparkHooks { |
16 | | - |
| 16 | + |
17 | 17 | /** |
18 | 18 | * Register the spark tag extension when the parser initializes. |
19 | | - * |
| 19 | + * |
20 | 20 | * @since 0.1 |
21 | | - * |
| 21 | + * |
22 | 22 | * @param Parser $parser |
23 | | - * |
| 23 | + * |
24 | 24 | * @return true |
25 | 25 | */ |
26 | 26 | public static function onParserFirstCallInit( Parser &$parser ) { |
27 | 27 | $parser->setHook( 'spark', __CLASS__ . '::onSparkRender' ); |
28 | 28 | return true; |
29 | 29 | } |
30 | | - |
| 30 | + |
31 | 31 | /** |
32 | 32 | * @since 0.1 |
33 | | - * |
| 33 | + * |
34 | 34 | * @param mixed $input |
35 | 35 | * @param array $args |
36 | 36 | * @param Parser $parser |
37 | 37 | * @param PPFrame $frame |
38 | 38 | */ |
39 | | - public static function onSparkRender( $input, array $args, Parser $parser, PPFrame $frame ) { |
| 39 | + public static function onSparkRender( $input, array $args, Parser $parser, $frame = null) { |
| 40 | + global $wgVersion; |
| 41 | + global $wgOut; |
| 42 | + global $egSparkScriptJquery; |
| 43 | + global $egSparkScriptJquerySpark; |
| 44 | + |
40 | 45 | static $loadedJs = false; |
41 | | - |
42 | | - if ( !$loadedJs ) { |
43 | | - $parser->getOutput()->addModules( 'ext.spark' ); |
44 | | - $loadedJs = true; |
| 46 | + |
| 47 | + if ( version_compare( $wgVersion, '1.17', '<' ) ) { |
| 48 | + // We do not have resource loader |
| 49 | + if ( !$loadedJs ) { |
| 50 | + $wgOut->addScript('<script src="'.$egSparkScriptJquery.'" type="text/javascript"></script>'); |
| 51 | + wfDebugLog( 'spark', "AddScript:".' <script src="'.$egSparkScriptJquery.'" type="text/javascript"></script>' ); |
| 52 | + //echo "AddScript:".' <script src="'.$egSparkScriptJquery.'" type="text/javascript"></script>'; |
| 53 | + $wgOut->addScript('<script src="'.$egSparkScriptJquerySpark.'" type="text/javascript"></script>'); |
| 54 | + wfDebugLog( 'spark', "AddScript:".' <script src="'.$egSparkScriptJquerySpark.'" type="text/javascript"></script>' ); |
| 55 | + //echo "AddScript:".' <script src="'.$egSparkScriptJquerySpark.'" type="text/javascript"></script>'; |
| 56 | + $loadedJs = true; |
| 57 | + } |
| 58 | + |
| 59 | + } else { |
| 60 | + // We have resource loader |
| 61 | + // If we have resource loader |
| 62 | + if ( !$loadedJs ) { |
| 63 | + $parser->getOutput()->addModules( 'ext.spark' ); |
| 64 | + $loadedJs = true; |
| 65 | + } |
45 | 66 | } |
46 | | - |
47 | 67 | $tag = new SparkTag( $args, $input ); |
| 68 | + |
| 69 | + // PPFrame maybe not existing |
48 | 70 | return $tag->render( $parser, $frame ); |
| 71 | + |
49 | 72 | } |
50 | | - |
| 73 | + |
51 | 74 | } |
\ No newline at end of file |
Index: trunk/extensions/Spark/Spark.class.php |
— | — | @@ -45,44 +45,80 @@ |
46 | 46 | * |
47 | 47 | * @return string |
48 | 48 | */ |
49 | | - public function render( Parser $parser, PPFrame $frame ) { |
| 49 | + public function render( Parser $parser, $frame ) { |
| 50 | + global $wgVersion; |
| 51 | + global $wgOut; |
| 52 | + global $egSparkScriptPath; |
50 | 53 | global $wgResourceModules; |
51 | | - |
52 | | - if ( array_key_exists( 'data-spark-query', $this->parameters ) ) { |
53 | | - $query = htmlspecialchars( $this->parameters['data-spark-query'] ); |
54 | | - |
| 54 | + |
| 55 | + // What is loaded already? |
| 56 | + static $loadedJsses = array(); |
| 57 | + |
| 58 | + wfDebugLog( 'myextension', 'Parameters alright? ' . print_r($this->parameters, true) ); |
| 59 | + if ( array_key_exists( egSparkQuery, $this->parameters ) ) { |
| 60 | + $query = htmlspecialchars( $this->parameters[egSparkQuery] ); |
| 61 | + |
55 | 62 | // Before that, shall we allow internal parse, at least for the query? |
56 | 63 | // We replace variables, templates etc. |
57 | 64 | $query = $parser->replaceVariables($query, $frame); |
58 | | - |
| 65 | + //$query = $parser->recursiveTagParse( $query ); |
| 66 | + |
59 | 67 | // Replace special characters |
60 | 68 | $query = str_replace( array( '<', '>' ), array( '<', '>' ), $query ); |
61 | | - |
62 | | - unset( $this->parameters['data-spark-query'] ); |
63 | | - |
| 69 | + |
| 70 | + unset( $this->parameters[egSparkQuery] ); |
| 71 | + |
64 | 72 | // 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'] ); |
| 73 | + if ( array_key_exists( egSparkFormat, $this->parameters ) ) { |
| 74 | + $format = htmlspecialchars( $this->parameters[egSparkFormat] ); |
67 | 75 | // Remove everything before "spark.XXX" |
68 | 76 | $format = substr($format , strpos($format, "spark.")); |
69 | 77 | // Remove .js at the end |
70 | 78 | $format = str_replace( array( '.js' ), array( '' ), $format ); |
71 | 79 | $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 ); |
75 | 80 | |
| 81 | + // for older versions of MW, different |
| 82 | + if ( version_compare( $wgVersion, '1.17', '<' ) ) { |
| 83 | + if (isset($wgResourceModules) && array_key_exists($module, $wgResourceModules)) { |
| 84 | + // only if not already loaded |
| 85 | + if (!isset($loadedJsses[$module])) { |
| 86 | + // scripts |
| 87 | + foreach ($wgResourceModules[$module]['scripts'] as $script) { |
| 88 | + $wgOut->addScript('<script src="'.$egSparkScriptPath."/".$script.'" type="text/javascript"></script>'); |
| 89 | + wfDebugLog( 'spark', "AddScript:".' <script src="'.$egSparkScriptPath."/".$script.'" type="text/javascript"></script>' ); |
| 90 | + } |
| 91 | + |
| 92 | + // css |
| 93 | + foreach ($wgResourceModules[$module]['styles'] as $style) { |
| 94 | + $wgOut->addScript('<link rel="stylesheet" href="'.$egSparkScriptPath."/".$style.'" type="text/css" />'); |
| 95 | + wfDebugLog( 'spark', "AddLink:".' <link rel="stylesheet" href="'.$egSparkScriptPath."/".$style.'" type="text/css" />' ); |
| 96 | + } |
| 97 | + $loadedJsses[$module] = true; |
| 98 | + } |
| 99 | + } |
| 100 | + } else { |
| 101 | + // $wgResourceModules might not exist |
| 102 | + if (isset($wgResourceModules) && array_key_exists($module, $wgResourceModules)) { |
| 103 | + // TODO: Do we need to check, whether module has been added already? |
| 104 | + $parser->getOutput()->addModules( $module ); |
| 105 | + } |
76 | 106 | } |
77 | 107 | } |
78 | | - |
| 108 | + |
79 | 109 | $html = '<div class="spark" data-spark-query="' . $query . '" ' . Html::expandAttributes( $this->parameters ) . ' >' . |
80 | 110 | ( is_null( $this->contents ) ? '' : htmlspecialchars( $this->contents ) ) . |
81 | 111 | '</div>'; |
82 | 112 | |
83 | 113 | // 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 |
84 | 114 | $html = preg_replace( '/[ \t]+(\?)/', '$1', $html ); |
85 | | - |
86 | | - return array( $parser->insertStripItem( $html, $parser->mStripState ), 'noparse' => true, 'isHTML' => true ); |
| 115 | + |
| 116 | + // for older versions of MW, different |
| 117 | + if ( version_compare( $wgVersion, '1.17', '<' ) ) { |
| 118 | + $parser->disableCache(); |
| 119 | + return $html; |
| 120 | + } else { |
| 121 | + return array( $parser->insertStripItem( $html, $parser->mStripState ), 'noparse' => true, 'isHTML' => true ); |
| 122 | + } |
87 | 123 | } |
88 | 124 | else { |
89 | 125 | return Html::element( 'i', array(), wfMsg( 'spark-missing-query' ) ); |
— | — | @@ -101,9 +137,12 @@ |
102 | 138 | protected function getSparkParameters( array $args ) { |
103 | 139 | $parameters = array(); |
104 | 140 | |
| 141 | + // For lower versions of MW, special chars were not allowed in tags, therefore, we simply add them, then. |
105 | 142 | foreach ( $args as $name => $value ) { |
106 | 143 | if ( strpos( $name, 'data-spark-' ) === 0 ) { |
107 | 144 | $parameters[$name] = $value; |
| 145 | + } else { |
| 146 | + $parameters['data-spark-'.$name] = $value; |
108 | 147 | } |
109 | 148 | } |
110 | 149 | |
Index: trunk/extensions/Spark/README |
— | — | @@ -39,4 +39,12 @@ |
40 | 40 | |
41 | 41 | * Visualization of data obtained via SPARQL queries. |
42 | 42 | * Support for all Spark visualizations. |
43 | | -* Use of the native Spark syntax, which can be copied from native spark divs to the spark tag and back. |
\ No newline at end of file |
| 43 | +* Use of the native Spark syntax, which can be copied from native spark divs to the spark tag and back. |
| 44 | + |
| 45 | +==== Adding of additionally required JavaScript files ==== |
| 46 | +* Some visualizations of Spark require additional JavaScript files. |
| 47 | +* Those can be defined in modules, see Spark.settings.php - Example configuration modules |
| 48 | + |
| 49 | +==== Support for MW versions without Resource Loader ==== |
| 50 | +* Here, the native Spark syntax cannot be used, completely. |
| 51 | +* E.g, instead of data-spark-endpoint, one needs to have only endpoint. |
\ No newline at end of file |