Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Commit 582d8a0

Browse files
committed
Support seqdiag, actdiag, nwdiag.
1 parent 900d80a commit 582d8a0

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

Diff for: README.rst

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Blockdiag MediaWiki Extension
55
requirement
66
===========
77

8-
- blockdiag_
8+
- blockdiag_ (or seqdiag, actdiag, nwdiag)
99
- mediawiki >1.16
1010

1111
.. _blockdiag: http://tk0miya.bitbucket.org/blockdiag/build/html/
@@ -33,6 +33,16 @@ example
3333
}
3434
</blockdiag>
3535

36+
If you want to use other *diag tools, specify a name before "{", like "seqdiag {".
37+
38+
::
39+
40+
<blockdiag>
41+
seqdiag {
42+
A -> B;
43+
B -> C;
44+
}
45+
</blockdiag>
3646

3747
known issues
3848
============

Diff for: blockdiag.php

+23-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
/**
99
blockdiag_example:
10-
{
10+
blockdiag {
1111
A -> B -> C
1212
B -> D
1313
}
@@ -54,7 +54,14 @@ function blockdiagDisplay( $input, $args, $parser ){
5454
* Blockdiag
5555
**/
5656
class Blockdiag {
57-
private $_blockdiag_path = '/usr/bin/blockdiag';
57+
private $_path_array = array(
58+
'blockdiag' => '/usr/local/bin/blockdiag',
59+
'seqdiag' => '/usr/local/bin/seqdiag',
60+
'actdiag' => '/usr/local/bin/actdiag',
61+
'nwdiag' => '/usr/local/bin/nwdiag',
62+
'rackdiag' => '/usr/local/bin/rackdiag', # in nwdiag
63+
'packetdiag' => '/usr/local/bin/packetdiag', # in nwdiag
64+
);
5865
private $_imgType = 'png';
5966
private $_hash;
6067
private $_source;
@@ -64,11 +71,6 @@ class Blockdiag {
6471

6572
public function __construct( $blockdiagDir, $blockdiagUrl, $tmpDir, $source )
6673
{
67-
if(!is_file($this->_blockdiag_path))
68-
{
69-
throw new Exception('blockdiag is not found at the specified place ($_blockdiag_path).', 1);
70-
return false;
71-
}
7274
$this->_blockdiagDir = $blockdiagDir;
7375
$this->_blockdiagUrl = $blockdiagUrl;
7476
$this->_tmpDir = $tmpDir;
@@ -87,6 +89,19 @@ public function showImage() {
8789
}
8890

8991
private function _generate() {
92+
if (preg_match('/^\s*(\w+)\s*{/', $this->_source, $matches)) {
93+
$diagram_type = $matches[1];
94+
} else {
95+
#return $this->_error("diagtype is not specified.");
96+
$diagram_type = 'blockdiag'; # blockdiag for default
97+
}
98+
99+
$diagprog_path = $this->_path_array[$diagram_type];
100+
if (!is_file($diagprog_path))
101+
{
102+
return $this->_error("$diagram_type is not found at the specified place.");
103+
}
104+
90105
// temporary directory check
91106
if( !file_exists( $this->_tmpDir ) ){
92107
if( !wfMkdirParents( $this->_tmpDir ) ) {
@@ -108,7 +123,7 @@ private function _generate() {
108123
fclose($fp);
109124

110125
// generate blockdiag image
111-
$cmd = $this->_blockdiag_path . ' -T ' .
126+
$cmd = $diagprog_path . ' -T ' .
112127
escapeshellarg( $this->_imgType ) . ' -o ' .
113128
escapeshellarg( $dstTmpName ) . ' ' .
114129
escapeshellarg( $srcTmpName );

0 commit comments

Comments
 (0)