r46879 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46878‎ | r46879 | r46880 >
Date:23:10, 5 February 2009
Author:jnatividad
Status:deferred
Tags:
Comment:
implemented bug 17356 enhancement (expose ploticus debug trace); fixed bug 17372 (make generated HTML snippets for various image formats cross-browser friendly); added width, height parameters so user can specify plot size (most useful for vector formats - SVG, SWF, EPS, PS); expanded README
Modified paths:
  • /trunk/extensions/SemanticResultFormats/Ploticus/README (modified) (history)
  • /trunk/extensions/SemanticResultFormats/Ploticus/SRF_Ploticus.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/Ploticus/SRF_Ploticus.php
@@ -34,6 +34,8 @@
3535 protected $m_drawdumpoutput = '';
3636 protected $m_tblwidth = '';
3737 protected $m_tblheight = '';
 38+ protected $m_width = '';
 39+ protected $m_height = '';
3840 protected $m_params = array();
3941
4042 protected function readParameters($params, $outputmode) {
@@ -86,6 +88,12 @@
8789 if (array_key_exists('tblheight', $this->m_params)) {
8890 $this->m_tblheight = trim($params['tblheight']);
8991 }
 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+ }
9098 }
9199
92100 protected function getResultText($res, $outputmode) {
@@ -108,7 +116,8 @@
109117 if (!in_array($this->m_imageformat, $validformats))
110118 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>");
111119
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
113122 if ($this->m_ploticusmode === 'prefab') {
114123 // we also remove line endings for prefab - this is done for readability so the user can specify the prefab
115124 // params over several lines rather than one long command line
@@ -169,6 +178,7 @@
170179 $graphFile = $ploticusDir . $hashname . '.' . $this->m_imageformat;
171180 $graphURL = $wgUploadPath . '/ploticus/' . $hashname . '.' . $this->m_imageformat;
172181 $errorFile = $ploticusDir . $hashname . '.err';
 182+ $errorURL = $wgUploadPath . '/ploticus/' . $hashname . '.err';
173183 $mapFile = $ploticusDir . $hashname . '.map';
174184 $mapURL = $wgUploadPath . '/ploticus/' . $hashname . '.map';
175185 $scriptFile = $ploticusDir . $hashname . '.plo';
@@ -201,9 +211,9 @@
202212 $commandline = empty($srfgEnvSettings) ? ' ' : $srfgEnvSettings . ' ';
203213
204214 if ($this->m_ploticusmode === 'script') {
205 - // Script mode. Search for special strings in ploticusparam
 215+ // Script mode. Search for special keywords in ploticusparam
206216 // 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%
208218 $replaces = array('%DATAFILE.CSV%' => wfEscapeShellArg($dataFile),
209219 '%WORKINGDIR%' => $ploticusDir);
210220 $literal_ploticusparams = strtr($sanitized_ploticusparams, $replaces);
@@ -212,14 +222,16 @@
213223 fclose($fhandle);
214224
215225 $commandline .= wfEscapeShellArg($srfgPloticusPath) .
216 - ' -' . $this->m_imageformat .
 226+ ($this->m_debug ? ' -debug':' ') .
 227+ ' -noshell -' . $this->m_imageformat .
217228 ' -o ' . wfEscapeShellArg($graphFile) .
218229 ' ' . $scriptFile;
219230
220231 } else {
221232 // prefab mode, build the command line accordingly
222233 $commandline .= wfEscapeShellArg($srfgPloticusPath) .
223 - ' ' . $sanitized_ploticusparams .
 234+ ($this->m_debug ? ' -debug':' ') .
 235+ ' -noshell ' . $sanitized_ploticusparams .
224236 ' data=' . wfEscapeShellArg($dataFile) .
225237 ' -' . $this->m_imageformat;
226238
@@ -241,7 +253,8 @@
242254 // Execute ploticus.
243255 wfShellExec($commandline);
244256 $errorData = file_get_contents($errorFile);
245 - @unlink($errorFile);
 257+ if (!$this->m_debug)
 258+ @unlink($errorFile);
246259
247260 $graphLastGenerated = time(); // faster than doing filemtime
248261
@@ -260,25 +273,34 @@
261274 (empty($this->m_tblwidth) ? ' ' : ' width="'. $this->m_tblwidth . '" ') .
262275 (empty($this->m_tblheight) ? ' ' : ' height="'. $this->m_tblheight . '" ') .
263276 '><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.
266280 $rtnstr .= '<th colspan="3"><strong>Error processing ploticus data:</strong></th></tr><tr><td colspan="3" align="center">' .
267281 $errorData . '</td></tr>';
268 - }
269 - else {
 282+ } else {
270283 $rtnstr .= '<td colspan="3" align="center">';
271284 switch ($this->m_imageformat) {
272285 case 'svg':
273286 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>';
278297 break;
279298 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>';
283305 break;
284306 case 'png':
285307 case 'gif':
@@ -287,19 +309,22 @@
288310 if (strpos($sanitized_ploticusparams, 'clickmap')) {
289311 $mapData = file_get_contents($mapFile);
290312 // 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.
291315 $mapData = str_replace("+","_",$mapData);
292316 $rtnstr .= '<map name="'. $orighash . '">'. $mapData .
293317 '</map><img src="' . $graphURL . '" border="0" usemap="#' . $orighash . '">';
294318 } else {
295 - $rtnstr .= '<img src="' . $graphURL . '" alt="' . $this->alttext .'">';
 319+ $rtnstr .= '<img src="' . $graphURL . '" alt="' . $this->m_alttext .'">';
296320 }
297321 break;
298322 case 'eps':
299323 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>';
304329 }
305330 $rtnstr .= '</td></tr>';
306331 }
@@ -346,9 +371,11 @@
347372 if ($this->m_debug) {
348373 if ($this->m_ploticusmode == 'script') {
349374 $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>';
351377 } 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">' .
353380 $commandline . '</td></tr>';
354381 }
355382 }
Index: trunk/extensions/SemanticResultFormats/Ploticus/README
@@ -1,3 +1,4 @@
 2+== Overview ==
23 SRF-Ploticus is a query printer for Semantic MediaWiki that uses
34 Ploticus to create plots, charts and graphics out of query results.
45
@@ -20,7 +21,7 @@
2122 GDFONTPATH=/usr/share/fonts/truetype/freefont:/usr/share/fonts/truetype/msttcorefonts
2223
2324 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
2526
2627 E.g. set global ploticus config parameters with a config file. See http://ploticus.sourceforge.net/doc/config.html for details.
2728 PLOTICUS_CONFIG=/etc/ploticus/ploticus.conf
@@ -50,6 +51,7 @@
5152 (see http://www.mediawiki.org/wiki/Manual:$wgUploadPath)
5253
5354 == Configuration and Usage ==
 55+
5456 The SRF-ploticus Result Format has the following parameters:
5557
5658 * ploticusmode (enum/optional)
@@ -63,7 +65,7 @@
6466 can and should be used in script mode. Otherwise, the ploticus script parser will fail.
6567
6668 * 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).
6870 Availability of format depends on how ploticus is built. When using svgz, make sure Apache
6971 is configured properly, i.e. you have the svgz mime-type and svgz encoding.
7072 AddType image/svg+xml svg svgz
@@ -79,6 +81,7 @@
8082
8183 * debug (bool/optional)
8284 - 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.
8386 Also turns showcsv on and bypasses the ploticus "cache".
8487
8588 * liveupdating (bool/optional)
@@ -101,15 +104,23 @@
102105 * showimagelink (bool/optional)
103106 - 0 (default). Shows a link to open the plot image in a separate window.
104107 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)
105112
 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+
