Extension:Flowchart

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Flowchart

Release status: unknown

Implementation Tag
Description Allows making ASCII art drawing of protocol flows
Author(s) User:Ruudschramp
License No license specified
Download see below
Check usage (experimental)

Flowchart extension allows making ASCII art drawings of protocol flows. The intention of course was to make something more fancy with real graphical arows, but this is the effort of just as single evening.

I would currently advise to use MscGen which does the same in a graphical way.

[edit] Example input

<flowchart>TCPClient:TCPServer:Server
'''TCPClient TCPServer Syn'''
TCPServer TCPClient Syn+Ack
TCPClient TCPServer Syn+Ack
TCPClient Server HTTPGet
Server TCPClient HTTPResponse</flowchart>

[edit] The corresponding output

this is how it looks aproximately.

TCPClient   TCPServer   Server   
|     Syn      |         |   
|   ------>    |         |   
|              |         |   
|  Syn+Ack     |         |   
| <------      |         |   
|              |         |   
|  Syn+Ack     |         |   
| ------>      |         |   
|              |         |   
|          HTTPGet       |          
| ------>    ------>     |   
|              |         |   
|        HTTPResponse    |   
| <------   <------      |   
|              |         |   

[edit] The code

<?php
# To activate the extension, include it from your LocalSettings.php
# with: include("extensions/YourExtensionName.php");

$wgExtensionFunctions[] = "wfFlowChartExtension";
 
function wfFlowChartExtension() {
    global $wgParser;
    # register the extension with the WikiText parser
    # the first parameter is the name of the new tag.
    # In this case it defines the tag <flowchart> ... </flowchart>
    # the second parameter is the callback function for
    # processing the text between the tags
    $wgParser->setHook( "flowchart", "renderFlowChart" );
}
 
# The callback function for converting the input text to HTML output
function renderFlowChart( $input ) {
# $argv is an array containing any arguments passed to the
# extension like <example argument="foo" bar>..
    $lines=split("\n",$input);
    $colums=split(":",$lines[0]);
    $count=count($colums);
    $output .= "<CENTER><TABLE cellpadding=\"0\" border=\"0\">\n<TR>";
    foreach($colums as $Name)
      $output .= "<TH>$Name</TH><TD/><TD/>";
    array_shift($lines); #remove first line
    foreach($lines as $line)
      if ($line != "") { #ignoring empty lines
        $output.="</TR>\n<TR>";
 
        $fields=split(" ",$line,$count);
        $col1=array_search($fields[0],$colums);
        $col2=array_search($fields[1],$colums);
        $mes=$fields[2];
        $dir= $col1<$col2 ? "------>" : "<------";
 
 
        $skip=min($col1,$col2);
        for($i=0;$i<$skip;$i++)
            $output.="<TD>|</TD><TD/><TD/>";
        $length=(abs($col1-$col2)*3)-1;
        $output.="<TD>|</TD><TD colspan=$length>$mes</TD>";
        $skip=$count-max($col1,$col2);
        for($i=0;$i<$skip;$i++)
            $output.="<TD>|</TD><TD/><TD/>";
        $output.="</TR>\n<TR>";
 
        $skip=min($col1,$col2);
        for($i=0;$i<$skip;$i++)
            $output.="<TD>|</TD><TD/><TD/>";
        $length=abs($col1-$col2)-1;
        $output.="<TD>|</TD><TD colspan=2>$dir</TD>";
        for($i=0;$i<$length;$i++)
            $output.="<TD colspan=3>$dir</TD>";
        $skip=$count-max($col1,$col2);
        for($i=0;$i<$skip;$i++)
            $output.="<TD>|</TD><TD/><TD/>";
        $output.="</TR>\n<TR>";
 
    };
    $output .= "</TR>\n</TABLE></CENTER>";
    return $output;
}
?>
Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox