includes/wikiengine/Parse/Mediawiki/Function.php
author Dan
Mon, 16 Feb 2009 16:17:25 -0500
changeset 832 7152ca0a0ce9
parent 1 fe660c52c48f
permissions -rw-r--r--
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message) - Pages are now stored with an extra metadata field called page_format which is "wikitext" or "xhtml" - New $flags parameter + RENDER_* constants added that control RenderMan::render() behavior - Several other changes: * Added a sprite API for Javascript and made editor use sprites when possible * Removed a number of config options from the default install schema, replaced with second parameter to getConfig() calls * MessageBox in editor mostly replaced with miniPrompt * A few bugfixes related to password changes (registration didn't even work) * Rewrote the bitfield compression algorithm used to serialize allowed MIME types * Fixed some typos in language files and strings * Fixed a Text_Wiki bug in Heading parser

<?php

/**
* 
* Parses for an API function documentation block.
* 
* @category Text
* 
* @package Text_Wiki
* 
* @author Paul M. Jones <pmjones@php.net>
* 
* @license LGPL
* 
* @version $Id: Function.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
* 
*/

/**
* 
* Parses for an API function documentation block.
*
* @category Text
* 
* @package Text_Wiki
* 
* @author Paul M. Jones <pmjones@php.net>
* 
*/

class Text_Wiki_Parse_Function extends Text_Wiki_Parse {

    var $regex = '/^(\<function\>)\n(.+)\n(\<\/function\>)(\s|$)/Umsi';
    
    function process(&$matches)
    {
        // default options
        $opts = array(
            'name' => null,
            'access' => null,
            'return' => null,
            'params' => array(),
            'throws' => array()
        );
        
        // split apart the markup lines and loop through them
        $lines = explode("\n", $matches[2]);
        foreach ($lines as $line) {
            
            // skip blank lines
            if (trim($line) == '') {
                continue;
            }
            
            // find the first ':' on the line; the left part is the 
            // type, the right part is the value. skip lines without
            // a ':' on them.
            $pos = strpos($line, ':');
            if ($pos === false) {
                continue;
            }
            
            // $type is the line type: name, access, return, param, throws
            // 012345678901234
            // name: something
            $type = trim(substr($line, 0, $pos));
            $val = trim(substr($line, $pos+1));
            
            switch($type) {
            
            case 'a':
            case 'access':
                $opts['access'] = $val;
                break;
                
            case 'n':
            case 'name':
                $opts['name'] = $val;
                break;
                
            case 'p':
            case 'param':
                $tmp = explode(',', $val);
                $k = count($tmp);
                if ($k == 1) {
                    $opts['params'][] = array(
                        'type' => $tmp[0],
                        'descr' => null,
                        'default' => null
                    );
                } elseif ($k == 2) {
                    $opts['params'][] = array(
                        'type' => $tmp[0],
                        'descr' => $tmp[1],
                        'default' => null
                    );
                } else {
                    $opts['params'][] = array(
                        'type' => $tmp[0],
                        'descr' => $tmp[1],
                        'default' => $tmp[2]
                    );
                }
                break;
            
            case 'r':
            case 'return':
            case 'returns':
                $opts['return'] = $val;
                break;
            
            case 't':
            case 'throws':
                $tmp = explode(',', $val);
                $k = count($tmp);
                if ($k == 1) {
                    $opts['throws'][] = array(
                        'type' => $tmp[0],
                        'descr' => null
                    );
                } else {
                    $opts['throws'][] = array(
                        'type' => $tmp[0],
                        'descr' => $tmp[1]
                    );
                }
                break;
        
            default:
                $opts[$type] = $val;
                break;
            
            }
        }
        
        // add the token back in place
        return $this->wiki->addToken($this->rule, $opts) . $matches[4];
    }
}

?>