Capitalization fix in memcached setting
[lhc/web/wiklou.git] / includes / ParserXML.php
index b3d816c..a4c30b1 100644 (file)
@@ -1,4 +1,4 @@
-<?
+<?php
 require_once ( "Parser.php" ) ;
 
 /**
@@ -36,7 +36,54 @@ class element {
                $ret .= "</" . $tag . ">\n" ;
       return $ret ;
        }
+       
+    function createInternalLink ( &$parser , $target , $display_title , $options )
+       {
+       $tp = explode ( ":" , $target ) ; # tp = target parts
+       $title = "" ;     # The plain title
+       $language = "" ;  # The language/meta/etc. part
+       $namespace = "" ; # The namespace, if any
+       $subtarget = "" ; # The '#' thingy
+       if ( count ( $tp ) == 1 ) $title = $target ; # Plain and simple case
+       else
+               {
+               # To be implemented
+               }
+       
+       if ( $language != "" ) # External link within the WikiMedia project
+               {
+               return "{language link}" ;
+               }
+       else if ( $namespace != "" ) # Link to another namespace, check for image/media stuff
+               {
+               return "{namespace link}" ;
+               }
+       else
+               {
+               return "{internal link}" ;
+               }
+       }
     
+    function makeInternalLink ( &$parser )
+       {
+       $target = "" ;
+       $option = array () ;
+      foreach ($this->children as $child) {
+            if ( is_string($child) ) {
+               # This shouldn't be the case!
+            } else {
+                if ( $child->name == "LINKTARGET" )
+                       $target = trim ( $child->makeXHTML ( $parser ) ) ;
+                   else
+                       $option[] = trim ( $child->makeXHTML ( $parser ) ) ;
+            }
+           }
+           
+      if ( count ( $option ) == 0 ) $option[] = $target ; # Create dummy display title
+      $display_title = array_pop ( $option ) ;
+      return $this->createInternalLink ( $parser , $target , $display_title , $option ) ;
+       }
+       
     function makeXHTML ( &$parser )
        {
        $ret = "" ;
@@ -52,11 +99,20 @@ class element {
        else if ( $n == "ITALICS" )
                $ret .= $this->sub_makeXHTML ( $parser , "em" ) ;
 
-       else if ( $n == "EXTENSION" )
+       else if ( $n == "LINK" )
+               $ret .= $this->makeInternalLink ( $parser ) ;
+       else if ( $n == "LINKTARGET" )
+               $ret .= $this->sub_makeXHTML ( $parser ) ;
+       else if ( $n == "LINKOPTION" )
+               $ret .= $this->sub_makeXHTML ( $parser ) ;
+               
+       else if ( $n == "EXTENSION" ) # This is currently a dummy!!!
                {
                $ext = $this->attrs["NAME"] ;
                
-#              $ret .= $this->sub_makeXHTML ( $parser , "em" ) ;
+               $ret .= "&lt;" . $ext . "&gt;" ;
+               $ret .= $this->sub_makeXHTML ( $parser ) ;
+               $ret .= "&lt;/" . $ext . "&gt; " ;
                }
 
        else if ( $n == "TABLE" )
@@ -86,8 +142,10 @@ class element {
                {
                $ret .= "&lt;" . $n . "&gt;" ;
                $ret .= $this->sub_makeXHTML ( $parser ) ;
-               $ret .= "&lt;/" . $n . "&gt;" ;
+               $ret .= "&lt;/" . $n . "&gt; " ;
                }
+       $ret = "\n{$ret}\n" ;
+       $ret = str_replace ( "\n\n" , "\n" , $ret ) ;
        return $ret ;
        }