From a0d72486852166b5f4777ac5d4c6c6de91f6a90d Mon Sep 17 00:00:00 2001 From: Magnus Manske Date: Wed, 3 Nov 2004 14:00:08 +0000 Subject: [PATCH] XML parser XHTML output --- includes/DefaultSettings.php | 3 + includes/ParserXML.php | 144 +++++++++++++++++++++++++++++++++++ includes/Setup.php | 5 +- 3 files changed, 151 insertions(+), 1 deletion(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index ee8495f5ab..2b618a6ada 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -702,6 +702,9 @@ $wgDefaultSkin = 'monobook'; # Whether or not to allow real name fields. Defaults to true. $wgAllowRealName = true; +# Use XML parser? +$wgUseXMLparser = false ; + # Extensions $wgSkinExtensionFunctions = array(); $wgExtensionFunctions = array(); diff --git a/includes/ParserXML.php b/includes/ParserXML.php index 059e271f6c..b3d816cee6 100644 --- a/includes/ParserXML.php +++ b/includes/ParserXML.php @@ -1,4 +1,6 @@ (X)HTML parser * Based on work by Jan Hidders and Magnus Manske @@ -14,6 +16,81 @@ class element { var $attrs = array(); var $children = array(); + function sub_makeXHTML ( &$parser , $tag = "" , $attr = "" ) + { + $ret = "" ; + if ( $tag != "" ) + { + $ret .= "<" . $tag ; + if ( $attr != "" ) $ret .= " " . $attr ; + $ret .= ">" ; + } + foreach ($this->children as $child) { + if ( is_string($child) ) { + $ret .= $child ; + } else { + $ret .= $child->makeXHTML ( $parser ); + } + } + if ( $tag != "" ) + $ret .= "\n" ; + return $ret ; + } + + function makeXHTML ( &$parser ) + { + $ret = "" ; + $n = $this->name ; # Shortcut + if ( $n == "ARTICLE" ) + $ret .= $this->sub_makeXHTML ( $parser ) ; + else if ( $n == "HEADING" ) + $ret .= $this->sub_makeXHTML ( $parser , "h" . $this->attrs["LEVEL"] ) ; + else if ( $n == "PARAGRAPH" ) + $ret .= $this->sub_makeXHTML ( $parser , "p" ) ; + else if ( $n == "BOLD" ) + $ret .= $this->sub_makeXHTML ( $parser , "strong" ) ; + else if ( $n == "ITALICS" ) + $ret .= $this->sub_makeXHTML ( $parser , "em" ) ; + + else if ( $n == "EXTENSION" ) + { + $ext = $this->attrs["NAME"] ; + +# $ret .= $this->sub_makeXHTML ( $parser , "em" ) ; + } + + else if ( $n == "TABLE" ) + { + $ret .= $this->sub_makeXHTML ( $parser , "table" ) ; + } + else if ( $n == "TABLEROW" ) + { + $ret .= $this->sub_makeXHTML ( $parser , "tr" ) ; + } + else if ( $n == "TABLECELL" ) + { + $ret .= $this->sub_makeXHTML ( $parser , "td" ) ; + } + + + else if ( $n == "LISTITEM" ) + $ret .= $this->sub_makeXHTML ( $parser , "li" ) ; + else if ( $n == "LIST" ) + { + $type = "ol" ; # Default + if ( $this->attrs["TYPE"] == "bullet" ) $type = "ul" ; + $ret .= $this->sub_makeXHTML ( $parser , $type ) ; + } + + else + { + $ret .= "<" . $n . ">" ; + $ret .= $this->sub_makeXHTML ( $parser ) ; + $ret .= "</" . $n . ">" ; + } + return $ret ; + } + function myPrint() { $ret = "