r46739 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46738‎ | r46739 | r46740 >
Date:22:10, 2 February 2009
Author:jnatividad
Status:deferred
Tags:
Comment:
Fixes bug 17318 (enable passing of ENV vars to SRF-Ploticus); bug 17319 (SRF-Ploticus should regenerate plot when any inline query param is changed); bug 17320 (Fix Ploticus-caching param interplay); bug 17321(Refactor Ploticus-cache sharded directory creation logic); expanded README and added Credits
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/README
@@ -14,12 +14,22 @@
1515 * $srfgPloticusPath (REQUIRED)
1616 - path to ploticus executable. (typically /usr/bin/ploticus or /usr/bin/pl)
1717
18 - * $srfgGDFontPath (default: '')
19 - - if you plan to use alternate TrueType fonts in your plot.
20 - (e.g. '/usr/share/fonts/truetype/freefont:/usr/share/fonts/truetype/msttcorefonts')
 18+ * $srfgEnvSettings (default: '')
 19+ - Ploticus behavior can be further modified by setting environment variables. You can pass this env vars using this setting.
 20+ E.g. if you plan to use alternate TrueType fonts in your plot.
 21+ GDFONTPATH=/usr/share/fonts/truetype/freefont:/usr/share/fonts/truetype/msttcorefonts
 22+
 23+ E.g. if you plan to use additional fonts in SWF files
 24+ SWF_FONTS_DIR=/usr/share/ming/fonts/ttf-dejavu/fdb/
 25+
 26+ E.g. set global ploticus config parameters with a config file. See http://ploticus.sourceforge.net/doc/config.html for details.
 27+ PLOTICUS_CONFIG=/etc/ploticus/ploticus.conf
 28+
 29+ Remember, you can pass multiple environment variables, e.g.
 30+ GDFONTPATH=/usr/share/fonts/truetype/freefont PLOTICUS_CONFIG=/etc/ploticus/ploticus.conf
2131
2232 * $srfgPloticusCacheAgeHours (default: 168 - 7 days)
23 - - number of hours cached plot files are stored in the ploticus cache before they are forcibly purged regardless of liveupdating setting.
 33+ - number of hours cached plot files are stored in the ploticus cache before they are forcibly purged.
2434 Set to 0 if you prefer to purge the cache manually.
2535 This is required, especially with liveupdating plots, since changing query results will "orphan" plot cache files as the computed hash filename
2636 will change even if the query definition itself is NOT changed.
@@ -35,7 +45,8 @@
3646
3747 * $wgEnableUploads (default: false - this is a MediaWiki setting)
3848 - must be true. Be sure the upload directory has the proper permissions. If you wish to use SRF-Ploticus without enabling uploads,
39 - you can create the 'ploticus' directory under the MW upload directory with permission 777.
 49+ you can manually create the 'ploticus' directory under the MW upload. Further, under the ploticus directory, subdirectories from 0 to f hex
 50+ (e.g. 0,1,2,3...9,a,b,c,d,e,f) should also be created, all with permission 777.
