allwiki首页  
天下维客 你可以修改的网络知识库
首页最近更改优秀条目专题展示电脑科技词典软件学习网络知识电脑安全明星时尚天下百科
 

MediaWiki扩展:流程图

天下维客,你可以修改的网络知识库

Jump to: navigation, search

本文取自元维基,欢迎共同翻译、整理与大家共享,促进中文wiki发展^_^

This 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.

Example input

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

The corresponding output

this is how it looks aproximately.

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

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;
}
?>

原文参见: Flowchart on MediaWiki

Personal tools
工具
金银币拍卖 金币拍卖预展  金银币网店 熊猫金银币 生肖金银币