r48037 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48036‎ | r48037 | r48038 >
Date:22:53, 4 March 2009
Author:jnatividad
Status:deferred
Tags:
Comment:
retired alttext parameter, replaced with more sensible titletext; removed csv imageformat now that built-in csv result format can support large results (http://svn.wikimedia.org/viewvc/mediawiki?view=rev&revision=47994); expanded/cleaned-up code comments
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
@@ -22,7 +22,7 @@
2323 class SRFPloticus extends SMWResultPrinter {
2424 protected $m_ploticusparams = '';
2525 protected $m_imageformat = 'png';
26 - protected $m_alttext = 'Ploticus chart';
 26+ protected $m_titletext = '';
2727 protected $m_showcsv = false;
2828 protected $m_ploticusmode = 'prefab';
2929 protected $m_debug = false;
@@ -36,7 +36,7 @@
3737 protected $m_tblheight = '';
3838 protected $m_width = '';
3939 protected $m_height = '';
40 - protected $mShowHeaders = false; // override and make it false by default coz of current known overflow problem with Ploticus
 40+ protected $mShowHeaders = false; // make false by default coz of current known buffer overflow with legends in Ploticus 2.40
4141
4242 protected function readParameters($params, $outputmode) {
4343 SMWResultPrinter::readParameters($params, $outputmode);
@@ -46,8 +46,8 @@
4747 if (array_key_exists('imageformat', $this->m_params)) {
4848 $this->m_imageformat = strtolower(trim($params['imageformat']));
4949 }
50 - if (array_key_exists('alttext', $this->m_params)) {
51 - $this->m_alttext = trim($params['alttext']);
 50+ if (array_key_exists('titletext', $this->m_params)) {
 51+ $this->m_titletext = trim($params['titletext']);
5252 }
5353 if (array_key_exists('showcsv', $this->m_params)) {
5454 $tmpcmp = strtolower(trim($params['showcsv']));
@@ -110,22 +110,23 @@
111111 $this->outputmode = SMW_OUTPUT_HTML;
112112
113113 // check parameters
114 - $validformats = array('svg', 'svgz','swf', 'png', 'gif', 'jpeg', 'drawdump', 'drawdumpa', 'eps', 'ps', 'csv');
 114+ $validformats = array('svg', 'svgz','swf', 'png', 'gif', 'jpeg', 'drawdump', 'drawdumpa', 'eps', 'ps');
115115 if (!in_array($this->m_imageformat, $validformats))
116116 return ('<p classid="srfperror">ERROR: '. $this->m_imageformat. ' is not a supported imageformat.<br/>Valid imageformats are: ' .
117117 implode(', ', $validformats) . '</p>');
118118
119 - if($this->m_imageformat != 'csv' && empty($this->m_ploticusparams))
 119+ if (empty($this->m_ploticusparams))
120120 return ('<p classid="srfperror">ERROR: <em>ploticusparams</em> required.</p>');
121121
122 - if($this->m_imageformat != 'csv' && empty($srfgPloticusPath))
 122+ if (empty($srfgPloticusPath))
123123 return ('<p classid="srfperror">ERROR: Set $srfgPloticusPath in LocalSettings.php (e.g. $srfgPloticusPath=/usr/bin/pl).</p>');
124124
125125 if (!file_exists($srfgPloticusPath))
126126 return ('<p classid=""srfperror">ERROR: Could not find ploticus in <em>' . $srfgPloticusPath . '</em></p>');
127127
128 - if($this->m_ploticusmode !== 'script' && $this->m_ploticusmode !== 'prefab')
129 - return ('<p classid="srfperror">ERROR: Unknown mode specified (' . $this->m_ploticusmode. '). Only "prefab" (default) and "script" mode supported.</p>');
 128+ if ($this->m_ploticusmode !== 'script' && $this->m_ploticusmode !== 'prefab')
 129+ return ('<p classid="srfperror">ERROR: Unknown mode specified (' . $this->m_ploticusmode .
 130+ '). Only "prefab" (default) and "script" mode supported.</p>');
130131
131132 // remove potentially dangerous keywords (prefab mode) or ploticus directives (script mode)
132133 // this is an extended check, JUST IN CASE, even though we're invoking ploticus with the noshell security parameter
@@ -154,8 +155,9 @@
155156 $tmpFile = tempnam($ploticusDir, 'srf-');
156157 if (($fhandle = fopen($tmpFile, 'w')) === false )
157158 return ('<p class="srfperror">ERROR: Cannot create data file - ' . $tmpFile . '. Check permissions.</p>');
158 - // create the header row if asked - kludgy but works
 159+
159160 if ($this->mShowHeaders) {
 161+ // create the header row
160162 $header_row = array();
161163 foreach ($res->getPrintRequests() as $pr) {
162164 $headertext = $pr->getLabel();
@@ -184,8 +186,8 @@
185187 // we create a hash based on params
186188 // this is a great way to see if the params and/or the query result has changed
187189 $hashname = hash('md5', $wgArticle->mTitle . $smwgIQRunningNumber . implode(',',$this->m_params));
188 - if ($this->m_imageformat != 'csv' && $this->m_liveupdating) {
189 - // only include contents of result csv in hash when liveupdating is on and imageformat != csv
 190+ if ($this->m_liveupdating) {
 191+ // only include contents of result csv in hash when liveupdating is on
190192 // in this way, doing file_exists check against hash filename will fail when query result has changed
191193 $hashname .= hash_file('md5',$tmpFile);
192194 }
@@ -198,10 +200,7 @@
199201 @rename($tmpFile, $dataFile);
200202 $dataURL = $wgUploadPath . '/ploticus/' . $hashname . '.csv';
201203 $srficonPath = $wgScriptPath . '/extensions/SemanticResultFormats/Ploticus/icons/';
202 -
203 - if ($this->m_imageformat == 'csv')
204 - return ('<a href="' . $dataURL . '" title="CSV file"><img src="'. $srficonPath . 'csv_16.png" alt="CSV file"></a>');
205 -
 204+
206205 $graphFile = $ploticusDir . $hashname . '.' . $this->m_imageformat;
207206 $graphURL = $wgUploadPath . '/ploticus/' . $hashname . '.' . $this->m_imageformat;
208207 $errorFile = $ploticusDir . $hashname . '.err';
@@ -211,9 +210,9 @@
212211 $scriptFile = $ploticusDir . $hashname . '.plo';
213212 $scriptURL = $wgUploadPath . '/ploticus/' . $hashname . '.plo';
214213
215 - // get time graph was last generated. Also check to see if the
216 - // generated plot has expired per the updatefrequency and needs to be redrawn
217214 if (($this->m_updatefrequency > 0) && file_exists($graphFile)) {
 215+ // get time graph was last generated. Also check to see if the
 216+ // generated plot has expired per the updatefrequency and needs to be redrawn
218217 $graphLastGenerated = filemtime($graphFile);
219218 $expireTime = $graphLastGenerated + $this->m_updatefrequency;
220219 if ( $expireTime < time()) {
@@ -302,15 +301,15 @@
303302 case 'svg':
304303 case 'svgz':
305304 // note that if clickmaps are specified, Ploticus will use + instead of _
306 - // for embedded spaces in target URLs which won't work in SMW.
 305+ // for embedded spaces in target URLs in the SVG XML Xlink elements which won't work in SMW.
307306 // A patch has been submitted to Steve Grubb (Ploticus creator)
308 - // that introduces the encodeclickmapurls parameter to fix this.
 307+ // that introduces the encodeclickmapurls parameter to fix this.
 308+ // The patch is also available in the add-ons directory.
309309 $rtnstr .= '<object data="' . $graphURL . '"' .
310310 (empty($this->m_width)? ' ' : ' width="'. $this->m_width . '" ') .
311311 (empty($this->m_height)? ' ' : ' height="'. $this->m_height . '" ') .
312312 'type="image/svg+xml"><param name="src" value="' . $graphURL .
313 - '"> alt : <a href="'. $graphURL . '">'. $this->m_alttext . ' - ' .
314 - 'Requires SVG capable browser</a></object>';
 313+ '"> alt : <a href="'. $graphURL . '">Requires SVG capable browser</a></object>';
315314 break;
316315 case 'swf':
317316 $rtnstr .= '<object type="application/x-shockwave-flash" data="' . $graphURL . '"' .
@@ -318,22 +317,23 @@
319318 (empty($this->m_height)? ' ' : ' height="'. $this->m_height . '" ') .
320319 '<param name="movie" value="' . $graphURL .
321320 '"><param name="loop" value="false"><param name="SCALE" value="noborder"> alt : <a href="'. $graphURL .
322 - '">' . $this->m_alttext . ' - ' . 'Requires Adobe Flash plugin</a></object>';
 321+ '">Requires Adobe Flash plugin</a></object>';
323322 break;
324323 case 'png':
325324 case 'gif':
326325 case 'jpeg':
327 - // we are using clickmaps, create HTML snippet to enable client-side imagemaps
328326 if (strpos($sanitized_ploticusparams, 'clickmap')) {
 327+ // we are using clickmaps, create HTML snippet to enable client-side imagemaps
329328 $mapData = file_get_contents($mapFile);
330329 // we replace + with _ since ploticus uses + to represent spaces which mediawiki does not understand
331330 // this is only required if you're using an unpatched copy of Ploticus (see SVG note above)
332 - // we're still leaving the str_replace in if SRF-Ploticus cannot get the encodeclickmapurls patch.
 331+ // regardless, we're still leaving the str_replace in place just in case the
 332+ // Ploticus encodeclickmapurls patch wasn't applied.
333333 $mapData = str_replace("+","_",$mapData);
334334 $rtnstr .= '<map name="'. $orighash . '">'. $mapData .
335335 '</map><img src="' . $graphURL . '" border="0" usemap="#' . $orighash . '">';
336336 } else {
337 - $rtnstr .= '<img src="' . $graphURL . '" alt="' . $this->m_alttext .'">';
 337+ $rtnstr .= '<img src="' . $graphURL . '" alt="' . $this->m_titletext .'" title="' . $this->m_titletext . '">';
338338 }
339339 break;
340340 case 'eps':
@@ -341,8 +341,7 @@
342342 $rtnstr .= '<object type="application/postscript" data="' . $graphURL . '"' .
343343 (empty($this->m_width)? ' ' : ' width="'. $this->m_width . '" ') .
344344 (empty($this->m_height)? ' ' : ' height="'. $this->m_height . '" ') .
345 - ' alt : <a href="'. $graphURL . '">' . $this->m_alttext . ' - ' .
346 - 'Requires PDF-capable browser</a></object>';
 345+ ' alt : <a href="'. $graphURL . '">Requires PDF-capable browser</a></object>';
347346 }
348347 $rtnstr .= '</td></tr>';
349348 }
@@ -371,10 +370,9 @@
372371 }
373372
374373 // INFOROW - col 2
375 - // we don't display anything here for now - perhaps we can show query name in the future
376 - $rtnstr .= '</td><td class="srfptitle" width="33%" colspan="1" align="center">';
 374+ // show titletext
 375+ $rtnstr .= '</td><td class="srfptitle" width="33%" colspan="1" align="center">' . $this->m_titletext;
377376
378 -
379377 // INFOROW - TIMESTAMP - col 3
380378 // if showtimestamp is on, add plot generation timestamp
381379 $rtnstr .= '</td><td class="srfptimestamp" width="33%" colspan="1" align="right">';
Index: trunk/extensions/SemanticResultFormats/Ploticus/README
@@ -68,28 +68,15 @@
6969 can and should be used in script mode. Otherwise, the ploticus script parser will fail.
7070
7171 * imageformat (enum/optional)
72 - - png (default), gif, jpeg, svg, svgz, swf, eps, ps, drawdump, drawdumpa (drawdump append) and csv.
 72+ - png (default), gif, jpeg, svg, svgz, swf, eps, ps, drawdump and drawdumpa (drawdump append).
7373 Availability of format depends on how ploticus is built. When using svgz, make sure Apache
7474 is configured properly, i.e. you have the svgz mime-type and svgz encoding.
7575 AddType image/svg+xml svg svgz
7676 AddEncoding gzip svgz
7777
78 - The csv format is a special case. It only generates the CSV result and sets showcsv=true (see below), and
79 - Ploticus is NOT actually invoked.
80 -
81 - This is useful in cases when the result set is very large and you want the ability to download the CSV file
82 - without bumping up against SMW and PHP memory limits.
83 -
84 - FYI, while the stock CSV result printer creates the file in memory, SRF-Ploticus streams the result directly to the filesystem.
85 - As a result, the resulting CSV file can be much bigger.
86 -
87 - As an added benefit, the CSV file is also persistent across sessions. That is, the generated URL for the CSV file is available
88 - without running the query, within bounds of the $srfgPloticusCacheAgeHours LocalSettings.php parameter.
89 -
90 - * alttext (string/optional)
91 - - alternate text displayed on mouseover for raster formats (PNG/JPEG/GIF). Ignored when client-side imagemap is generated.
92 - On vector formats (SVG/SVGZ/EPS/PS), alttext is prepended to the warning message if the browser is not capable of displaying
93 - the plot.
 78+ * titletext (string/optional)
 79+ - text displayed underneath the chart. Its also displayed on mouseover for raster formats (PNG/JPEG/GIF) and
 80+ when imagemaps are not used.
9481
9582 * showcsv (bool/optional)
9683 - 0 (default). When 1, displays link to CSV file used to generate plot. Beware that the CSV

Status & tagging log