4051 (see http://www.mediawiki.org/wiki/Manual:$wgUploadPath)
4152
4253 == Configuration and Usage ==
@@ -71,17 +82,18 @@
7283 Also turns showcsv on and bypasses the ploticus "cache".
7384
7485 * liveupdating (bool/optional)
75 - - 1 (default). When 1, will check if the query result has changed and regenerate the plot based
76 - on the updatefrequency parameter.
77 - Otherwise, when 0, the plot will only be generated once and stored in the ploticus "cache".
78 - Its recommended to set showtimestamp to 1 when liveupdating is 0 or when updatefrequency > 0.
 86+ - 1 (default). When 1, will check if the query result has changed and regenerate the plot if so.
 87+ Otherwise, when 0, the plot will only be generated once and stored in the ploticus "cache", even
 88+ if the query results have changed.
7989
8090 * updatefrequency (secs/optional)
81 - - 60 (default). specifies how old a plot should be before its regenerated. Only valid when
82 - liveupdating is 1. If you do not want to "cache" the plot, set updatefrequency to 0.
 91+ - 3600 (default). Specifies how old a plot should be before its regenerated even if the underlying
 92+ result data has not changed.
 93+ If you do not want to "cache" a plot, set updatefrequency to 0.
8394
8495 * showtimestamp (bool/optional)
8596 - 0 (default). Shows timestamp when the plot was last regenerated.
 97+ Its recommended to set showtimestamp to 1 when liveupdating is 0 or when updatefrequency > 0.
8698
8799 * showrefresh (bool/optional)
88100 - 0 (default). Shows a Refresh link to force refresh of the WHOLE article.
@@ -130,6 +142,8 @@
131143 * #sql
132144 * #write
133145 * #cat
 146+
 147+ ======= USAGE NOTES =========
134148
135149 Overlaying and combining plots from multiple queries
136150 ====================================================
@@ -168,12 +182,22 @@
169183 where mydump is the name of the file passed to the drawdumpoutput parameter in the earlier SRF-Ploticus queries.
170184
171185
172 -NOTE:
173 -=====
 186+Imagemaps:
 187+=========
174188 Client-side imagemaps are automatically generated by SRF-Ploticus if it detects the clickmap directive in
175189 either prefab and script mode.
176190 Typically, Imagemaps "links/labels" should be set to resolve to "Article URL/Article Name".
177191 Note that imagemaps are only valid for the imageformats PNG, GIF and JPEG.
178192
 193+
 194+
 195+CREDITS:
 196+=======
 197+SRF-Ploticus is only possible because of all the great work done
 198+by Steve Grubb (stevegrubb@gmail.com) in creating Ploticus.
 199+Ploticus is distributed via the GPL license (http://ploticus.sourceforge.net/doc/Copyright.html),
 200+which is compatible with the GPL license under which Semantic Result Formats is distributed.
 201+
 202+
179203 For up-to-date documentation and examples please refer to
180204 http://semantic-mediawiki.org/wiki/Help:Ploticus_format
\ No newline at end of file
Index: trunk/extensions/SemanticResultFormats/Ploticus/SRF_Ploticus.php
@@ -27,13 +27,14 @@
2828 protected $m_ploticusmode = 'prefab';
2929 protected $m_debug = false;
3030 protected $m_liveupdating = true;
31 - protected $m_updatefrequency = 60; // by default, generate plot only once per minute
 31+ protected $m_updatefrequency = 3600; // by default, generate plot only once per hour
3232 protected $m_showtimestamp = false;
3333 protected $m_showrefresh = false;
3434 protected $m_showimagelink = false;
3535 protected $m_drawdumpoutput = '';
3636 protected $m_tblwidth = '';
3737 protected $m_tblheight = '';
 38+ protected $m_params = array();
3839
3940 protected function readParameters($params, $outputmode) {
4041 SMWResultPrinter::readParameters($params, $outputmode);
@@ -88,9 +89,10 @@
8990 }
9091
9192 protected function getResultText($res, $outputmode) {
92 - global $smwgIQRunningNumber, $wgUploadDirectory, $wgUploadPath, $wgScriptPath, $srfgPloticusPath, $srfgGDFontPath;
 93+ global $smwgIQRunningNumber, $wgUploadDirectory, $wgUploadPath, $wgScriptPath, $srfgPloticusPath, $srfgEnvSettings;
9394
9495 $this->isHTML = true;
 96+ $this->outputmode = SMW_OUTPUT_HTML;
9597
9698 // check parameters
9799 if(empty($this->m_ploticusparams))
@@ -120,14 +122,12 @@
121123 $sanitized_ploticusparams = preg_replace($searches, $replaces, $this->m_ploticusparams);
122124
123125 // Create the ploticus data directory if it doesn't exist
124 - // create sharded directory structure to stay under the file no limits of filesystem
 126+ // create sharded directory structure for data partitioning/scalability purposes
125127 $ploticusDir = $wgUploadDirectory . '/ploticus/';
126128 if (!is_dir($ploticusDir)) {
127129 mkdir($ploticusDir, 0777);
128 - for ($idx=0; $idx < 10; $idx++)
129 - mkdir($ploticusDir . $idx);
130 - foreach(range('a','f') as $idx)
131 - mkdir($ploticusDir . $idx);
 130+ for ($idx=0; $idx < 16; $idx++)
 131+ mkdir($ploticusDir . dechex($idx), 0777);
132132 }
133133
134134 // create result csv file that we pass on to ploticus
@@ -151,8 +151,7 @@
152152
153153 // we create a hash based on params and csv file.
154154 // this is a great way to see if the params and/or the query result has changed
155 - $hashname = hash('md5',$this->m_ploticusparams . $this->m_imageformat . $this->m_showcsv . $this->m_ploticusmode .
156 - $this->m_liveupdating . $this->m_updatefrequency . $this->m_showtimestamp);
 155+ $hashname = hash('md5', implode(',',$this->m_params));
157156 if ($this->m_liveupdating) {
158157 // only include contents of result csv in hash when liveupdating is on
159158 // in this way, doing file_exists check against hash filename will fail when query result has changed
@@ -175,12 +174,12 @@
176175 $scriptFile = $ploticusDir . $hashname . '.plo';
177176 $scriptURL = $wgUploadPath . '/ploticus/' . $hashname . '.plo';
178177
179 - // get time graph was last generated and if liveupdating is on, check to see if the
 178+ // get time graph was last generated. Also check to see if the
180179 // generated plot has expired per the updatefrequency and needs to be redrawn
181 - if (file_exists($graphFile)) {
 180+ if (($this->m_updatefrequency > 0) && file_exists($graphFile)) {
182181 $graphLastGenerated = filemtime($graphFile);
183182 $expireTime = $graphLastGenerated + $this->m_updatefrequency;
184 - if ($this->m_liveupdating && $expireTime < time()) {
 183+ if ( $expireTime < time()) {
185184 @unlink($graphFile);
186185 }
187186 }
@@ -198,8 +197,8 @@
199198 $srfgPloticusPath . '</em></strong></p>');
200199 }
201200
202 - // we set GDFONTPATH if specified
203 - $commandline = empty($srfgGDFontPath) ? ' ' : 'GDFONTPATH=' . $srfgGDFontPath . ' ';
 201+ // we set $srfgEnvSettings if specified
 202+ $commandline = empty($srfgEnvSettings) ? ' ' : $srfgEnvSettings . ' ';
204203
205204 if ($this->m_ploticusmode === 'script') {
206205 // Script mode. Search for special strings in ploticusparam

Status & tagging log