r99153 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99152‎ | r99153 | r99154 >
Date:22:18, 6 October 2011
Author:bkaempgen
Status:deferred
Tags:
Comment:
=== 2011-10-06 ===
* Added CHANGELOG
* Added support for older versions of MW that do not have a resource loader
* Spark sometimes needs additional JavaScript. It can be given in LocalSettings.php using the variable $wgResourceModules
Modified paths:
  • /trunk/extensions/Spark/CHANGELOG (modified) (history)
  • /trunk/extensions/Spark/README (modified) (history)
  • /trunk/extensions/Spark/Spark.class.php (modified) (history)
  • /trunk/extensions/Spark/Spark.hooks.php (modified) (history)
  • /trunk/extensions/Spark/Spark.i18n.php (modified) (history)
  • /trunk/extensions/Spark/Spark.php (modified) (history)
  • /trunk/extensions/Spark/Spark.settings.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Spark/Spark.i18n.php
@@ -77,22 +77,6 @@
7878 'spark-missing-query' => 'Es necessari specificar un consulta usante le parametro "data-spark-query".',
7979 );
8080
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 -
9781 /** Macedonian (Македонски)
9882 * @author Bjankuloski06
9983 */
Index: trunk/extensions/Spark/Spark.settings.php
@@ -19,33 +19,37 @@
2020 die( 'Not an entry point.' );
2121 }
2222
 23+/// Parameters /////
 24+define("egSparkQuery", "data-spark-query");
 25+define("egSparkFormat", "data-spark-format");
 26+
2327 /*
2428 * 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 -);
3429
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+ );
4338
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+ );
5256 */
\ No newline at end of file
Index: trunk/extensions/Spark/Spark.php
@@ -2,7 +2,7 @@
33
44 /**
55 * Initialization file for the Spark extension.
6 - *
 6+ *
77 * Documentation: http://www.mediawiki.org/wiki/Extension:Spark
88 * Support http://www.mediawiki.org/wiki/Extension_talk:Spark
99 * Source code: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Spark
@@ -24,8 +24,9 @@
2525 die( 'Not an entry point.' );
2626 }
2727
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.' );
3031 }
3132
3233 define( 'Spark_VERSION', '0.2 alpha' );
@@ -36,27 +37,36 @@
3738 'version' => Spark_VERSION,
3839 'author' => array(
3940 '[http://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]',
40 - ),
 41+),
4142 'url' => 'http://www.mediawiki.org/wiki/Extension:Spark',
4243 'descriptionmsg' => 'spark-desc'
4344 );
4445
45 -$egSparkScriptPath = ( $wgExtensionAssetsPath === false ? $wgScriptPath . '/extensions' : $wgExtensionAssetsPath ) . '/Spark';
 46+// $wgExtensionAssetsPath does possibly not exist.
 47+$egSparkScriptPath = ( (!isset($wgExtensionAssetsPath) || $wgExtensionAssetsPath === false) ? $wgScriptPath . '/extensions' : $wgExtensionAssetsPath ) . '/Spark';
4648
4749 $wgExtensionMessagesFiles['Spark'] = dirname( __FILE__ ) . '/Spark.i18n.php';
4850
4951 $wgAutoloadClasses['SparkHooks'] = dirname( __FILE__ ) . '/Spark.hooks.php';
5052 $wgAutoloadClasses['SparkTag'] = dirname( __FILE__ ) . '/Spark.class.php';
5153
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(
5361 'localBasePath' => dirname( __FILE__ ),
5462 'remoteBasePath' => $egSparkScriptPath,
5563 'styles' => array(),
5664 'scripts' => array( 'rdf-spark/jquery.spark.js' ),
5765 'dependencies' => array(),
5866 'messages' => array()
59 -);
 67+ );
 68+}
6069
 70+
6171 $wgHooks['ParserFirstCallInit'][] = 'SparkHooks::onParserFirstCallInit';
6272
6373 require_once 'Spark.settings.php';
\ No newline at end of file
Index: trunk/extensions/Spark/CHANGELOG
@@ -7,3 +7,4 @@
88 * Added support for older versions of MW that do not have a resource loader
99 * Spark sometimes needs additional JavaScript. IT can be given in LocalSettings.php using the variable $wgResourceModules
1010
 11+
Index: trunk/extensions/Spark/Spark.hooks.php
@@ -2,49 +2,72 @@
33
44 /**
55 * Static class for hooks handled by the Spark extension.
6 - *
 6+ *
77 * @since 0.1
8 - *
 8+ *
99 * @file Spark.hooks.php
1010 * @ingroup Spark
11 - *
 11+ *
1212 * @licence GNU GPL v3+
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
1515 final class SparkHooks {
16 -
 16+
1717 /**
1818 * Register the spark tag extension when the parser initializes.
19 - *
 19+ *
2020 * @since 0.1
21 - *
 21+ *
2222 * @param Parser $parser
23 - *
 23+ *
2424 * @return true
2525 */
2626 public static function onParserFirstCallInit( Parser &$parser ) {
2727 $parser->setHook( 'spark', __CLASS__ . '::onSparkRender' );
2828 return true;
2929 }
30 -
 30+
