r30033 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r30032‎ | r30033 | r30034 >
Date:20:48, 21 January 2008
Author:magnusmanske
Status:old
Tags:
Comment:
patch by Steve Bjorg
Modified paths:
  • /trunk/wiki2xml/php/wiki2xml.php (modified) (history)

Diff [purge]

Index: trunk/wiki2xml/php/wiki2xml.php
@@ -61,6 +61,21 @@
6262 # Some often used functions
6363
6464 /**
 65+ * Inherit settings from an existing parser
 66+ */
 67+ function inherit ( &$base )
 68+ {
 69+ $this->protocols = $base->protocols ;
 70+ $this->errormessage = $base->errormessage ;
 71+ $this->compensate_markup_errors = $base->compensate_markup_errors ;
 72+ $this->auto_fill_templates = $base->auto_fill_templates ;
 73+ $this->use_space_tag = $base->use_space_tag ;
 74+ $this->compensate_markup_errors = $base->compensate_markup_errors ;
 75+ $this->allowed = $base->allowed ;
 76+ $this->directhtmltags = $base->directhtmltags ;
 77+ }
 78+
 79+ /**
6580 * Matches a function to the current text (default:once)
6681 */
6782 function once ( &$a , &$xml , $f , $atleastonce = true , $many = false )
@@ -267,6 +282,7 @@
268283 if ( !$this->p_internal_link_target ( $b , $x , "}}" ) ) return false ;
269284 $target = $x ;
270285 $variables = array () ;
 286+ $varnames = array () ;
271287 $vcount = 1 ;
272288 while ( 1 )
273289 {
@@ -277,7 +293,10 @@
278294 $v = substr ( $x , $l1 ) ;
279295 $v = explode ( "=" , $v ) ;
280296 if ( count ( $v ) < 2 ) $vk = $vcount ;
281 - else $vk = trim ( array_shift ( $v ) ) ;
 297+ else {
 298+ $vk = trim ( array_shift ( $v ) ) ;
 299+ $varnames[$vcount] = $vk;
 300+ }
282301 $vv = array_shift ( $v ) ;
283302 $variables[$vk] = $vv ;
284303 if ( !isset ( $variables[$vcount] ) ) $variables[$vcount] = $vv ;
@@ -333,7 +352,12 @@
334353 $this->w = $w1 . $between . $w2 ;
335354 $this->wl = strlen ( $this->w ) ;
336355 } else {
337 - $xml .= "<template>{$x}</template>" ;
 356+ $xml .= "<template><target>{$target}</target>";
 357+ for ( $i = 1 ; $i < $vcount ; $i++ ) {
 358+ if ( isset( $varnames[$i] ) ) $xml .= "<arg name=\"{$varnames[$i]}\">{$variables[$i]}</arg>";
 359+ else $xml .= "<arg>{$variables[$i]}</arg>";
 360+ }
 361+ $xml .= "</template>" ;
338362 $a = $b ;
339363 }
340364 return true ;
@@ -843,7 +867,8 @@
844868 $last = $b ;
845869 if ( !$this->p_html_tag ( $b , $x2 , $tag2 , $closing , $selfclosing ) )
846870 {
847 - if ( $tag != "nowiki" && $this->w[$b] == '{' && $this->p_template ( $b , $x ) ) # Template, doesn't alter $b or $x
 871+ $dummy = "";
 872+ if ( $tag != "nowiki" && $this->w[$b] == '{' && $this->p_template ( $b , $dummy ) )
848873 continue ;
849874 $b++ ;
850875 continue ;
@@ -869,6 +894,7 @@
870895
871896 # Parse the part in between the tags
872897 $subparser = new wiki2xml ;
 898+ $subparser->inherit ( $this ) ;
873899 $between2 = $subparser->parse ( $between ) ;
874900
875901 # Was the parsing correct?
@@ -997,6 +1023,7 @@
9981024 {
9991025 # Creating a temporary new parser to run the attribute list in
10001026 $np = new wiki2xml ;
 1027+ $np->inherit ( $this ) ;
10011028 $np->w = $x ;
10021029 $np->wl = strlen ( $x ) ;
10031030
@@ -1316,6 +1343,7 @@
13171344 # Parse cell substring
13181345 $s = substr ( $this->w , $a , $b - $a ) ;
13191346 $p = new wiki2xml ;
 1347+ $p->inherit ( $this ) ;
13201348 $x = $p->parse ( $s ) ;
13211349 if ( $x == $this->errormessage ) return false ;
13221350

Status & tagging log