Index: trunk/extensions/SemanticResultFormats/Ploticus/SRF_Ploticus.php |
— | — | @@ -34,6 +34,8 @@ |
35 | 35 | protected $m_drawdumpoutput = ''; |
36 | 36 | protected $m_tblwidth = ''; |
37 | 37 | protected $m_tblheight = ''; |
| 38 | + protected $m_width = ''; |
| 39 | + protected $m_height = ''; |
38 | 40 | protected $m_params = array(); |
39 | 41 | |
40 | 42 | protected function readParameters($params, $outputmode) { |
— | — | @@ -86,6 +88,12 @@ |
87 | 89 | if (array_key_exists('tblheight', $this->m_params)) { |
88 | 90 | $this->m_tblheight = trim($params['tblheight']); |
89 | 91 | } |
| 92 | + if (array_key_exists('width', $this->m_params)) { |
| 93 | + $this->m_width = trim($params['width']); |
| 94 | + } |
| 95 | + if (array_key_exists('height', $this->m_params)) { |
| 96 | + $this->m_height = trim($params['height']); |
| 97 | + } |
90 | 98 | } |
91 | 99 | |
92 | 100 | protected function getResultText($res, $outputmode) { |
— | — | @@ -108,7 +116,8 @@ |
109 | 117 | if (!in_array($this->m_imageformat, $validformats)) |
110 | 118 | return ("<p><strong>ERROR: $this->m_imageformat is not a supported format. Valid values are: svg, svg, swf, png, gif, jpeg, drawdump, drawdumpa, eps, ps</strong></p>"); |
111 | 119 | |
112 | | - // remove potentially dangerous keywords (prefab mode) or ploticus directives (script mode); |
| 120 | + // remove potentially dangerous keywords (prefab mode) or ploticus directives (script mode) |
| 121 | + // this is an extended check, JUST IN CASE, even though we're invoking ploticus with the noshell security parameter |
113 | 122 | if ($this->m_ploticusmode === 'prefab') { |
114 | 123 | // we also remove line endings for prefab - this is done for readability so the user can specify the prefab |
115 | 124 | // params over several lines rather than one long command line |
— | — | @@ -169,6 +178,7 @@ |
170 | 179 | $graphFile = $ploticusDir . $hashname . '.' . $this->m_imageformat; |
171 | 180 | $graphURL = $wgUploadPath . '/ploticus/' . $hashname . '.' . $this->m_imageformat; |
172 | 181 | $errorFile = $ploticusDir . $hashname . '.err'; |
| 182 | + $errorURL = $wgUploadPath . '/ploticus/' . $hashname . '.err'; |
173 | 183 | $mapFile = $ploticusDir . $hashname . '.map'; |
174 | 184 | $mapURL = $wgUploadPath . '/ploticus/' . $hashname . '.map'; |
175 | 185 | $scriptFile = $ploticusDir . $hashname . '.plo'; |
— | — | @@ -201,9 +211,9 @@ |
202 | 212 | $commandline = empty($srfgEnvSettings) ? ' ' : $srfgEnvSettings . ' '; |
203 | 213 | |
204 | 214 | if ($this->m_ploticusmode === 'script') { |
205 | | - // Script mode. Search for special strings in ploticusparam |
| 215 | + // Script mode. Search for special keywords in ploticusparam |
206 | 216 | // and replace it with actual values. (case-sensitive) |
207 | | - // The special strings currently are: %DATAFILE.CSV%, %WORKINGDIR% |
| 217 | + // The special keywords currently are: %DATAFILE.CSV%, %WORKINGDIR% |
208 | 218 | $replaces = array('%DATAFILE.CSV%' => wfEscapeShellArg($dataFile), |
209 | 219 | '%WORKINGDIR%' => $ploticusDir); |
210 | 220 | $literal_ploticusparams = strtr($sanitized_ploticusparams, $replaces); |
— | — | @@ -212,14 +222,16 @@ |
213 | 223 | fclose($fhandle); |
214 | 224 | |
215 | 225 | $commandline .= wfEscapeShellArg($srfgPloticusPath) . |
216 | | - ' -' . $this->m_imageformat . |
| 226 | + ($this->m_debug ? ' -debug':' ') . |
| 227 | + ' -noshell -' . $this->m_imageformat . |
217 | 228 | ' -o ' . wfEscapeShellArg($graphFile) . |
218 | 229 | ' ' . $scriptFile; |
219 | 230 | |
220 | 231 | } else { |
221 | 232 | // prefab mode, build the command line accordingly |
222 | 233 | $commandline .= wfEscapeShellArg($srfgPloticusPath) . |
223 | | - ' ' . $sanitized_ploticusparams . |
| 234 | + ($this->m_debug ? ' -debug':' ') . |
| 235 | + ' -noshell ' . $sanitized_ploticusparams . |
224 | 236 | ' data=' . wfEscapeShellArg($dataFile) . |
225 | 237 | ' -' . $this->m_imageformat; |
226 | 238 | |
— | — | @@ -241,7 +253,8 @@ |
242 | 254 | // Execute ploticus. |
243 | 255 | wfShellExec($commandline); |
244 | 256 | $errorData = file_get_contents($errorFile); |
245 | | - @unlink($errorFile); |
| 257 | + if (!$this->m_debug) |
| 258 | + @unlink($errorFile); |
246 | 259 | |
247 | 260 | $graphLastGenerated = time(); // faster than doing filemtime |
248 | 261 | |
— | — | @@ -260,25 +273,34 @@ |
261 | 274 | (empty($this->m_tblwidth) ? ' ' : ' width="'. $this->m_tblwidth . '" ') . |
262 | 275 | (empty($this->m_tblheight) ? ' ' : ' height="'. $this->m_tblheight . '" ') . |
263 | 276 | '><tr>'; |
264 | | - if (!empty($errorData)) { |
265 | | - // there was an error |
| 277 | + if (!empty($errorData) && !$this->m_debug) { |
| 278 | + // there was an error. We do the not debug check since ploticus by default sends the debug trace to stderr too |
| 279 | + // so when debug is on, having a non-empty errorData does not necessarily indicate an error. |
266 | 280 | $rtnstr .= '<th colspan="3"><strong>Error processing ploticus data:</strong></th></tr><tr><td colspan="3" align="center">' . |
267 | 281 | $errorData . '</td></tr>'; |
268 | | - } |
269 | | - else { |
| 282 | + } else { |
270 | 283 | $rtnstr .= '<td colspan="3" align="center">'; |
271 | 284 | switch ($this->m_imageformat) { |
272 | 285 | case 'svg': |
273 | 286 | case 'svgz': |
274 | | - // TODO: fix generated clickmap URLs to use _ instead of + for embedded spaces |
275 | | - // TODO: either patch ploticus or do regex (kinda expensive though on SVG XML files) |
276 | | - $rtnstr .= '<object data="' . $graphURL . |
277 | | - '" type="image/svg+xml">Requires SVG-capable browser</object>'; |
| 287 | + // note that if clickmaps are specified, Ploticus will use + instead of _ |
| 288 | + // for embedded spaces in target URLs which won't work in SMW. |
| 289 | + // A patch has been submitted to Steve Grubb (Ploticus creator) |
| 290 | + // that introduces the encodeclickmapurls parameter to fix this. |
| 291 | + $rtnstr .= '<object data="' . $graphURL . '"' . |
| 292 | + (empty($this->m_width)? ' ' : ' width="'. $this->m_width . '" ') . |
| 293 | + (empty($this->m_height)? ' ' : ' height="'. $this->m_height . '" ') . |
| 294 | + 'type="image/svg+xml"><param name="src" value="' . $graphURL . |
| 295 | + '"> alt : <a href="'. $graphURL . '">'. $this->m_alttext . ' - ' . |
| 296 | + 'Requires SVG capable browser</a></object>'; |
278 | 297 | break; |
279 | 298 | case 'swf': |
280 | | - $rtnstr .= '<embed src="' . $graphURL . |
281 | | - '" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"' . |
282 | | - 'type="application/x-shockwave-flash"></embed>'; |
| 299 | + $rtnstr .= '<object type="application/x-shockwave-flash" data="' . $graphURL . '"' . |
| 300 | + (empty($this->m_width)? ' ' : ' width="'. $this->m_width . '" ') . |
| 301 | + (empty($this->m_height)? ' ' : ' height="'. $this->m_height . '" ') . |
| 302 | + '<param name="movie" value="' . $graphURL . |
| 303 | + '"><param name="loop" value="false"><param name="SCALE" value="noborder"> alt : <a href="'. $graphURL . |
| 304 | + '">' . $this->m_alttext . ' - ' . 'Requires Adobe Flash plugin</a></object>'; |
283 | 305 | break; |
284 | 306 | case 'png': |
285 | 307 | case 'gif': |
— | — | @@ -287,19 +309,22 @@ |
288 | 310 | if (strpos($sanitized_ploticusparams, 'clickmap')) { |
289 | 311 | $mapData = file_get_contents($mapFile); |
290 | 312 | // we replace + with _ since ploticus uses + to represent spaces which mediawiki does not understand |
| 313 | + // this is only required if you're using an unpatched copy of Ploticus (see SVG note above) |
| 314 | + // we're still leaving the str_replace in if SRF-Ploticus cannot get the encodeclickmapurls patch. |
291 | 315 | $mapData = str_replace("+","_",$mapData); |
292 | 316 | $rtnstr .= '<map name="'. $orighash . '">'. $mapData . |
293 | 317 | '</map><img src="' . $graphURL . '" border="0" usemap="#' . $orighash . '">'; |
294 | 318 | } else { |
295 | | - $rtnstr .= '<img src="' . $graphURL . '" alt="' . $this->alttext .'">'; |
| 319 | + $rtnstr .= '<img src="' . $graphURL . '" alt="' . $this->m_alttext .'">'; |
296 | 320 | } |
297 | 321 | break; |
298 | 322 | case 'eps': |
299 | 323 | case 'ps': |
300 | | - // encapsulated postscript/postscript are not viewable on browsers |
301 | | - // just display a link |
302 | | - $rtnstr .= 'Download '. strtoupper($this->m_imageformat) . ' file.'; |
303 | | - |
| 324 | + $rtnstr .= '<object type="application/postscript" data="' . $graphURL . '"' . |
| 325 | + (empty($this->m_width)? ' ' : ' width="'. $this->m_width . '" ') . |
| 326 | + (empty($this->m_height)? ' ' : ' height="'. $this->m_height . '" ') . |
| 327 | + ' alt : <a href="'. $graphURL . '">' . $this->m_alttext . ' - ' . |
| 328 | + 'Requires PDF-capable browser</a></object>'; |
304 | 329 | } |
305 | 330 | $rtnstr .= '</td></tr>'; |
306 | 331 | } |
— | — | @@ -346,9 +371,11 @@ |
347 | 372 | if ($this->m_debug) { |
348 | 373 | if ($this->m_ploticusmode == 'script') { |
349 | 374 | $rtnstr .= '<tr><td align="center" colspan="3"><strong>DEBUG: <a href="' . |
350 | | - $scriptURL . '" target="_blank">SCRIPT</a></strong></td></tr>'; |
| 375 | + $scriptURL . '" target="_blank">SCRIPT</a> (<a href="'. |
| 376 | + $errorURL . '" target="_blank">Ploticus Trace</a>)</strong></td></tr>'; |
351 | 377 | } else { |
352 | | - $rtnstr .= '<tr><td align="center" colspan="3"><strong>DEBUG: PREFAB</strong></td></tr><tr><td colspan="3">' . |
| 378 | + $rtnstr .= '<tr><td align="center" colspan="3"><strong>DEBUG: PREFAB (<a href="' . |
| 379 | + $errorURL .'" target="_blank">Ploticus Trace</a>)</strong></td></tr><tr><td colspan="3">' . |
353 | 380 | $commandline . '</td></tr>'; |
354 | 381 | } |
355 | 382 | } |
Index: trunk/extensions/SemanticResultFormats/Ploticus/README |
— | — | @@ -1,3 +1,4 @@ |
| 2 | +== Overview == |
2 | 3 | SRF-Ploticus is a query printer for Semantic MediaWiki that uses |
3 | 4 | Ploticus to create plots, charts and graphics out of query results. |
4 | 5 | |
— | — | @@ -20,7 +21,7 @@ |
21 | 22 | GDFONTPATH=/usr/share/fonts/truetype/freefont:/usr/share/fonts/truetype/msttcorefonts |
22 | 23 | |
23 | 24 | E.g. if you plan to use additional fonts in SWF files |
24 | | - SWF_FONTS_DIR=/usr/share/ming/fonts/ttf-dejavu/fdb/ |
| 25 | + SWF_FONTS_DIR=/usr/share/ming/fonts/ttf-dejavu/fdb |
25 | 26 | |
26 | 27 | E.g. set global ploticus config parameters with a config file. See http://ploticus.sourceforge.net/doc/config.html for details. |
27 | 28 | PLOTICUS_CONFIG=/etc/ploticus/ploticus.conf |
— | — | @@ -50,6 +51,7 @@ |
51 | 52 | (see http://www.mediawiki.org/wiki/Manual:$wgUploadPath) |
52 | 53 | |
53 | 54 | == Configuration and Usage == |
| 55 | + |
54 | 56 | The SRF-ploticus Result Format has the following parameters: |
55 | 57 | |
56 | 58 | * ploticusmode (enum/optional) |
— | — | @@ -63,7 +65,7 @@ |
64 | 66 | can and should be used in script mode. Otherwise, the ploticus script parser will fail. |
65 | 67 | |
66 | 68 | * imageformat (enum/optional) |
67 | | - - png (default), gif, jpeg, svg, svgz, swf, eps, ps, drawdump, drawdumpa (drawdump add). |
| 69 | + - png (default), gif, jpeg, svg, svgz, swf, eps, ps, drawdump, drawdumpa (drawdump append). |
68 | 70 | Availability of format depends on how ploticus is built. When using svgz, make sure Apache |
69 | 71 | is configured properly, i.e. you have the svgz mime-type and svgz encoding. |
70 | 72 | AddType image/svg+xml svg svgz |
— | — | @@ -79,6 +81,7 @@ |
80 | 82 | |
81 | 83 | * debug (bool/optional) |
82 | 84 | - 0 (default). When 1, displays ploticus prefab cmdline or script used to generate plot. |
| 85 | + It also invokes ploticus itself in debug mode and creates a link to the debug file. |
83 | 86 | Also turns showcsv on and bypasses the ploticus "cache". |
84 | 87 | |
85 | 88 | * liveupdating (bool/optional) |
— | — | @@ -101,15 +104,23 @@ |
102 | 105 | * showimagelink (bool/optional) |
103 | 106 | - 0 (default). Shows a link to open the plot image in a separate window. |
104 | 107 | Especially useful for SVG and SWF file formats since they are scalable formats. |
| 108 | + |
| 109 | + * width (string/optional) |
| 110 | + - sets the width of the plot proper in pixel/percent units (e.g. 100, 80%). |
| 111 | + This is especially useful for vector formats (SWF, SVG, EPS, PS) |
105 | 112 | |
| 113 | + * height (string/optional) |
| 114 | + - sets the height of the plot proper in pixel/percent units. |
| 115 | + This is especially useful for vector formats (SWF, SVG, EPS, PS) |
| 116 | + |
106 | 117 | * tblwidth (string/optional) |
107 | | - - sets the width of SRF-Ploticus result HTML table. Can be set to pixel/percent units (e.g. 100px, 80%). |
| 118 | + - sets the width of SRF-Ploticus result HTML table (which contains the plot) in pixel/percent units. |
108 | 119 | If not set, the table will fit the width of the generated plot. For vector formats (svg, svgz, swf), |
109 | | - you may want to set this to "100%" |
| 120 | + you may want to set this to "100%". |
110 | 121 | |
111 | 122 | * tblheight (string/optional) |
112 | | - - sets the height of the SRF-Ploticus result HTML table. Normally left unset. |
113 | | - Remember that this is for the entire HTML table, which may include additional rows (action buttons/debug info) |
| 123 | + - sets the height of the SRF-Ploticus result HTML table in pixel/percent units. Normally left unset. |
| 124 | + Remember that this is for the ENTIRE HTML table, which may include additional rows (action buttons/debug info) |
114 | 125 | and not just for the plot image. |
115 | 126 | |
116 | 127 | * drawdumpoutput (string/optional) |
— | — | @@ -122,10 +133,11 @@ |
123 | 134 | In prefab mode, ploticusparams expects commandline parameters that one would normally use when |
124 | 135 | invoking stand-alone ploticus in prefab mode. |
125 | 136 | |
126 | | -However, the following prefab commandline parameters should NOT be specified: |
| 137 | +However, the following Ploticus commandline prefab parameters should NOT be specified: |
127 | 138 | * data - automatically generated by the extension |
128 | 139 | * output - automatically generated by the extension |
129 | 140 | * format (e.g. -png, -gif, etc.) - use the SRF-ploticus imageformat parameter. |
| 141 | + * debug - use the SRF-Ploticus debug parameter instead |
130 | 142 | |
131 | 143 | SCRIPT MODE |
132 | 144 | =========== |
— | — | @@ -161,7 +173,7 @@ |
162 | 174 | ploticusparams= -prefab scat "rectangle= 1 1 3 3" .... |
163 | 175 | ... |
164 | 176 | |
165 | | - - subsequent queries should use the drawdumpa (drawdump add) imageformat, making sure to use the |
| 177 | + - subsequent queries should use the drawdumpa (drawdump append) imageformat, making sure to use the |
166 | 178 | SAME drawdumpoutput SRF-Ploticus parameter as the first query. |
167 | 179 | |
168 | 180 | ... |
— | — | @@ -184,13 +196,24 @@ |
185 | 197 | |
186 | 198 | Imagemaps: |
187 | 199 | ========= |
188 | | -Client-side imagemaps are automatically generated by SRF-Ploticus if it detects the clickmap directive in |
189 | | -either prefab and script mode. |
190 | | -Typically, Imagemaps "links/labels" should be set to resolve to "Article URL/Article Name". |
191 | | -Note that imagemaps are only valid for the imageformats PNG, GIF and JPEG. |
| 200 | +Client-side imagemaps are automatically generated by SRF-Ploticus if it detects the clickmap directive. |
192 | 201 | |
| 202 | +Typically, imagemaps "links/labels" should be set to resolve to "Article URL/Article Name". |
| 203 | +Note that imagemaps are only valid for PNG, GIF, JPEG and SVG. |
193 | 204 | |
| 205 | +However, Ploticus 2.40 currently uses plus signs (+) instead of underscores (_) when generating |
| 206 | +clickmap URL targets. This won't work in SMW. |
194 | 207 | |
| 208 | +A patch has been submitted to Steve Grubb (Ploticus creator) to change this behavior. |
| 209 | +(http://tech.groups.yahoo.com/group/ploticus/message/2166) |
| 210 | + |
| 211 | +At the moment, SRF-Ploticus corrects the clickmap URL targets for PNG, GIF and JPEG raster formats, swapping out the + for _. |
| 212 | +SVG clickmaps will require the patch to work properly. |
| 213 | + |
| 214 | +Once the patch is applied, a new PLOTICUS_CONFIG parameter is now available - encodeclickmapurls. This should be set to |
| 215 | +yes in the PLOTICUS_CONFIG file (e.g. encodeclickmapurls: yes). See http://ploticus.sourceforge.net/doc/config.html. |
| 216 | + |
| 217 | + |
195 | 218 | CREDITS: |
196 | 219 | ======= |
197 | 220 | SRF-Ploticus is only possible because of all the great work done |