Index: trunk/wiki2xml/php/wiki2xml.php |
— | — | @@ -61,6 +61,21 @@ |
62 | 62 | # Some often used functions |
63 | 63 | |
64 | 64 | /** |
| 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 | + /** |
65 | 80 | * Matches a function to the current text (default:once) |
66 | 81 | */ |
67 | 82 | function once ( &$a , &$xml , $f , $atleastonce = true , $many = false ) |
— | — | @@ -267,6 +282,7 @@ |
268 | 283 | if ( !$this->p_internal_link_target ( $b , $x , "}}" ) ) return false ; |
269 | 284 | $target = $x ; |
270 | 285 | $variables = array () ; |
| 286 | + $varnames = array () ; |
271 | 287 | $vcount = 1 ; |
272 | 288 | while ( 1 ) |
273 | 289 | { |
— | — | @@ -277,7 +293,10 @@ |
278 | 294 | $v = substr ( $x , $l1 ) ; |
279 | 295 | $v = explode ( "=" , $v ) ; |
280 | 296 | 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 | + } |
282 | 301 | $vv = array_shift ( $v ) ; |
283 | 302 | $variables[$vk] = $vv ; |
284 | 303 | if ( !isset ( $variables[$vcount] ) ) $variables[$vcount] = $vv ; |
— | — | @@ -333,7 +352,12 @@ |
334 | 353 | $this->w = $w1 . $between . $w2 ; |
335 | 354 | $this->wl = strlen ( $this->w ) ; |
336 | 355 | } 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>" ; |
338 | 362 | $a = $b ; |
339 | 363 | } |
340 | 364 | return true ; |
— | — | @@ -843,7 +867,8 @@ |
844 | 868 | $last = $b ; |
845 | 869 | if ( !$this->p_html_tag ( $b , $x2 , $tag2 , $closing , $selfclosing ) ) |
846 | 870 | { |
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 ) ) |
848 | 873 | continue ; |
849 | 874 | $b++ ; |
850 | 875 | continue ; |
— | — | @@ -869,6 +894,7 @@ |
870 | 895 | |
871 | 896 | # Parse the part in between the tags |
872 | 897 | $subparser = new wiki2xml ; |
| 898 | + $subparser->inherit ( $this ) ; |
873 | 899 | $between2 = $subparser->parse ( $between ) ; |
874 | 900 | |
875 | 901 | # Was the parsing correct? |
— | — | @@ -997,6 +1023,7 @@ |
998 | 1024 | { |
999 | 1025 | # Creating a temporary new parser to run the attribute list in |
1000 | 1026 | $np = new wiki2xml ; |
| 1027 | + $np->inherit ( $this ) ; |
1001 | 1028 | $np->w = $x ; |
1002 | 1029 | $np->wl = strlen ( $x ) ; |
1003 | 1030 | |
— | — | @@ -1316,6 +1343,7 @@ |
1317 | 1344 | # Parse cell substring |
1318 | 1345 | $s = substr ( $this->w , $a , $b - $a ) ; |
1319 | 1346 | $p = new wiki2xml ; |
| 1347 | + $p->inherit ( $this ) ; |
1320 | 1348 | $x = $p->parse ( $s ) ; |
1321 | 1349 | if ( $x == $this->errormessage ) return false ; |
1322 | 1350 | |