Extension:SimpleForms.php
<?
- MediaWiki SimpleForms Extension
- - See http://www.mediawiki.org/wiki/Extension:Simple_Forms for installation and usage details
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: http://www.organicdesign.co.nz/nad
- {{#Security:*|dev}}{{#Security:view|*}}Template:Php
$wgSimpleFormsVersion = 'Version 0.01 (2007-04-25)';
$wgSimpleFormsFormMagic = "form"; # the parser-function name for form containers $wgSimpleFormsInputMagic = "input"; # the parser-function name for form inputs $wgSimpleFormsQsMagic = "qs"; # the parser-function name for query-string access
$wgExtensionFunctions[] = 'wfSetupSimpleForms'; $wgHooks['LanguageGetMagic'][] = 'wfSimpleFormsLanguageGetMagic';
class SimpleForms {
var $id = 0; var $tagname; var $opentag; var $closetag;
# Constructor function SimpleForms() { global $wgParser,$wgHooks,$wgSimpleFormsFormMagic,$wgSimpleFormsInputMagic,$wgSimpleFormsQsMagic; $wgParser->setFunctionHook($wgSimpleFormsFormMagic, array($this,'form')); $wgParser->setFunctionHook($wgSimpleFormsInputMagic,array($this,'input')); $wgParser->setFunctionHook($wgSimpleFormsQsMagic, array($this,'qs')); $this->tagname = 'this_should_be_random'; $this->opentag = 'this_should_be_random2'; $this->closetag = 'this_should_be_random3'; $wgParser->setHook($this->tagname,'tagHook'); }
function form(&$parser) { global $wgJavaScriptFunctions; $id = $this->id++; $tag = $this->tagname; $args = ; foreach (func_get_args() as $arg) if (!is_object($arg)) { if (preg_match('/^(.+?)=(.+)$/',$arg,$match)) $args .= " $match[1]=\"$match[2]\""; else $form = $arg; } $wgJavaScriptFunctions['SimpleFormsFunctions'] = ' function live() { } '; return "<$tag $args>$form</$tag>"; }
function input(&$parser) { $ot = $this->opentag; $ct = $this->closetag; $content = ;
# Process args foreach (func_get_args() as $arg) if (!is_object($arg)) { if (preg_match('/^([a-z0-9_]+?)=(.+)$/',$arg,$match)) $argv[strtolower(trim($match[1]))] = trim($match[2]); else $content = trim($arg); } $type = $argv['type']; unset($argv['type']);
# Textarea if ($argv['type'] == 'textarea') $input = $ot."textarea$args$ct$content$ot/textarea$ct";
# Select list elseif ($argv['type'] == 'select') { $content = preg_replace('/<\\/?ul>/i',,$content); # DPL makes ul/li not * $content = preg_replace('/<\\/li>/i',,$content);
$content = preg_replace('/
- Called from $wgExtensionFunctions array when initialising extensions
- Needed in MediaWiki >1.8.0 for magic word hooks to work properly



