Index: trunk/extensions/SemanticResultFormats/jqPlot/SRF_jqPlotPie.php |
— | — | @@ -3,6 +3,7 @@ |
4 | 4 | * A query printer for pie charts using the jqPlot JavaScript library. |
5 | 5 | * |
6 | 6 | * @author Sanyam Goyal |
| 7 | + * @author Yaron Koren |
7 | 8 | */ |
8 | 9 | |
9 | 10 | if ( !defined( 'MEDIAWIKI' ) ) { |
— | — | @@ -32,12 +33,53 @@ |
33 | 34 | return wfMsg( 'srf_printername_jqplotpie' ); |
34 | 35 | } |
35 | 36 | |
36 | | - protected function getResultText( $res, $outputmode ) { |
37 | | - global $smwgIQRunningNumber, $wgOut, $srfgScriptPath, $smwgScriptPath; |
38 | | - global $wgParser; |
| 37 | + public static function registerResourceModules() { |
| 38 | + global $wgResourceModules, $srfgIP; |
| 39 | + |
| 40 | + $resourceTemplate = array( |
| 41 | + 'localBasePath' => $srfgIP . '/jqPlot', |
| 42 | + 'remoteExtPath' => 'SemanticResultFormats' |
| 43 | + ); |
| 44 | + $wgResourceModules['ext.srf.jqplot'] = $resourceTemplate + array( |
| 45 | + 'scripts' => array( |
| 46 | + 'jquery.jqplot.min.js', |
| 47 | + ), |
| 48 | + 'styles' => array( |
| 49 | + 'jquery.jqplot.css', |
| 50 | + ), |
| 51 | + 'dependencies' => array( |
| 52 | + 'jquery', |
| 53 | + ), |
| 54 | + ); |
| 55 | + $wgResourceModules['ext.srf.jqplotpie'] = $resourceTemplate + array( |
| 56 | + 'scripts' => array( |
| 57 | + 'jqplot.pieRenderer.min.js', |
| 58 | + ), |
| 59 | + 'styles' => array( |
| 60 | + ), |
| 61 | + 'dependencies' => array( |
| 62 | + 'ext.srf.jqplot', |
| 63 | + ), |
| 64 | + ); |
| 65 | + } |
| 66 | + |
| 67 | + protected function loadJavascriptAndCSS() { |
| 68 | + global $wgOut; |
| 69 | + $wgOut->addModules( 'ext.srf.jqplotpie' ); |
| 70 | + } |
| 71 | + |
| 72 | + protected function addJavascriptAndCSS() { |
| 73 | + if ( self::$m_piechartnum > 1 ) { |
| 74 | + return; |
| 75 | + } |
| 76 | + |
| 77 | + // MW 1.17 + |
| 78 | + if ( class_exists( 'ResourceLoader' ) ) { |
| 79 | + self::loadJavascriptAndCSS(); |
| 80 | + return; |
| 81 | + } |
| 82 | + global $wgOut, $srfgScriptPath; |
39 | 83 | global $smwgJQueryIncluded, $srfgJQPlotIncluded; |
40 | | - |
41 | | - $wgParser->disableCache(); |
42 | 84 | |
43 | 85 | if ( !$smwgJQueryIncluded ) { |
44 | 86 | if ( method_exists( 'OutputPage', 'includeJQuery' ) ) { |
— | — | @@ -54,12 +96,19 @@ |
55 | 97 | $wgOut->addScriptFile( "$srfgScriptPath/jqPlot/jquery.jqplot.min.js" ); |
56 | 98 | } |
57 | 99 | |
58 | | - if ( self::$m_piechartnum == 1 ) { |
59 | | - $wgOut->addScriptFile( "$srfgScriptPath/jqPlot/jqplot.pieRenderer.min.js" ); |
60 | | - } |
| 100 | + $wgOut->addScriptFile( "$srfgScriptPath/jqPlot/jqplot.pieRenderer.min.js" ); |
61 | 101 | |
62 | 102 | // CSS file |
63 | 103 | $wgOut->addExtensionStyle( "$srfgScriptPath/jqPlot/jquery.jqplot.css" ); |
| 104 | + } |
| 105 | + |
| 106 | + protected function getResultText( $res, $outputmode ) { |
| 107 | + global $wgOut, $wgParser; |
| 108 | + |
| 109 | + $wgParser->disableCache(); |
| 110 | + |
| 111 | + self::addJavascriptAndCSS(); |
| 112 | + |
64 | 113 | $this->isHTML = true; |
65 | 114 | |
66 | 115 | $t = ""; |
— | — | @@ -67,6 +116,7 @@ |
68 | 117 | // print all result rows |
69 | 118 | while ( $row = $res->getNext() ) { |
70 | 119 | $name = $row[0]->getNextObject()->getShortWikiText(); |
| 120 | + $name = str_replace( "'", "\'", $name ); |
71 | 121 | foreach ( $row as $field ) { |
72 | 122 | while ( ( $object = $field->getNextObject() ) !== false ) { |
73 | 123 | if ( $object->isNumeric() ) { // use numeric sortkey |
— | — | @@ -75,12 +125,12 @@ |
76 | 126 | } else { |
77 | 127 | $nr = $object->getNumericValue(); |
78 | 128 | } |
79 | | - $jqplot_data[] .= "['$name', $nr]"; |
| 129 | + $pie_data[] .= "['$name', $nr]"; |
80 | 130 | } |
81 | 131 | } |
82 | 132 | } |
83 | 133 | } |
84 | | - $jqplot_data_str = "[[" . implode( ', ', $jqplot_data ) . "]]"; |
| 134 | + $pie_data_str = "[[" . implode( ', ', $pie_data ) . "]]"; |
85 | 135 | $pieID = 'pie' . self::$m_piechartnum; |
86 | 136 | self::$m_piechartnum++; |
87 | 137 | |
— | — | @@ -89,7 +139,7 @@ |
90 | 140 | jQuery.noConflict(); |
91 | 141 | jQuery(document).ready(function(){ |
92 | 142 | jQuery.jqplot.config.enablePlugins = true; |
93 | | - plot1 = jQuery.jqplot('$pieID', $jqplot_data_str, { |
| 143 | + plot1 = jQuery.jqplot('$pieID', $pie_data_str, { |
94 | 144 | title: '$this->m_charttitle', |
95 | 145 | seriesDefaults: { |
96 | 146 | renderer: jQuery.jqplot.PieRenderer, |
— | — | @@ -101,9 +151,8 @@ |
102 | 152 | }); |
103 | 153 | }); |
104 | 154 | </script> |
105 | | - |
106 | 155 | END; |
107 | | - $wgOut->addScript($js_pie); |
| 156 | + $wgOut->addScript( $js_pie ); |
108 | 157 | |
109 | 158 | $text =<<<END |
110 | 159 | <div id="$pieID" style="margin-top: 20px; margin-left: 20px; width: {$this->m_width}px; height: {$this->m_height}px;"></div> |
Index: trunk/extensions/SemanticResultFormats/jqPlot/SRF_jqPlotBar.php |
— | — | @@ -52,13 +52,59 @@ |
53 | 53 | return wfMsg( 'srf_printername_jqplotbar' ); |
54 | 54 | } |
55 | 55 | |
56 | | - protected function getResultText( $res, $outputmode ) { |
57 | | - global $smwgIQRunningNumber, $wgOut, $srfgScriptPath; |
58 | | - global $srfgJQPlotIncluded, $smwgJQueryIncluded; |
59 | | - global $wgParser; |
60 | | - $wgParser->disableCache(); |
| 56 | + public static function registerResourceModules() { |
| 57 | + global $wgResourceModules, $srfgIP; |
61 | 58 | |
62 | | - //adding scripts - this code may be moved to some other location |
| 59 | + $resourceTemplate = array( |
| 60 | + 'localBasePath' => $srfgIP . '/jqPlot', |
| 61 | + 'remoteExtPath' => 'SemanticResultFormats' |
| 62 | + ); |
| 63 | + $wgResourceModules['ext.srf.jqplot'] = $resourceTemplate + array( |
| 64 | + 'scripts' => array( |
| 65 | + 'jquery.jqplot.min.js', |
| 66 | + ), |
| 67 | + 'styles' => array( |
| 68 | + 'jquery.jqplot.css', |
| 69 | + ), |
| 70 | + 'dependencies' => array( |
| 71 | + 'jquery', |
| 72 | + ), |
| 73 | + ); |
| 74 | + $wgResourceModules['ext.srf.jqplotbar'] = $resourceTemplate + array( |
| 75 | + 'scripts' => array( |
| 76 | + 'jqplot.categoryAxisRenderer.min.js', |
| 77 | + 'jqplot.barRenderer.min.js', |
| 78 | + 'jqplot.canvasAxisTickRenderer.min.js', |
| 79 | + 'jqplot.canvasTextRenderer.min.js', |
| 80 | + ), |
| 81 | + 'styles' => array( |
| 82 | + ), |
| 83 | + 'dependencies' => array( |
| 84 | + 'ext.srf.jqplot', |
| 85 | + ), |
| 86 | + ); |
| 87 | + } |
| 88 | + |
| 89 | + protected function loadJavascriptAndCSS() { |
| 90 | + global $wgOut; |
| 91 | + $wgOut->addModules( 'ext.srf.jqplot' ); |
| 92 | + $wgOut->addModules( 'ext.srf.jqplotbar' ); |
| 93 | + } |
| 94 | + |
| 95 | + static public function addJavascriptAndCSS() { |
| 96 | + if ( self::$m_barchartnum > 1 ) { |
| 97 | + return; |
| 98 | + } |
| 99 | + |
| 100 | + // MW 1.17 + |
| 101 | + if ( class_exists( 'ResourceLoader' ) ) { |
| 102 | + self::loadJavascriptAndCSS(); |
| 103 | + return; |
| 104 | + } |
| 105 | + |
| 106 | + global $wgOut, $smwgJQueryIncluded, $srfgJQPlotIncluded; |
| 107 | + global $srfgScriptPath; |
| 108 | + |
63 | 109 | $scripts = array(); |
64 | 110 | if ( !$smwgJQueryIncluded ) { |
65 | 111 | if ( method_exists( 'OutputPage', 'includeJQuery' ) ) { |
— | — | @@ -75,12 +121,10 @@ |
76 | 122 | $srfgJQPlotIncluded = true; |
77 | 123 | } |
78 | 124 | |
79 | | - if ( self::$m_barchartnum == 1 ) { |
80 | | - $scripts[] = "$srfgScriptPath/jqPlot/jqplot.categoryAxisRenderer.min.js"; |
81 | | - $scripts[] = "$srfgScriptPath/jqPlot/jqplot.barRenderer.min.js"; |
82 | | - $scripts[] = "$srfgScriptPath/jqPlot/jqplot.canvasAxisTickRenderer.min.js"; |
83 | | - $scripts[] = "$srfgScriptPath/jqPlot/jqplot.canvasTextRenderer.min.js"; |
84 | | - } |
| 125 | + $scripts[] = "$srfgScriptPath/jqPlot/jqplot.categoryAxisRenderer.min.js"; |
| 126 | + $scripts[] = "$srfgScriptPath/jqPlot/jqplot.barRenderer.min.js"; |
| 127 | + $scripts[] = "$srfgScriptPath/jqPlot/jqplot.canvasAxisTickRenderer.min.js"; |
| 128 | + $scripts[] = "$srfgScriptPath/jqPlot/jqplot.canvasTextRenderer.min.js"; |
85 | 129 | |
86 | 130 | foreach ( $scripts as $script ) { |
87 | 131 | $wgOut->addScriptFile( $script ); |
— | — | @@ -88,6 +132,15 @@ |
89 | 133 | |
90 | 134 | // CSS file |
91 | 135 | $wgOut->addExtensionStyle( "$srfgScriptPath/jqPlot/jquery.jqplot.css" ); |
| 136 | + } |
| 137 | + |
| 138 | + protected function getResultText( $res, $outputmode ) { |
| 139 | + global $wgOut, $wgParser; |
| 140 | + |
| 141 | + $wgParser->disableCache(); |
| 142 | + |
| 143 | + self::addJavascriptAndCSS(); |
| 144 | + |
92 | 145 | $this->isHTML = true; |
93 | 146 | |
94 | 147 | $numbers = array(); |
— | — | @@ -98,6 +151,7 @@ |
99 | 152 | $min_number = 0; |
100 | 153 | while ( $row = $res->getNext() ) { |
101 | 154 | $name = $row[0]->getNextObject()->getShortWikiText(); |
| 155 | + $name = str_replace( "'", "\'", $name ); |
102 | 156 | foreach ( $row as $field ) { |
103 | 157 | while ( ( $object = $field->getNextObject() ) !== false ) { |
104 | 158 | if ( $object->isNumeric() ) { // use numeric sortkey |
— | — | @@ -213,9 +267,8 @@ |
214 | 268 | }); |
215 | 269 | }); |
216 | 270 | </script> |
217 | | - |
218 | 271 | END; |
219 | | - $wgOut->addScript($js_bar); |
| 272 | + $wgOut->addScript( $js_bar ); |
220 | 273 | $text =<<<END |
221 | 274 | <div id="$barID" style="margin-top: 20px; margin-left: 20px; width: {$this->m_width}px; height: {$this->m_height}px;"></div> |
222 | 275 | |