Property changes on: trunk/extensions/LiquidThreads/newmessages.js |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 1 | + native |
Property changes on: trunk/extensions/LiquidThreads/api/ApiThreadAction.php |
___________________________________________________________________ |
Name: svn:eol-style |
2 | 2 | + native |
Index: trunk/extensions/SemanticResultFormats/GraphViz/SRF_Process.php |
— | — | @@ -1,1188 +1,1188 @@ |
2 | | -<?php
|
3 | | -/*******************************************************************************
|
4 | | -* This file contains the Process Printer for SemanticResultFormats
|
5 | | -* (http://www.mediawiki.org/wiki/Extension:Semantic_Result_Formats)
|
6 | | -*
|
7 | | -* Copyright (c) 2008 - 2009 Frank Dengler and Hans-J�rg Happel
|
8 | | -*
|
9 | | -* Process Printer is free software: you can redistribute it and/or modify
|
10 | | -* it under the terms of the GNU General Public License as published by
|
11 | | -* the Free Software Foundation, either version 3 of the License, or
|
12 | | -* (at your option) any later version.
|
13 | | -*
|
14 | | -* Process Printer is distributed in the hope that it will be useful,
|
15 | | -* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 | | -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 | | -* GNU General Public License for more details.
|
18 | | -*
|
19 | | -* You should have received a copy of the GNU General Public License
|
20 | | -* along with Process Printer. If not, see <http://www.gnu.org/licenses/>.
|
21 | | -*******************************************************************************/
|
22 | | -
|
23 | | -if( !defined( 'MEDIAWIKI' ) ) {
|
24 | | - die( 'Not an entry point.' );
|
25 | | -}
|
26 | | -
|
27 | | -/**
|
28 | | - * This is a contribution to Semtantic Result Formats (SRF) which are an
|
29 | | - * extension of Semantic MediaWiki (SMW) which in turn is an extension
|
30 | | - * of MediaWiki
|
31 | | - *
|
32 | | - * SRF defines certain "printers" to render the results of SMW semantic
|
33 | | - * "ASK"-queries. Some of these printers make use of the GraphViz/dot
|
34 | | - * library (which is wrapped by a separate MediaWiki extension).
|
35 | | - *
|
36 | | - * The purpose of this extension, is to render results of ASK-Queries
|
37 | | - * (e.g. Classes with Attributes) as GraphViz-layouted process graphs
|
38 | | - *
|
39 | | - *
|
40 | | - * @author Frank Dengler
|
41 | | - * @author Hans-J�rg Happel
|
42 | | - * @ingroup SemanticResultFormats
|
43 | | - *
|
44 | | - * @note AUTOLOADED
|
45 | | - */
|
46 | | -
|
47 | | -//global variable defining picture path
|
48 | | -
|
49 | | -$srfgPicturePath = "/images/";
|
50 | | -
|
51 | | -
|
52 | | -
|
53 | | -class SRFProcess extends SMWResultPrinter {
|
54 | | -
|
55 | | - // configuration variables
|
56 | | - protected $m_graphValidation = false;
|
57 | | - protected $m_isDebugSet = false;
|
58 | | - protected $m_processCategory = 'Process'; // Category for processes - required for rendering compound nodes
|
59 | | -
|
60 | | - // internal variables
|
61 | | - protected $m_process; // process to be rendered
|
62 | | -
|
63 | | -
|
64 | | - /**
|
65 | | - * This method is called before rendering the output to push
|
66 | | - * the parameters for result formatting to the printer
|
67 | | - *
|
68 | | - * @param params array of parameters provided for the ask-query
|
69 | | - * @param outputmode ?
|
70 | | - * @return void
|
71 | | - *
|
72 | | - */
|
73 | | - protected function readParameters($params,$outputmode) {
|
74 | | -
|
75 | | - SMWResultPrinter::readParameters($params,$outputmode);
|
76 | | -
|
77 | | - // init process graph instance
|
78 | | - $this->m_process = new ProcessGraph();
|
79 | | -
|
80 | | - // process configuration
|
81 | | -
|
82 | | - if (array_key_exists('graphname', $params)) {
|
83 | | - $this->m_process->setGraphName(trim($params['graphname']));
|
84 | | - }
|
85 | | -
|
86 | | - if (array_key_exists('graphsize', $params)) {
|
87 | | - $this->m_process->setGraphSize(trim($params['graphsize']));
|
88 | | - }
|
89 | | -
|
90 | | - if (array_key_exists('clustercolor', $params)) {
|
91 | | - $this->m_process->setClusterColor(trim($params['clustercolor']));
|
92 | | - }
|
93 | | -
|
94 | | - if (array_key_exists('rankdir', $params)) {
|
95 | | - $this->m_process->setRankdir(strtoupper(trim($params['rankdir'])));
|
96 | | - }
|
97 | | -
|
98 | | - if (array_key_exists('showroles', $params)) {
|
99 | | - if (self::isTrue($params['showroles'])) $this->m_process->setShowRoles(true);
|
100 | | - }
|
101 | | -
|
102 | | - if (array_key_exists('showstatus', $params)) {
|
103 | | - if (self::isTrue($params['showstatus'])) $this->m_process->setShowStatus(true);
|
104 | | - }
|
105 | | -
|
106 | | - if (array_key_exists('showresources', $params)) {
|
107 | | - if (self::isTrue($params['showresources'])) $this->m_process->setShowRessources(true);
|
108 | | - }
|
109 | | -
|
110 | | - if (array_key_exists('highlight', $params)) {
|
111 | | - $this->m_process->setHighlightNode(trim($params['highlight']));
|
112 | | - }
|
113 | | -
|
114 | | - if (array_key_exists('highlightcolor', $params)) {
|
115 | | - $this->m_process->setHighlightColor(trim($params['highlightcolor']));
|
116 | | - }
|
117 | | -
|
118 | | - if (array_key_exists('redlinkcolor', $params)) {
|
119 | | - $this->m_process->setHighlightColor(trim($params['redlinkcolor']));
|
120 | | - }
|
121 | | -
|
122 | | - if (array_key_exists('showredlinks', $params)) {
|
123 | | - if (self::isTrue($params['showredlinks'])) $this->m_process->setShowRedLinks(true);
|
124 | | - }
|
125 | | -
|
126 | | - if (array_key_exists('showcompound', $params)) {
|
127 | | - if (self::isTrue($params['showcompound'])) $this->m_process->setShowCompound(true);
|
128 | | - }
|
129 | | -
|
130 | | - // method configuration
|
131 | | -
|
132 | | - if (array_key_exists('debug', $params)) {
|
133 | | - if (self::isTrue($params['debug'])) $this->m_isDebugSet = true;
|
134 | | - }
|
135 | | -
|
136 | | - if (array_key_exists('graphvalidation', $params)) {
|
137 | | - if (self::isTrue($params['graphvalidation'])) $this->m_graphValidation = true;
|
138 | | - }
|
139 | | -
|
140 | | - if (array_key_exists('processcat', $params)) {
|
141 | | - $this->m_processCategory = $params['processcat'];
|
142 | | - }
|
143 | | -
|
144 | | - }
|
145 | | -
|
146 | | - public static function isTrue($value){
|
147 | | - $res = false;
|
148 | | - if ((strtolower(trim($value))=='yes') || (strtolower(trim($value)) == 'true')) $res = true;
|
149 | | - return $res;
|
150 | | - }
|
151 | | -
|
152 | | -
|
153 | | - /**
|
154 | | - * This method renders the result set provided by SMW according to the printer
|
155 | | - *
|
156 | | - * @param res SMWQueryResult, result set of the ask query provided by SMW
|
157 | | - * @param outputmode ?
|
158 | | - * @returns String, rendered HTML output of this printer for the ask-query
|
159 | | - *
|
160 | | - */
|
161 | | - protected function getResultText($res, $outputmode) {
|
162 | | - global $wgContLang; // content language object
|
163 | | -
|
164 | | - //
|
165 | | - // GraphViz settings
|
166 | | - //
|
167 | | -
|
168 | | - $wgGraphVizSettings = new GraphVizSettings;
|
169 | | - $this->isHTML = true;
|
170 | | -
|
171 | | -
|
172 | | - //
|
173 | | - // Iterate all rows in result set
|
174 | | - //
|
175 | | -
|
176 | | - $row = $res->getNext(); // get initial row (i.e. array of SMWResultArray)
|
177 | | -
|
178 | | - while ( $row !== false) {
|
179 | | -
|
180 | | - $node;
|
181 | | - $cond_edge;
|
182 | | -
|
183 | | -
|
184 | | - $subject = $row[0]->getResultSubject(); // get Subject of the Result
|
185 | | - // creates a new node if $val has type wikipage
|
186 | | - if ( $subject->getTypeID() == '_wpg' ) {
|
187 | | - $val = $subject->getShortWikiText();
|
188 | | - $node = $this->m_process->makeNode($val, $val);
|
189 | | - }
|
190 | | -
|
191 | | - //
|
192 | | - // Iterate all colums of the row (which describe properties of the proces node)
|
193 | | - //
|
194 | | -
|
195 | | - foreach ($row as $field) {
|
196 | | -
|
197 | | - // check column title
|
198 | | - $req = $field->getPrintRequest();
|
199 | | - switch ((strtolower($req->getLabel()))) {
|
200 | | -
|
201 | | -
|
202 | | -
|
203 | | - case strtolower($wgContLang->getNsText(NS_CATEGORY)):
|
204 | | -
|
205 | | - foreach ($field->getContent() as $value) {
|
206 | | - $val = $value->getShortWikiText();
|
207 | | - if ($val == ($wgContLang->getNsText(NS_CATEGORY) . ':' . $this->m_processCategory)) $node->setAtomic(false);
|
208 | | - }
|
209 | | -
|
210 | | - break;
|
211 | | -
|
212 | | - case "hasrole":
|
213 | | - foreach ($field->getContent() as $value) {
|
214 | | - $val = $value->getShortWikiText();
|
215 | | - $role = $this->m_process->makeRole($val, $val);
|
216 | | - $node->addRole($role);
|
217 | | - }
|
218 | | - break;
|
219 | | -
|
220 | | - case "usesresource":
|
221 | | - foreach ($field->getContent() as $value) {
|
222 | | - $val = $value->getShortWikiText();
|
223 | | - $xres = $this->m_process->makeRessource($val, $val);
|
224 | | - $node->addUsedRessource($xres);
|
225 | | - }
|
226 | | - break;
|
227 | | -
|
228 | | - case "producesresource":
|
229 | | - foreach ($field->getContent() as $value) {
|
230 | | - $val = $value->getShortWikiText();
|
231 | | - $xres = $this->m_process->makeRessource($val, $val);
|
232 | | - $node->addProducedRessource($xres);
|
233 | | - }
|
234 | | - break;
|
235 | | -
|
236 | | - case "hassuccessor":
|
237 | | -
|
238 | | - if (count($field->getContent()) > 1){
|
239 | | -
|
240 | | - // SplitParallel
|
241 | | - $edge = new SplitParallelEdge();
|
242 | | - $edge->setFrom($node);
|
243 | | - foreach ($field->getContent() as $value) {
|
244 | | - $val = $value->getShortWikiText();
|
245 | | - $edge->addTo($this->m_process->makeNode($val, $val));
|
246 | | - }
|
247 | | -
|
248 | | - } else {
|
249 | | -
|
250 | | - // Sequence
|
251 | | - foreach ($field->getContent() as $value) {
|
252 | | - $val = $value->getShortWikiText();
|
253 | | - $edge = new SequentialEdge();
|
254 | | - $edge->setFrom($node);
|
255 | | - $edge->setTo($this->m_process->makeNode($val, $val));
|
256 | | - }
|
257 | | - }
|
258 | | -
|
259 | | - break;
|
260 | | -
|
261 | | - case "hasorsuccessor":
|
262 | | -
|
263 | | - if (count($field->getContent()) > 0){
|
264 | | -
|
265 | | - // SplitExclusiveOr
|
266 | | - $edge = new SplitExclusiveOrEdge();
|
267 | | - $edge->setFrom($node);
|
268 | | - foreach ($field->getContent() as $value) {
|
269 | | - $val = $value->getShortWikiText();
|
270 | | - $edge->addTo($this->m_process->makeNode($val, $val));
|
271 | | - }
|
272 | | - }
|
273 | | -
|
274 | | - break;
|
275 | | -
|
276 | | - case "hascontruesuccessor":
|
277 | | -
|
278 | | - if (count($field->getContent()) > 0){
|
279 | | -
|
280 | | - // SplitConditional
|
281 | | - if (!isset($cond_edge)){
|
282 | | - $cond_edge = new SplitConditionalOrEdge();
|
283 | | - $cond_edge->setFrom($node);
|
284 | | - }
|
285 | | -
|
286 | | - // should be only one
|
287 | | - foreach ($field->getContent() as $value) {
|
288 | | - $val = $value->getShortWikiText();
|
289 | | - $cond_edge->setToTrue($this->m_process->makeNode($val, $val));
|
290 | | - }
|
291 | | -
|
292 | | - }
|
293 | | -
|
294 | | - break;
|
295 | | -
|
296 | | - case "hasconfalsesuccessor":
|
297 | | -
|
298 | | - if (count($field->getContent()) > 0){
|
299 | | -
|
300 | | - // SplitConditional
|
301 | | - if (!isset($cond_edge)){
|
302 | | - $cond_edge = new SplitConditionalOrEdge();
|
303 | | - $cond_edge->setFrom($node);
|
304 | | - }
|
305 | | -
|
306 | | - // should be only one
|
307 | | - foreach ($field->getContent() as $value) {
|
308 | | - $val = $value->getShortWikiText();
|
309 | | - $cond_edge->setToFalse($this->m_process->makeNode($val, $val));
|
310 | | - }
|
311 | | - }
|
312 | | -
|
313 | | - break;
|
314 | | -
|
315 | | - case "hascondition":
|
316 | | -
|
317 | | - if (count($field->getContent()) > 0){
|
318 | | -
|
319 | | - // SplitConditional
|
320 | | - if (!isset($cond_edge)){
|
321 | | - $cond_edge = new SplitConditionalOrEdge();
|
322 | | - $cond_edge->setFrom($node);
|
323 | | - }
|
324 | | -
|
325 | | - // should be only one
|
326 | | - foreach ($field->getContent() as $value) {
|
327 | | - $val = $value->getShortWikiText();
|
328 | | - $cond_edge->setConditionText($val);
|
329 | | -
|
330 | | - }
|
331 | | - }
|
332 | | -
|
333 | | - break;
|
334 | | -
|
335 | | - case "hasstatus":
|
336 | | -
|
337 | | - // should be only one
|
338 | | - foreach ($field->getContent() as $value) {
|
339 | | - $val = $value->getShortWikiText();
|
340 | | - $node->setStatus($val);
|
341 | | - }
|
342 | | -
|
343 | | - break;
|
344 | | -
|
345 | | - default:
|
346 | | -
|
347 | | - // TODO - redundant column in result
|
348 | | -
|
349 | | - }
|
350 | | - }
|
351 | | -
|
352 | | - // reset row variables
|
353 | | - unset($node);
|
354 | | - unset($cond_edge);
|
355 | | -
|
356 | | - $row = $res->getNext(); // switch to next row
|
357 | | - }
|
358 | | -
|
359 | | - //
|
360 | | - // generate graphInput
|
361 | | - //
|
362 | | - $graphInput = $this->m_process->getGraphVizCode();
|
363 | | -
|
364 | | - //
|
365 | | - // render graphViz code
|
366 | | - //
|
367 | | - $result = renderGraphviz($graphInput);
|
368 | | -
|
369 | | - $debug = '';
|
370 | | - if ($this->m_isDebugSet) $debug = '<pre>' . $graphInput . '</pre>';
|
371 | | -
|
372 | | - return $result . $debug;;
|
373 | | -
|
374 | | -
|
375 | | - }
|
376 | | -}
|
377 | | -
|
378 | | -/**
|
379 | | - * Class representing a process graph
|
380 | | - */
|
381 | | -class ProcessGraph{
|
382 | | -
|
383 | | - // configuration variables
|
384 | | - protected $m_graphName = '';
|
385 | | - protected $m_rankdir = 'TB';
|
386 | | - protected $m_graphSize = '';
|
387 | | - protected $m_clusterColor = 'lightgrey';
|
388 | | - protected $m_showStatus = false; // should status be rendered?
|
389 | | - protected $m_showRoles = false; // should roles be rendered?
|
390 | | - protected $m_showRessources = false; // should ressources be rendered?
|
391 | | - protected $m_highlightNode = ''; // node to be highlighted
|
392 | | - protected $m_highlightColor = 'blue'; // highlight font color
|
393 | | - protected $m_showRedLinks = false; // check and highlight red links?
|
394 | | - protected $m_redLinkColor = 'red'; // red link font color
|
395 | | - protected $m_showCompound = true; // highlight compound nodes (=subprocesses)
|
396 | | -
|
397 | | - // instance variables
|
398 | | - protected $m_nodes = array(); // list of all nodes
|
399 | | - protected $m_startnodes = array(); // list of start nodes
|
400 | | - protected $m_endnodes = array(); // list of end nodes
|
401 | | - protected $m_ressources = array(); // list of ressources
|
402 | | - protected $m_roles = array(); // list of roles
|
403 | | - protected $m_errors = array(); // list of errors
|
404 | | -
|
405 | | -
|
406 | | - /**
|
407 | | - * This method should be used for getting new or existing nodes
|
408 | | - * If a node does not exist yet, it will be created
|
409 | | - *
|
410 | | - * @param $id string, node id
|
411 | | - * @param $label string, node label
|
412 | | - * @return Object of type ProcessNode
|
413 | | - */
|
414 | | - public function makeNode($id, $label){
|
415 | | - $node;
|
416 | | -
|
417 | | - // check if node exists
|
418 | | - if (isset($this->m_nodes[$id])){
|
419 | | - // take existing node
|
420 | | - $node = $this->m_nodes[$id];
|
421 | | -
|
422 | | - } else {
|
423 | | - // create new node
|
424 | | -
|
425 | | - $node = new ProcessNode();
|
426 | | - $node->setId($id);
|
427 | | - $node->setLabel($label);
|
428 | | - $node->setProcess($this);
|
429 | | -
|
430 | | - // is actual node name the same like the one to highlight?
|
431 | | - if (strcasecmp($id , $this->m_highlightNode) == 0){
|
432 | | - $node->setFontColor($this->m_highlightColor);
|
433 | | - }
|
434 | | -
|
435 | | - // is the node a red link (i.e. corresponding wiki page does not yet exist)?
|
436 | | - if ($this->m_showRedLinks){
|
437 | | - $title = new Title();
|
438 | | - $title = $title->newFromDBkey($id);
|
439 | | - if (isset($title) && (!$title->exists())) $node->setFontColor($this->m_redLinkColor);
|
440 | | - }
|
441 | | -
|
442 | | - // add new node to process
|
443 | | - $this->m_nodes[$id] = $node;
|
444 | | - }
|
445 | | -
|
446 | | - return $node;
|
447 | | -
|
448 | | - }
|
449 | | -
|
450 | | - public function makeRole($id, $label){
|
451 | | - $role;
|
452 | | -
|
453 | | - // check if role exists
|
454 | | - if (isset($this->m_roles[$id])){
|
455 | | - // take existing roles
|
456 | | - $role = $this->m_roles[$id];
|
457 | | -
|
458 | | - } else {
|
459 | | - $role = new ProcessRole();
|
460 | | - $role->setId($id);
|
461 | | - $role->setLabel($label);
|
462 | | -
|
463 | | - // add new role to process
|
464 | | - $this->m_roles[$id] = $role;
|
465 | | - }
|
466 | | -
|
467 | | - return $role;
|
468 | | -
|
469 | | - }
|
470 | | -
|
471 | | - public function makeRessource($id, $label){
|
472 | | - $res;
|
473 | | -
|
474 | | - // check if res exists
|
475 | | - if (isset($this->m_ressources[$id])){
|
476 | | - // take existing res
|
477 | | - $res = $this->m_ressources[$id];
|
478 | | -
|
479 | | - } else {
|
480 | | - $res = new ProcessRessource();
|
481 | | - $res->setId($id);
|
482 | | - $res->setLabel($label);
|
483 | | -
|
484 | | - // add new res to process
|
485 | | - $this->m_ressources[$id] = $res;
|
486 | | -
|
487 | | - }
|
488 | | -
|
489 | | - return $res;
|
490 | | -
|
491 | | - }
|
492 | | -
|
493 | | - public function getEndNodes(){
|
494 | | - if (count($this->m_endnodes) == 0){
|
495 | | - foreach($this->m_nodes as $node){
|
496 | | - if (count($node->getSucc()) == 0) $this->m_endnodes[] = $node;
|
497 | | - }
|
498 | | - }
|
499 | | -
|
500 | | - return $this->m_endnodes;
|
501 | | - }
|
502 | | -
|
503 | | - public function getStartNodes(){
|
504 | | -
|
505 | | - if (count($this->m_startnodes) == 0){
|
506 | | - foreach($this->m_nodes as $node){
|
507 | | - if (count($node->getPred()) == 0){
|
508 | | - $this->m_startnodes[] = $node;
|
509 | | - }
|
510 | | - }
|
511 | | - }
|
512 | | -
|
513 | | - return $this->m_startnodes;
|
514 | | - }
|
515 | | -
|
516 | | - public function setShowStatus($show){
|
517 | | - $this->m_showStatus = $show;
|
518 | | - }
|
519 | | -
|
520 | | - public function getShowStatus(){
|
521 | | - return $this->m_showStatus;
|
522 | | - }
|
523 | | -
|
524 | | - public function setShowRoles($show){
|
525 | | - $this->m_showRoles = $show;
|
526 | | - }
|
527 | | -
|
528 | | - public function getShowRoles(){
|
529 | | - return $this->m_showRoles;
|
530 | | - }
|
531 | | -
|
532 | | - public function setShowCompound($show){
|
533 | | - $this->m_showCompound = $show;
|
534 | | - }
|
535 | | -
|
536 | | - public function getShowCompound(){
|
537 | | - return $this->m_showCompound;
|
538 | | - }
|
539 | | -
|
540 | | - public function setShowRessources($show){
|
541 | | - $this->m_showRessources = $show;
|
542 | | - }
|
543 | | -
|
544 | | - public function getShowRessources(){
|
545 | | - return $this->m_showRessources;
|
546 | | - }
|
547 | | -
|
548 | | - public function setGraphName($name){
|
549 | | - $this->m_graphName = $name;
|
550 | | - }
|
551 | | -
|
552 | | - public function getGraphName(){
|
553 | | - if ($this->m_graphName == '') $this->m_graphName = 'ProcessQueryResult' . rand(1, 99999);
|
554 | | - return $this->m_graphName;
|
555 | | - }
|
556 | | -
|
557 | | - public function setGraphSize($size){
|
558 | | - $this->m_graphSize = $size;
|
559 | | - }
|
560 | | -
|
561 | | - public function setRankdir($rankdir){
|
562 | | - $this->m_rankdir = $rankdir;
|
563 | | - }
|
564 | | -
|
565 | | - public function setClusterColor($color){
|
566 | | - $this->m_clusterColor = $color;
|
567 | | - }
|
568 | | -
|
569 | | - public function setHighlightColor($color){
|
570 | | - $this->m_highlightColor = $color;
|
571 | | - }
|
572 | | -
|
573 | | - public function setRedLinkColor($color){
|
574 | | - $this->m_redLinkColor = $color;
|
575 | | - }
|
576 | | -
|
577 | | - public function setShowRedLinks($show){
|
578 | | - $this->m_showRedLinks = $show;
|
579 | | - }
|
580 | | -
|
581 | | - public function setHighlightNode($name){
|
582 | | - $this->m_highlightNode = $name;
|
583 | | - }
|
584 | | -
|
585 | | - public function addError($error){
|
586 | | - $this->m_errors[] = $error;
|
587 | | - }
|
588 | | -
|
589 | | - public function getErrors(){
|
590 | | - return $this->m_errors;
|
591 | | - }
|
592 | | -
|
593 | | - public function getGraphVizCode(){
|
594 | | - //
|
595 | | - // header
|
596 | | - //
|
597 | | - $res = 'digraph ' . $this->getGraphName() .' {
|
598 | | -
|
599 | | - ranksep="0.5";';
|
600 | | - if ($this->m_graphSize != '') $res .='
|
601 | | - size="'. $this->m_graphSize . '";';
|
602 | | - $res .='
|
603 | | - rankdir=' . $this->m_rankdir . ';
|
604 | | - ';
|
605 | | -
|
606 | | - //
|
607 | | - // add startnodes
|
608 | | - //
|
609 | | - // TODO I18N
|
610 | | - $res .='
|
611 | | - {rank=source; "Start";}
|
612 | | - "Start"[shape=box,label="Start",style=filled,color=green];';
|
613 | | -
|
614 | | - foreach ($this->getStartNodes() as $node){
|
615 | | - $res .= '
|
616 | | - "Start" -> "' . $node->getId() . '";';
|
617 | | - }
|
618 | | -
|
619 | | - $res .= '
|
620 | | - ';
|
621 | | -
|
622 | | - //
|
623 | | - // add endnodes
|
624 | | - //
|
625 | | - // TODO I18N
|
626 | | - $res .= '
|
627 | | - {rank=sink; "End"; }
|
628 | | - "End"[shape=box,label="End",style=filled,color=green];';
|
629 | | -
|
630 | | - foreach ($this->getEndNodes() as $node){
|
631 | | - $res .= '
|
632 | | - "' . $node->getId() . '" -> "End";';
|
633 | | - }
|
634 | | -
|
635 | | - $res .= '
|
636 | | -
|
637 | | - ';
|
638 | | -
|
639 | | - //
|
640 | | - // add subnodes
|
641 | | - //
|
642 | | - foreach($this->m_nodes as $node){
|
643 | | - $res .= $node->getGraphVizCode();
|
644 | | - }
|
645 | | -
|
646 | | - //
|
647 | | - // add final stuff
|
648 | | - //
|
649 | | - $res .=
|
650 | | - '
|
651 | | - }';
|
652 | | -
|
653 | | - return $res;
|
654 | | -
|
655 | | - }
|
656 | | -
|
657 | | -}
|
658 | | -
|
659 | | -abstract class ProcessElement{
|
660 | | -
|
661 | | - // TODO I18N
|
662 | | - private $m_id = 'no_id';
|
663 | | - private $m_label = 'unlabeled';
|
664 | | -
|
665 | | - public function getId(){
|
666 | | - return $this->m_id;
|
667 | | - }
|
668 | | -
|
669 | | - public function setId($id){
|
670 | | - $this->m_id = $id;
|
671 | | - }
|
672 | | -
|
673 | | - public function getLabel(){
|
674 | | - return $this->m_label;
|
675 | | - }
|
676 | | -
|
677 | | - public function setLabel($label){
|
678 | | - $this->m_label = $label;
|
679 | | - }
|
680 | | -
|
681 | | -}
|
682 | | -
|
683 | | -class ProcessRessource extends ProcessElement{
|
684 | | -
|
685 | | - private $m_usedby = array();
|
686 | | - private $m_producedby = array();
|
687 | | -
|
688 | | - public function getProducers(){
|
689 | | - return $this->m_producedby;
|
690 | | - }
|
691 | | -
|
692 | | - public function getUsers(){
|
693 | | - return $this->m_usedby;
|
694 | | - }
|
695 | | -
|
696 | | - public function addProducer($node){
|
697 | | - $this->m_producedby[] = $node;
|
698 | | - }
|
699 | | -
|
700 | | - public function addUser($node){
|
701 | | - $this->m_usedby[] = $node;
|
702 | | - }
|
703 | | -
|
704 | | -}
|
705 | | -
|
706 | | -class ProcessRole extends ProcessElement{
|
707 | | -
|
708 | | - private $m_nodes = array();
|
709 | | -
|
710 | | - public function getNodes(){
|
711 | | - return $this->m_nodes;
|
712 | | - }
|
713 | | -
|
714 | | - public function addNode($node){
|
715 | | - $this->m_nodes[] = $node;
|
716 | | - }
|
717 | | -
|
718 | | -}
|
719 | | -
|
720 | | -/**
|
721 | | - * Class reperesning a process node
|
722 | | - */
|
723 | | -class ProcessNode extends ProcessElement{
|
724 | | -
|
725 | | - private $m_is_startnode = false; // explicit statement if this is a start node
|
726 | | - private $m_is_endnode = false; // explicit statement if this is a termination node
|
727 | | - private $m_status; // status value
|
728 | | - private $m_is_atomic = true; // set false if this is a compound node
|
729 | | -
|
730 | | - private $m_process; // reference to parent process
|
731 | | -
|
732 | | - private $m_fontColor = ''; // font color to render
|
733 | | -
|
734 | | - private $m_usedressources = array(); // ressources used by this node
|
735 | | - private $m_producedressources = array(); // ressources produces by this node
|
736 | | - private $m_roles = array(); // roles related to this node
|
737 | | -
|
738 | | - private $m_edgeout; // outgoing edge (can be only one)
|
739 | | - private $m_edgesin = array(); // incoming edges (can be many)
|
740 | | -
|
741 | | - public function setStatus($status){
|
742 | | - $this->m_status = $status;
|
743 | | - }
|
744 | | -
|
745 | | - public function getStatus(){
|
746 | | - return $this->m_status;
|
747 | | - }
|
748 | | -
|
749 | | - public function setFontColor($color){
|
750 | | - $this->m_fontColor = $color;
|
751 | | - }
|
752 | | -
|
753 | | - public function setProcess($proc){
|
754 | | - $this->m_process = $proc;
|
755 | | - }
|
756 | | -
|
757 | | - public function getProcess(){
|
758 | | - return $this->m_process;
|
759 | | - }
|
760 | | -
|
761 | | - public function getPred(){
|
762 | | - $res = array();
|
763 | | -
|
764 | | - foreach ($this->m_edgesin as $edge){
|
765 | | - $res = array_merge($res, $edge->getPred());
|
766 | | - }
|
767 | | -
|
768 | | - return $res;
|
769 | | - }
|
770 | | -
|
771 | | - public function getSucc(){
|
772 | | - $res = array();
|
773 | | -
|
774 | | - if (isset($this->m_edgeout)){
|
775 | | - $res = $this->m_edgeout->getSucc();
|
776 | | - }
|
777 | | -
|
778 | | - return $res;
|
779 | | - }
|
780 | | -
|
781 | | - public function setEdgeOut($edge){
|
782 | | - $this->m_edgeout = $edge;
|
783 | | - }
|
784 | | -
|
785 | | - public function getEdgeOut(){
|
786 | | - return $this->m_edgeout;
|
787 | | - }
|
788 | | -
|
789 | | - public function addEdgeIn($edge){
|
790 | | - $this->m_edgesin[] = $edge;
|
791 | | - }
|
792 | | -
|
793 | | - public function getEdgesIn(){
|
794 | | - return $this->m_edgesin;
|
795 | | - }
|
796 | | -
|
797 | | - public function addRole($role){
|
798 | | - $this->m_roles[] = $role;
|
799 | | - $role->addNode($this);
|
800 | | - }
|
801 | | -
|
802 | | - public function getRoles(){
|
803 | | - return $this->m_roles;
|
804 | | - }
|
805 | | -
|
806 | | - public function addUsedRessource($res){
|
807 | | - $this->m_usedressources[] = $res;
|
808 | | - $res->addUser($this);
|
809 | | - }
|
810 | | -
|
811 | | - public function getUsedRessources(){
|
812 | | - return $this->m_usedressources;
|
813 | | - }
|
814 | | -
|
815 | | - public function addProducedRessource($res){
|
816 | | - $this->m_producedressources[] = $res;
|
817 | | - $res->addProducer($this);
|
818 | | - }
|
819 | | -
|
820 | | - public function getProducedRessources(){
|
821 | | - return $this->m_producedressources;
|
822 | | - }
|
823 | | -
|
824 | | - public function isAtomic(){
|
825 | | - return $this->m_is_atomic;
|
826 | | - }
|
827 | | -
|
828 | | - public function setAtomic($atomic){
|
829 | | - $this->m_is_atomic = $atomic;
|
830 | | - }
|
831 | | -
|
832 | | - public function getGraphVizCode(){
|
833 | | - global $IP, $srfgPicturePath, $srfgIP;
|
834 | | - //
|
835 | | - // show node status
|
836 | | - //
|
837 | | - $status = '';
|
838 | | - if ($this->getProcess()->getShowStatus()){
|
839 | | -
|
840 | | - if (file_exists($IP . "/images/p000.png")) {
|
841 | | - $PicturePath = $IP . "/images/";
|
842 | | - } elseif (file_exists($srfgIP . "/GraphViz/images/p000.png")) {
|
843 | | - $PicturePath = $srfgIP . "/GraphViz/images/";
|
844 | | - } else {
|
845 | | - $PicturePath = $IP . $srfgPicturePath;
|
846 | | - }
|
847 | | - //$color = 'grey' . $this->getStatus();
|
848 | | - //$color = 'grey' . rand(1, 100);
|
849 | | - //$status = ',style=filled,color=' . $color;
|
850 | | - if ($this->getStatus() != ''){
|
851 | | - if ($this->getStatus() < 25){
|
852 | | - $status = ',image="'. $PicturePath .'p000.png"';
|
853 | | - } else if ($this->getStatus() < 50){
|
854 | | - $status = ',image="'. $PicturePath .'p025.png"';
|
855 | | - } else if ($this->getStatus() < 75){
|
856 | | - $status = ',image="'. $PicturePath .'p050.png"';
|
857 | | - } else if ($this->getStatus() < 100){
|
858 | | - $status = ',image="'. $PicturePath .'p075.png"';
|
859 | | - } else if ($this->getStatus() == 100){
|
860 | | - $status = ',image="' . $PicturePath .'p100.png"';
|
861 | | - }
|
862 | | - }
|
863 | | -
|
864 | | - }
|
865 | | -
|
866 | | - // use highlight color if set (either CURRENTPAGE or REDLINK highlighting - see ProcessGraph::makeNode()
|
867 | | - $high = '';
|
868 | | - if( $this->m_fontColor != '') {
|
869 | | - $high = ',fontcolor=' . $this->m_fontColor;
|
870 | | - }
|
871 | | -
|
872 | | - // make double circle for non-atomic nodes (i.e. subprocesses)
|
873 | | - $compound = '';
|
874 | | - if ($this->getProcess()->getShowCompound() && !$this->isAtomic()) $compound = ',penwidth=2.0';
|
875 | | -
|
876 | | -
|
877 | | - //
|
878 | | - // render node itself
|
879 | | - //
|
880 | | - $res =
|
881 | | - '"' . $this->getId() . '" [URL="[[' . $this->getId() . ']]",label="' . $this->getLabel() . '"' . $status . $high . $compound . '];
|
882 | | - ';
|
883 | | -
|
884 | | - //
|
885 | | - // render outgoing node
|
886 | | - //
|
887 | | - if (isset($this->m_edgeout)) $res .= $this->m_edgeout->getGraphVizCode();
|
888 | | -
|
889 | | -
|
890 | | - //
|
891 | | - // show cluster for roles and ressources
|
892 | | - //
|
893 | | - $rrcluster = false;
|
894 | | - $rrcode = 'subgraph "cluster_role' . rand(1,9999) . '" { style=filled;color=lightgrey;';
|
895 | | -
|
896 | | - // show roles
|
897 | | - if ($this->getProcess()->getShowRoles()){
|
898 | | -
|
899 | | - foreach ($this->getRoles() as $role){
|
900 | | - $rrcluster = true;
|
901 | | - $rrcode .= '
|
902 | | - "' . $role->getId() . '"[label="' . $role->getLabel() . '",shape=doubleoctagon, color=red, URL="[[' . $role->getId() . ']]"];
|
903 | | - "' . $role->getId() . '" -> "' . $this->getId() . '" [color=red,arrowhead = none,constraint=false];
|
904 | | - ';
|
905 | | -
|
906 | | - }
|
907 | | - }
|
908 | | -
|
909 | | - if ($this->getProcess()->getShowRessources()){
|
910 | | -
|
911 | | - foreach ($this->getUsedRessources() as $xres){
|
912 | | - $rrcluster = true;
|
913 | | - $rrcode .= '
|
914 | | - "' . $xres->getId() . '"[label="' . $xres->getLabel() . '",shape=folder, color=blue, URL="[[' . $xres->getId() . ']]"];
|
915 | | - "' . $xres->getId() . '" -> "' . $this->getId() . '" [color=blue,constraint=false];
|
916 | | - ';
|
917 | | - }
|
918 | | -
|
919 | | - foreach ($this->getProducedRessources() as $xres){
|
920 | | - $rrcluster = true;
|
921 | | - $rrcode .= '
|
922 | | - "' . $xres->getId() . '"[label="' . $xres->getLabel() . '",shape=folder, color=blue, URL="[[' . $xres->getId() . ']]"];
|
923 | | - "' . $this->getId() . '" -> "' . $xres->getId() . '" [color=blue,constraint=false];
|
924 | | - ';
|
925 | | - }
|
926 | | -
|
927 | | - }
|
928 | | -
|
929 | | - if ($rrcluster) $res .= $rrcode . '}';
|
930 | | -
|
931 | | - $res .= '
|
932 | | - ';
|
933 | | -
|
934 | | - return $res;
|
935 | | - }
|
936 | | -
|
937 | | -}
|
938 | | -
|
939 | | -/**
|
940 | | - * Abstract base class for edges in a process graph
|
941 | | - */
|
942 | | -abstract class ProcessEdge{
|
943 | | -
|
944 | | - private $m_id;
|
945 | | -
|
946 | | - public function getId(){
|
947 | | - if (!isset($this->m_id)){
|
948 | | - $this->m_id = 'edge' . rand(1, 99999);
|
949 | | - }
|
950 | | -
|
951 | | - return $this->m_id;
|
952 | | - }
|
953 | | -
|
954 | | - abstract public function getSucc();
|
955 | | - abstract public function getPred();
|
956 | | -
|
957 | | - abstract public function getGraphVizCode();
|
958 | | -}
|
959 | | -
|
960 | | -abstract class SplitEdge extends ProcessEdge{
|
961 | | -
|
962 | | - protected $m_from;
|
963 | | - protected $m_to = array();
|
964 | | -
|
965 | | - public function setFrom($node){
|
966 | | - $this->m_from = $node;
|
967 | | - $node->setEdgeOut($this);
|
968 | | - }
|
969 | | -
|
970 | | - public function addTo($node){
|
971 | | - $this->m_to[] = $node;
|
972 | | - $node->addEdgeIn($this);
|
973 | | - }
|
974 | | -
|
975 | | - public function getPred(){
|
976 | | - return array($this->m_from);
|
977 | | - }
|
978 | | -
|
979 | | - public function getSucc(){
|
980 | | - return $this->m_to;
|
981 | | - }
|
982 | | -
|
983 | | -}
|
984 | | -
|
985 | | -class SplitConditionalOrEdge extends ProcessEdge{
|
986 | | -
|
987 | | - protected $m_from;
|
988 | | - protected $m_to_true;
|
989 | | - protected $m_to_false;
|
990 | | - protected $m_con_text = 'empty_condition';
|
991 | | -
|
992 | | - public function getSucc(){
|
993 | | - return array($this->m_to_false, $this->m_to_true);
|
994 | | - }
|
995 | | -
|
996 | | - public function getPred(){
|
997 | | - return array($this->m_from);
|
998 | | - }
|
999 | | -
|
1000 | | - public function setFrom($node){
|
1001 | | - $this->m_from = $node;
|
1002 | | - $node->setEdgeOut($this);
|
1003 | | - }
|
1004 | | -
|
1005 | | - public function setToFalse($node){
|
1006 | | - $this->m_to_false = $node;
|
1007 | | - $node->addEdgeIn($this);
|
1008 | | - }
|
1009 | | -
|
1010 | | - public function setToTrue($node){
|
1011 | | - $this->m_to_true = $node;
|
1012 | | - $node->addEdgeIn($this);
|
1013 | | - }
|
1014 | | -
|
1015 | | - public function setConditionText($cond){
|
1016 | | - $this->m_con_text = $cond;
|
1017 | | - }
|
1018 | | -
|
1019 | | - public function getGraphVizCode(){
|
1020 | | -
|
1021 | | - $p = $this->m_from;
|
1022 | | -
|
1023 | | - if ((!isset($this->m_from)) || (!isset($this->m_to_false)) || (!isset($this->m_to_true))){
|
1024 | | -
|
1025 | | - echo "error with SplitConditionalOrEdge"; // TODO
|
1026 | | - exit;
|
1027 | | - }
|
1028 | | -
|
1029 | | -
|
1030 | | - $res =
|
1031 | | - 'subgraph "clus_' . $this->getId() . '" { ;
|
1032 | | - ';
|
1033 | | -
|
1034 | | - // cond-Shape
|
1035 | | - $con = 'con' . rand(1, 99999);
|
1036 | | - $res .=
|
1037 | | - '"'. $con . '"[shape=diamond,label="' . $this->m_con_text . '",style=filled,color=skyblue];
|
1038 | | - "' . $p->getId() . '" -> "'. $con . '";
|
1039 | | - ';
|
1040 | | -
|
1041 | | - // True Succ
|
1042 | | - $res .=
|
1043 | | - '"' . $this->m_to_true->getId() . '" [URL = "[['. $this->m_to_true->getId() . ']]"];
|
1044 | | - ';
|
1045 | | -
|
1046 | | - $res .=
|
1047 | | - '"'. $con .'" -> "' . $this->m_to_true->getId() .'" [label="true"];
|
1048 | | - ';
|
1049 | | -
|
1050 | | - // False Succ
|
1051 | | - $res .=
|
1052 | | - '"' . $this->m_to_false->getId() . '" [URL = "[['. $this->m_to_false->getId() . ']]"];
|
1053 | | - ';
|
1054 | | -
|
1055 | | - $res .=
|
1056 | | - '"'. $con .'" -> "' . $this->m_to_false->getId() .'" [label="false"];';
|
1057 | | -
|
1058 | | -
|
1059 | | - $res .= '
|
1060 | | - }
|
1061 | | - ';
|
1062 | | -
|
1063 | | - return $res;
|
1064 | | - }
|
1065 | | -
|
1066 | | -}
|
1067 | | -
|
1068 | | -class SplitExclusiveOrEdge extends SplitEdge{
|
1069 | | -
|
1070 | | - public function getGraphVizCode(){
|
1071 | | -
|
1072 | | - $p = $this->getPred();
|
1073 | | - $p = $p[0];
|
1074 | | -
|
1075 | | - $res =
|
1076 | | - 'subgraph "clus_' . $this->getId() . '" { ;
|
1077 | | - ';
|
1078 | | -
|
1079 | | - // add OR-Shape
|
1080 | | - $orx = 'or' . rand(1, 99999);
|
1081 | | - $res .=
|
1082 | | - '"'. $orx . '"[shape=box,label="+",style=filled,color=gold];
|
1083 | | - "' . $p->getId() . '" -> "'. $orx . '";
|
1084 | | - ';
|
1085 | | -
|
1086 | | - foreach ($this->getSucc() as $s){
|
1087 | | - $res .=
|
1088 | | - '"' . $s->getId() . '" [URL="[['. $s->getId() . ']]"];
|
1089 | | - ';
|
1090 | | -
|
1091 | | - $res .=
|
1092 | | - '"'. $orx .'" -> "' . $s->getId() .'";
|
1093 | | - ';
|
1094 | | - }
|
1095 | | -
|
1096 | | - $res .= '
|
1097 | | - }
|
1098 | | - ';
|
1099 | | -
|
1100 | | - return $res;
|
1101 | | - }
|
1102 | | -
|
1103 | | -}
|
1104 | | -
|
1105 | | -class SplitParallelEdge extends SplitEdge{
|
1106 | | -
|
1107 | | -
|
1108 | | - public function getGraphVizCode(){
|
1109 | | -
|
1110 | | - $p = $this->getPred();
|
1111 | | - $p = $p[0];
|
1112 | | -
|
1113 | | - $res =
|
1114 | | - 'subgraph "clus_' . $this->getId() . '" { ;
|
1115 | | - ';
|
1116 | | -
|
1117 | | - // add AND-Shape
|
1118 | | - $and = 'and' . rand(1, 99999);
|
1119 | | - $res .=
|
1120 | | - '"'. $and . '"[shape=box,label="||",style=filled,color=palegreen];
|
1121 | | - "' . $p->getId() . '" -> "'. $and . '";
|
1122 | | - ';
|
1123 | | -
|
1124 | | - foreach ($this->getSucc() as $s){
|
1125 | | - $res .=
|
1126 | | - '"' . $s->getId() . '" [URL = "[['. $s->getId() . ']]"];
|
1127 | | - ';
|
1128 | | -
|
1129 | | - $res .=
|
1130 | | - '"'. $and .'" -> "' . $s->getId() .'";
|
1131 | | - ';
|
1132 | | - }
|
1133 | | -
|
1134 | | - $res .= '
|
1135 | | - }
|
1136 | | - ';
|
1137 | | -
|
1138 | | - return $res;
|
1139 | | - }
|
1140 | | -
|
1141 | | -}
|
1142 | | -
|
1143 | | -class SequentialEdge extends ProcessEdge{
|
1144 | | -
|
1145 | | - private $m_from;
|
1146 | | - private $m_to;
|
1147 | | -
|
1148 | | - public function setFrom($node){
|
1149 | | - $this->m_from = $node;
|
1150 | | - $node->setEdgeOut($this);
|
1151 | | - }
|
1152 | | -
|
1153 | | - public function setTo($node){
|
1154 | | - $this->m_to = $node;
|
1155 | | - $node->addEdgeIn($this);
|
1156 | | - }
|
1157 | | -
|
1158 | | - public function getPred(){
|
1159 | | - return array($this->m_from);
|
1160 | | - }
|
1161 | | -
|
1162 | | - public function getSucc(){
|
1163 | | - return array($this->m_to);
|
1164 | | - }
|
1165 | | -
|
1166 | | - public function getGraphVizCode(){
|
1167 | | -
|
1168 | | - $p = $this->m_from;
|
1169 | | - $s = $this->m_to;
|
1170 | | -
|
1171 | | - $res =
|
1172 | | - 'subgraph "clus_' . $this->getId() . '" { ;
|
1173 | | - ';
|
1174 | | -
|
1175 | | - $res .=
|
1176 | | - '"' . $s->getId() . '" [URL = "[['. $s->getId() . ']]"];
|
1177 | | - ';
|
1178 | | -
|
1179 | | - $res .=
|
1180 | | - '"'. $p->getId() .'" -> "' . $s->getId() .'";';
|
1181 | | -
|
1182 | | - $res .= '
|
1183 | | - }
|
1184 | | - ';
|
1185 | | -
|
1186 | | - return $res;
|
1187 | | - }
|
1188 | | -
|
1189 | | -}
|
| 2 | +<?php |
| 3 | +/******************************************************************************* |
| 4 | +* This file contains the Process Printer for SemanticResultFormats |
| 5 | +* (http://www.mediawiki.org/wiki/Extension:Semantic_Result_Formats) |
| 6 | +* |
| 7 | +* Copyright (c) 2008 - 2009 Frank Dengler and Hans-J�rg Happel |
| 8 | +* |
| 9 | +* Process Printer is free software: you can redistribute it and/or modify |
| 10 | +* it under the terms of the GNU General Public License as published by |
| 11 | +* the Free Software Foundation, either version 3 of the License, or |
| 12 | +* (at your option) any later version. |
| 13 | +* |
| 14 | +* Process Printer is distributed in the hope that it will be useful, |
| 15 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | +* GNU General Public License for more details. |
| 18 | +* |
| 19 | +* You should have received a copy of the GNU General Public License |
| 20 | +* along with Process Printer. If not, see <http://www.gnu.org/licenses/>. |
| 21 | +*******************************************************************************/ |
| 22 | + |
| 23 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 24 | + die( 'Not an entry point.' ); |
| 25 | +} |
| 26 | + |
| 27 | +/** |
| 28 | + * This is a contribution to Semtantic Result Formats (SRF) which are an |
| 29 | + * extension of Semantic MediaWiki (SMW) which in turn is an extension |
| 30 | + * of MediaWiki |
| 31 | + * |
| 32 | + * SRF defines certain "printers" to render the results of SMW semantic |
| 33 | + * "ASK"-queries. Some of these printers make use of the GraphViz/dot |
| 34 | + * library (which is wrapped by a separate MediaWiki extension). |
| 35 | + * |
| 36 | + * The purpose of this extension, is to render results of ASK-Queries |
| 37 | + * (e.g. Classes with Attributes) as GraphViz-layouted process graphs |
| 38 | + * |
| 39 | + * |
| 40 | + * @author Frank Dengler |
| 41 | + * @author Hans-J�rg Happel |
| 42 | + * @ingroup SemanticResultFormats |
| 43 | + * |
| 44 | + * @note AUTOLOADED |
| 45 | + */ |
| 46 | + |
| 47 | +//global variable defining picture path |
| 48 | + |
| 49 | +$srfgPicturePath = "/images/"; |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +class SRFProcess extends SMWResultPrinter { |
| 54 | + |
| 55 | + // configuration variables |
| 56 | + protected $m_graphValidation = false; |
| 57 | + protected $m_isDebugSet = false; |
| 58 | + protected $m_processCategory = 'Process'; // Category for processes - required for rendering compound nodes |
| 59 | + |
| 60 | + // internal variables |
| 61 | + protected $m_process; // process to be rendered |
| 62 | + |
| 63 | + |
| 64 | + /** |
| 65 | + * This method is called before rendering the output to push |
| 66 | + * the parameters for result formatting to the printer |
| 67 | + * |
| 68 | + * @param params array of parameters provided for the ask-query |
| 69 | + * @param outputmode ? |
| 70 | + * @return void |
| 71 | + * |
| 72 | + */ |
| 73 | + protected function readParameters($params,$outputmode) { |
| 74 | + |
| 75 | + SMWResultPrinter::readParameters($params,$outputmode); |
| 76 | + |
| 77 | + // init process graph instance |
| 78 | + $this->m_process = new ProcessGraph(); |
| 79 | + |
| 80 | + // process configuration |
| 81 | + |
| 82 | + if (array_key_exists('graphname', $params)) { |
| 83 | + $this->m_process->setGraphName(trim($params['graphname'])); |
| 84 | + } |
| 85 | + |
| 86 | + if (array_key_exists('graphsize', $params)) { |
| 87 | + $this->m_process->setGraphSize(trim($params['graphsize'])); |
| 88 | + } |
| 89 | + |
| 90 | + if (array_key_exists('clustercolor', $params)) { |
| 91 | + $this->m_process->setClusterColor(trim($params['clustercolor'])); |
| 92 | + } |
| 93 | + |
| 94 | + if (array_key_exists('rankdir', $params)) { |
| 95 | + $this->m_process->setRankdir(strtoupper(trim($params['rankdir']))); |
| 96 | + } |
| 97 | + |
| 98 | + if (array_key_exists('showroles', $params)) { |
| 99 | + if (self::isTrue($params['showroles'])) $this->m_process->setShowRoles(true); |
| 100 | + } |
| 101 | + |
| 102 | + if (array_key_exists('showstatus', $params)) { |
| 103 | + if (self::isTrue($params['showstatus'])) $this->m_process->setShowStatus(true); |
| 104 | + } |
| 105 | + |
| 106 | + if (array_key_exists('showresources', $params)) { |
| 107 | + if (self::isTrue($params['showresources'])) $this->m_process->setShowRessources(true); |
| 108 | + } |
| 109 | + |
| 110 | + if (array_key_exists('highlight', $params)) { |
| 111 | + $this->m_process->setHighlightNode(trim($params['highlight'])); |
| 112 | + } |
| 113 | + |
| 114 | + if (array_key_exists('highlightcolor', $params)) { |
| 115 | + $this->m_process->setHighlightColor(trim($params['highlightcolor'])); |
| 116 | + } |
| 117 | + |
| 118 | + if (array_key_exists('redlinkcolor', $params)) { |
| 119 | + $this->m_process->setHighlightColor(trim($params['redlinkcolor'])); |
| 120 | + } |
| 121 | + |
| 122 | + if (array_key_exists('showredlinks', $params)) { |
| 123 | + if (self::isTrue($params['showredlinks'])) $this->m_process->setShowRedLinks(true); |
| 124 | + } |
| 125 | + |
| 126 | + if (array_key_exists('showcompound', $params)) { |
| 127 | + if (self::isTrue($params['showcompound'])) $this->m_process->setShowCompound(true); |
| 128 | + } |
| 129 | + |
| 130 | + // method configuration |
| 131 | + |
| 132 | + if (array_key_exists('debug', $params)) { |
| 133 | + if (self::isTrue($params['debug'])) $this->m_isDebugSet = true; |
| 134 | + } |
| 135 | + |
| 136 | + if (array_key_exists('graphvalidation', $params)) { |
| 137 | + if (self::isTrue($params['graphvalidation'])) $this->m_graphValidation = true; |
| 138 | + } |
| 139 | + |
| 140 | + if (array_key_exists('processcat', $params)) { |
| 141 | + $this->m_processCategory = $params['processcat']; |
| 142 | + } |
| 143 | + |
| 144 | + } |
| 145 | + |
| 146 | + public static function isTrue($value){ |
| 147 | + $res = false; |
| 148 | + if ((strtolower(trim($value))=='yes') || (strtolower(trim($value)) == 'true')) $res = true; |
| 149 | + return $res; |
| 150 | + } |
| 151 | + |
| 152 | + |
| 153 | + /** |
| 154 | + * This method renders the result set provided by SMW according to the printer |
| 155 | + * |
| 156 | + * @param res SMWQueryResult, result set of the ask query provided by SMW |
| 157 | + * @param outputmode ? |
| 158 | + * @returns String, rendered HTML output of this printer for the ask-query |
| 159 | + * |
| 160 | + */ |
| 161 | + protected function getResultText($res, $outputmode) { |
| 162 | + global $wgContLang; // content language object |
| 163 | + |
| 164 | + // |
| 165 | + // GraphViz settings |
| 166 | + // |
| 167 | + |
| 168 | + $wgGraphVizSettings = new GraphVizSettings; |
| 169 | + $this->isHTML = true; |
| 170 | + |
| 171 | + |
| 172 | + // |
| 173 | + // Iterate all rows in result set |
| 174 | + // |
| 175 | + |
| 176 | + $row = $res->getNext(); // get initial row (i.e. array of SMWResultArray) |
| 177 | + |
| 178 | + while ( $row !== false) { |
| 179 | + |
| 180 | + $node; |
| 181 | + $cond_edge; |
| 182 | + |
| 183 | + |
| 184 | + $subject = $row[0]->getResultSubject(); // get Subject of the Result |
| 185 | + // creates a new node if $val has type wikipage |
| 186 | + if ( $subject->getTypeID() == '_wpg' ) { |
| 187 | + $val = $subject->getShortWikiText(); |
| 188 | + $node = $this->m_process->makeNode($val, $val); |
| 189 | + } |
| 190 | + |
| 191 | + // |
| 192 | + // Iterate all colums of the row (which describe properties of the proces node) |
| 193 | + // |
| 194 | + |
| 195 | + foreach ($row as $field) { |
| 196 | + |
| 197 | + // check column title |
| 198 | + $req = $field->getPrintRequest(); |
| 199 | + switch ((strtolower($req->getLabel()))) { |
| 200 | + |
| 201 | + |
| 202 | + |
| 203 | + case strtolower($wgContLang->getNsText(NS_CATEGORY)): |
| 204 | + |
| 205 | + foreach ($field->getContent() as $value) { |
| 206 | + $val = $value->getShortWikiText(); |
| 207 | + if ($val == ($wgContLang->getNsText(NS_CATEGORY) . ':' . $this->m_processCategory)) $node->setAtomic(false); |
| 208 | + } |
| 209 | + |
| 210 | + break; |
| 211 | + |
| 212 | + case "hasrole": |
| 213 | + foreach ($field->getContent() as $value) { |
| 214 | + $val = $value->getShortWikiText(); |
| 215 | + $role = $this->m_process->makeRole($val, $val); |
| 216 | + $node->addRole($role); |
| 217 | + } |
| 218 | + break; |
| 219 | + |
| 220 | + case "usesresource": |
| 221 | + foreach ($field->getContent() as $value) { |
| 222 | + $val = $value->getShortWikiText(); |
| 223 | + $xres = $this->m_process->makeRessource($val, $val); |
| 224 | + $node->addUsedRessource($xres); |
| 225 | + } |
| 226 | + break; |
| 227 | + |
| 228 | + case "producesresource": |
| 229 | + foreach ($field->getContent() as $value) { |
| 230 | + $val = $value->getShortWikiText(); |
| 231 | + $xres = $this->m_process->makeRessource($val, $val); |
| 232 | + $node->addProducedRessource($xres); |
| 233 | + } |
| 234 | + break; |
| 235 | + |
| 236 | + case "hassuccessor": |
| 237 | + |
| 238 | + if (count($field->getContent()) > 1){ |
| 239 | + |
| 240 | + // SplitParallel |
| 241 | + $edge = new SplitParallelEdge(); |
| 242 | + $edge->setFrom($node); |
| 243 | + foreach ($field->getContent() as $value) { |
| 244 | + $val = $value->getShortWikiText(); |
| 245 | + $edge->addTo($this->m_process->makeNode($val, $val)); |
| 246 | + } |
| 247 | + |
| 248 | + } else { |
| 249 | + |
| 250 | + // Sequence |
| 251 | + foreach ($field->getContent() as $value) { |
| 252 | + $val = $value->getShortWikiText(); |
| 253 | + $edge = new SequentialEdge(); |
| 254 | + $edge->setFrom($node); |
| 255 | + $edge->setTo($this->m_process->makeNode($val, $val)); |
| 256 | + } |
| 257 | + } |
| 258 | + |
| 259 | + break; |
| 260 | + |
| 261 | + case "hasorsuccessor": |
| 262 | + |
| 263 | + if (count($field->getContent()) > 0){ |
| 264 | + |
| 265 | + // SplitExclusiveOr |
| 266 | + $edge = new SplitExclusiveOrEdge(); |
| 267 | + $edge->setFrom($node); |
| 268 | + foreach ($field->getContent() as $value) { |
| 269 | + $val = $value->getShortWikiText(); |
| 270 | + $edge->addTo($this->m_process->makeNode($val, $val)); |
| 271 | + } |
| 272 | + } |
| 273 | + |
| 274 | + break; |
| 275 | + |
| 276 | + case "hascontruesuccessor": |
| 277 | + |
| 278 | + if (count($field->getContent()) > 0){ |
| 279 | + |
| 280 | + // SplitConditional |
| 281 | + if (!isset($cond_edge)){ |
| 282 | + $cond_edge = new SplitConditionalOrEdge(); |
| 283 | + $cond_edge->setFrom($node); |
| 284 | + } |
| 285 | + |
| 286 | + // should be only one |
| 287 | + foreach ($field->getContent() as $value) { |
| 288 | + $val = $value->getShortWikiText(); |
| 289 | + $cond_edge->setToTrue($this->m_process->makeNode($val, $val)); |
| 290 | + } |
| 291 | + |
| 292 | + } |
| 293 | + |
| 294 | + break; |
| 295 | + |
| 296 | + case "hasconfalsesuccessor": |
| 297 | + |
| 298 | + if (count($field->getContent()) > 0){ |
| 299 | + |
| 300 | + // SplitConditional |
| 301 | + if (!isset($cond_edge)){ |
| 302 | + $cond_edge = new SplitConditionalOrEdge(); |
| 303 | + $cond_edge->setFrom($node); |
| 304 | + } |
| 305 | + |
| 306 | + // should be only one |
| 307 | + foreach ($field->getContent() as $value) { |
| 308 | + $val = $value->getShortWikiText(); |
| 309 | + $cond_edge->setToFalse($this->m_process->makeNode($val, $val)); |
| 310 | + } |
| 311 | + } |
| 312 | + |
| 313 | + break; |
| 314 | + |
| 315 | + case "hascondition": |
| 316 | + |
| 317 | + if (count($field->getContent()) > 0){ |
| 318 | + |
| 319 | + // SplitConditional |
| 320 | + if (!isset($cond_edge)){ |
| 321 | + $cond_edge = new SplitConditionalOrEdge(); |
| 322 | + $cond_edge->setFrom($node); |
| 323 | + } |
| 324 | + |
| 325 | + // should be only one |
| 326 | + foreach ($field->getContent() as $value) { |
| 327 | + $val = $value->getShortWikiText(); |
| 328 | + $cond_edge->setConditionText($val); |
| 329 | + |
| 330 | + } |
| 331 | + } |
| 332 | + |
| 333 | + break; |
| 334 | + |
| 335 | + case "hasstatus": |
| 336 | + |
| 337 | + // should be only one |
| 338 | + foreach ($field->getContent() as $value) { |
| 339 | + $val = $value->getShortWikiText(); |
| 340 | + $node->setStatus($val); |
| 341 | + } |
| 342 | + |
| 343 | + break; |
| 344 | + |
| 345 | + default: |
| 346 | + |
| 347 | + // TODO - redundant column in result |
| 348 | + |
| 349 | + } |
| 350 | + } |
| 351 | + |
| 352 | + // reset row variables |
| 353 | + unset($node); |
| 354 | + unset($cond_edge); |
| 355 | + |
| 356 | + $row = $res->getNext(); // switch to next row |
| 357 | + } |
| 358 | + |
| 359 | + // |
| 360 | + // generate graphInput |
| 361 | + // |
| 362 | + $graphInput = $this->m_process->getGraphVizCode(); |
| 363 | + |
| 364 | + // |
| 365 | + // render graphViz code |
| 366 | + // |
| 367 | + $result = renderGraphviz($graphInput); |
| 368 | + |
| 369 | + $debug = ''; |
| 370 | + if ($this->m_isDebugSet) $debug = '<pre>' . $graphInput . '</pre>'; |
| 371 | + |
| 372 | + return $result . $debug;; |
| 373 | + |
| 374 | + |
| 375 | + } |
| 376 | +} |
| 377 | + |
| 378 | +/** |
| 379 | + * Class representing a process graph |
| 380 | + */ |
| 381 | +class ProcessGraph{ |
| 382 | + |
| 383 | + // configuration variables |
| 384 | + protected $m_graphName = ''; |
| 385 | + protected $m_rankdir = 'TB'; |
| 386 | + protected $m_graphSize = ''; |
| 387 | + protected $m_clusterColor = 'lightgrey'; |
| 388 | + protected $m_showStatus = false; // should status be rendered? |
| 389 | + protected $m_showRoles = false; // should roles be rendered? |
| 390 | + protected $m_showRessources = false; // should ressources be rendered? |
| 391 | + protected $m_highlightNode = ''; // node to be highlighted |
| 392 | + protected $m_highlightColor = 'blue'; // highlight font color |
| 393 | + protected $m_showRedLinks = false; // check and highlight red links? |
| 394 | + protected $m_redLinkColor = 'red'; // red link font color |
| 395 | + protected $m_showCompound = true; // highlight compound nodes (=subprocesses) |
| 396 | + |
| 397 | + // instance variables |
| 398 | + protected $m_nodes = array(); // list of all nodes |
| 399 | + protected $m_startnodes = array(); // list of start nodes |
| 400 | + protected $m_endnodes = array(); // list of end nodes |
| 401 | + protected $m_ressources = array(); // list of ressources |
| 402 | + protected $m_roles = array(); // list of roles |
| 403 | + protected $m_errors = array(); // list of errors |
| 404 | + |
| 405 | + |
| 406 | + /** |
| 407 | + * This method should be used for getting new or existing nodes |
| 408 | + * If a node does not exist yet, it will be created |
| 409 | + * |
| 410 | + * @param $id string, node id |
| 411 | + * @param $label string, node label |
| 412 | + * @return Object of type ProcessNode |
| 413 | + */ |
| 414 | + public function makeNode($id, $label){ |
| 415 | + $node; |
| 416 | + |
| 417 | + // check if node exists |
| 418 | + if (isset($this->m_nodes[$id])){ |
| 419 | + // take existing node |
| 420 | + $node = $this->m_nodes[$id]; |
| 421 | + |
| 422 | + } else { |
| 423 | + // create new node |
| 424 | + |
| 425 | + $node = new ProcessNode(); |
| 426 | + $node->setId($id); |
| 427 | + $node->setLabel($label); |
| 428 | + $node->setProcess($this); |
| 429 | + |
| 430 | + // is actual node name the same like the one to highlight? |
| 431 | + if (strcasecmp($id , $this->m_highlightNode) == 0){ |
| 432 | + $node->setFontColor($this->m_highlightColor); |
| 433 | + } |
| 434 | + |
| 435 | + // is the node a red link (i.e. corresponding wiki page does not yet exist)? |
| 436 | + if ($this->m_showRedLinks){ |
| 437 | + $title = new Title(); |
| 438 | + $title = $title->newFromDBkey($id); |
| 439 | + if (isset($title) && (!$title->exists())) $node->setFontColor($this->m_redLinkColor); |
| 440 | + } |
| 441 | + |
| 442 | + // add new node to process |
| 443 | + $this->m_nodes[$id] = $node; |
| 444 | + } |
| 445 | + |
| 446 | + return $node; |
| 447 | + |
| 448 | + } |
| 449 | + |
| 450 | + public function makeRole($id, $label){ |
| 451 | + $role; |
| 452 | + |
| 453 | + // check if role exists |
| 454 | + if (isset($this->m_roles[$id])){ |
| 455 | + // take existing roles |
| 456 | + $role = $this->m_roles[$id]; |
| 457 | + |
| 458 | + } else { |
| 459 | + $role = new ProcessRole(); |
| 460 | + $role->setId($id); |
| 461 | + $role->setLabel($label); |
| 462 | + |
| 463 | + // add new role to process |
| 464 | + $this->m_roles[$id] = $role; |
| 465 | + } |
| 466 | + |
| 467 | + return $role; |
| 468 | + |
| 469 | + } |
| 470 | + |
| 471 | + public function makeRessource($id, $label){ |
| 472 | + $res; |
| 473 | + |
| 474 | + // check if res exists |
| 475 | + if (isset($this->m_ressources[$id])){ |
| 476 | + // take existing res |
| 477 | + $res = $this->m_ressources[$id]; |
| 478 | + |
| 479 | + } else { |
| 480 | + $res = new ProcessRessource(); |
| 481 | + $res->setId($id); |
| 482 | + $res->setLabel($label); |
| 483 | + |
| 484 | + // add new res to process |
| 485 | + $this->m_ressources[$id] = $res; |
| 486 | + |
| 487 | + } |
| 488 | + |
| 489 | + return $res; |
| 490 | + |
| 491 | + } |
| 492 | + |
| 493 | + public function getEndNodes(){ |
| 494 | + if (count($this->m_endnodes) == 0){ |
| 495 | + foreach($this->m_nodes as $node){ |
| 496 | + if (count($node->getSucc()) == 0) $this->m_endnodes[] = $node; |
| 497 | + } |
| 498 | + } |
| 499 | + |
| 500 | + return $this->m_endnodes; |
| 501 | + } |
| 502 | + |
| 503 | + public function getStartNodes(){ |
| 504 | + |
| 505 | + if (count($this->m_startnodes) == 0){ |
| 506 | + foreach($this->m_nodes as $node){ |
| 507 | + if (count($node->getPred()) == 0){ |
| 508 | + $this->m_startnodes[] = $node; |
| 509 | + } |
| 510 | + } |
| 511 | + } |
| 512 | + |
| 513 | + return $this->m_startnodes; |
| 514 | + } |
| 515 | + |
| 516 | + public function setShowStatus($show){ |
| 517 | + $this->m_showStatus = $show; |
| 518 | + } |
| 519 | + |
| 520 | + public function getShowStatus(){ |
| 521 | + return $this->m_showStatus; |
| 522 | + } |
| 523 | + |
| 524 | + public function setShowRoles($show){ |
| 525 | + $this->m_showRoles = $show; |
| 526 | + } |
| 527 | + |
| 528 | + public function getShowRoles(){ |
| 529 | + return $this->m_showRoles; |
| 530 | + } |
| 531 | + |
| 532 | + public function setShowCompound($show){ |
| 533 | + $this->m_showCompound = $show; |
| 534 | + } |
| 535 | + |
| 536 | + public function getShowCompound(){ |
| 537 | + return $this->m_showCompound; |
| 538 | + } |
| 539 | + |
| 540 | + public function setShowRessources($show){ |
| 541 | + $this->m_showRessources = $show; |
| 542 | + } |
| 543 | + |
| 544 | + public function getShowRessources(){ |
| 545 | + return $this->m_showRessources; |
| 546 | + } |
| 547 | + |
| 548 | + public function setGraphName($name){ |
| 549 | + $this->m_graphName = $name; |
| 550 | + } |
| 551 | + |
| 552 | + public function getGraphName(){ |
| 553 | + if ($this->m_graphName == '') $this->m_graphName = 'ProcessQueryResult' . rand(1, 99999); |
| 554 | + return $this->m_graphName; |
| 555 | + } |
| 556 | + |
| 557 | + public function setGraphSize($size){ |
| 558 | + $this->m_graphSize = $size; |
| 559 | + } |
| 560 | + |
| 561 | + public function setRankdir($rankdir){ |
| 562 | + $this->m_rankdir = $rankdir; |
| 563 | + } |
| 564 | + |
| 565 | + public function setClusterColor($color){ |
| 566 | + $this->m_clusterColor = $color; |
| 567 | + } |
| 568 | + |
| 569 | + public function setHighlightColor($color){ |
| 570 | + $this->m_highlightColor = $color; |
| 571 | + } |
| 572 | + |
| 573 | + public function setRedLinkColor($color){ |
| 574 | + $this->m_redLinkColor = $color; |
| 575 | + } |
| 576 | + |
| 577 | + public function setShowRedLinks($show){ |
| 578 | + $this->m_showRedLinks = $show; |
| 579 | + } |
| 580 | + |
| 581 | + public function setHighlightNode($name){ |
| 582 | + $this->m_highlightNode = $name; |
| 583 | + } |
| 584 | + |
| 585 | + public function addError($error){ |
| 586 | + $this->m_errors[] = $error; |
| 587 | + } |
| 588 | + |
| 589 | + public function getErrors(){ |
| 590 | + return $this->m_errors; |
| 591 | + } |
| 592 | + |
| 593 | + public function getGraphVizCode(){ |
| 594 | + // |
| 595 | + // header |
| 596 | + // |
| 597 | + $res = 'digraph ' . $this->getGraphName() .' { |
| 598 | + |
| 599 | + ranksep="0.5";'; |
| 600 | + if ($this->m_graphSize != '') $res .=' |
| 601 | + size="'. $this->m_graphSize . '";'; |
| 602 | + $res .=' |
| 603 | + rankdir=' . $this->m_rankdir . '; |
| 604 | + '; |
| 605 | + |
| 606 | + // |
| 607 | + // add startnodes |
| 608 | + // |
| 609 | + // TODO I18N |
| 610 | + $res .=' |
| 611 | + {rank=source; "Start";} |
| 612 | + "Start"[shape=box,label="Start",style=filled,color=green];'; |
| 613 | + |
| 614 | + foreach ($this->getStartNodes() as $node){ |
| 615 | + $res .= ' |
| 616 | + "Start" -> "' . $node->getId() . '";'; |
| 617 | + } |
| 618 | + |
| 619 | + $res .= ' |
| 620 | + '; |
| 621 | + |
| 622 | + // |
| 623 | + // add endnodes |
| 624 | + // |
| 625 | + // TODO I18N |
| 626 | + $res .= ' |
| 627 | + {rank=sink; "End"; } |
| 628 | + "End"[shape=box,label="End",style=filled,color=green];'; |
| 629 | + |
| 630 | + foreach ($this->getEndNodes() as $node){ |
| 631 | + $res .= ' |
| 632 | + "' . $node->getId() . '" -> "End";'; |
| 633 | + } |
| 634 | + |
| 635 | + $res .= ' |
| 636 | + |
| 637 | + '; |
| 638 | + |
| 639 | + // |
| 640 | + // add subnodes |
| 641 | + // |
| 642 | + foreach($this->m_nodes as $node){ |
| 643 | + $res .= $node->getGraphVizCode(); |
| 644 | + } |
| 645 | + |
| 646 | + // |
| 647 | + // add final stuff |
| 648 | + // |
| 649 | + $res .= |
| 650 | + ' |
| 651 | + }'; |
| 652 | + |
| 653 | + return $res; |
| 654 | + |
| 655 | + } |
| 656 | + |
| 657 | +} |
| 658 | + |
| 659 | +abstract class ProcessElement{ |
| 660 | + |
| 661 | + // TODO I18N |
| 662 | + private $m_id = 'no_id'; |
| 663 | + private $m_label = 'unlabeled'; |
| 664 | + |
| 665 | + public function getId(){ |
| 666 | + return $this->m_id; |
| 667 | + } |
| 668 | + |
| 669 | + public function setId($id){ |
| 670 | + $this->m_id = $id; |
| 671 | + } |
| 672 | + |
| 673 | + public function getLabel(){ |
| 674 | + return $this->m_label; |
| 675 | + } |
| 676 | + |
| 677 | + public function setLabel($label){ |
| 678 | + $this->m_label = $label; |
| 679 | + } |
| 680 | + |
| 681 | +} |
| 682 | + |
| 683 | +class ProcessRessource extends ProcessElement{ |
| 684 | + |
| 685 | + private $m_usedby = array(); |
| 686 | + private $m_producedby = array(); |
| 687 | + |
| 688 | + public function getProducers(){ |
| 689 | + return $this->m_producedby; |
| 690 | + } |
| 691 | + |
| 692 | + public function getUsers(){ |
| 693 | + return $this->m_usedby; |
| 694 | + } |
| 695 | + |
| 696 | + public function addProducer($node){ |
| 697 | + $this->m_producedby[] = $node; |
| 698 | + } |
| 699 | + |
| 700 | + public function addUser($node){ |
| 701 | + $this->m_usedby[] = $node; |
| 702 | + } |
| 703 | + |
| 704 | +} |
| 705 | + |
| 706 | +class ProcessRole extends ProcessElement{ |
| 707 | + |
| 708 | + private $m_nodes = array(); |
| 709 | + |
| 710 | + public function getNodes(){ |
| 711 | + return $this->m_nodes; |
| 712 | + } |
| 713 | + |
| 714 | + public function addNode($node){ |
| 715 | + $this->m_nodes[] = $node; |
| 716 | + } |
| 717 | + |
| 718 | +} |
| 719 | + |
| 720 | +/** |
| 721 | + * Class reperesning a process node |
| 722 | + */ |
| 723 | +class ProcessNode extends ProcessElement{ |
| 724 | + |
| 725 | + private $m_is_startnode = false; // explicit statement if this is a start node |
| 726 | + private $m_is_endnode = false; // explicit statement if this is a termination node |
| 727 | + private $m_status; // status value |
| 728 | + private $m_is_atomic = true; // set false if this is a compound node |
| 729 | + |
| 730 | + private $m_process; // reference to parent process |
| 731 | + |
| 732 | + private $m_fontColor = ''; // font color to render |
| 733 | + |
| 734 | + private $m_usedressources = array(); // ressources used by this node |
| 735 | + private $m_producedressources = array(); // ressources produces by this node |
| 736 | + private $m_roles = array(); // roles related to this node |
| 737 | + |
| 738 | + private $m_edgeout; // outgoing edge (can be only one) |
| 739 | + private $m_edgesin = array(); // incoming edges (can be many) |
| 740 | + |
| 741 | + public function setStatus($status){ |
| 742 | + $this->m_status = $status; |
| 743 | + } |
| 744 | + |
| 745 | + public function getStatus(){ |
| 746 | + return $this->m_status; |
| 747 | + } |
| 748 | + |
| 749 | + public function setFontColor($color){ |
| 750 | + $this->m_fontColor = $color; |
| 751 | + } |
| 752 | + |
| 753 | + public function setProcess($proc){ |
| 754 | + $this->m_process = $proc; |
| 755 | + } |
| 756 | + |
| 757 | + public function getProcess(){ |
| 758 | + return $this->m_process; |
| 759 | + } |
| 760 | + |
| 761 | + public function getPred(){ |
| 762 | + $res = array(); |
| 763 | + |
| 764 | + foreach ($this->m_edgesin as $edge){ |
| 765 | + $res = array_merge($res, $edge->getPred()); |
| 766 | + } |
| 767 | + |
| 768 | + return $res; |
| 769 | + } |
| 770 | + |
| 771 | + public function getSucc(){ |
| 772 | + $res = array(); |
| 773 | + |
| 774 | + if (isset($this->m_edgeout)){ |
| 775 | + $res = $this->m_edgeout->getSucc(); |
| 776 | + } |
| 777 | + |
| 778 | + return $res; |
| 779 | + } |
| 780 | + |
| 781 | + public function setEdgeOut($edge){ |
| 782 | + $this->m_edgeout = $edge; |
| 783 | + } |
| 784 | + |
| 785 | + public function getEdgeOut(){ |
| 786 | + return $this->m_edgeout; |
| 787 | + } |
| 788 | + |
| 789 | + public function addEdgeIn($edge){ |
| 790 | + $this->m_edgesin[] = $edge; |
| 791 | + } |
| 792 | + |
| 793 | + public function getEdgesIn(){ |
| 794 | + return $this->m_edgesin; |
| 795 | + } |
| 796 | + |
| 797 | + public function addRole($role){ |
| 798 | + $this->m_roles[] = $role; |
| 799 | + $role->addNode($this); |
| 800 | + } |
| 801 | + |
| 802 | + public function getRoles(){ |
| 803 | + return $this->m_roles; |
| 804 | + } |
| 805 | + |
| 806 | + public function addUsedRessource($res){ |
| 807 | + $this->m_usedressources[] = $res; |
| 808 | + $res->addUser($this); |
| 809 | + } |
| 810 | + |
| 811 | + public function getUsedRessources(){ |
| 812 | + return $this->m_usedressources; |
| 813 | + } |
| 814 | + |
| 815 | + public function addProducedRessource($res){ |
| 816 | + $this->m_producedressources[] = $res; |
| 817 | + $res->addProducer($this); |
| 818 | + } |
| 819 | + |
| 820 | + public function getProducedRessources(){ |
| 821 | + return $this->m_producedressources; |
| 822 | + } |
| 823 | + |
| 824 | + public function isAtomic(){ |
| 825 | + return $this->m_is_atomic; |
| 826 | + } |
| 827 | + |
| 828 | + public function setAtomic($atomic){ |
| 829 | + $this->m_is_atomic = $atomic; |
| 830 | + } |
| 831 | + |
| 832 | + public function getGraphVizCode(){ |
| 833 | + global $IP, $srfgPicturePath, $srfgIP; |
| 834 | + // |
| 835 | + // show node status |
| 836 | + // |
| 837 | + $status = ''; |
| 838 | + if ($this->getProcess()->getShowStatus()){ |
| 839 | + |
| 840 | + if (file_exists($IP . "/images/p000.png")) { |
| 841 | + $PicturePath = $IP . "/images/"; |
| 842 | + } elseif (file_exists($srfgIP . "/GraphViz/images/p000.png")) { |
| 843 | + $PicturePath = $srfgIP . "/GraphViz/images/"; |
| 844 | + } else { |
| 845 | + $PicturePath = $IP . $srfgPicturePath; |
| 846 | + } |
| 847 | + //$color = 'grey' . $this->getStatus(); |
| 848 | + //$color = 'grey' . rand(1, 100); |
| 849 | + //$status = ',style=filled,color=' . $color; |
| 850 | + if ($this->getStatus() != ''){ |
| 851 | + if ($this->getStatus() < 25){ |
| 852 | + $status = ',image="'. $PicturePath .'p000.png"'; |
| 853 | + } else if ($this->getStatus() < 50){ |
| 854 | + $status = ',image="'. $PicturePath .'p025.png"'; |
| 855 | + } else if ($this->getStatus() < 75){ |
| 856 | + $status = ',image="'. $PicturePath .'p050.png"'; |
| 857 | + } else if ($this->getStatus() < 100){ |
| 858 | + $status = ',image="'. $PicturePath .'p075.png"'; |
| 859 | + } else if ($this->getStatus() == 100){ |
| 860 | + $status = ',image="' . $PicturePath .'p100.png"'; |
| 861 | + } |
| 862 | + } |
| 863 | + |
| 864 | + } |
| 865 | + |
| 866 | + // use highlight color if set (either CURRENTPAGE or REDLINK highlighting - see ProcessGraph::makeNode() |
| 867 | + $high = ''; |
| 868 | + if( $this->m_fontColor != '') { |
| 869 | + $high = ',fontcolor=' . $this->m_fontColor; |
| 870 | + } |
| 871 | + |
| 872 | + // make double circle for non-atomic nodes (i.e. subprocesses) |
| 873 | + $compound = ''; |
| 874 | + if ($this->getProcess()->getShowCompound() && !$this->isAtomic()) $compound = ',penwidth=2.0'; |
| 875 | + |
| 876 | + |
| 877 | + // |
| 878 | + // render node itself |
| 879 | + // |
| 880 | + $res = |
| 881 | + '"' . $this->getId() . '" [URL="[[' . $this->getId() . ']]",label="' . $this->getLabel() . '"' . $status . $high . $compound . ']; |
| 882 | + '; |
| 883 | + |
| 884 | + // |
| 885 | + // render outgoing node |
| 886 | + // |
| 887 | + if (isset($this->m_edgeout)) $res .= $this->m_edgeout->getGraphVizCode(); |
| 888 | + |
| 889 | + |
| 890 | + // |
| 891 | + // show cluster for roles and ressources |
| 892 | + // |
| 893 | + $rrcluster = false; |
| 894 | + $rrcode = 'subgraph "cluster_role' . rand(1,9999) . '" { style=filled;color=lightgrey;'; |
| 895 | + |
| 896 | + // show roles |
| 897 | + if ($this->getProcess()->getShowRoles()){ |
| 898 | + |
| 899 | + foreach ($this->getRoles() as $role){ |
| 900 | + $rrcluster = true; |
| 901 | + $rrcode .= ' |
| 902 | + "' . $role->getId() . '"[label="' . $role->getLabel() . '",shape=doubleoctagon, color=red, URL="[[' . $role->getId() . ']]"]; |
| 903 | + "' . $role->getId() . '" -> "' . $this->getId() . '" [color=red,arrowhead = none,constraint=false]; |
| 904 | + '; |
| 905 | + |
| 906 | + } |
| 907 | + } |
| 908 | + |
| 909 | + if ($this->getProcess()->getShowRessources()){ |
| 910 | + |
| 911 | + foreach ($this->getUsedRessources() as $xres){ |
| 912 | + $rrcluster = true; |
| 913 | + $rrcode .= ' |
| 914 | + "' . $xres->getId() . '"[label="' . $xres->getLabel() . '",shape=folder, color=blue, URL="[[' . $xres->getId() . ']]"]; |
| 915 | + "' . $xres->getId() . '" -> "' . $this->getId() . '" [color=blue,constraint=false]; |
| 916 | + '; |
| 917 | + } |
| 918 | + |
| 919 | + foreach ($this->getProducedRessources() as $xres){ |
| 920 | + $rrcluster = true; |
| 921 | + $rrcode .= ' |
| 922 | + "' . $xres->getId() . '"[label="' . $xres->getLabel() . '",shape=folder, color=blue, URL="[[' . $xres->getId() . ']]"]; |
| 923 | + "' . $this->getId() . '" -> "' . $xres->getId() . '" [color=blue,constraint=false]; |
| 924 | + '; |
| 925 | + } |
| 926 | + |
| 927 | + } |
| 928 | + |
| 929 | + if ($rrcluster) $res .= $rrcode . '}'; |
| 930 | + |
| 931 | + $res .= ' |
| 932 | + '; |
| 933 | + |
| 934 | + return $res; |
| 935 | + } |
| 936 | + |
| 937 | +} |
| 938 | + |
| 939 | +/** |
| 940 | + * Abstract base class for edges in a process graph |
| 941 | + */ |
| 942 | +abstract class ProcessEdge{ |
| 943 | + |
| 944 | + private $m_id; |
| 945 | + |
| 946 | + public function getId(){ |
| 947 | + if (!isset($this->m_id)){ |
| 948 | + $this->m_id = 'edge' . rand(1, 99999); |
| 949 | + } |
| 950 | + |
| 951 | + return $this->m_id; |
| 952 | + } |
| 953 | + |
| 954 | + abstract public function getSucc(); |
| 955 | + abstract public function getPred(); |
| 956 | + |
| 957 | + abstract public function getGraphVizCode(); |
| 958 | +} |
| 959 | + |
| 960 | +abstract class SplitEdge extends ProcessEdge{ |
| 961 | + |
| 962 | + protected $m_from; |
| 963 | + protected $m_to = array(); |
| 964 | + |
| 965 | + public function setFrom($node){ |
| 966 | + $this->m_from = $node; |
| 967 | + $node->setEdgeOut($this); |
| 968 | + } |
| 969 | + |
| 970 | + public function addTo($node){ |
| 971 | + $this->m_to[] = $node; |
| 972 | + $node->addEdgeIn($this); |
| 973 | + } |
| 974 | + |
| 975 | + public function getPred(){ |
| 976 | + return array($this->m_from); |
| 977 | + } |
| 978 | + |
| 979 | + public function getSucc(){ |
| 980 | + return $this->m_to; |
| 981 | + } |
| 982 | + |
| 983 | +} |
| 984 | + |
| 985 | +class SplitConditionalOrEdge extends ProcessEdge{ |
| 986 | + |
| 987 | + protected $m_from; |
| 988 | + protected $m_to_true; |
| 989 | + protected $m_to_false; |
| 990 | + protected $m_con_text = 'empty_condition'; |
| 991 | + |
| 992 | + public function getSucc(){ |
| 993 | + return array($this->m_to_false, $this->m_to_true); |
| 994 | + } |
| 995 | + |
| 996 | + public function getPred(){ |
| 997 | + return array($this->m_from); |
| 998 | + } |
| 999 | + |
| 1000 | + public function setFrom($node){ |
| 1001 | + $this->m_from = $node; |
| 1002 | + $node->setEdgeOut($this); |
| 1003 | + } |
| 1004 | + |
| 1005 | + public function setToFalse($node){ |
| 1006 | + $this->m_to_false = $node; |
| 1007 | + $node->addEdgeIn($this); |
| 1008 | + } |
| 1009 | + |
| 1010 | + public function setToTrue($node){ |
| 1011 | + $this->m_to_true = $node; |
| 1012 | + $node->addEdgeIn($this); |
| 1013 | + } |
| 1014 | + |
| 1015 | + public function setConditionText($cond){ |
| 1016 | + $this->m_con_text = $cond; |
| 1017 | + } |
| 1018 | + |
| 1019 | + public function getGraphVizCode(){ |
| 1020 | + |
| 1021 | + $p = $this->m_from; |
| 1022 | + |
| 1023 | + if ((!isset($this->m_from)) || (!isset($this->m_to_false)) || (!isset($this->m_to_true))){ |
| 1024 | + |
| 1025 | + echo "error with SplitConditionalOrEdge"; // TODO |
| 1026 | + exit; |
| 1027 | + } |
| 1028 | + |
| 1029 | + |
| 1030 | + $res = |
| 1031 | + 'subgraph "clus_' . $this->getId() . '" { ; |
| 1032 | + '; |
| 1033 | + |
| 1034 | + // cond-Shape |
| 1035 | + $con = 'con' . rand(1, 99999); |
| 1036 | + $res .= |
| 1037 | + '"'. $con . '"[shape=diamond,label="' . $this->m_con_text . '",style=filled,color=skyblue]; |
| 1038 | + "' . $p->getId() . '" -> "'. $con . '"; |
| 1039 | + '; |
| 1040 | + |
| 1041 | + // True Succ |
| 1042 | + $res .= |
| 1043 | + '"' . $this->m_to_true->getId() . '" [URL = "[['. $this->m_to_true->getId() . ']]"]; |
| 1044 | + '; |
| 1045 | + |
| 1046 | + $res .= |
| 1047 | + '"'. $con .'" -> "' . $this->m_to_true->getId() .'" [label="true"]; |
| 1048 | + '; |
| 1049 | + |
| 1050 | + // False Succ |
| 1051 | + $res .= |
| 1052 | + '"' . $this->m_to_false->getId() . '" [URL = "[['. $this->m_to_false->getId() . ']]"]; |
| 1053 | + '; |
| 1054 | + |
| 1055 | + $res .= |
| 1056 | + '"'. $con .'" -> "' . $this->m_to_false->getId() .'" [label="false"];'; |
| 1057 | + |
| 1058 | + |
| 1059 | + $res .= ' |
| 1060 | + } |
| 1061 | + '; |
| 1062 | + |
| 1063 | + return $res; |
| 1064 | + } |
| 1065 | + |
| 1066 | +} |
| 1067 | + |
| 1068 | +class SplitExclusiveOrEdge extends SplitEdge{ |
| 1069 | + |
| 1070 | + public function getGraphVizCode(){ |
| 1071 | + |
| 1072 | + $p = $this->getPred(); |
| 1073 | + $p = $p[0]; |
| 1074 | + |
| 1075 | + $res = |
| 1076 | + 'subgraph "clus_' . $this->getId() . '" { ; |
| 1077 | + '; |
| 1078 | + |
| 1079 | + // add OR-Shape |
| 1080 | + $orx = 'or' . rand(1, 99999); |
| 1081 | + $res .= |
| 1082 | + '"'. $orx . '"[shape=box,label="+",style=filled,color=gold]; |
| 1083 | + "' . $p->getId() . '" -> "'. $orx . '"; |
| 1084 | + '; |
| 1085 | + |
| 1086 | + foreach ($this->getSucc() as $s){ |
| 1087 | + $res .= |
| 1088 | + '"' . $s->getId() . '" [URL="[['. $s->getId() . ']]"]; |
| 1089 | + '; |
| 1090 | + |
| 1091 | + $res .= |
| 1092 | + '"'. $orx .'" -> "' . $s->getId() .'"; |
| 1093 | + '; |
| 1094 | + } |
| 1095 | + |
| 1096 | + $res .= ' |
| 1097 | + } |
| 1098 | + '; |
| 1099 | + |
| 1100 | + return $res; |
| 1101 | + } |
| 1102 | + |
| 1103 | +} |
| 1104 | + |
| 1105 | +class SplitParallelEdge extends SplitEdge{ |
| 1106 | + |
| 1107 | + |
| 1108 | + public function getGraphVizCode(){ |
| 1109 | + |
| 1110 | + $p = $this->getPred(); |
| 1111 | + $p = $p[0]; |
| 1112 | + |
| 1113 | + $res = |
| 1114 | + 'subgraph "clus_' . $this->getId() . '" { ; |
| 1115 | + '; |
| 1116 | + |
| 1117 | + // add AND-Shape |
| 1118 | + $and = 'and' . rand(1, 99999); |
| 1119 | + $res .= |
| 1120 | + '"'. $and . '"[shape=box,label="||",style=filled,color=palegreen]; |
| 1121 | + "' . $p->getId() . '" -> "'. $and . '"; |
| 1122 | + '; |
| 1123 | + |
| 1124 | + foreach ($this->getSucc() as $s){ |
| 1125 | + $res .= |
| 1126 | + '"' . $s->getId() . '" [URL = "[['. $s->getId() . ']]"]; |
| 1127 | + '; |
| 1128 | + |
| 1129 | + $res .= |
| 1130 | + '"'. $and .'" -> "' . $s->getId() .'"; |
| 1131 | + '; |
| 1132 | + } |
| 1133 | + |
| 1134 | + $res .= ' |
| 1135 | + } |
| 1136 | + '; |
| 1137 | + |
| 1138 | + return $res; |
| 1139 | + } |
| 1140 | + |
| 1141 | +} |
| 1142 | + |
| 1143 | +class SequentialEdge extends ProcessEdge{ |
| 1144 | + |
| 1145 | + private $m_from; |
| 1146 | + private $m_to; |
| 1147 | + |
| 1148 | + public function setFrom($node){ |
| 1149 | + $this->m_from = $node; |
| 1150 | + $node->setEdgeOut($this); |
| 1151 | + } |
| 1152 | + |
| 1153 | + public function setTo($node){ |
| 1154 | + $this->m_to = $node; |
| 1155 | + $node->addEdgeIn($this); |
| 1156 | + } |
| 1157 | + |
| 1158 | + public function getPred(){ |
| 1159 | + return array($this->m_from); |
| 1160 | + } |
| 1161 | + |
| 1162 | + public function getSucc(){ |
| 1163 | + return array($this->m_to); |
| 1164 | + } |
| 1165 | + |
| 1166 | + public function getGraphVizCode(){ |
| 1167 | + |
| 1168 | + $p = $this->m_from; |
| 1169 | + $s = $this->m_to; |
| 1170 | + |
| 1171 | + $res = |
| 1172 | + 'subgraph "clus_' . $this->getId() . '" { ; |
| 1173 | + '; |
| 1174 | + |
| 1175 | + $res .= |
| 1176 | + '"' . $s->getId() . '" [URL = "[['. $s->getId() . ']]"]; |
| 1177 | + '; |
| 1178 | + |
| 1179 | + $res .= |
| 1180 | + '"'. $p->getId() .'" -> "' . $s->getId() .'";'; |
| 1181 | + |
| 1182 | + $res .= ' |
| 1183 | + } |
| 1184 | + '; |
| 1185 | + |
| 1186 | + return $res; |
| 1187 | + } |
| 1188 | + |
| 1189 | +} |
Property changes on: trunk/extensions/SemanticResultFormats/GraphViz/SRF_Process.php |
___________________________________________________________________ |
Name: svn:eol-style |
1190 | 1190 | + native |
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php |
— | — | @@ -1,140 +1,140 @@ |
2 | | -<?php
|
3 | | -
|
4 | | -/**
|
5 | | - *
|
6 | | - *
|
7 | | - * @file Maps_DisplayPoint.php
|
8 | | - * @ingroup Maps
|
9 | | - *
|
10 | | - * @author Jeroen De Dauw
|
11 | | - */
|
12 | | -
|
13 | | -if( !defined( 'MEDIAWIKI' ) ) {
|
14 | | - die( 'Not an entry point.' );
|
15 | | -}
|
16 | | -
|
17 | | -$wgAutoloadClasses['MapsDisplayPoint'] = $egMapsIP . '/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php';
|
18 | | -$wgAutoloadClasses['MapsBasePointMap'] = $egMapsIP . '/ParserFunctions/DisplayPoint/Maps_BasePointMap.php';
|
19 | | -
|
20 | | -$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayPointMagic';
|
21 | | -$wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayPoint';
|
22 | | -
|
23 | | -/**
|
24 | | - * Adds the magic words for the parser functions
|
25 | | - */
|
26 | | -function efMapsDisplayPointMagic( &$magicWords, $langCode ) {
|
27 | | - $magicWords['display_point'] = array( 0, 'display_point', 'display_points' );
|
28 | | - $magicWords['display_address'] = array( 0, 'display_address', 'display_addresses' );
|
29 | | -
|
30 | | - return true; // Unless we return true, other parser functions won't get loaded
|
31 | | -}
|
32 | | -
|
33 | | -/**
|
34 | | - * Adds the parser function hooks
|
35 | | - */
|
36 | | -function efMapsRegisterDisplayPoint(&$wgParser) {
|
37 | | - // Hooks to enable the '#display_point' and '#display_points' parser functions
|
38 | | - $wgParser->setFunctionHook( 'display_point', array('MapsDisplayPoint', 'displayPointRender') );
|
39 | | -
|
40 | | - // Hooks to enable the '#display_adress' and '#display_adresses' parser functions
|
41 | | - $wgParser->setFunctionHook( 'display_address', array('MapsDisplayPoint', 'displayAddressRender') );
|
42 | | -
|
43 | | - return true;
|
44 | | -}
|
45 | | -
|
46 | | -/**
|
47 | | - *
|
48 | | - *
|
49 | | - * @author Jeroen De Dauw
|
50 | | - *
|
51 | | - */
|
52 | | -final class MapsDisplayPoint {
|
53 | | -
|
54 | | - /**
|
55 | | - * Sets the default map properties, gets the map HTML depending
|
56 | | - * on the provided service, and then returns it.
|
57 | | - *
|
58 | | - * @param unknown_type $parser
|
59 | | - * @return array
|
60 | | - */
|
61 | | - public static function displayPointRender(&$parser) {
|
62 | | - $params = func_get_args();
|
63 | | - array_shift( $params ); // We already know the $parser ...
|
64 | | -
|
65 | | - // TODO: auto geocode when required
|
66 | | -
|
67 | | - return self::getMapHtml($parser, $params, 'display_point');
|
68 | | - }
|
69 | | -
|
70 | | - /**
|
71 | | - * Turns the address parameter into coordinates, then calls
|
72 | | - * getMapHtml() and returns it's result.
|
73 | | - *
|
74 | | - * @param unknown_type $parser
|
75 | | - * @return array
|
76 | | - */
|
77 | | - public static function displayAddressRender(&$parser) {
|
78 | | - // TODO: remove
|
79 | | - $params = func_get_args();
|
80 | | - array_shift( $params ); // We already know the $parser ...
|
81 | | -
|
82 | | - $fails = MapsParserGeocoder::changeAddressToCoords($params);
|
83 | | -
|
84 | | - return self::getMapHtml($parser, $params, 'display_point', $fails);
|
85 | | - }
|
86 | | -
|
87 | | - public static function getMapHtml(&$parser, array $params, $parserFunction, array $coordFails = array()) {
|
88 | | - global $wgLang;
|
89 | | -
|
90 | | - $map = array();
|
91 | | -
|
92 | | - // Go through all parameters, split their names and values, and put them in the $map array.
|
93 | | - foreach($params as $param) {
|
94 | | - $split = split('=', $param);
|
95 | | - if (count($split) > 1) {
|
96 | | - $paramName = strtolower(trim($split[0]));
|
97 | | - $paramValue = trim($split[1]);
|
98 | | - if (strlen($paramName) > 0 && strlen($paramValue) > 0) {
|
99 | | - $map[$paramName] = $paramValue;
|
100 | | - }
|
101 | | - }
|
102 | | - else if (count($split) == 1) { // Default parameter (without name)
|
103 | | - $split[0] = trim($split[0]);
|
104 | | - if (strlen($split[0]) > 0) $map['coordinates'] = $split[0];
|
105 | | - }
|
106 | | - }
|
107 | | -
|
108 | | - $coords = MapsMapper::getParamValue('coordinates', $map);
|
109 | | -
|
110 | | - if ($coords) {
|
111 | | - if (! MapsMapper::paramIsPresent('service', $map)) $map['service'] = '';
|
112 | | - $map['service'] = MapsMapper::getValidService($map['service'], 'pf');
|
113 | | -
|
114 | | - $mapClass = self::getParserClassInstance($map['service'], $parserFunction);
|
115 | | -
|
116 | | - // Call the function according to the map service to get the HTML output
|
117 | | - $output = $mapClass->displayMap($parser, $map);
|
118 | | -
|
119 | | - if (count($coordFails) > 0) {
|
120 | | - $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText($coordFails ), count( $coordFails ) ) . '</i>';
|
121 | | - }
|
122 | | - }
|
123 | | - elseif (trim($coords) == "" && count($coordFails) > 0) {
|
124 | | - $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>';
|
125 | | - }
|
126 | | - else {
|
127 | | - $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>';
|
128 | | - }
|
129 | | -
|
130 | | - // Return the result
|
131 | | - return array( $output, 'noparse' => true, 'isHTML' => true );
|
132 | | - }
|
133 | | -
|
134 | | - private static function getParserClassInstance($service, $parserFunction) {
|
135 | | - global $egMapsServices;
|
136 | | - // TODO: add check to see if the service actually supports this parser function, and return false for error handling if not.
|
137 | | - //die($egMapsServices[$service]['pf'][$parserFunction]['class']);
|
138 | | - return new $egMapsServices[$service]['pf'][$parserFunction]['class']();
|
139 | | - }
|
140 | | -
|
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * |
| 6 | + * |
| 7 | + * @file Maps_DisplayPoint.php |
| 8 | + * @ingroup Maps |
| 9 | + * |
| 10 | + * @author Jeroen De Dauw |
| 11 | + */ |
| 12 | + |
| 13 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 14 | + die( 'Not an entry point.' ); |
| 15 | +} |
| 16 | + |
| 17 | +$wgAutoloadClasses['MapsDisplayPoint'] = $egMapsIP . '/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php'; |
| 18 | +$wgAutoloadClasses['MapsBasePointMap'] = $egMapsIP . '/ParserFunctions/DisplayPoint/Maps_BasePointMap.php'; |
| 19 | + |
| 20 | +$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayPointMagic'; |
| 21 | +$wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayPoint'; |
| 22 | + |
| 23 | +/** |
| 24 | + * Adds the magic words for the parser functions |
| 25 | + */ |
| 26 | +function efMapsDisplayPointMagic( &$magicWords, $langCode ) { |
| 27 | + $magicWords['display_point'] = array( 0, 'display_point', 'display_points' ); |
| 28 | + $magicWords['display_address'] = array( 0, 'display_address', 'display_addresses' ); |
| 29 | + |
| 30 | + return true; // Unless we return true, other parser functions won't get loaded |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * Adds the parser function hooks |
| 35 | + */ |
| 36 | +function efMapsRegisterDisplayPoint(&$wgParser) { |
| 37 | + // Hooks to enable the '#display_point' and '#display_points' parser functions |
| 38 | + $wgParser->setFunctionHook( 'display_point', array('MapsDisplayPoint', 'displayPointRender') ); |
| 39 | + |
| 40 | + // Hooks to enable the '#display_adress' and '#display_adresses' parser functions |
| 41 | + $wgParser->setFunctionHook( 'display_address', array('MapsDisplayPoint', 'displayAddressRender') ); |
| 42 | + |
| 43 | + return true; |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * |
| 48 | + * |
| 49 | + * @author Jeroen De Dauw |
| 50 | + * |
| 51 | + */ |
| 52 | +final class MapsDisplayPoint { |
| 53 | + |
| 54 | + /** |
| 55 | + * Sets the default map properties, gets the map HTML depending |
| 56 | + * on the provided service, and then returns it. |
| 57 | + * |
| 58 | + * @param unknown_type $parser |
| 59 | + * @return array |
| 60 | + */ |
| 61 | + public static function displayPointRender(&$parser) { |
| 62 | + $params = func_get_args(); |
| 63 | + array_shift( $params ); // We already know the $parser ... |
| 64 | + |
| 65 | + // TODO: auto geocode when required |
| 66 | + |
| 67 | + return self::getMapHtml($parser, $params, 'display_point'); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Turns the address parameter into coordinates, then calls |
| 72 | + * getMapHtml() and returns it's result. |
| 73 | + * |
| 74 | + * @param unknown_type $parser |
| 75 | + * @return array |
| 76 | + */ |
| 77 | + public static function displayAddressRender(&$parser) { |
| 78 | + // TODO: remove |
| 79 | + $params = func_get_args(); |
| 80 | + array_shift( $params ); // We already know the $parser ... |
| 81 | + |
| 82 | + $fails = MapsParserGeocoder::changeAddressToCoords($params); |
| 83 | + |
| 84 | + return self::getMapHtml($parser, $params, 'display_point', $fails); |
| 85 | + } |
| 86 | + |
| 87 | + public static function getMapHtml(&$parser, array $params, $parserFunction, array $coordFails = array()) { |
| 88 | + global $wgLang; |
| 89 | + |
| 90 | + $map = array(); |
| 91 | + |
| 92 | + // Go through all parameters, split their names and values, and put them in the $map array. |
| 93 | + foreach($params as $param) { |
| 94 | + $split = split('=', $param); |
| 95 | + if (count($split) > 1) { |
| 96 | + $paramName = strtolower(trim($split[0])); |
| 97 | + $paramValue = trim($split[1]); |
| 98 | + if (strlen($paramName) > 0 && strlen($paramValue) > 0) { |
| 99 | + $map[$paramName] = $paramValue; |
| 100 | + } |
| 101 | + } |
| 102 | + else if (count($split) == 1) { // Default parameter (without name) |
| 103 | + $split[0] = trim($split[0]); |
| 104 | + if (strlen($split[0]) > 0) $map['coordinates'] = $split[0]; |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + $coords = MapsMapper::getParamValue('coordinates', $map); |
| 109 | + |
| 110 | + if ($coords) { |
| 111 | + if (! MapsMapper::paramIsPresent('service', $map)) $map['service'] = ''; |
| 112 | + $map['service'] = MapsMapper::getValidService($map['service'], 'pf'); |
| 113 | + |
| 114 | + $mapClass = self::getParserClassInstance($map['service'], $parserFunction); |
| 115 | + |
| 116 | + // Call the function according to the map service to get the HTML output |
| 117 | + $output = $mapClass->displayMap($parser, $map); |
| 118 | + |
| 119 | + if (count($coordFails) > 0) { |
| 120 | + $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText($coordFails ), count( $coordFails ) ) . '</i>'; |
| 121 | + } |
| 122 | + } |
| 123 | + elseif (trim($coords) == "" && count($coordFails) > 0) { |
| 124 | + $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; |
| 125 | + } |
| 126 | + else { |
| 127 | + $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>'; |
| 128 | + } |
| 129 | + |
| 130 | + // Return the result |
| 131 | + return array( $output, 'noparse' => true, 'isHTML' => true ); |
| 132 | + } |
| 133 | + |
| 134 | + private static function getParserClassInstance($service, $parserFunction) { |
| 135 | + global $egMapsServices; |
| 136 | + // TODO: add check to see if the service actually supports this parser function, and return false for error handling if not. |
| 137 | + //die($egMapsServices[$service]['pf'][$parserFunction]['class']); |
| 138 | + return new $egMapsServices[$service]['pf'][$parserFunction]['class'](); |
| 139 | + } |
| 140 | + |
141 | 141 | } |
\ No newline at end of file |
Property changes on: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php |
___________________________________________________________________ |
Name: svn:eol-style |
142 | 142 | + native |
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php |
— | — | @@ -1,164 +1,164 @@ |
2 | | -<?php
|
3 | | -
|
4 | | -/**
|
5 | | - * Abstract class MapsBasePointMap provides the scafolding for classes handling display_point(s)
|
6 | | - * and display_address(es) calls for a spesific mapping service. It inherits from MapsMapFeature and therefore
|
7 | | - * forces inheriting classes to implement sereveral methods.
|
8 | | - *
|
9 | | - * @file Maps_BasePointMap.php
|
10 | | - * @ingroup Maps
|
11 | | - *
|
12 | | - * @author Jeroen De Dauw
|
13 | | - */
|
14 | | -
|
15 | | -if( !defined( 'MEDIAWIKI' ) ) {
|
16 | | - die( 'Not an entry point.' );
|
17 | | -}
|
18 | | -
|
19 | | -abstract class MapsBasePointMap extends MapsMapFeature {
|
20 | | -
|
21 | | - protected $markerData = array();
|
22 | | -
|
23 | | - /**
|
24 | | - * Handles the request from the parser hook by doing the work that's common for all
|
25 | | - * mapping services, calling the specific methods and finally returning the resulting output.
|
26 | | - *
|
27 | | - * @param unknown_type $parser
|
28 | | - * @param array $params
|
29 | | - *
|
30 | | - * @return html
|
31 | | - */
|
32 | | - public final function displayMap(&$parser, array $params) {
|
33 | | - $this->setMapSettings();
|
34 | | -
|
35 | | - $coords = $this->manageMapProperties($params);
|
36 | | -
|
37 | | - $this->doMapServiceLoad();
|
38 | | -
|
39 | | - $this->setMapName();
|
40 | | -
|
41 | | - $this->setCoordinates($parser);
|
42 | | -
|
43 | | - $this->setZoom();
|
44 | | -
|
45 | | - $this->setCentre();
|
46 | | -
|
47 | | - $this->doParsing($parser);
|
48 | | -
|
49 | | - $this->doEscaping();
|
50 | | -
|
51 | | - $this->addSpecificMapHTML();
|
52 | | -
|
53 | | - return $this->output;
|
54 | | - }
|
55 | | -
|
56 | | - /**
|
57 | | - * (non-PHPdoc)
|
58 | | - * @see smw/extensions/Maps/MapsMapFeature#manageMapProperties($mapProperties, $className)
|
59 | | - */
|
60 | | - protected function manageMapProperties($params) {
|
61 | | - parent::manageMapProperties($params, __CLASS__);
|
62 | | - }
|
63 | | -
|
64 | | - /**
|
65 | | - * Sets the zoom level to the provided value. When no zoom is provided, set
|
66 | | - * it to the default when there is only one location, or the best fitting soom when
|
67 | | - * there are multiple locations.
|
68 | | - *
|
69 | | - */
|
70 | | - private function setZoom() {
|
71 | | - if (strlen($this->zoom) < 1) {
|
72 | | - if (count($this->markerData) > 1) {
|
73 | | - $this->zoom = 'null';
|
74 | | - }
|
75 | | - else {
|
76 | | - $this->zoom = $this->defaultZoom;
|
77 | | - }
|
78 | | - }
|
79 | | - }
|
80 | | -
|
81 | | - /**
|
82 | | - * Fills the $markerData array with the locations and their meta data.
|
83 | | - *
|
84 | | - * @param unknown_type $parser
|
85 | | - */
|
86 | | - private function setCoordinates($parser) {
|
87 | | - $this->coordinates = explode(';', $this->coordinates);
|
88 | | -
|
89 | | - foreach($this->coordinates as $coordinates) {
|
90 | | - $args = explode('~', $coordinates);
|
91 | | -
|
92 | | - $args[0] = str_replace('″', '"', $args[0]);
|
93 | | - $args[0] = str_replace('′', "'", $args[0]);
|
94 | | -
|
95 | | - $markerData = MapsUtils::getLatLon($args[0]);
|
96 | | -
|
97 | | - if (count($args) > 1) {
|
98 | | - $markerData['title'] = $parser->recursiveTagParse( $args[1] );
|
99 | | -
|
100 | | - if (count($args) > 2) {
|
101 | | - $markerData['label'] = $parser->recursiveTagParse( $args[2] );
|
102 | | -
|
103 | | - if (count($args) > 3) {
|
104 | | - $markerData['icon'] = $args[3];
|
105 | | - }
|
106 | | - }
|
107 | | - }
|
108 | | -
|
109 | | - $this->markerData[] = $markerData;
|
110 | | - }
|
111 | | - }
|
112 | | -
|
113 | | - /**
|
114 | | - * Sets the $centre_lat and $centre_lon fields.
|
115 | | - * Note: this needs to be done AFTRE the maker coordinates are set.
|
116 | | - *
|
117 | | - */
|
118 | | - private function setCentre() {
|
119 | | - if (empty($this->centre)) {
|
120 | | - if (count($this->markerData) == 1) {
|
121 | | - // If centre is not set and there is exactelly one marker, use it's coordinates.
|
122 | | - $this->centre_lat = $this->markerData[0]['lat'];
|
123 | | - $this->centre_lon = $this->markerData[0]['lon'];
|
124 | | - }
|
125 | | - elseif (count($this->markerData) > 1) {
|
126 | | - // If centre is not set and there are multiple markers, set the values to null,
|
127 | | - // to be auto determined by the JS of the mapping API.
|
128 | | - $this->centre_lat = 'null';
|
129 | | - $this->centre_lon = 'null';
|
130 | | - }
|
131 | | - else {
|
132 | | - // If centre is not set and there are no markers, use the default latitude and longitutde.
|
133 | | - global $egMapsMapLat, $egMapsMapLon;
|
134 | | - $this->centre_lat = $egMapsMapLat;
|
135 | | - $this->centre_lon = $egMapsMapLon;
|
136 | | - }
|
137 | | - }
|
138 | | - else {
|
139 | | - // If a centre value is set, use it.
|
140 | | - $centre = MapsUtils::getLatLon($this->centre);
|
141 | | - $this->centre_lat = $centre['lat'];
|
142 | | - $this->centre_lon = $centre['lon'];
|
143 | | - }
|
144 | | - }
|
145 | | -
|
146 | | - /**
|
147 | | - * Parse the wiki text in the title and label values.
|
148 | | - *
|
149 | | - * @param unknown_type $parser
|
150 | | - */
|
151 | | - private function doParsing(&$parser) {
|
152 | | - $this->title = $parser->recursiveTagParse( $this->title );
|
153 | | - $this->label = $parser->recursiveTagParse( $this->label );
|
154 | | - }
|
155 | | -
|
156 | | - /**
|
157 | | - * Escape the title and label text
|
158 | | - *
|
159 | | - */
|
160 | | - private function doEscaping() {
|
161 | | - $this->title = str_replace("'", "\'", $this->title);
|
162 | | - $this->label = str_replace("'", "\'", $this->label);
|
163 | | - }
|
164 | | -
|
165 | | -}
|
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Abstract class MapsBasePointMap provides the scafolding for classes handling display_point(s) |
| 6 | + * and display_address(es) calls for a spesific mapping service. It inherits from MapsMapFeature and therefore |
| 7 | + * forces inheriting classes to implement sereveral methods. |
| 8 | + * |
| 9 | + * @file Maps_BasePointMap.php |
| 10 | + * @ingroup Maps |
| 11 | + * |
| 12 | + * @author Jeroen De Dauw |
| 13 | + */ |
| 14 | + |
| 15 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 16 | + die( 'Not an entry point.' ); |
| 17 | +} |
| 18 | + |
| 19 | +abstract class MapsBasePointMap extends MapsMapFeature { |
| 20 | + |
| 21 | + protected $markerData = array(); |
| 22 | + |
| 23 | + /** |
| 24 | + * Handles the request from the parser hook by doing the work that's common for all |
| 25 | + * mapping services, calling the specific methods and finally returning the resulting output. |
| 26 | + * |
| 27 | + * @param unknown_type $parser |
| 28 | + * @param array $params |
| 29 | + * |
| 30 | + * @return html |
| 31 | + */ |
| 32 | + public final function displayMap(&$parser, array $params) { |
| 33 | + $this->setMapSettings(); |
| 34 | + |
| 35 | + $coords = $this->manageMapProperties($params); |
| 36 | + |
| 37 | + $this->doMapServiceLoad(); |
| 38 | + |
| 39 | + $this->setMapName(); |
| 40 | + |
| 41 | + $this->setCoordinates($parser); |
| 42 | + |
| 43 | + $this->setZoom(); |
| 44 | + |
| 45 | + $this->setCentre(); |
| 46 | + |
| 47 | + $this->doParsing($parser); |
| 48 | + |
| 49 | + $this->doEscaping(); |
| 50 | + |
| 51 | + $this->addSpecificMapHTML(); |
| 52 | + |
| 53 | + return $this->output; |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * (non-PHPdoc) |
| 58 | + * @see smw/extensions/Maps/MapsMapFeature#manageMapProperties($mapProperties, $className) |
| 59 | + */ |
| 60 | + protected function manageMapProperties($params) { |
| 61 | + parent::manageMapProperties($params, __CLASS__); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Sets the zoom level to the provided value. When no zoom is provided, set |
| 66 | + * it to the default when there is only one location, or the best fitting soom when |
| 67 | + * there are multiple locations. |
| 68 | + * |
| 69 | + */ |
| 70 | + private function setZoom() { |
| 71 | + if (strlen($this->zoom) < 1) { |
| 72 | + if (count($this->markerData) > 1) { |
| 73 | + $this->zoom = 'null'; |
| 74 | + } |
| 75 | + else { |
| 76 | + $this->zoom = $this->defaultZoom; |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Fills the $markerData array with the locations and their meta data. |
| 83 | + * |
| 84 | + * @param unknown_type $parser |
| 85 | + */ |
| 86 | + private function setCoordinates($parser) { |
| 87 | + $this->coordinates = explode(';', $this->coordinates); |
| 88 | + |
| 89 | + foreach($this->coordinates as $coordinates) { |
| 90 | + $args = explode('~', $coordinates); |
| 91 | + |
| 92 | + $args[0] = str_replace('″', '"', $args[0]); |
| 93 | + $args[0] = str_replace('′', "'", $args[0]); |
| 94 | + |
| 95 | + $markerData = MapsUtils::getLatLon($args[0]); |
| 96 | + |
| 97 | + if (count($args) > 1) { |
| 98 | + $markerData['title'] = $parser->recursiveTagParse( $args[1] ); |
| 99 | + |
| 100 | + if (count($args) > 2) { |
| 101 | + $markerData['label'] = $parser->recursiveTagParse( $args[2] ); |
| 102 | + |
| 103 | + if (count($args) > 3) { |
| 104 | + $markerData['icon'] = $args[3]; |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + $this->markerData[] = $markerData; |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Sets the $centre_lat and $centre_lon fields. |
| 115 | + * Note: this needs to be done AFTRE the maker coordinates are set. |
| 116 | + * |
| 117 | + */ |
| 118 | + private function setCentre() { |
| 119 | + if (empty($this->centre)) { |
| 120 | + if (count($this->markerData) == 1) { |
| 121 | + // If centre is not set and there is exactelly one marker, use it's coordinates. |
| 122 | + $this->centre_lat = $this->markerData[0]['lat']; |
| 123 | + $this->centre_lon = $this->markerData[0]['lon']; |
| 124 | + } |
| 125 | + elseif (count($this->markerData) > 1) { |
| 126 | + // If centre is not set and there are multiple markers, set the values to null, |
| 127 | + // to be auto determined by the JS of the mapping API. |
| 128 | + $this->centre_lat = 'null'; |
| 129 | + $this->centre_lon = 'null'; |
| 130 | + } |
| 131 | + else { |
| 132 | + // If centre is not set and there are no markers, use the default latitude and longitutde. |
| 133 | + global $egMapsMapLat, $egMapsMapLon; |
| 134 | + $this->centre_lat = $egMapsMapLat; |
| 135 | + $this->centre_lon = $egMapsMapLon; |
| 136 | + } |
| 137 | + } |
| 138 | + else { |
| 139 | + // If a centre value is set, use it. |
| 140 | + $centre = MapsUtils::getLatLon($this->centre); |
| 141 | + $this->centre_lat = $centre['lat']; |
| 142 | + $this->centre_lon = $centre['lon']; |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * Parse the wiki text in the title and label values. |
| 148 | + * |
| 149 | + * @param unknown_type $parser |
| 150 | + */ |
| 151 | + private function doParsing(&$parser) { |
| 152 | + $this->title = $parser->recursiveTagParse( $this->title ); |
| 153 | + $this->label = $parser->recursiveTagParse( $this->label ); |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * Escape the title and label text |
| 158 | + * |
| 159 | + */ |
| 160 | + private function doEscaping() { |
| 161 | + $this->title = str_replace("'", "\'", $this->title); |
| 162 | + $this->label = str_replace("'", "\'", $this->label); |
| 163 | + } |
| 164 | + |
| 165 | +} |
Property changes on: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php |
___________________________________________________________________ |
Name: svn:eol-style |
166 | 166 | + native |
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php |
— | — | @@ -1,120 +1,120 @@ |
2 | | -<?php
|
3 | | -
|
4 | | -/**
|
5 | | - *
|
6 | | - *
|
7 | | - * @file Maps_DisplayMap.php
|
8 | | - * @ingroup Maps
|
9 | | - *
|
10 | | - * @author Jeroen De Dauw
|
11 | | - */
|
12 | | -
|
13 | | -if( !defined( 'MEDIAWIKI' ) ) {
|
14 | | - die( 'Not an entry point.' );
|
15 | | -}
|
16 | | -
|
17 | | -$wgAutoloadClasses['MapsDisplayMap'] = $egMapsIP . '/ParserFunctions/DisplayMap/Maps_DisplayMap.php';
|
18 | | -$wgAutoloadClasses['MapsBaseMap'] = $egMapsIP . '/ParserFunctions/DisplayMap/Maps_BaseMap.php';
|
19 | | -
|
20 | | -$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayMapMagic';
|
21 | | -$wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayMap';
|
22 | | -
|
23 | | -/**
|
24 | | - * Adds the magic words for the parser functions
|
25 | | - */
|
26 | | -function efMapsDisplayMapMagic( &$magicWords, $langCode ) {
|
27 | | - $magicWords['display_map'] = array( 0, 'display_map');
|
28 | | -
|
29 | | - return true; // Unless we return true, other parser functions won't get loaded
|
30 | | -}
|
31 | | -
|
32 | | -/**
|
33 | | - * Adds the parser function hooks
|
34 | | - */
|
35 | | -function efMapsRegisterDisplayMap(&$wgParser) {
|
36 | | - // A hook to enable the '#display_map' parser function
|
37 | | - $wgParser->setFunctionHook( 'display_map', array('MapsDisplayMap', 'displayMapRender') );
|
38 | | -
|
39 | | - return true;
|
40 | | -}
|
41 | | -
|
42 | | -/**
|
43 | | - *
|
44 | | - *
|
45 | | - * @author Jeroen De Dauw
|
46 | | - *
|
47 | | - */
|
48 | | -final class MapsDisplayMap {
|
49 | | -
|
50 | | - /**
|
51 | | - * If an address value is provided, turn it into coordinates,
|
52 | | - * then calls getMapHtml() and returns it's result.
|
53 | | - *
|
54 | | - * @param unknown_type $parser
|
55 | | - * @return array
|
56 | | - */
|
57 | | - public static function displayMapRender(&$parser) {
|
58 | | - $params = func_get_args();
|
59 | | - array_shift( $params ); // We already know the $parser ...
|
60 | | -
|
61 | | - // TODO: auto geocode when required
|
62 | | - //$fails = MapsParserGeocoder::changeAddressToCoords($params);
|
63 | | -
|
64 | | - return self::getMapHtml($parser, $params, 'display_map');
|
65 | | - }
|
66 | | -
|
67 | | - public static function getMapHtml(&$parser, array $params, $parserFunction, array $coordFails = array()) {
|
68 | | - global $wgLang;
|
69 | | -
|
70 | | - $map = array();
|
71 | | -
|
72 | | - // Go through all parameters, split their names and values, and put them in the $map array.
|
73 | | - foreach($params as $param) {
|
74 | | - $split = split('=', $param);
|
75 | | - if (count($split) > 1) {
|
76 | | - $paramName = strtolower(trim($split[0]));
|
77 | | - $paramValue = trim($split[1]);
|
78 | | - if (strlen($paramName) > 0 && strlen($paramValue) > 0) {
|
79 | | - $map[$paramName] = $paramValue;
|
80 | | - }
|
81 | | - }
|
82 | | - else if (count($split) == 1) { // Default parameter (without name)
|
83 | | - $split[0] = trim($split[0]);
|
84 | | - if (strlen($split[0]) > 0) $map['coordinates'] = $split[0];
|
85 | | - }
|
86 | | - }
|
87 | | -
|
88 | | - $coords = MapsMapper::getParamValue('coordinates', $map);
|
89 | | -
|
90 | | - if ($coords) {
|
91 | | - if (! MapsMapper::paramIsPresent('service', $map)) $map['service'] = '';
|
92 | | - $map['service'] = MapsMapper::getValidService($map['service'], 'pf');
|
93 | | -
|
94 | | - $mapClass = self::getParserClassInstance($map['service'], $parserFunction);
|
95 | | -
|
96 | | - // Call the function according to the map service to get the HTML output
|
97 | | - $output = $mapClass->displayMap($parser, $map);
|
98 | | -
|
99 | | - if (count($coordFails) > 0) {
|
100 | | - $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText($coordFails ), count( $coordFails ) ) . '</i>';
|
101 | | - }
|
102 | | - }
|
103 | | - elseif (trim($coords) == "" && count($coordFails) > 0) {
|
104 | | - $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>';
|
105 | | - }
|
106 | | - else {
|
107 | | - $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>';
|
108 | | - }
|
109 | | -
|
110 | | - // Return the result
|
111 | | - return array( $output, 'noparse' => true, 'isHTML' => true );
|
112 | | - }
|
113 | | -
|
114 | | - private static function getParserClassInstance($service, $parserFunction) {
|
115 | | - global $egMapsServices;
|
116 | | - // TODO: add check to see if the service actually supports this parser function, and return false for error handling if not.
|
117 | | - //die($egMapsServices[$service]['pf'][$parserFunction]['class']);
|
118 | | - return new $egMapsServices[$service]['pf'][$parserFunction]['class']();
|
119 | | - }
|
120 | | -
|
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * |
| 6 | + * |
| 7 | + * @file Maps_DisplayMap.php |
| 8 | + * @ingroup Maps |
| 9 | + * |
| 10 | + * @author Jeroen De Dauw |
| 11 | + */ |
| 12 | + |
| 13 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 14 | + die( 'Not an entry point.' ); |
| 15 | +} |
| 16 | + |
| 17 | +$wgAutoloadClasses['MapsDisplayMap'] = $egMapsIP . '/ParserFunctions/DisplayMap/Maps_DisplayMap.php'; |
| 18 | +$wgAutoloadClasses['MapsBaseMap'] = $egMapsIP . '/ParserFunctions/DisplayMap/Maps_BaseMap.php'; |
| 19 | + |
| 20 | +$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayMapMagic'; |
| 21 | +$wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayMap'; |
| 22 | + |
| 23 | +/** |
| 24 | + * Adds the magic words for the parser functions |
| 25 | + */ |
| 26 | +function efMapsDisplayMapMagic( &$magicWords, $langCode ) { |
| 27 | + $magicWords['display_map'] = array( 0, 'display_map'); |
| 28 | + |
| 29 | + return true; // Unless we return true, other parser functions won't get loaded |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Adds the parser function hooks |
| 34 | + */ |
| 35 | +function efMapsRegisterDisplayMap(&$wgParser) { |
| 36 | + // A hook to enable the '#display_map' parser function |
| 37 | + $wgParser->setFunctionHook( 'display_map', array('MapsDisplayMap', 'displayMapRender') ); |
| 38 | + |
| 39 | + return true; |
| 40 | +} |
| 41 | + |
| 42 | +/** |
| 43 | + * |
| 44 | + * |
| 45 | + * @author Jeroen De Dauw |
| 46 | + * |
| 47 | + */ |
| 48 | +final class MapsDisplayMap { |
| 49 | + |
| 50 | + /** |
| 51 | + * If an address value is provided, turn it into coordinates, |
| 52 | + * then calls getMapHtml() and returns it's result. |
| 53 | + * |
| 54 | + * @param unknown_type $parser |
| 55 | + * @return array |
| 56 | + */ |
| 57 | + public static function displayMapRender(&$parser) { |
| 58 | + $params = func_get_args(); |
| 59 | + array_shift( $params ); // We already know the $parser ... |
| 60 | + |
| 61 | + // TODO: auto geocode when required |
| 62 | + //$fails = MapsParserGeocoder::changeAddressToCoords($params); |
| 63 | + |
| 64 | + return self::getMapHtml($parser, $params, 'display_map'); |
| 65 | + } |
| 66 | + |
| 67 | + public static function getMapHtml(&$parser, array $params, $parserFunction, array $coordFails = array()) { |
| 68 | + global $wgLang; |
| 69 | + |
| 70 | + $map = array(); |
| 71 | + |
| 72 | + // Go through all parameters, split their names and values, and put them in the $map array. |
| 73 | + foreach($params as $param) { |
| 74 | + $split = split('=', $param); |
| 75 | + if (count($split) > 1) { |
| 76 | + $paramName = strtolower(trim($split[0])); |
| 77 | + $paramValue = trim($split[1]); |
| 78 | + if (strlen($paramName) > 0 && strlen($paramValue) > 0) { |
| 79 | + $map[$paramName] = $paramValue; |
| 80 | + } |
| 81 | + } |
| 82 | + else if (count($split) == 1) { // Default parameter (without name) |
| 83 | + $split[0] = trim($split[0]); |
| 84 | + if (strlen($split[0]) > 0) $map['coordinates'] = $split[0]; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + $coords = MapsMapper::getParamValue('coordinates', $map); |
| 89 | + |
| 90 | + if ($coords) { |
| 91 | + if (! MapsMapper::paramIsPresent('service', $map)) $map['service'] = ''; |
| 92 | + $map['service'] = MapsMapper::getValidService($map['service'], 'pf'); |
| 93 | + |
| 94 | + $mapClass = self::getParserClassInstance($map['service'], $parserFunction); |
| 95 | + |
| 96 | + // Call the function according to the map service to get the HTML output |
| 97 | + $output = $mapClass->displayMap($parser, $map); |
| 98 | + |
| 99 | + if (count($coordFails) > 0) { |
| 100 | + $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText($coordFails ), count( $coordFails ) ) . '</i>'; |
| 101 | + } |
| 102 | + } |
| 103 | + elseif (trim($coords) == "" && count($coordFails) > 0) { |
| 104 | + $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; |
| 105 | + } |
| 106 | + else { |
| 107 | + $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>'; |
| 108 | + } |
| 109 | + |
| 110 | + // Return the result |
| 111 | + return array( $output, 'noparse' => true, 'isHTML' => true ); |
| 112 | + } |
| 113 | + |
| 114 | + private static function getParserClassInstance($service, $parserFunction) { |
| 115 | + global $egMapsServices; |
| 116 | + // TODO: add check to see if the service actually supports this parser function, and return false for error handling if not. |
| 117 | + //die($egMapsServices[$service]['pf'][$parserFunction]['class']); |
| 118 | + return new $egMapsServices[$service]['pf'][$parserFunction]['class'](); |
| 119 | + } |
| 120 | + |
121 | 121 | } |
\ No newline at end of file |
Property changes on: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php |
___________________________________________________________________ |
Name: svn:eol-style |
122 | 122 | + native |
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php |
— | — | @@ -1,71 +1,71 @@ |
2 | | -<?php
|
3 | | -
|
4 | | -/**
|
5 | | - * Abstract class MapsBaseMap provides the scafolding for classes handling display_map
|
6 | | - * calls for a spesific mapping service. It inherits from MapsMapFeature and therefore
|
7 | | - * forces inheriting classes to implement sereveral methods.
|
8 | | - *
|
9 | | - * @file Maps_BaseMap.php
|
10 | | - * @ingroup Maps
|
11 | | - *
|
12 | | - * @author Jeroen De Dauw
|
13 | | - */
|
14 | | -
|
15 | | -if( !defined( 'MEDIAWIKI' ) ) {
|
16 | | - die( 'Not an entry point.' );
|
17 | | -}
|
18 | | -
|
19 | | -abstract class MapsBaseMap extends MapsMapFeature {
|
20 | | -
|
21 | | - /**
|
22 | | - * Handles the request from the parser hook by doing the work that's common for all
|
23 | | - * mapping services, calling the specific methods and finally returning the resulting output.
|
24 | | - *
|
25 | | - * @param unknown_type $parser
|
26 | | - * @param array $params
|
27 | | - *
|
28 | | - * @return html
|
29 | | - */
|
30 | | - public final function displayMap(&$parser, array $params) {
|
31 | | -die('disp map');
|
32 | | -
|
33 | | - $this->setMapSettings();
|
34 | | -
|
35 | | - $coords = $this->manageMapProperties($params);
|
36 | | -
|
37 | | - $this->doMapServiceLoad();
|
38 | | -
|
39 | | - $this->setMapName();
|
40 | | -
|
41 | | - $this->setZoom();
|
42 | | -
|
43 | | - $this->setCentre();
|
44 | | -
|
45 | | - $this->addSpecificMapHTML();
|
46 | | -
|
47 | | - return $this->output;
|
48 | | - }
|
49 | | -
|
50 | | - /**
|
51 | | - * (non-PHPdoc)
|
52 | | - * @see smw/extensions/Maps/MapsMapFeature#manageMapProperties($mapProperties, $className)
|
53 | | - */
|
54 | | - protected function manageMapProperties($params) {
|
55 | | - parent::manageMapProperties($params, __CLASS__);
|
56 | | - }
|
57 | | -
|
58 | | - /**
|
59 | | - * Sets the zoom level to the provided value. When no zoom is provided, set
|
60 | | - * it to the default when there is only one location, or the best fitting soom when
|
61 | | - * there are multiple locations.
|
62 | | - *
|
63 | | - */
|
64 | | - private function setZoom() {
|
65 | | - if (strlen($this->zoom) < 1) $this->zoom = $this->defaultZoom;
|
66 | | - }
|
67 | | -
|
68 | | - private function setCentre() {
|
69 | | - if (strlen($this->centre) < 1) $this->centre = $this->defaultZoom;
|
70 | | - }
|
71 | | -
|
72 | | -}
|
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Abstract class MapsBaseMap provides the scafolding for classes handling display_map |
| 6 | + * calls for a spesific mapping service. It inherits from MapsMapFeature and therefore |
| 7 | + * forces inheriting classes to implement sereveral methods. |
| 8 | + * |
| 9 | + * @file Maps_BaseMap.php |
| 10 | + * @ingroup Maps |
| 11 | + * |
| 12 | + * @author Jeroen De Dauw |
| 13 | + */ |
| 14 | + |
| 15 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 16 | + die( 'Not an entry point.' ); |
| 17 | +} |
| 18 | + |
| 19 | +abstract class MapsBaseMap extends MapsMapFeature { |
| 20 | + |
| 21 | + /** |
| 22 | + * Handles the request from the parser hook by doing the work that's common for all |
| 23 | + * mapping services, calling the specific methods and finally returning the resulting output. |
| 24 | + * |
| 25 | + * @param unknown_type $parser |
| 26 | + * @param array $params |
| 27 | + * |
| 28 | + * @return html |
| 29 | + */ |
| 30 | + public final function displayMap(&$parser, array $params) { |
| 31 | +die('disp map'); |
| 32 | + |
| 33 | + $this->setMapSettings(); |
| 34 | + |
| 35 | + $coords = $this->manageMapProperties($params); |
| 36 | + |
| 37 | + $this->doMapServiceLoad(); |
| 38 | + |
| 39 | + $this->setMapName(); |
| 40 | + |
| 41 | + $this->setZoom(); |
| 42 | + |
| 43 | + $this->setCentre(); |
| 44 | + |
| 45 | + $this->addSpecificMapHTML(); |
| 46 | + |
| 47 | + return $this->output; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * (non-PHPdoc) |
| 52 | + * @see smw/extensions/Maps/MapsMapFeature#manageMapProperties($mapProperties, $className) |
| 53 | + */ |
| 54 | + protected function manageMapProperties($params) { |
| 55 | + parent::manageMapProperties($params, __CLASS__); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Sets the zoom level to the provided value. When no zoom is provided, set |
| 60 | + * it to the default when there is only one location, or the best fitting soom when |
| 61 | + * there are multiple locations. |
| 62 | + * |
| 63 | + */ |
| 64 | + private function setZoom() { |
| 65 | + if (strlen($this->zoom) < 1) $this->zoom = $this->defaultZoom; |
| 66 | + } |
| 67 | + |
| 68 | + private function setCentre() { |
| 69 | + if (strlen($this->centre) < 1) $this->centre = $this->defaultZoom; |
| 70 | + } |
| 71 | + |
| 72 | +} |
Property changes on: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php |
___________________________________________________________________ |
Name: svn:eol-style |
73 | 73 | + native |
Index: trunk/extensions/Maps/ParserFunctions/Geocode/Maps_Geocoder.php |
— | — | @@ -1,216 +1,216 @@ |
2 | | -<?php
|
3 | | -
|
4 | | -/**
|
5 | | - * File containing the MapsGeocoder class which handles the non specific geocoding tasks
|
6 | | - *
|
7 | | - * {{#geocode:<Address>|<param1>=<value1>|<param2>=<value2>}}
|
8 | | - * {{#geocodelat:<Address>|<param1>=<value1>|<param2>=<value2>}}
|
9 | | - * {{#geocodelng:<Address>|<param1>=<value1>|<param2>=<value2>}}
|
10 | | - *
|
11 | | - * @file Maps_Geocoder.php
|
12 | | - * @ingroup Maps
|
13 | | - *
|
14 | | - * @author Jeroen De Dauw
|
15 | | - * @author Sergey Chernyshev
|
16 | | - */
|
17 | | -
|
18 | | -if( !defined( 'MEDIAWIKI' ) ) {
|
19 | | - die( 'Not an entry point.' );
|
20 | | -}
|
21 | | -
|
22 | | -$wgHooks['LanguageGetMagic'][] = 'efMapsGeoFunctionMagic';
|
23 | | -$wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterGeoFunctions';
|
24 | | -
|
25 | | -/**
|
26 | | - * Adds the magic words for the parser functions
|
27 | | - */
|
28 | | -function efMapsGeoFunctionMagic( &$magicWords, $langCode ) {
|
29 | | - $magicWords['geocode'] = array( 0, 'geocode' );
|
30 | | - $magicWords['geocodelat'] = array ( 0, 'geocodelat' );
|
31 | | - $magicWords['geocodelng'] = array ( 0, 'geocodelng' );
|
32 | | -
|
33 | | - return true; // Unless we return true, other parser functions won't get loaded
|
34 | | -}
|
35 | | -
|
36 | | -/**
|
37 | | - * Adds the parser function hooks
|
38 | | - */
|
39 | | -function efMapsRegisterGeoFunctions(&$wgParser) {
|
40 | | - // Hooks to enable the geocoding parser functions
|
41 | | - $wgParser->setFunctionHook( 'geocode', array('MapsGeocoder', 'renderGeocoder') );
|
42 | | - $wgParser->setFunctionHook( 'geocodelat', array('MapsGeocoder', 'renderGeocoderLat') );
|
43 | | - $wgParser->setFunctionHook( 'geocodelng', array('MapsGeocoder', 'renderGeocoderLng') );
|
44 | | -
|
45 | | - return true;
|
46 | | -}
|
47 | | -
|
48 | | -final class MapsGeocoder {
|
49 | | -
|
50 | | - /**
|
51 | | - * Holds if geocoded data should be cached or not.
|
52 | | - *
|
53 | | - * @var boolean
|
54 | | - */
|
55 | | - private static $mEnableCache = true;
|
56 | | -
|
57 | | - /**
|
58 | | - * The geocoder cache, holding geocoded data when enabled.
|
59 | | - *
|
60 | | - * @var array
|
61 | | - */
|
62 | | - private static $mGeocoderCache = array();
|
63 | | -
|
64 | | - /**
|
65 | | - * Handler for the geocode parser function. Returns the latitude and longitude
|
66 | | - * for the provided address, or an empty string, when the geocoding fails.
|
67 | | - *
|
68 | | - * @param unknown_type $parser
|
69 | | - * @param string $address The address to geocode.
|
70 | | - * @param string $service Optional. The geocoding service to use.
|
71 | | - * @param string $mappingService Optional. The mapping service that will use the geocoded data.
|
72 | | - * @return string
|
73 | | - */
|
74 | | - public static function renderGeocoder($parser, $address, $service = '', $mappingService = '') {
|
75 | | - $geovalues = MapsGeocoder::geocode($address, $service, $mappingService);
|
76 | | - return $geovalues ? $geovalues['lat'].', '.$geovalues['lon'] : '';
|
77 | | - }
|
78 | | -
|
79 | | - /**
|
80 | | - * Handler for the geocode parser function. Returns the latitude
|
81 | | - * for the provided address, or an empty string, when the geocoding fails.
|
82 | | - *
|
83 | | - * @param unknown_type $parser
|
84 | | - * @param string $address The address to geocode.
|
85 | | - * @param string $service Optional. The geocoding service to use.
|
86 | | - * @param string $mappingService Optional. The mapping service that will use the geocoded data.
|
87 | | - * @return string
|
88 | | - */
|
89 | | - public static function renderGeocoderLat(&$parser, $address, $service = '', $mappingService = '') {
|
90 | | - $geovalues = MapsGeocoder::geocode($address, $service, $mappingService);
|
91 | | - return $geovalues ? $geovalues['lat'] : '';
|
92 | | - }
|
93 | | -
|
94 | | - /**
|
95 | | - * Handler for the geocode parser function. Returns the longitude
|
96 | | - * for the provided address, or an empty string, when the geocoding fails.
|
97 | | - *
|
98 | | - * @param unknown_type $parser
|
99 | | - * @param string $address The address to geocode.
|
100 | | - * @param string $service Optional. The geocoding service to use.
|
101 | | - * @param string $mappingService Optional. The mapping service that will use the geocoded data.
|
102 | | - * @return string
|
103 | | - */
|
104 | | - public static function renderGeocoderLng(&$parser, $address, $service = '', $mappingService = '') {
|
105 | | - $geovalues = MapsGeocoder::geocode($address, $service, $mappingService);
|
106 | | - return $geovalues ? $geovalues['lon'] : '';
|
107 | | - }
|
108 | | -
|
109 | | - /**
|
110 | | - * Geocodes an address with the provided geocoding service and returns the result
|
111 | | - * as a string with the optionally provided format, or false when the geocoding failed.
|
112 | | - *
|
113 | | - * @param string $address
|
114 | | - * @param string $service
|
115 | | - * @param string $mappingService
|
116 | | - * @param string $format
|
117 | | - * @return formatted coordinate string or false
|
118 | | - */
|
119 | | - public static function geocodeToString($address, $service = '', $mappingService = '', $format = '%1$s, %2$s') {
|
120 | | - $geovalues = MapsGeocoder::geocode($address, $service, $mappingService);
|
121 | | - return $geovalues ? sprintf($format, $geovalues['lat'], $geovalues['lon']) : false;
|
122 | | - }
|
123 | | -
|
124 | | - /**
|
125 | | - * Geocodes an address with the provided geocoding service and returns the result
|
126 | | - * as an array, or false when the geocoding failed.
|
127 | | - *
|
128 | | - * @param string $address
|
129 | | - * @param string $service
|
130 | | - * @param string $mappingService
|
131 | | - * @return array with coordinates or false
|
132 | | - */
|
133 | | - private static function geocode($address, $service, $mappingService) {
|
134 | | - global $egMapsAvailableGeoServices, $egMapsDefaultGeoService;
|
135 | | -
|
136 | | - // If the adress is already in the cache and the cache is enabled, return the coordinates
|
137 | | - if (self::$mEnableCache && array_key_exists($address, MapsGeocoder::$mGeocoderCache)) {
|
138 | | - return self::$mGeocoderCache[$address];
|
139 | | - }
|
140 | | -
|
141 | | - $coordinates = false;
|
142 | | -
|
143 | | - $service = self::getValidGeoService($service, $mappingService);
|
144 | | -
|
145 | | - // If not, use the selected geocoding service to geocode the provided adress
|
146 | | - switch(strtolower($service)) {
|
147 | | - case 'google':
|
148 | | - self::addAutoloadClassIfNeeded('MapsGoogleGeocoder', 'Maps_GoogleGeocoder.php');
|
149 | | - $coordinates = MapsGoogleGeocoder::geocode($address);
|
150 | | - break;
|
151 | | - case 'yahoo':
|
152 | | - self::addAutoloadClassIfNeeded('MapsYahooGeocoder', 'Maps_YahooGeocoder.php');
|
153 | | - $coordinates = MapsYahooGeocoder::geocode($address);
|
154 | | - break;
|
155 | | - case 'geonames':
|
156 | | - self::addAutoloadClassIfNeeded('MapsGeonamesGeocoder', 'Maps_GeonamesGeocoder.php');
|
157 | | - $coordinates = MapsGeonamesGeocoder::geocode($address);
|
158 | | - break;
|
159 | | - }
|
160 | | -
|
161 | | - // Add the obtained coordinates to the cache when there is a result and the cache is enabled
|
162 | | - if (self::$mEnableCache && $coordinates) {
|
163 | | - MapsGeocoder::$mGeocoderCache[$address] = $coordinates;
|
164 | | - }
|
165 | | -
|
166 | | - return $coordinates;
|
167 | | - }
|
168 | | -
|
169 | | - /**
|
170 | | - * Add a geocoder class to the $wgAutoloadClasses array when it's not present yet.
|
171 | | - *
|
172 | | - * @param string $className
|
173 | | - * @param string $fileName
|
174 | | - */
|
175 | | - private static function addAutoloadClassIfNeeded($className, $fileName) {
|
176 | | - global $wgAutoloadClasses, $egMapsIP;
|
177 | | - if (!array_key_exists($className, $wgAutoloadClasses)) $wgAutoloadClasses[$className] = $egMapsIP . '/Geocoders/' . $fileName;
|
178 | | - }
|
179 | | -
|
180 | | - /**
|
181 | | - * Makes sure that the geo service is one of the available ones.
|
182 | | - * Also enforces licencing restrictions when no geocoding service is explicitly provided.
|
183 | | - *
|
184 | | - * @param string $service
|
185 | | - * @param string $mappingService
|
186 | | - * @return string
|
187 | | - */
|
188 | | - private static function getValidGeoService($service, $mappingService) {
|
189 | | - global $egMapsAvailableGeoServices, $egMapsDefaultGeoService;
|
190 | | -
|
191 | | - if (strlen($service) < 1) {
|
192 | | -
|
193 | | - // Set the default geocoding services.
|
194 | | - // Note that googlemaps and yahoomaps are excetions to the general rule due to licencing.
|
195 | | - switch ($mappingService) {
|
196 | | - case 'googlemaps' :
|
197 | | - $service = 'google';
|
198 | | - break;
|
199 | | - case 'yahoomaps' :
|
200 | | - $service = 'yahoo';
|
201 | | - break;
|
202 | | - default :
|
203 | | - $service = $egMapsDefaultGeoService;
|
204 | | - break;
|
205 | | - }
|
206 | | -
|
207 | | - }
|
208 | | - else {
|
209 | | - if(!in_array($service, $egMapsAvailableGeoServices)) $service = $egMapsDefaultGeoService;
|
210 | | - }
|
211 | | -
|
212 | | - return $service;
|
213 | | - }
|
214 | | -}
|
215 | | -
|
216 | | -
|
217 | | -
|
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * File containing the MapsGeocoder class which handles the non specific geocoding tasks |
| 6 | + * |
| 7 | + * {{#geocode:<Address>|<param1>=<value1>|<param2>=<value2>}} |
| 8 | + * {{#geocodelat:<Address>|<param1>=<value1>|<param2>=<value2>}} |
| 9 | + * {{#geocodelng:<Address>|<param1>=<value1>|<param2>=<value2>}} |
| 10 | + * |
| 11 | + * @file Maps_Geocoder.php |
| 12 | + * @ingroup Maps |
| 13 | + * |
| 14 | + * @author Jeroen De Dauw |
| 15 | + * @author Sergey Chernyshev |
| 16 | + */ |
| 17 | + |
| 18 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 19 | + die( 'Not an entry point.' ); |
| 20 | +} |
| 21 | + |
| 22 | +$wgHooks['LanguageGetMagic'][] = 'efMapsGeoFunctionMagic'; |
| 23 | +$wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterGeoFunctions'; |
| 24 | + |
| 25 | +/** |
| 26 | + * Adds the magic words for the parser functions |
| 27 | + */ |
| 28 | +function efMapsGeoFunctionMagic( &$magicWords, $langCode ) { |
| 29 | + $magicWords['geocode'] = array( 0, 'geocode' ); |
| 30 | + $magicWords['geocodelat'] = array ( 0, 'geocodelat' ); |
| 31 | + $magicWords['geocodelng'] = array ( 0, 'geocodelng' ); |
| 32 | + |
| 33 | + return true; // Unless we return true, other parser functions won't get loaded |
| 34 | +} |
| 35 | + |
| 36 | +/** |
| 37 | + * Adds the parser function hooks |
| 38 | + */ |
| 39 | +function efMapsRegisterGeoFunctions(&$wgParser) { |
| 40 | + // Hooks to enable the geocoding parser functions |
| 41 | + $wgParser->setFunctionHook( 'geocode', array('MapsGeocoder', 'renderGeocoder') ); |
| 42 | + $wgParser->setFunctionHook( 'geocodelat', array('MapsGeocoder', 'renderGeocoderLat') ); |
| 43 | + $wgParser->setFunctionHook( 'geocodelng', array('MapsGeocoder', 'renderGeocoderLng') ); |
| 44 | + |
| 45 | + return true; |
| 46 | +} |
| 47 | + |
| 48 | +final class MapsGeocoder { |
| 49 | + |
| 50 | + /** |
| 51 | + * Holds if geocoded data should be cached or not. |
| 52 | + * |
| 53 | + * @var boolean |
| 54 | + */ |
| 55 | + private static $mEnableCache = true; |
| 56 | + |
| 57 | + /** |
| 58 | + * The geocoder cache, holding geocoded data when enabled. |
| 59 | + * |
| 60 | + * @var array |
| 61 | + */ |
| 62 | + private static $mGeocoderCache = array(); |
| 63 | + |
| 64 | + /** |
| 65 | + * Handler for the geocode parser function. Returns the latitude and longitude |
| 66 | + * for the provided address, or an empty string, when the geocoding fails. |
| 67 | + * |
| 68 | + * @param unknown_type $parser |
| 69 | + * @param string $address The address to geocode. |
| 70 | + * @param string $service Optional. The geocoding service to use. |
| 71 | + * @param string $mappingService Optional. The mapping service that will use the geocoded data. |
| 72 | + * @return string |
| 73 | + */ |
| 74 | + public static function renderGeocoder($parser, $address, $service = '', $mappingService = '') { |
| 75 | + $geovalues = MapsGeocoder::geocode($address, $service, $mappingService); |
| 76 | + return $geovalues ? $geovalues['lat'].', '.$geovalues['lon'] : ''; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Handler for the geocode parser function. Returns the latitude |
| 81 | + * for the provided address, or an empty string, when the geocoding fails. |
| 82 | + * |
| 83 | + * @param unknown_type $parser |
| 84 | + * @param string $address The address to geocode. |
| 85 | + * @param string $service Optional. The geocoding service to use. |
| 86 | + * @param string $mappingService Optional. The mapping service that will use the geocoded data. |
| 87 | + * @return string |
| 88 | + */ |
| 89 | + public static function renderGeocoderLat(&$parser, $address, $service = '', $mappingService = '') { |
| 90 | + $geovalues = MapsGeocoder::geocode($address, $service, $mappingService); |
| 91 | + return $geovalues ? $geovalues['lat'] : ''; |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Handler for the geocode parser function. Returns the longitude |
| 96 | + * for the provided address, or an empty string, when the geocoding fails. |
| 97 | + * |
| 98 | + * @param unknown_type $parser |
| 99 | + * @param string $address The address to geocode. |
| 100 | + * @param string $service Optional. The geocoding service to use. |
| 101 | + * @param string $mappingService Optional. The mapping service that will use the geocoded data. |
| 102 | + * @return string |
| 103 | + */ |
| 104 | + public static function renderGeocoderLng(&$parser, $address, $service = '', $mappingService = '') { |
| 105 | + $geovalues = MapsGeocoder::geocode($address, $service, $mappingService); |
| 106 | + return $geovalues ? $geovalues['lon'] : ''; |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Geocodes an address with the provided geocoding service and returns the result |
| 111 | + * as a string with the optionally provided format, or false when the geocoding failed. |
| 112 | + * |
| 113 | + * @param string $address |
| 114 | + * @param string $service |
| 115 | + * @param string $mappingService |
| 116 | + * @param string $format |
| 117 | + * @return formatted coordinate string or false |
| 118 | + */ |
| 119 | + public static function geocodeToString($address, $service = '', $mappingService = '', $format = '%1$s, %2$s') { |
| 120 | + $geovalues = MapsGeocoder::geocode($address, $service, $mappingService); |
| 121 | + return $geovalues ? sprintf($format, $geovalues['lat'], $geovalues['lon']) : false; |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * Geocodes an address with the provided geocoding service and returns the result |
| 126 | + * as an array, or false when the geocoding failed. |
| 127 | + * |
| 128 | + * @param string $address |
| 129 | + * @param string $service |
| 130 | + * @param string $mappingService |
| 131 | + * @return array with coordinates or false |
| 132 | + */ |
| 133 | + private static function geocode($address, $service, $mappingService) { |
| 134 | + global $egMapsAvailableGeoServices, $egMapsDefaultGeoService; |
| 135 | + |
| 136 | + // If the adress is already in the cache and the cache is enabled, return the coordinates |
| 137 | + if (self::$mEnableCache && array_key_exists($address, MapsGeocoder::$mGeocoderCache)) { |
| 138 | + return self::$mGeocoderCache[$address]; |
| 139 | + } |
| 140 | + |
| 141 | + $coordinates = false; |
| 142 | + |
| 143 | + $service = self::getValidGeoService($service, $mappingService); |
| 144 | + |
| 145 | + // If not, use the selected geocoding service to geocode the provided adress |
| 146 | + switch(strtolower($service)) { |
| 147 | + case 'google': |
| 148 | + self::addAutoloadClassIfNeeded('MapsGoogleGeocoder', 'Maps_GoogleGeocoder.php'); |
| 149 | + $coordinates = MapsGoogleGeocoder::geocode($address); |
| 150 | + break; |
| 151 | + case 'yahoo': |
| 152 | + self::addAutoloadClassIfNeeded('MapsYahooGeocoder', 'Maps_YahooGeocoder.php'); |
| 153 | + $coordinates = MapsYahooGeocoder::geocode($address); |
| 154 | + break; |
| 155 | + case 'geonames': |
| 156 | + self::addAutoloadClassIfNeeded('MapsGeonamesGeocoder', 'Maps_GeonamesGeocoder.php'); |
| 157 | + $coordinates = MapsGeonamesGeocoder::geocode($address); |
| 158 | + break; |
| 159 | + } |
| 160 | + |
| 161 | + // Add the obtained coordinates to the cache when there is a result and the cache is enabled |
| 162 | + if (self::$mEnableCache && $coordinates) { |
| 163 | + MapsGeocoder::$mGeocoderCache[$address] = $coordinates; |
| 164 | + } |
| 165 | + |
| 166 | + return $coordinates; |
| 167 | + } |
| 168 | + |
| 169 | + /** |
| 170 | + * Add a geocoder class to the $wgAutoloadClasses array when it's not present yet. |
| 171 | + * |
| 172 | + * @param string $className |
| 173 | + * @param string $fileName |
| 174 | + */ |
| 175 | + private static function addAutoloadClassIfNeeded($className, $fileName) { |
| 176 | + global $wgAutoloadClasses, $egMapsIP; |
| 177 | + if (!array_key_exists($className, $wgAutoloadClasses)) $wgAutoloadClasses[$className] = $egMapsIP . '/Geocoders/' . $fileName; |
| 178 | + } |
| 179 | + |
| 180 | + /** |
| 181 | + * Makes sure that the geo service is one of the available ones. |
| 182 | + * Also enforces licencing restrictions when no geocoding service is explicitly provided. |
| 183 | + * |
| 184 | + * @param string $service |
| 185 | + * @param string $mappingService |
| 186 | + * @return string |
| 187 | + */ |
| 188 | + private static function getValidGeoService($service, $mappingService) { |
| 189 | + global $egMapsAvailableGeoServices, $egMapsDefaultGeoService; |
| 190 | + |
| 191 | + if (strlen($service) < 1) { |
| 192 | + |
| 193 | + // Set the default geocoding services. |
| 194 | + // Note that googlemaps and yahoomaps are excetions to the general rule due to licencing. |
| 195 | + switch ($mappingService) { |
| 196 | + case 'googlemaps' : |
| 197 | + $service = 'google'; |
| 198 | + break; |
| 199 | + case 'yahoomaps' : |
| 200 | + $service = 'yahoo'; |
| 201 | + break; |
| 202 | + default : |
| 203 | + $service = $egMapsDefaultGeoService; |
| 204 | + break; |
| 205 | + } |
| 206 | + |
| 207 | + } |
| 208 | + else { |
| 209 | + if(!in_array($service, $egMapsAvailableGeoServices)) $service = $egMapsDefaultGeoService; |
| 210 | + } |
| 211 | + |
| 212 | + return $service; |
| 213 | + } |
| 214 | +} |
| 215 | + |
| 216 | + |
| 217 | + |
Property changes on: trunk/extensions/Maps/ParserFunctions/Geocode/Maps_Geocoder.php |
___________________________________________________________________ |
Name: svn:eol-style |
218 | 218 | + native |
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserGeocoder.php |
— | — | @@ -1,87 +1,87 @@ |
2 | | -<?php
|
3 | | -
|
4 | | -/**
|
5 | | - *
|
6 | | - *
|
7 | | - * @file Maps_ParserGeocoder.php
|
8 | | - * @ingroup Maps
|
9 | | - *
|
10 | | - * @author Jeroen De Dauw
|
11 | | - */
|
12 | | -
|
13 | | -if( !defined( 'MEDIAWIKI' ) ) {
|
14 | | - die( 'Not an entry point.' );
|
15 | | -}
|
16 | | -
|
17 | | -/**
|
18 | | - * Class that holds static helpers for the mapping parser functions. The helpers aid in
|
19 | | - * determining the availability of the geocoding parser functions and calling them.
|
20 | | - *
|
21 | | - * @author Jeroen De Dauw
|
22 | | - *
|
23 | | - */
|
24 | | -final class MapsParserGeocoder {
|
25 | | -
|
26 | | - /**
|
27 | | - * Changes the values of the address or addresses parameter into coordinates
|
28 | | - * in the provided array. Returns an array containing the addresses that
|
29 | | - * could not be geocoded.
|
30 | | - *
|
31 | | - * @param array $params
|
32 | | - */
|
33 | | - public static function changeAddressToCoords(&$params) {
|
34 | | - global $egMapsDefaultService;
|
35 | | -
|
36 | | - $fails = array();
|
37 | | -
|
38 | | - for ($i = 0; $i < count($params); $i++) {
|
39 | | - $split = split('=', $params[$i]);
|
40 | | - if (MapsMapper::inParamAliases(strtolower(trim($split[0])), 'service') && count($split) > 1) {
|
41 | | - $service = trim($split[1]);
|
42 | | - }
|
43 | | - else if (strtolower(trim($split[0])) == 'geoservice' && count($split) > 1) {
|
44 | | - $geoservice = trim($split[1]);
|
45 | | - }
|
46 | | - }
|
47 | | -
|
48 | | - $service = isset($service) ? MapsMapper::getValidService($service, 'pf') : $egMapsDefaultService;
|
49 | | -
|
50 | | - $geoservice = isset($geoservice) ? $geoservice : '';
|
51 | | -
|
52 | | - for ($i = 0; $i < count($params); $i++) {
|
53 | | -
|
54 | | - $split = split('=', $params[$i]);
|
55 | | - $isAddress = ((strtolower(trim($split[0])) == 'address' || strtolower(trim($split[0])) == 'addresses') && count($split) > 1);
|
56 | | -
|
57 | | - if ($isAddress || count($split) == 1) {
|
58 | | - $address_srting = count($split) == 1 ? $split[0] : $split[1];
|
59 | | - $addresses = explode(';', $address_srting);
|
60 | | -
|
61 | | - $coordinates = array();
|
62 | | -
|
63 | | - foreach($addresses as $address) {
|
64 | | - $args = explode('~', $address);
|
65 | | - $args[0] = trim($args[0]);
|
66 | | -
|
67 | | - if (strlen($args[0]) > 0) {
|
68 | | - $coords = MapsGeocoder::geocodeToString($args[0], $geoservice, $service);
|
69 | | -
|
70 | | - if ($coords) {
|
71 | | - $args[0] = $coords;
|
72 | | - $coordinates[] = implode('~', $args);
|
73 | | - }
|
74 | | - else {
|
75 | | - $fails[] = $args[0];
|
76 | | - }
|
77 | | - }
|
78 | | - }
|
79 | | -
|
80 | | - $params[$i] = 'coordinates=' . implode(';', $coordinates);
|
81 | | -
|
82 | | - }
|
83 | | - }
|
84 | | -
|
85 | | - return $fails;
|
86 | | - }
|
87 | | -
|
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * |
| 6 | + * |
| 7 | + * @file Maps_ParserGeocoder.php |
| 8 | + * @ingroup Maps |
| 9 | + * |
| 10 | + * @author Jeroen De Dauw |
| 11 | + */ |
| 12 | + |
| 13 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 14 | + die( 'Not an entry point.' ); |
| 15 | +} |
| 16 | + |
| 17 | +/** |
| 18 | + * Class that holds static helpers for the mapping parser functions. The helpers aid in |
| 19 | + * determining the availability of the geocoding parser functions and calling them. |
| 20 | + * |
| 21 | + * @author Jeroen De Dauw |
| 22 | + * |
| 23 | + */ |
| 24 | +final class MapsParserGeocoder { |
| 25 | + |
| 26 | + /** |
| 27 | + * Changes the values of the address or addresses parameter into coordinates |
| 28 | + * in the provided array. Returns an array containing the addresses that |
| 29 | + * could not be geocoded. |
| 30 | + * |
| 31 | + * @param array $params |
| 32 | + */ |
| 33 | + public static function changeAddressToCoords(&$params) { |
| 34 | + global $egMapsDefaultService; |
| 35 | + |
| 36 | + $fails = array(); |
| 37 | + |
| 38 | + for ($i = 0; $i < count($params); $i++) { |
| 39 | + $split = split('=', $params[$i]); |
| 40 | + if (MapsMapper::inParamAliases(strtolower(trim($split[0])), 'service') && count($split) > 1) { |
| 41 | + $service = trim($split[1]); |
| 42 | + } |
| 43 | + else if (strtolower(trim($split[0])) == 'geoservice' && count($split) > 1) { |
| 44 | + $geoservice = trim($split[1]); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + $service = isset($service) ? MapsMapper::getValidService($service, 'pf') : $egMapsDefaultService; |
| 49 | + |
| 50 | + $geoservice = isset($geoservice) ? $geoservice : ''; |
| 51 | + |
| 52 | + for ($i = 0; $i < count($params); $i++) { |
| 53 | + |
| 54 | + $split = split('=', $params[$i]); |
| 55 | + $isAddress = ((strtolower(trim($split[0])) == 'address' || strtolower(trim($split[0])) == 'addresses') && count($split) > 1); |
| 56 | + |
| 57 | + if ($isAddress || count($split) == 1) { |
| 58 | + $address_srting = count($split) == 1 ? $split[0] : $split[1]; |
| 59 | + $addresses = explode(';', $address_srting); |
| 60 | + |
| 61 | + $coordinates = array(); |
| 62 | + |
| 63 | + foreach($addresses as $address) { |
| 64 | + $args = explode('~', $address); |
| 65 | + $args[0] = trim($args[0]); |
| 66 | + |
| 67 | + if (strlen($args[0]) > 0) { |
| 68 | + $coords = MapsGeocoder::geocodeToString($args[0], $geoservice, $service); |
| 69 | + |
| 70 | + if ($coords) { |
| 71 | + $args[0] = $coords; |
| 72 | + $coordinates[] = implode('~', $args); |
| 73 | + } |
| 74 | + else { |
| 75 | + $fails[] = $args[0]; |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + $params[$i] = 'coordinates=' . implode(';', $coordinates); |
| 81 | + |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + return $fails; |
| 86 | + } |
| 87 | + |
88 | 88 | } |
\ No newline at end of file |
Property changes on: trunk/extensions/Maps/ParserFunctions/Maps_ParserGeocoder.php |
___________________________________________________________________ |
Name: svn:eol-style |
89 | 89 | + native |
Property changes on: trunk/extensions/SecurePoll/test/3way-test.xml |
___________________________________________________________________ |
Name: svn:eol-style |
90 | 90 | + native |
Property changes on: trunk/extensions/SecurePoll/test/approval-test.xml |
___________________________________________________________________ |
Name: svn:eol-style |
91 | 91 | + native |
Property changes on: trunk/extensions/SecurePoll/test/radio-range.xml |
___________________________________________________________________ |
Name: svn:eol-style |
92 | 92 | + native |
Property changes on: trunk/extensions/SecurePoll/test/schulze-test.xml |
___________________________________________________________________ |
Name: svn:eol-style |
93 | 93 | + native |