Index: trunk/extensions/GraphViz/GraphViz.php |
— | — | @@ -1,109 +1,109 @@ |
2 | 2 | <?php |
3 | | - /* |
4 | | - * @date: 2010-11-01 |
5 | | - * @version: 0.9 (by hummel-riegel) |
6 | | - * |
7 | | - * See mediawiki.org/wiki/Extension:GraphViz for more information |
8 | | - * |
9 | | - * Extension to allow Graphviz to work inside MediaWiki. |
10 | | - * This Version is based on CoffMan's nice Graphviz Extension. |
11 | | - * |
12 | | - * Licence: http://www.gnu.org/copyleft/fdl.html |
13 | | - * |
14 | | - * Configuration |
15 | | - * |
16 | | - * These settings can be overwritten in LocalSettings.php. |
17 | | - * Configuration must be done AFTER including this extension using |
18 | | - * require("extensions/Graphviz.php"); |
19 | | - * |
20 | | - * $wgGraphVizSettings->execPath |
21 | | - * Describes where your actual (dot) executable remains. |
22 | | - * |
23 | | - * Windows Default: C:/Programme/ATT/Graphviz/bin/ |
24 | | - * Other Platform : /usr/local/bin/dot |
25 | | - * |
26 | | - * $wgGraphVizSettings->mscgenPath |
27 | | - * Describes where your actual mscgen-executable remains |
28 | | - * |
29 | | - * $wgGraphVizSettings->named |
30 | | - * Describes the way graph-files are named. |
31 | | - * |
32 | | - * named: name of your graph and its type determine its filename |
33 | | - * md5 : name of your graph is based on a md5 hash of its source. |
34 | | - * sha1 : name of your graph is based on a SHA1 hash of its source. |
35 | | - * |
36 | | - * Default : named |
37 | | - * |
38 | | - * $wgGraphVizSettings->install |
39 | | - * Gets you an errormessage if something fails, but maybe ruins your |
40 | | - * wiki's look. This message is in English, always. |
41 | | - * |
42 | | - * Default : false (not really implemented yet) |
43 | | - * |
44 | | - * Features |
45 | | - * - normally selects defaults for Windows or Unix-like automatically. |
46 | | - * - should run out of the box |
47 | | - * - Creates png (or maybe other image) + MAP File |
48 | | - * - additional storage modes (see discussion below) |
49 | | - * - Meaningful filename |
50 | | - * - Hash based filename |
51 | | - * - Configurable (name/md5/sha1) |
52 | | - * |
53 | | - * Storage Modes: |
54 | | - * MD5: |
55 | | - * + don't worry about graphnames |
56 | | - * + pretty fast hash |
57 | | - * - permanent cleanup necesary (manually or scripted) |
58 | | - * - md5 is buggy - possibility that 2 graphs have the same hash but |
59 | | - * are not the same |
60 | | - * SHA1: |
61 | | - * + don't worry about graphnames |
62 | | - * + no hash-bug as md5 |
63 | | - * - permanent cleanup necessary (manually or scripted) |
64 | | - * - not so fast as md5 |
65 | | - * Named: |
66 | | - * + Graphs have a name, now it's used |
67 | | - * + no permanent cleanup necessary. |
68 | | - * - Naming Conflicts |
69 | | - * a) if you have multiple graphs of the same name in the same |
70 | | - * article, you will only get 1 picture - independently if they're |
71 | | - * the same or not. |
72 | | - * b) possible naming conflicts in obscure cases (that should not happen) |
73 | | - * Read code for possibilities / exploits |
74 | | - * |
75 | | - */ |
| 3 | +/* |
| 4 | + * @date: 2010-11-01 |
| 5 | + * @version: 0.9 (by hummel-riegel) |
| 6 | + * |
| 7 | + * See mediawiki.org/wiki/Extension:GraphViz for more information |
| 8 | + * |
| 9 | + * Extension to allow Graphviz to work inside MediaWiki. |
| 10 | + * This Version is based on CoffMan's nice Graphviz Extension. |
| 11 | + * |
| 12 | + * Licence: http://www.gnu.org/copyleft/fdl.html |
| 13 | + * |
| 14 | + * Configuration |
| 15 | + * |
| 16 | + * These settings can be overwritten in LocalSettings.php. |
| 17 | + * Configuration must be done AFTER including this extension using |
| 18 | + * require("extensions/Graphviz.php"); |
| 19 | + * |
| 20 | + * $wgGraphVizSettings->execPath |
| 21 | + * Describes where your actual (dot) executable remains. |
| 22 | + * |
| 23 | + * Windows Default: C:/Programme/ATT/Graphviz/bin/ |
| 24 | + * Other Platform : /usr/local/bin/dot |
| 25 | + * |
| 26 | + * $wgGraphVizSettings->mscgenPath |
| 27 | + * Describes where your actual mscgen-executable remains |
| 28 | + * |
| 29 | + * $wgGraphVizSettings->named |
| 30 | + * Describes the way graph-files are named. |
| 31 | + * |
| 32 | + * named: name of your graph and its type determine its filename |
| 33 | + * md5 : name of your graph is based on a md5 hash of its source. |
| 34 | + * sha1 : name of your graph is based on a SHA1 hash of its source. |
| 35 | + * |
| 36 | + * Default : named |
| 37 | + * |
| 38 | + * $wgGraphVizSettings->install |
| 39 | + * Gets you an errormessage if something fails, but maybe ruins your |
| 40 | + * wiki's look. This message is in English, always. |
| 41 | + * |
| 42 | + * Default : false (not really implemented yet) |
| 43 | + * |
| 44 | + * Features |
| 45 | + * - normally selects defaults for Windows or Unix-like automatically. |
| 46 | + * - should run out of the box |
| 47 | + * - Creates png (or maybe other image) + MAP File |
| 48 | + * - additional storage modes (see discussion below) |
| 49 | + * - Meaningful filename |
| 50 | + * - Hash based filename |
| 51 | + * - Configurable (name/md5/sha1) |
| 52 | + * |
| 53 | + * Storage Modes: |
| 54 | + * MD5: |
| 55 | + * + don't worry about graphnames |
| 56 | + * + pretty fast hash |
| 57 | + * - permanent cleanup necesary (manually or scripted) |
| 58 | + * - md5 is buggy - possibility that 2 graphs have the same hash but |
| 59 | + * are not the same |
| 60 | + * SHA1: |
| 61 | + * + don't worry about graphnames |
| 62 | + * + no hash-bug as md5 |
| 63 | + * - permanent cleanup necessary (manually or scripted) |
| 64 | + * - not so fast as md5 |
| 65 | + * Named: |
| 66 | + * + Graphs have a name, now it's used |
| 67 | + * + no permanent cleanup necessary. |
| 68 | + * - Naming Conflicts |
| 69 | + * a) if you have multiple graphs of the same name in the same |
| 70 | + * article, you will only get 1 picture - independently if they're |
| 71 | + * the same or not. |
| 72 | + * b) possible naming conflicts in obscure cases (that should not happen) |
| 73 | + * Read code for possibilities / exploits |
| 74 | + * |
| 75 | + */ |
76 | 76 | |
77 | 77 | if ( !defined( 'MEDIAWIKI' ) ) die(); |
78 | 78 | |
79 | 79 | define( 'GraphViz_VERSION', '0.9.1 alpha' ); |
80 | 80 | |
81 | | - /* |
| 81 | +/* |
82 | 82 | * The GraphViz-Class with the essential settings |
83 | 83 | */ |
84 | 84 | class GraphVizSettings { |
85 | | - public $execPath, $mscgenPath, $named; // Execution Parameters |
86 | | - // public $uploadPath, $uploadDirectory; // where are the images/maps saved |
87 | | - public $outputType, $imageFormatting; // produced image |
88 | | - public $install, $info; // Information aboutfunctionality |
89 | | - public $pruneEnabled, $pruneStrategy, $pruneValue, $pruneAmount; // Pruning Parameters |
| 85 | + public $execPath, $mscgenPath, $named; // Execution Parameters |
| 86 | + // public $uploadPath, $uploadDirectory; // where are the images/maps saved |
| 87 | + public $outputType, $imageFormatting; // produced image |
| 88 | + public $install, $info; // Information aboutfunctionality |
| 89 | + public $pruneEnabled, $pruneStrategy, $pruneValue, $pruneAmount; // Pruning Parameters |
90 | 90 | }; |
91 | 91 | |
92 | 92 | |
93 | 93 | $wgGraphVizSettings = new GraphVizSettings(); // create new instance of GraphVizSettings |
94 | 94 | |
95 | | - /* |
| 95 | +/* |
96 | 96 | * Configuration of the graphviz instance |
97 | 97 | * if parameters are overwritten in the LocalSettings.php nothing will be changed |
98 | 98 | */ |
99 | 99 | |
100 | | - // Set execution path |
| 100 | +// Set execution path |
101 | 101 | if ( stristr( PHP_OS, 'WIN' ) && !stristr( PHP_OS, 'Darwin' ) ) { |
102 | | - $wgGraphVizSettings->execPath = 'C:/Program Files/Graphviz/bin/'; // '/' will be converted to '\\' later on, so feel free how to write your path C:/ or C:\\ |
| 102 | + $wgGraphVizSettings->execPath = 'C:/Program Files/Graphviz/bin/'; // '/' will be converted to '\\' later on, so feel free how to write your path C:/ or C:\\ |
103 | 103 | } else { |
104 | | - $wgGraphVizSettings->execPath = '/usr/bin/'; // common: '/usr/bin/' '/usr/local/bin/' or (if set) '$DOT_PATH/' |
| 104 | + $wgGraphVizSettings->execPath = '/usr/bin/'; // common: '/usr/bin/' '/usr/local/bin/' or (if set) '$DOT_PATH/' |
105 | 105 | } |
106 | 106 | |
107 | | - // Set further default values for parameters |
| 107 | +// Set further default values for parameters |
108 | 108 | $wgGraphVizSettings->mscgenPath = ''; // installation path for mscgen-renderer |
109 | 109 | $wgGraphVizSettings->named = 'named'; // naming scheme for the maps/images |
110 | 110 | $wgGraphVizSettings->outputType = 'png'; // can be changed to gif, svg, ... |
— | — | @@ -112,27 +112,27 @@ |
113 | 113 | $wgGraphVizSettings->info = false; // Do you want additional info to your renders displayed? |
114 | 114 | $wgGraphVizSettings->pruneEnabled = false; // Do you want to prune? |
115 | 115 | $wgGraphVizSettings->pruneStrategy = 'filenumber'; // pruning strategy to use |
116 | | - // filesize - limit total size of files to amount of bytes |
117 | | - // filenumber - limit total number of files |
| 116 | +// filesize - limit total size of files to amount of bytes |
| 117 | +// filenumber - limit total number of files |
118 | 118 | |
119 | 119 | $wgGraphVizSettings->pruneValue = '10000'; // value to apply to 'pruneStrategy' |
120 | | - // total file size (in bytes) |
121 | | - // total number of files allowed |
| 120 | +// total file size (in bytes) |
| 121 | +// total number of files allowed |
122 | 122 | |
123 | 123 | $wgGraphVizSettings->pruneAmount = '0.5'; // amount by which we prune |
124 | | - // Removes this fraction of the oldest files come prune time |
| 124 | +// Removes this fraction of the oldest files come prune time |
125 | 125 | |
126 | 126 | |
127 | 127 | |
128 | | - /* |
| 128 | +/* |
129 | 129 | * Media Wiki Plugin Stuff |
130 | 130 | */ |
131 | 131 | |
132 | | - // Check if the Wiki supports the new extension syntax |
| 132 | +// Check if the Wiki supports the new extension syntax |
133 | 133 | if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { |
134 | | - $wgHooks['ParserFirstCallInit'][] = 'wfGraphVizExtension'; |
| 134 | + $wgHooks['ParserFirstCallInit'][] = 'wfGraphVizExtension'; |
135 | 135 | } else { // Otherwise do things the old fashioned way |
136 | | - $wgExtensionFunctions[] = 'wfGraphVizExtension'; |
| 136 | + $wgExtensionFunctions[] = 'wfGraphVizExtension'; |
137 | 137 | } |
138 | 138 | |
139 | 139 | // Information about the people did this Parserhook |
— | — | @@ -144,93 +144,96 @@ |
145 | 145 | '[http://wickle.com CoffMan]', |
146 | 146 | '[mailto://arno.venner@gmail.com MasterOfDesaster]', |
147 | 147 | '[http://hummel-universe.net Thomas Hummel]' |
148 | | - ), |
| 148 | + ), |
149 | 149 | 'url' => 'http://www.mediawiki.org/wiki/Extension:GraphViz', |
150 | 150 | 'descriptionmsg' => 'graphviz-desc' |
151 | | -); |
152 | | - |
153 | | -$wgExtensionMessagesFiles['GraphViz'] = dirname( __FILE__ ) . '/GraphViz.i18n.php'; |
| 151 | + ); |
154 | 152 | |
155 | | - /* |
156 | | - * Information about the hooks used |
157 | | - */ |
158 | | -function wfGraphVizExtension() { |
159 | | - global $wgParser; |
160 | | - $wgParser->setHook( 'graphviz', 'renderGraphviz' ); |
161 | | - $wgParser->setHook( 'mscgen', 'renderMscGen' ); |
162 | | - return true; |
163 | | -} |
| 153 | + $wgExtensionMessagesFiles['GraphViz'] = dirname( __FILE__ ) . '/GraphViz.i18n.php'; |
164 | 154 | |
165 | | -/** |
166 | | -* The renderingfunction for the mscgen-hook implementation |
167 | | -* @author Matthewpearson |
168 | | -*/ |
169 | | -function renderMscGen( $timelinesrc, $args = null, $parser = null ) |
170 | | -{ |
| 155 | + /* |
| 156 | + * Information about the hooks used |
| 157 | + */ |
| 158 | + function wfGraphVizExtension() { |
| 159 | + global $wgParser; |
| 160 | + $wgParser->setHook( 'graphviz', 'renderGraphviz' ); |
| 161 | + $wgParser->setHook( 'mscgen', 'renderMscGen' ); |
| 162 | + return true; |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * The renderingfunction for the mscgen-hook implementation |
| 167 | + * @author Matthewpearson |
| 168 | + */ |
| 169 | + function renderMscGen( $timelinesrc, $args = null, $parser = null ) |
| 170 | + { |
171 | 171 | $args["renderer"] = "mscgen"; // set renderer to mscgen - not that nice, could be done better |
172 | 172 | return renderEngine( $timelinesrc, $args, $parser ); // go to the "normal" rendering stuff |
173 | | -} |
174 | | -/** |
175 | | -* The renderingfunction for the graphviz-implementation |
176 | | -* @author Thomas Hummel |
177 | | -*/ |
178 | | -function renderGraphviz( $timelinesrc, $args = null, $parser = null ) // Raw Script data |
179 | | -{ |
180 | | - if ( isset( $args["renderer"] ) ) { |
| 173 | + } |
| 174 | + /** |
| 175 | + * The renderingfunction for the graphviz-implementation |
| 176 | + * @author Thomas Hummel |
| 177 | + */ |
| 178 | + function renderGraphviz( $timelinesrc, $args = null, $parser = null ) // Raw Script data |
| 179 | + { |
| 180 | + |
| 181 | + if ( isset( $args["renderer"] ) ) { |
181 | 182 | switch( $args["renderer"] ) { |
182 | | - case 'circo': |
183 | | - case 'dot': |
184 | | - case 'fdp': |
185 | | - case 'sfdp': |
186 | | - case 'neato': |
187 | | - case 'twopi': |
188 | | - break; |
189 | | - default: |
190 | | - $args["renderer"] = 'dot'; |
191 | | - } |
192 | | - } else { |
193 | | - $args["renderer"] = "dot"; |
194 | | - } |
195 | | - return renderEngine( $timelinesrc, $args, $parser ); // go to the "normal" rendering stuff |
| 183 | + case 'circo': |
| 184 | + case 'dot': |
| 185 | + case 'fdp': |
| 186 | + case 'sfdp': |
| 187 | + case 'neato': |
| 188 | + case 'twopi': |
| 189 | + break; |
| 190 | + default: |
| 191 | + $args["renderer"] = 'dot'; |
| 192 | + } |
| 193 | + } else { |
| 194 | + $args["renderer"] = "dot"; |
| 195 | + } |
196 | 196 | |
197 | | -} |
198 | | - /* |
199 | | - * The actual renderingfunction for handling all the stuff |
200 | | - */ |
201 | | -function renderEngine( $timelinesrc, $args = null, $parser = null ) // Raw Script data |
202 | | - { |
| 197 | + return renderEngine( $timelinesrc, $args, $parser ); // go to the "normal" rendering stuff |
203 | 198 | |
204 | | - global |
205 | | - $wgUploadDirectory, // Storage of the final image (e.g. png) & map |
206 | | - $wgUploadPath, // HTML Reference |
207 | | - $wgGraphVizSettings, // Plugin Config |
208 | | - $info; // some html-output for retracing what we did |
| 199 | + } |
| 200 | + /* |
| 201 | + * The actual renderingfunction for handling all the stuff |
| 202 | + */ |
| 203 | + function renderEngine( $timelinesrc, $args = null, $parser = null ) // Raw Script data |
| 204 | + { |
209 | 205 | |
| 206 | + global |
| 207 | + $wgTitle, |
| 208 | + $wgUploadDirectory, // Storage of the final image (e.g. png) & map |
| 209 | + $wgUploadPath, // HTML Reference |
| 210 | + $wgGraphVizSettings, // Plugin Config |
| 211 | + $info; // some html-output for retracing what we did |
210 | 212 | |
211 | | - $info = "<h1>Graphviz Information</h1>"; |
212 | | - $info .= "<h2>Called render</h2>"; |
213 | 213 | |
214 | | - /* Prepare Directories |
215 | | - */ |
216 | | - $dest = $wgUploadDirectory . "/graphviz/"; |
217 | | - if ( stristr( PHP_OS, 'WIN' ) && !stristr( PHP_OS, 'Darwin' ) ) { |
218 | | - $dest = str_replace( "/", '\\', $dest ); // switch the slashes for windows |
219 | | - $isWindows = true; |
220 | | - } else { |
221 | | - $isWindows = false; |
222 | | - } |
223 | | - if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 );} // create directory if it isn't there |
| 214 | + $info = "<h1>Graphviz Information</h1>"; |
| 215 | + $info .= "<h2>Called render</h2>"; |
224 | 216 | |
| 217 | + /* Prepare Directories |
| 218 | + */ |
| 219 | + $dest = $wgUploadDirectory . "/graphviz/"; |
| 220 | + if ( stristr( PHP_OS, 'WIN' ) && !stristr( PHP_OS, 'Darwin' ) ) { |
| 221 | + $dest = str_replace( "/", '\\', $dest ); // switch the slashes for windows |
| 222 | + $isWindows = true; |
| 223 | + } else { |
| 224 | + $isWindows = false; |
| 225 | + } |
| 226 | + if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 );} // create directory if it isn't there |
225 | 227 | |
226 | | - /* Start pruning (if enabled) - use directory generated before |
227 | | - * prune before creating a new image so that it won't be pruned right after creation |
228 | | - */ |
229 | | - if ( $wgGraphVizSettings->pruneEnabled ) { |
230 | | - prune( $dest,$wgGraphVizSettings->pruneStrategy,$wgGraphVizSettings->pruneValue,$wgGraphVizSettings->pruneAmount ); // prune the collection first |
231 | | - } |
232 | 228 | |
| 229 | + /* Start pruning (if enabled) - use directory generated before |
| 230 | + * prune before creating a new image so that it won't be pruned right after creation |
| 231 | + */ |
| 232 | + if ( $wgGraphVizSettings->pruneEnabled ) { |
| 233 | + prune( $dest,$wgGraphVizSettings->pruneStrategy,$wgGraphVizSettings->pruneValue,$wgGraphVizSettings->pruneAmount ); // prune the collection first |
| 234 | + } |
| 235 | + |
233 | 236 | /* Check renderer - renderer should be set at least in renderMscgen or renderGraphviz but for security we check agaion and set some additional params |
234 | | - */ |
| 237 | + */ |
235 | 238 | if ( isset( $args['renderer'] ) ) { |
236 | 239 | $renderer = $args['renderer']; |
237 | 240 | } else { |
— | — | @@ -245,238 +248,246 @@ |
246 | 249 | case 'neato': |
247 | 250 | case 'twopi': |
248 | 251 | $mapDashTOption = ' -Tcmapx '; |
249 | | - $inputOption = ''; |
| 252 | + $inputOption = ''; |
250 | 253 | break; |
251 | 254 | case 'mscgen': |
252 | 255 | if ( $wgGraphVizSettings->mscgenPath != null ) { // check if path to mscgen is set - if not use agaion graphviz with dot |
253 | 256 | $inputOption = '-i '; |
254 | | - $mapDashTOption = ' -T ismap '; |
| 257 | + $mapDashTOption = ' -T ismap '; |
255 | 258 | $wgGraphVizSettings->execPath =$wgGraphVizSettings->mscgenPath; // not that nice but functional: overwrite execPath with the path to mscgen |
256 | 259 | } else { |
257 | 260 | $renderer = 'dot'; |
258 | 261 | $mapDashTOption = ' -Tcmapx '; |
259 | | - $inputOption = ''; |
| 262 | + $inputOption = ''; |
260 | 263 | } |
261 | 264 | break; |
262 | 265 | |
263 | 266 | default: |
264 | 267 | $renderer = 'dot'; |
265 | 268 | $mapDashTOption = ' -Tcmapx '; |
266 | | - $inputOption = ''; |
| 269 | + $inputOption = ''; |
267 | 270 | } |
268 | 271 | |
269 | 272 | /* create the command for graphviz or mscgen |
270 | | - */ |
| 273 | + */ |
271 | 274 | $cmd = $renderer; |
272 | 275 | $cmd =$wgGraphVizSettings->execPath . $cmd; // example: /user/bin/dot |
273 | 276 | if ( $isWindows ) { |
274 | 277 | $cmd = $cmd . '.exe'; // executables in windows |
275 | 278 | } |
276 | 279 | |
277 | | - $info .= "<pre>Dir=$dest</pre>"; |
278 | | - $info .= "<pre>execPath=" .$wgGraphVizSettings->execPath . "</pre>"; |
279 | | - $info .= "<pre>named=" .$wgGraphVizSettings->named . "</pre>"; |
| 280 | + $info .= "<pre>Dir=$dest</pre>"; |
| 281 | + $info .= "<pre>execPath=" .$wgGraphVizSettings->execPath . "</pre>"; |
| 282 | + $info .= "<pre>named=" .$wgGraphVizSettings->named . "</pre>"; |
280 | 283 | |
281 | | - /* create actual storagename |
282 | | - */ |
283 | | - $wgGraphVizSettings->named = strtolower($wgGraphVizSettings->named ); // avoid problems with upper/lowercase |
| 284 | + /* create actual storagename |
| 285 | + */ |
| 286 | + $wgGraphVizSettings->named = strtolower($wgGraphVizSettings->named ); // avoid problems with upper/lowercase |
| 287 | + |
| 288 | + /* get title name from parser. If parser not set, use $wgTitle instead |
| 289 | + */ |
| 290 | + if ($parser!=null){ |
| 291 | + $title = $parser->getTitle()->getFulltext(); |
| 292 | + } else{ |
| 293 | + $title = $wgTitle->getFulltext(); |
| 294 | + } |
| 295 | + |
| 296 | + $storagename = str_replace( "%", '_perc_', urlencode( $title ) ) . '---'; // clean up pagename (special chars etc) |
284 | 297 | |
285 | | - $storagename = str_replace( "%", '_perc_', urlencode( $_GET['title'] ) ) . '---'; // clean up pagename (special chars etc) |
286 | | - |
287 | | - if ( $wgGraphVizSettings->named == 'md5' ) { |
288 | | - $storagename .= md5( $timelinesrc ); // produce md5-hash out of the storagename !can be duplicate! |
289 | | - } elseif ( $wgGraphVizSettings->named == 'sha1' ) { |
290 | | - $storagename .= sha1( $timelinesrc ); // produce sha1-hash |
291 | | - } else { // named == 'named' |
292 | | - $storagename .= str_replace( "%", '_perc_', |
293 | | - urlencode( |
294 | | - trim( |
295 | | - str_replace( "\n", '', |
296 | | - str_replace( "\\", '/', |
297 | | - substr( $timelinesrc, 0, strpos( $timelinesrc, '{' ) ) // extract the name of the graph out of the graph |
298 | | - ) |
299 | | - ) |
300 | | - ) |
301 | | - ) |
302 | | - ); |
| 298 | + if ( $wgGraphVizSettings->named == 'md5' ) { |
| 299 | + $storagename .= md5( $timelinesrc ); // produce md5-hash out of the storagename !can be duplicate! |
| 300 | + } elseif ( $wgGraphVizSettings->named == 'sha1' ) { |
| 301 | + $storagename .= sha1( $timelinesrc ); // produce sha1-hash |
| 302 | + } else { // named == 'named' |
| 303 | + $storagename .= str_replace( "%", '_perc_', |
| 304 | + urlencode( |
| 305 | + trim( |
| 306 | + str_replace( "\n", '', |
| 307 | + str_replace( "\\", '/', |
| 308 | + substr( $timelinesrc, 0, strpos( $timelinesrc, '{' ) ) // extract the name of the graph out of the graph |
| 309 | + ) |
| 310 | + ) |
| 311 | + ) |
| 312 | + ) |
| 313 | + ); |
303 | 314 | } |
304 | | - $info .= "<pre>storagename=" . $storagename . "</pre>"; |
| 315 | + $info .= "<pre>storagename=" . $storagename . "</pre>"; |
305 | 316 | |
306 | 317 | |
307 | | - /* check if some outputtype is specified in the wikipage - else use the default value |
308 | | - */ |
309 | | - if ( isset( $args['format'] ) ) { |
310 | | - $outputType = $args['format']; |
311 | | - } else { |
312 | | - $outputType =$wgGraphVizSettings->outputType; |
313 | | - } |
| 318 | + /* check if some outputtype is specified in the wikipage - else use the default value |
| 319 | + */ |
| 320 | + if ( isset( $args['format'] ) ) { |
| 321 | + $outputType = $args['format']; |
| 322 | + } else { |
| 323 | + $outputType =$wgGraphVizSettings->outputType; |
| 324 | + } |
314 | 325 | |
315 | 326 | |
316 | 327 | |
317 | | - /* inputcheck of supported image types |
318 | | - */ |
319 | | - if ( $renderer != 'mscgen' ) { |
320 | | - // see supported types by graphviz itself (here only those that seem to be kind of useful) - http://www.graphviz.org/doc/info/output.html |
321 | | - switch( $outputType ) { |
322 | | - case 'bmp': |
323 | | - case 'gif': |
324 | | - case 'jpg': |
325 | | - case 'jpeg': |
326 | | - case 'png': |
327 | | - case 'svg': // for svg you need extra MediaWiki configuration |
328 | | - case 'svgz': // same as for svg |
329 | | - // case 'tif': |
330 | | - // case 'tiff': |
331 | | - break; |
332 | | - default: |
333 | | - $outputType = 'png'; |
334 | | - } |
335 | | - } else { |
336 | | - // mscgen does only support png, svg and eps |
337 | | - switch( $outputType ) { |
338 | | - case 'png': |
339 | | - case 'svg': |
340 | | - break; |
341 | | - default: |
342 | | - $outputType = 'png'; |
343 | | - } |
344 | | - } |
345 | | - $info .= "<pre>outputType=" . $outputType . "</pre>"; |
| 328 | + /* inputcheck of supported image types |
| 329 | + */ |
| 330 | + if ( $renderer != 'mscgen' ) { |
| 331 | + // see supported types by graphviz itself (here only those that seem to be kind of useful) - http://www.graphviz.org/doc/info/output.html |
| 332 | + switch( $outputType ) { |
| 333 | + case 'bmp': |
| 334 | + case 'gif': |
| 335 | + case 'jpg': |
| 336 | + case 'jpeg': |
| 337 | + case 'png': |
| 338 | + case 'svg': // for svg you need extra MediaWiki configuration |
| 339 | + case 'svgz': // same as for svg |
| 340 | + // case 'tif': |
| 341 | + // case 'tiff': |
| 342 | + break; |
| 343 | + default: |
| 344 | + $outputType = 'png'; |
| 345 | + } |
| 346 | + } else { |
| 347 | + // mscgen does only support png, svg and eps |
| 348 | + switch( $outputType ) { |
| 349 | + case 'png': |
| 350 | + case 'svg': |
| 351 | + break; |
| 352 | + default: |
| 353 | + $outputType = 'png'; |
| 354 | + } |
| 355 | + } |
| 356 | + $info .= "<pre>outputType=" . $outputType . "</pre>"; |
346 | 357 | |
347 | 358 | |
348 | | - /* prepare the actual files |
349 | | - */ |
350 | | - $src = $dest . $storagename; // the raw input code - needed for the renderers - e.g. /graphviz/imagename (will be deleted later on) |
351 | | - $imgn = $src . '.' . $outputType; // the whole image name - e.g. /graphviz/imagename.png |
352 | | - $mapn = $src . '.map'; // the whole map name - e.g. /graphviz/imagename.map |
| 359 | + /* prepare the actual files |
| 360 | + */ |
| 361 | + $src = $dest . $storagename; // the raw input code - needed for the renderers - e.g. /graphviz/imagename (will be deleted later on) |
| 362 | + $imgn = $src . '.' . $outputType; // the whole image name - e.g. /graphviz/imagename.png |
| 363 | + $mapn = $src . '.map'; // the whole map name - e.g. /graphviz/imagename.map |
353 | 364 | |
354 | 365 | |
355 | | - $info .= '<pre>Src=' . $src . '</pre>'; |
356 | | - $info .= '<pre>imgn=' . $imgn . '</pre>'; |
357 | | - $info .= '<pre>mapn=' . $mapn . '</pre>'; |
| 366 | + $info .= '<pre>Src=' . $src . '</pre>'; |
| 367 | + $info .= '<pre>imgn=' . $imgn . '</pre>'; |
| 368 | + $info .= '<pre>mapn=' . $mapn . '</pre>'; |
358 | 369 | |
359 | 370 | |
360 | | - /* The actual commands for the rendering |
361 | | - * check first if we have to overwrite the file (if we don't use hashes) or if it already exists |
362 | | - */ |
363 | | - if ( $wgGraphVizSettings->named == 'named' || !( file_exists( $imgn ) || file_exists( $src . ".err" ) ) ) |
364 | | - { |
365 | | - $timelinesrc = rewriteWikiUrls( $timelinesrc ); // if we use wiki-links we transform them to real urls |
| 371 | + /* The actual commands for the rendering |
| 372 | + * check first if we have to overwrite the file (if we don't use hashes) or if it already exists |
| 373 | + */ |
| 374 | + if ( $wgGraphVizSettings->named == 'named' || !( file_exists( $imgn ) || file_exists( $src . ".err" ) ) ) |
| 375 | + { |
| 376 | + $timelinesrc = rewriteWikiUrls( $timelinesrc ); // if we use wiki-links we transform them to real urls |
366 | 377 | |
367 | | - // write the given dot-commands into a textfile |
368 | | - $handle = fopen( $src, "w" ); |
| 378 | + // write the given dot-commands into a textfile |
| 379 | + $handle = fopen( $src, "w" ); |
369 | 380 | if ( ! $handle ) return 'Error writing graphviz file to disk.'; |
370 | | - $ret2 = fwrite( $handle, $timelinesrc ); |
371 | | - $ret3 = fclose( $handle ); |
| 381 | + $ret2 = fwrite( $handle, $timelinesrc ); |
| 382 | + $ret3 = fclose( $handle ); |
372 | 383 | |
373 | | - $info .= '<pre>Opened and closed $src, handle=' . $handle . ', timeelinesrc=' . $timelinesrc . ', ret2=' . $ret2 . ', ret3=' . $ret3 . '</pre>'; |
| 384 | + $info .= '<pre>Opened and closed $src, handle=' . $handle . ', timeelinesrc=' . $timelinesrc . ', ret2=' . $ret2 . ', ret3=' . $ret3 . '</pre>'; |
374 | 385 | |
375 | | - // prepare the whole commands for image and map |
376 | | - $cmdline = wfEscapeShellArg( $cmd ) . ' -T ' . $outputType . ' -o ' . wfEscapeShellArg( $imgn ) . ' ' . $inputOption . wfEscapeShellArg( $src ); |
377 | | - $cmdlinemap = wfEscapeShellArg( $cmd ) . $mapDashTOption . '-o ' . wfEscapeShellArg( $mapn ) . ' ' . $inputOption . wfEscapeShellArg( $src ); |
| 386 | + // prepare the whole commands for image and map |
| 387 | + $cmdline = wfEscapeShellArg( $cmd ) . ' -T ' . $outputType . ' -o ' . wfEscapeShellArg( $imgn ) . ' ' . $inputOption . wfEscapeShellArg( $src ); |
| 388 | + $cmdlinemap = wfEscapeShellArg( $cmd ) . $mapDashTOption . '-o ' . wfEscapeShellArg( $mapn ) . ' ' . $inputOption . wfEscapeShellArg( $src ); |
378 | 389 | |
379 | 390 | |
380 | | - // run the commands |
| 391 | + // run the commands |
381 | 392 | if ( $isWindows ) { |
382 | | - $WshShell = new COM( "WScript.Shell" ); |
383 | | - $ret = $WshShell->Exec( $cmdline ); |
384 | | - $retmap = $WshShell->Exec( $cmdlinemap ); |
| 393 | + $WshShell = new COM( "WScript.Shell" ); |
| 394 | + $ret = $WshShell->Exec( $cmdline ); |
| 395 | + $retmap = $WshShell->Exec( $cmdlinemap ); |
385 | 396 | } else { |
386 | | - $ret = shell_exec( $cmdline ); |
387 | | - $retmap = shell_exec( $cmdlinemap ); |
| 397 | + $ret = shell_exec( $cmdline ); |
| 398 | + $retmap = shell_exec( $cmdlinemap ); |
388 | 399 | } |
389 | 400 | |
390 | | - $info .= '<pre>Ran cmd line (image). ret=$ret cmdline=' . $cmdline . '</pre>'; |
391 | | - $info .= '<pre>Ran cmd line (map). ret=$ret cmdlinemap=' . $cmdlinemap . '</pre>'; |
| 401 | + $info .= '<pre>Ran cmd line (image). ret=$ret cmdline=' . $cmdline . '</pre>'; |
| 402 | + $info .= '<pre>Ran cmd line (map). ret=$ret cmdlinemap=' . $cmdlinemap . '</pre>'; |
392 | 403 | |
393 | | - // Error messages for image-creation |
| 404 | + // Error messages for image-creation |
394 | 405 | if ( $wgGraphVizSettings->install && $ret == "" ) { |
395 | | - echo '<div id="toc"><tt>Timeline error: Executable not found.' . "\n" . 'Command line was: ' . $cmdline . '</tt></div>'; |
396 | | - $info .= '<div id="toc"><tt>Timeline error: Executable not found.' . "\n" . 'Command line was: ' . $cmdline . '</tt></div>'; |
397 | | - exit; |
| 406 | + echo '<div id="toc"><tt>Timeline error: Executable not found.' . "\n" . 'Command line was: ' . $cmdline . '</tt></div>'; |
| 407 | + $info .= '<div id="toc"><tt>Timeline error: Executable not found.' . "\n" . 'Command line was: ' . $cmdline . '</tt></div>'; |
| 408 | + exit; |
398 | 409 | } |
399 | 410 | |
400 | | - // Error messages for map-creation |
| 411 | + // Error messages for map-creation |
401 | 412 | if ( $wgGraphVizSettings->install && $retmap == "" ) { |
402 | | - echo '<div id="toc"><tt>Timeline error: Executable not found.' . "\n" . 'Command line was: ' . $cmdlinemap . '</tt></div>'; |
403 | | - $info .= '<div id="toc"><tt>Timeline error: Executable not found.' . "\n" . 'Command line was: ' . $cmdlinemap . '</tt></div>'; |
404 | | - exit; |
| 413 | + echo '<div id="toc"><tt>Timeline error: Executable not found.' . "\n" . 'Command line was: ' . $cmdlinemap . '</tt></div>'; |
| 414 | + $info .= '<div id="toc"><tt>Timeline error: Executable not found.' . "\n" . 'Command line was: ' . $cmdlinemap . '</tt></div>'; |
| 415 | + exit; |
405 | 416 | } |
406 | 417 | |
407 | | - // let some other programs do their stuff |
| 418 | + // let some other programs do their stuff |
408 | 419 | if ( $isWindows ) { |
409 | 420 | while ( $ret->Status == 0 || $retmap->Status == 0 ) { |
410 | 421 | usleep( 100 ); |
411 | 422 | } |
412 | 423 | } |
413 | 424 | |
414 | | - unlink( $src ); // delete the src right away |
415 | | - } |
| 425 | + unlink( $src ); // delete the src right away |
| 426 | + } |
416 | 427 | |
417 | 428 | |
418 | | - /* put the produced into the website |
419 | | - */ |
420 | | - @$err = file_get_contents( $src . ".err" );// not really used |
| 429 | + /* put the produced into the website |
| 430 | + */ |
| 431 | + @$err = file_get_contents( $src . ".err" );// not really used |
421 | 432 | |
422 | | - if ( $err != "" ) { |
423 | | - $info .= '<div id="toc"><tt>' . $err . '</tt></div>'; // print error message |
424 | | - } else { |
| 433 | + if ( $err != "" ) { |
| 434 | + $info .= '<div id="toc"><tt>' . $err . '</tt></div>'; // print error message |
| 435 | + } else { |
425 | 436 | if ( false == ( $map = file_get_contents( $mapn ) ) ) { |
426 | | - if ( $wgGraphVizSettings->install ) { |
427 | | - echo '<div id="toc"><tt>File: ' . $mapn . ' is missing or empty.</tt></div>'; |
428 | | - $info .= '<div id="toc"><tt>File: ' . $mapn . ' is missing or empty.</tt></div>'; |
429 | | - } |
| 437 | + if ( $wgGraphVizSettings->install ) { |
| 438 | + echo '<div id="toc"><tt>File: ' . $mapn . ' is missing or empty.</tt></div>'; |
| 439 | + $info .= '<div id="toc"><tt>File: ' . $mapn . ' is missing or empty.</tt></div>'; |
| 440 | + } |
430 | 441 | } |
431 | 442 | |
432 | | - // clean up map-name |
433 | | - $map = preg_replace( '#<ma(.*)>#', ' ', $map ); |
434 | | - $map = str_replace( '</map>', '', $map ); |
| 443 | + // clean up map-name |
| 444 | + $map = preg_replace( '#<ma(.*)>#', ' ', $map ); |
| 445 | + $map = str_replace( '</map>', '', $map ); |
435 | 446 | if ( $renderer == 'mscgen' ) { |
436 | | - $mapbefore = $map; |
437 | | - $map = preg_replace( '/(\w+)\s([_:%#/\w]+)\s(\d+,\d+)\s(\d+,\d+)/', |
| 447 | + $mapbefore = $map; |
| 448 | + $map = preg_replace( '/(\w+)\s([_:%#/\w]+)\s(\d+,\d+)\s(\d+,\d+)/', |
438 | 449 | '<area shape="$1" href="$2" title="$2" alt="$2" coords="$3,$4" />', |
439 | | - $map ); |
| 450 | + $map ); |
440 | 451 | } |
441 | 452 | |
442 | | - /* Procduce html |
443 | | - */ |
444 | | - if ( $wgGraphVizSettings->imageFormatting ) |
445 | | - { |
446 | | - $txt = imageAtrributes( $args, $storagename, $map, $outputType, $wgUploadPath ); // if we want borders/position/... |
447 | | - } else { |
448 | | - $txt = '<map name="' . $storagename . '">' . $map . '</map>' . |
| 453 | + /* Procduce html |
| 454 | + */ |
| 455 | + if ( $wgGraphVizSettings->imageFormatting ) |
| 456 | + { |
| 457 | + $txt = imageAtrributes( $args, $storagename, $map, $outputType, $wgUploadPath ); // if we want borders/position/... |
| 458 | + } else { |
| 459 | + $txt = '<map name="' . $storagename . '">' . $map . '</map>' . |
449 | 460 | '<img src="' . $wgUploadPath . '/graphviz/' . $storagename . '.' . $outputType . '"' . |
450 | 461 | ' usemap="#' . $storagename . '" />'; |
451 | | - } |
| 462 | + } |
452 | 463 | |
453 | 464 | |
454 | 465 | |
455 | | - } |
| 466 | + } |
456 | 467 | |
457 | | - /* give it back to your wiki |
458 | | - */ |
459 | | - if ( $wgGraphVizSettings->info ) { $txt .= $info;} // do we want the information snipptes? |
460 | | - return $txt; |
461 | | -} |
| 468 | + /* give it back to your wiki |
| 469 | + */ |
| 470 | + if ( $wgGraphVizSettings->info ) { $txt .= $info;} // do we want the information snipptes? |
| 471 | + return $txt; |
| 472 | + } |
462 | 473 | |
463 | 474 | |
464 | | -function rewriteWikiUrls( &$source ) |
465 | | -{ |
| 475 | + function rewriteWikiUrls( &$source ) |
| 476 | + { |
466 | 477 | |
467 | | - $line = preg_replace( |
| 478 | + $line = preg_replace( |
468 | 479 | '|\[\[([^]]+)\]\]|e', |
469 | 480 | 'Title::newFromText("$1")->getFullURL()', |
470 | 481 | $source |
471 | | - ); |
472 | | - return $line; |
473 | | -} |
| 482 | + ); |
| 483 | + return $line; |
| 484 | + } |
474 | 485 | |
475 | 486 | /** |
476 | 487 | * Prunes the repository of generated files |
477 | 488 | * @author Gregory Szorc <gregory.szorc@gmail.com> |
478 | 489 | * @author Thomas Hummel (modified only) |
479 | 490 | */ |
480 | | -function prune( $dest, $pruneStrategy, $pruneValue, $pruneAmount ) |
| 491 | + function prune( $dest, $pruneStrategy, $pruneValue, $pruneAmount ) |
481 | 492 | { |
482 | 493 | $pruneList = array(); // array of files that are prune candidates |
483 | 494 | $pruneListSize = 0; // size (in bytes) of prunable files |
— | — | @@ -487,8 +498,8 @@ |
488 | 499 | // only look for actual files |
489 | 500 | if ( $file->isFile() ) { |
490 | 501 | // only mark files with defined prefix as prune candidates |
491 | | - $pruneList[$file->getPathname()] = $file->getMTime(); |
492 | | - $pruneListSize += $file->getSize(); |
| 502 | + $pruneList[$file->getPathname()] = $file->getMTime(); |
| 503 | + $pruneListSize += $file->getSize(); |
493 | 504 | |
494 | 505 | } |
495 | 506 | } |
— | — | @@ -524,118 +535,118 @@ |
525 | 536 | } |
526 | 537 | |
527 | 538 | /*//every time we create a new file, we run the pruning algorithm |
528 | | - //we prune first so that in case settings aren't sane, we don't prune what we create |
529 | | - self::prune(); //prune the collection first |
530 | | - */ |
| 539 | + //we prune first so that in case settings aren't sane, we don't prune what we create |
| 540 | + self::prune(); //prune the collection first |
| 541 | + */ |
531 | 542 | |
532 | | -/** |
533 | | -* Image Attributes (orientated on MediaWiki-Syntax like here: http://en.wikipedia.org/wiki/Wikipedia:Extended_image_syntax) |
534 | | -* syntax is <graphviz attribute='value'> |
535 | | -* @author Thomas Hummel |
536 | | -*/ |
537 | | -function imageAtrributes( $args = null, $storagename, $map, $outputType, $wgUploadPath ) { |
538 | | - // Initialize Variables |
539 | | - $varnames = array( "outerDivClass", "middleDivClass", "innerDivClass", "imageClass" ); |
540 | | - $varnames[] = "imageStyle"; |
541 | | - foreach ( $varnames as $varname ) |
542 | | - $$varname = ''; |
| 543 | + /** |
| 544 | + * Image Attributes (orientated on MediaWiki-Syntax like here: http://en.wikipedia.org/wiki/Wikipedia:Extended_image_syntax) |
| 545 | + * syntax is <graphviz attribute='value'> |
| 546 | + * @author Thomas Hummel |
| 547 | + */ |
| 548 | + function imageAtrributes( $args = null, $storagename, $map, $outputType, $wgUploadPath ) { |
| 549 | + // Initialize Variables |
| 550 | + $varnames = array( "outerDivClass", "middleDivClass", "innerDivClass", "imageClass" ); |
| 551 | + $varnames[] = "imageStyle"; |
| 552 | + foreach ( $varnames as $varname ) |
| 553 | + $$varname = ''; |
543 | 554 | |
544 | | - // Caption that is put below the image (can be overwritten by Type) |
545 | | - if ( isset( $args['caption'] ) ) { $caption = $args['caption'];} |
| 555 | + // Caption that is put below the image (can be overwritten by Type) |
| 556 | + if ( isset( $args['caption'] ) ) { $caption = $args['caption'];} |
546 | 557 | |
547 | | - // Alt-Text for missing pictures, screenreaders, ... if not set use caption and at least default-String |
548 | | - if ( isset( $args['alt'] ) ) { $alt = $args['alt']; |
549 | | - } elseif ( isset( $args['caption'] ) ) { $alt = $args['caption']; |
550 | | - } else { $alt = "This is a graph with borders and nodes. Maybe there is an Imagemap used so the nodes may be linking to some Pages."; |
551 | | - } |
| 558 | + // Alt-Text for missing pictures, screenreaders, ... if not set use caption and at least default-String |
| 559 | + if ( isset( $args['alt'] ) ) { $alt = $args['alt']; |
| 560 | + } elseif ( isset( $args['caption'] ) ) { $alt = $args['caption']; |
| 561 | + } else { $alt = "This is a graph with borders and nodes. Maybe there is an Imagemap used so the nodes may be linking to some Pages."; |
| 562 | + } |
552 | 563 | |
553 | | - // For a border write <graphviz border='border'> |
554 | | - if ( isset( $args['border'] ) ) { |
555 | | - switch( $args['border'] ) { |
556 | | - case 'frame': |
557 | | - case 'border': $imageClass .= 'thumbborder'; break; |
558 | | - } |
559 | | - } |
| 564 | + // For a border write <graphviz border='border'> |
| 565 | + if ( isset( $args['border'] ) ) { |
| 566 | + switch( $args['border'] ) { |
| 567 | + case 'frame': |
| 568 | + case 'border': $imageClass .= 'thumbborder'; break; |
| 569 | + } |
| 570 | + } |
560 | 571 | |
561 | | - // Location defining horizontal alignment |
562 | | - if ( isset( $args['location'] ) ) { |
563 | | - switch( $args['location'] ) { |
564 | | - case 'left': $outerDivClass = 'floatleft'; break; |
565 | | - case 'middle': |
566 | | - case 'center': $outerDivClass = 'center'; $innerDivClass = 'floatnone'; break; |
567 | | - case 'right': $outerDivClass = 'floatright'; break; |
568 | | - case 'none': $outerDivClass = 'floatnone'; break; |
569 | | - } |
570 | | - } |
| 572 | + // Location defining horizontal alignment |
| 573 | + if ( isset( $args['location'] ) ) { |
| 574 | + switch( $args['location'] ) { |
| 575 | + case 'left': $outerDivClass = 'floatleft'; break; |
| 576 | + case 'middle': |
| 577 | + case 'center': $outerDivClass = 'center'; $innerDivClass = 'floatnone'; break; |
| 578 | + case 'right': $outerDivClass = 'floatright'; break; |
| 579 | + case 'none': $outerDivClass = 'floatnone'; break; |
| 580 | + } |
| 581 | + } |
571 | 582 | |
572 | | - // Alignment for the vertical alignment |
573 | | - if ( isset( $args['alignment'] ) ) { |
574 | | - switch( $args['alignment'] ) { |
575 | | - case 'baseline': |
576 | | - case 'middle': |
577 | | - case 'sub': |
578 | | - case 'super': |
579 | | - case 'text-top': |
580 | | - case 'text-bottom': |
581 | | - case 'top': |
582 | | - case 'bottom': |
583 | | - $imageStyle = 'vertical-align: ' . $args['alignment']; break; |
584 | | - } |
585 | | - } |
| 583 | + // Alignment for the vertical alignment |
| 584 | + if ( isset( $args['alignment'] ) ) { |
| 585 | + switch( $args['alignment'] ) { |
| 586 | + case 'baseline': |
| 587 | + case 'middle': |
| 588 | + case 'sub': |
| 589 | + case 'super': |
| 590 | + case 'text-top': |
| 591 | + case 'text-bottom': |
| 592 | + case 'top': |
| 593 | + case 'bottom': |
| 594 | + $imageStyle = 'vertical-align: ' . $args['alignment']; break; |
| 595 | + } |
| 596 | + } |
586 | 597 | |
587 | 598 | |
588 | 599 | |
589 | | - // Type: |
590 | | - if ( isset( $args['type'] ) ) { |
591 | | - switch( $args['type'] ) { |
592 | | - case 'frame': |
593 | | - case 'framed': // little bug (optical): if you center a framed Graph there will be a border over the whole width of the wiki-page |
594 | | - $middleDivClass = 'thumb'; |
595 | | - if ( $outerDivClass != null ) { $middleDivClass .= ' tnone';} else { $middleDivClass = 'tright';} |
596 | | - $innerDivClass = 'thumbinner'; |
597 | | - $imageClass = 'thumbimage'; |
598 | | - $captionDivClass = 'thumbcaption'; |
599 | | - break; |
600 | | - case 'thumb': |
601 | | - case 'thumbnail': |
602 | | - // Differences to the MediaWiki-Behaviour: No extra Thumbs are generated - the browser has to resize the image itself! |
603 | | - // !!Please take into consideration that the mindmap will not fit to your smaller image!! |
604 | | - $middleDivClass = 'thumb'; |
605 | | - if ( $outerDivClass != null ) { $middleDivClass .= ' tnone';} else { $middleDivClass = 'tright';} |
606 | | - $innerDivClass = 'thumbinner" style="width:222px;'; |
607 | | - $imageClass = 'thumbimage" width="220px'; |
608 | | - $captionDivClass = 'thumbcaption'; |
609 | | - $caption .= ' <a href="' . $wgUploadPath . '/graphviz/' . $storagename . '.' . $outputType . '">(+)</a>'; |
610 | | - break; |
611 | | - case 'frameless': |
612 | | - $imageClass = '" width="220px'; |
613 | | - default: // nothing specified |
614 | | - $caption = ''; // no caption as it is defined on the wiki page |
| 600 | + // Type: |
| 601 | + if ( isset( $args['type'] ) ) { |
| 602 | + switch( $args['type'] ) { |
| 603 | + case 'frame': |
| 604 | + case 'framed': // little bug (optical): if you center a framed Graph there will be a border over the whole width of the wiki-page |
| 605 | + $middleDivClass = 'thumb'; |
| 606 | + if ( $outerDivClass != null ) { $middleDivClass .= ' tnone';} else { $middleDivClass = 'tright';} |
| 607 | + $innerDivClass = 'thumbinner'; |
| 608 | + $imageClass = 'thumbimage'; |
| 609 | + $captionDivClass = 'thumbcaption'; |
| 610 | + break; |
| 611 | + case 'thumb': |
| 612 | + case 'thumbnail': |
| 613 | + // Differences to the MediaWiki-Behaviour: No extra Thumbs are generated - the browser has to resize the image itself! |
| 614 | + // !!Please take into consideration that the mindmap will not fit to your smaller image!! |
| 615 | + $middleDivClass = 'thumb'; |
| 616 | + if ( $outerDivClass != null ) { $middleDivClass .= ' tnone';} else { $middleDivClass = 'tright';} |
| 617 | + $innerDivClass = 'thumbinner" style="width:222px;'; |
| 618 | + $imageClass = 'thumbimage" width="220px'; |
| 619 | + $captionDivClass = 'thumbcaption'; |
| 620 | + $caption .= ' <a href="' . $wgUploadPath . '/graphviz/' . $storagename . '.' . $outputType . '">(+)</a>'; |
| 621 | + break; |
| 622 | + case 'frameless': |
| 623 | + $imageClass = '" width="220px'; |
| 624 | + default: // nothing specified |
| 625 | + $caption = ''; // no caption as it is defined on the wiki page |
| 626 | + } |
| 627 | + } else { |
| 628 | + $caption = ''; // no caption as it is defined on the wiki page |
615 | 629 | } |
616 | | - } else { |
617 | | - $caption = ''; // no caption as it is defined on the wiki page |
618 | | - } |
619 | 630 | |
620 | | - // Produce the basic html |
621 | | - $txt = '<map name="' . $storagename . '">' . $map . '</map>' . |
| 631 | + // Produce the basic html |
| 632 | + $txt = '<map name="' . $storagename . '">' . $map . '</map>' . |
622 | 633 | '<img class="' . $imageClass . '" style="' . $imageStyle . '"' . |
623 | 634 | 'alt="' . $alt . '" src="' . $wgUploadPath . '/graphviz/' . $storagename . '.' . $outputType . '"' . |
624 | 635 | ' usemap="#' . $storagename . '" />'; |
625 | 636 | |
626 | | - // Add necessary containers |
627 | | - if ( $caption != null ) { |
628 | | - $txt .= '<div class="' . $captionDivClass . '">' . $caption . '</div>'; |
629 | | - } |
630 | | - if ( $innerDivClass != null ) { |
631 | | - $txt = '<div class="' . $innerDivClass . '">' . $txt . '</div>'; |
632 | | - } |
633 | | - if ( $middleDivClass != null ) { |
634 | | - $txt = '<div class="' . $middleDivClass . '">' . $txt . '</div>'; |
635 | | - } |
636 | | - if ( $outerDivClass != null ) { |
637 | | - $txt = '<div class="' . $outerDivClass . '">' . $txt . '</div>'; |
638 | | - } |
| 637 | + // Add necessary containers |
| 638 | + if ( $caption != null ) { |
| 639 | + $txt .= '<div class="' . $captionDivClass . '">' . $caption . '</div>'; |
| 640 | + } |
| 641 | + if ( $innerDivClass != null ) { |
| 642 | + $txt = '<div class="' . $innerDivClass . '">' . $txt . '</div>'; |
| 643 | + } |
| 644 | + if ( $middleDivClass != null ) { |
| 645 | + $txt = '<div class="' . $middleDivClass . '">' . $txt . '</div>'; |
| 646 | + } |
| 647 | + if ( $outerDivClass != null ) { |
| 648 | + $txt = '<div class="' . $outerDivClass . '">' . $txt . '</div>'; |
| 649 | + } |
639 | 650 | |
640 | | - return $txt; |
641 | | -} |
| 651 | + return $txt; |
| 652 | + } |
642 | 653 | |