From: Magnus Manske Date: Tue, 21 Dec 2004 13:51:15 +0000 (+0000) Subject: can now handle templates (no recursive check, yet) X-Git-Tag: 1.5.0alpha1~1063 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=9079e54474b40e5c60d58b23e9b2da84f1a5636d;p=lhc%2Fweb%2Fwiklou.git can now handle templates (no recursive check, yet) --- diff --git a/includes/ParserXML.php b/includes/ParserXML.php index 2c5661a847..83f4c09904 100644 --- a/includes/ParserXML.php +++ b/includes/ParserXML.php @@ -145,6 +145,35 @@ class element { return $this->createInternalLink ( $parser , $target , $display_title , $option ) ; } + function getTemplateXHTML ( $title , $parts , &$parser ) { + global $wgLang , $wgUser ; + $skin = $wgUser->getSkin() ; + $ot = $title ; # Original title + if ( count ( explode ( ":" , $title ) ) == 1 ) + $title = $wgLang->getNsText ( NS_TEMPLATE ) . ":" . $title ; + $nt = Title::newFromText ( $title ) ; + $id = $nt->getArticleID() ; + if ( $id == 0 ) { # No/non-existing page + return $skin->makeBrokenLink ( $title , $ot ) ; + } + + $a = 0 ; + $tv = array () ; # Template variables + foreach ( $parts AS $part ) { + $a++ ; + $x = explode ( "=" , $part , 2 ) ; + if ( count ( $x ) == 1 ) $key = "{$a}" ; + else $key = $x[0] ; + $value = array_pop ( $x ) ; + $tv[$key] = $value ; + } + $art = new Article ( $nt ) ; + $text = $art->getContent ( false ) ; + $parser->plain_parse ( $text , true , $tv ) ; + + return $text ; + } + /** * This function actually converts wikiXML into XHTML tags */ @@ -197,6 +226,23 @@ class element { else if ( $n == "LINKOPTION" ) $ret .= $this->sub_makeXHTML ( $parser ) ; + else if ( $n == "TEMPLATE" ) + { + $parts = $this->sub_makeXHTML ( $parser ) ; + $parts = explode ( "|" , $parts ) ; + $title = array_shift ( $parts ) ; + $ret .= $this->getTemplateXHTML ( $title , $parts , &$parser ) ; + } + else if ( $n == "TEMPLATEVAR" ) + { + $x = $this->sub_makeXHTML ( $parser ) ; + if ( isset ( $parser->mCurrentTemplateOptions["{$x}"] ) ) + $ret .= $parser->mCurrentTemplateOptions["{$x}"] ; + } + + else if ( $n == "IGNORE" ) # Internal use, not generated by wiki2xml parser + $ret .= $this->sub_makeXHTML ( $parser ) ; + else if ( $n == "NOWIKI" ) { $parser->nowiki++ ; @@ -372,16 +418,6 @@ class xml2php { } -/* Example code: - - $w = new xml2php; - $filename = 'sample.xml'; - $result = $w->scanFile( $filename ); - print $result->myPrint(); -*/ - -$dummytext = "
R-type image:a.jpg123textThe video gamecomputer game R-type is cool & stuff because:it's niceit's fastit has:graphicssoundVersion 1 not badVersion 2 much better
This is a || token in the middle of text.
" ; - class ParserXML EXTENDS Parser { /**#@+ @@ -401,7 +437,7 @@ class ParserXML EXTENDS Parser $mTemplatePath; // stores an unsorted hash of all the templates already loaded // in this path. Used for loop detection. - var $nowikicount ; + var $nowikicount , $mCurrentTemplateOptions ; /**#@-*/ @@ -450,15 +486,27 @@ class ParserXML EXTENDS Parser unlink($tmpfname); } - function parse( $text, &$title, $options, $linestart = true, $clearState = true ) { + function plain_parse ( &$text , $inline = false , $templateOptions = array () ) { $this->runXMLparser ( $text ) ; $nowikicount = 0 ; $w = new xml2php; $result = $w->scanString( $text ); + $oldTemplateOptions = $this->mCurrentTemplateOptions ; + $this->mCurrentTemplateOptions = $templateOptions ; + + if ( $inline ) { # Inline rendering off for templates + if ( count ( $result->children ) == 1 ) + $result->children[0]->name = "IGNORE" ; + } + if ( 1 ) $text = $result->makeXHTML ( $this ) ; # No debugging info else $text = $result->makeXHTML ( $this ) . "
" . $text . "
" . $result->myPrint(); - + $this->mCurrentTemplateOptions = $oldTemplateOptions ; + } + + function parse( $text, &$title, $options, $linestart = true, $clearState = true ) { + $this->plain_parse ( $text ) ; $this->mOutput->setText ( $text ) ; return $this->mOutput; }