<?php
+/**
+ *
+ * @package MediaWiki
+ * @subpackage Experimental
+ */
+
+/** */
require_once ( "Parser.php" ) ;
/**
/**
* the base class for an element
+ * @package MediaWiki
+ * @subpackage Experimental
*/
class element {
var $name = '';
*/
function getSourceAttrs ()
{
- $ret = "" ;
- foreach ($this->children as $child)
- {
- if ( !is_string($child) AND $child->name == "ATTRS" )
- {
- $ret = $child->makeXHTML ( $parser );
+ $ret = '' ;
+ foreach ($this->children as $child) {
+ if ( !is_string($child) AND $child->name == 'ATTRS' ) {
+ $ret = $child->makeXHTML ( $parser );
+ }
}
- }
return $ret ;
}
/**
* This collects the ATTR thingies for getSourceAttrs()
*/
- function getTheseAttrs ()
- {
- $ret = array() ;
- foreach ($this->children as $child)
- {
- if ( !is_string($child) AND $child->name == "ATTR" )
- {
- $ret[] = $child->attrs["NAME"] . "='" . $child->children[0] . "'" ;
+ function getTheseAttrs () {
+ $ret = array() ;
+ foreach ($this->children as $child) {
+ if ( !is_string($child) AND $child->name == 'ATTR' ) {
+ $ret[] = $child->attrs["NAME"] . "='" . $child->children[0] . "'" ;
+ }
}
- }
- return implode ( " " , $ret ) ;
+ return implode ( ' ' , $ret ) ;
}
- function fixLinkTails ( &$parser , $key )
- {
- $k2 = $key + 1 ;
- if ( !isset ( $this->children[$k2] ) ) return ;
- if ( !is_string ( $this->children[$k2]) ) return ;
- if ( is_string ( $this->children[$key]) ) return ;
- if ( $this->children[$key]->name != "LINK" ) return ;
-
- $n = $this->children[$k2] ;
- $s = "" ;
- while ( $n != "" AND
- ( ( $n[0] >= 'a' AND $n[0] <= 'z' ) OR
- $n[0] == 'ä' OR $n[0] == 'ö' OR
- $n[0] == 'ü' OR $n[0] == 'ß' ) )
- {
- $s .= $n[0] ;
- $n = substr ( $n , 1 ) ;
- }
- $this->children[$k2] = $n ;
-
- if ( count ( $this->children[$key]->children ) > 1 )
- {
- $kl = array_keys ( $this->children[$key]->children ) ;
- $kl = array_pop ( $kl ) ;
- $this->children[$key]->children[$kl]->children[] = $s ;
- }
- else
- {
- $e = new element ;
- $e->name = "LINKOPTION" ;
- $t = $this->children[$key]->sub_makeXHTML ( $parser ) ;
- $e->children[] = trim ( $t ) . $s ;
- $this->children[$key]->children[] = $e ;
- }
+ function fixLinkTails ( &$parser , $key ) {
+ $k2 = $key + 1 ;
+ if ( !isset ( $this->children[$k2] ) ) return ;
+ if ( !is_string ( $this->children[$k2]) ) return ;
+ if ( is_string ( $this->children[$key]) ) return ;
+ if ( $this->children[$key]->name != "LINK" ) return ;
+
+ $n = $this->children[$k2] ;
+ $s = ;
+ while ( $n != '' AND
+ ( ( $n[0] >= 'a' AND $n[0] <= 'z' ) OR
+ $n[0] == 'ä' OR $n[0] == 'ö' OR
+ $n[0] == 'ü' OR $n[0] == 'ß' ) )
+ {
+ $s .= $n[0] ;
+ $n = substr ( $n , 1 ) ;
+ }
+ $this->children[$k2] = $n ;
+
+ if ( count ( $this->children[$key]->children ) > 1 ) {
+ $kl = array_keys ( $this->children[$key]->children ) ;
+ $kl = array_pop ( $kl ) ;
+ $this->children[$key]->children[$kl]->children[] = $s ;
+ } else {
+ $e = new element ;
+ $e->name = "LINKOPTION" ;
+ $t = $this->children[$key]->sub_makeXHTML ( $parser ) ;
+ $e->children[] = trim ( $t ) . $s ;
+ $this->children[$key]->children[] = $e ;
+ }
}
/**
* This function generates the XHTML for the entire subtree
*/
- function sub_makeXHTML ( &$parser , $tag = "" , $attr = "" )
- {
- $ret = "" ;
+ function sub_makeXHTML ( &$parser , $tag = '' , $attr = '' ){
+ $ret = '' ;
$attr2 = $this->getSourceAttrs () ;
- if ( $attr != "" AND $attr2 != "" ) $attr .= " " ;
+ if ( $attr != '' AND $attr2 != ) $attr .= ' ' ;
$attr .= $attr2 ;
if ( $tag != "" )
$ancStack = array(); // the stack with ancestral elements
-// Three global functions needed for parsing, sorry guys
+// START Three global functions needed for parsing, sorry guys
+/** @todo document */
function wgXMLstartElement($parser, $name, $attrs) {
global $ancStack;
array_push($ancStack, $newElem);
}
+/** @todo document */
function wgXMLendElement($parser, $name) {
global $ancStack, $rootElem;
// pop element off stack
array_push ($ancStack[count($ancStack)-1]->children, $elem);
}
+/** @todo document */
function wgXMLcharacterData($parser, $data) {
global $ancStack;
$data = trim ($data); // Don't add blank lines, they're no use...
array_push ($ancStack[count($ancStack)-1]->children, $data);
}
}
-
+// END Three global functions needed for parsing, sorry guys
/**
* Here's the class that generates a nice tree
+ * @package MediaWiki
+ * @subpackage Experimental
*/
class xml2php {
+ /** @todo document */
function &scanFile( $filename ) {
global $ancStack, $rootElem;
$ancStack = array();
return $rootElem;
}
+ /** @todo document */
function scanString ( $input ) {
global $ancStack, $rootElem;
$ancStack = array();
}
-class ParserXML EXTENDS Parser
+/**
+ * @todo document
+ * @package MediaWiki
+ * @subpackage Experimental
+ */
+class ParserXML extends Parser
{
/**#@+
* @access private
unlink($tmpfname);
}
+ /** @todo document */
function runXMLparser ( &$text ) {
global $wgWiki2xml ;
unlink($tmpfname);
}
+ /** @todo document */
function plain_parse ( &$text , $inline = false , $templateOptions = array () ) {
$this->runXMLparser ( $text ) ;
$nowikicount = 0 ;
$this->mCurrentTemplateOptions = $oldTemplateOptions ;
}
+ /** @todo document */
function parse( $text, &$title, $options, $linestart = true, $clearState = true ) {
$this->plain_parse ( $text ) ;
$this->mOutput->setText ( $text ) ;
return $this->mOutput;
}
-
- }
-?>
+}
+?>
\ No newline at end of file