3131 /**
3232 * @since 0.1
33 - *
 33+ *
3434 * @param mixed $input
3535 * @param array $args
3636 * @param Parser $parser
3737 * @param PPFrame $frame
3838 */
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+
4045 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+ }
4566 }
46 -
4767 $tag = new SparkTag( $args, $input );
 68+
 69+ // PPFrame maybe not existing
4870 return $tag->render( $parser, $frame );
 71+
4972 }
50 -
 73+
5174 }
\ No newline at end of file
Index: trunk/extensions/Spark/Spark.class.php
@@ -45,44 +45,80 @@
4646 *
4747 * @return string
4848 */
49 - public function render( Parser $parser, PPFrame $frame ) {
 49+ public function render( Parser $parser, $frame ) {
 50+ global $wgVersion;
 51+ global $wgOut;
 52+ global $egSparkScriptPath;
5053 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+
5562 // Before that, shall we allow internal parse, at least for the query?
5663 // We replace variables, templates etc.
5764 $query = $parser->replaceVariables($query, $frame);
58 -
 65+ //$query = $parser->recursiveTagParse( $query );
 66+
5967 // Replace special characters
6068 $query = str_replace( array( '&lt;', '&gt;' ), array( '<', '>' ), $query );
61 -
62 - unset( $this->parameters['data-spark-query'] );
63 -
 69+
 70+ unset( $this->parameters[egSparkQuery] );
 71+
6472 // 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] );
6775 // Remove everything before "spark.XXX"
6876 $format = substr($format , strpos($format, "spark."));
6977 // Remove .js at the end
7078 $format = str_replace( array( '.js' ), array( '' ), $format );
7179 $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 );
7580
 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+ }
76106 }
77107 }
78 -
 108+
79109 $html = '<div class="spark" data-spark-query="' . $query . '" ' . Html::expandAttributes( $this->parameters ) . ' >' .
80110 ( is_null( $this->contents ) ? '' : htmlspecialchars( $this->contents ) ) .
81111 '</div>';
82112
83113 // In MW 1.17 there seems to be the problem that ? after an empty space is replaced by a non-breaking space (&#160;) Therefore we remove all spaces before ? which should still make the SPARQL query work
84114 $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+ }
87123 }
88124 else {
89125 return Html::element( 'i', array(), wfMsg( 'spark-missing-query' ) );
@@ -101,9 +137,12 @@
102138 protected function getSparkParameters( array $args ) {
103139 $parameters = array();
104140
 141+ // For lower versions of MW, special chars were not allowed in tags, therefore, we simply add them, then.
105142 foreach ( $args as $name => $value ) {
106143 if ( strpos( $name, 'data-spark-' ) === 0 ) {
107144 $parameters[$name] = $value;
 145+ } else {
 146+ $parameters['data-spark-'.$name] = $value;
108147 }
109148 }
110149
Index: trunk/extensions/Spark/README
@@ -39,4 +39,12 @@
4040
4141 * Visualization of data obtained via SPARQL queries.
4242 * 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

Follow-up revisions

RevisionCommit summaryAuthorDate
r99219Partly revert r99153: Removal of translations by accident (forgotten to svn up?)raymond17:08, 7 October 2011

Status & tagging log