106117 * 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.
108119 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%".
110121
111122 * 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)
114125 and not just for the plot image.
115126
116127 * drawdumpoutput (string/optional)
@@ -122,10 +133,11 @@
123134 In prefab mode, ploticusparams expects commandline parameters that one would normally use when
124135 invoking stand-alone ploticus in prefab mode.
125136
126 -However, the following prefab commandline parameters should NOT be specified:
 137+However, the following Ploticus commandline prefab parameters should NOT be specified:
127138 * data - automatically generated by the extension
128139 * output - automatically generated by the extension
129140 * format (e.g. -png, -gif, etc.) - use the SRF-ploticus imageformat parameter.
 141+ * debug - use the SRF-Ploticus debug parameter instead
130142
131143 SCRIPT MODE
132144 ===========
@@ -161,7 +173,7 @@
162174 ploticusparams= -prefab scat "rectangle= 1 1 3 3" ....
163175 ...
164176
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
166178 SAME drawdumpoutput SRF-Ploticus parameter as the first query.
167179
168180 ...
@@ -184,13 +196,24 @@
185197
186198 Imagemaps:
187199 =========
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.
192201
 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.
193204
 205+However, Ploticus 2.40 currently uses plus signs (+) instead of underscores (_) when generating
 206+clickmap URL targets. This won't work in SMW.
194207
 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+
195218 CREDITS:
196219 =======
197220 SRF-Ploticus is only possible because of all the great work done

Status & tagging log