Index: trunk/wiki2xml/php/wiki2xml.php |
— | — | @@ -293,24 +293,35 @@ |
294 | 294 | else $replace_template = false ; |
295 | 295 | } |
296 | 296 | |
297 | | - if ( $replace_template ) { # Do not generate <template> sections, but rather replace the template call with the template text |
298 | | - # Get template text |
299 | | - $between = trim ( $content_provider->get_template_text ( $target ) ) ; |
300 | | - add_authors ( $content_provider->authors ) ; |
| 297 | + if ( substr ( $target , 0 , 1 ) == '#' ) { # Try template logic |
| 298 | + $between = $this->process_template_logic ( $target , $variables ) ; |
| 299 | + # Change source (!) |
| 300 | + $w1 = substr ( $this->w , 0 , $a ) ; |
| 301 | + $w2 = substr ( $this->w , $b ) ; |
| 302 | + $this->w = $w1 . $between . $w2 ; |
| 303 | + $this->wl = strlen ( $this->w ) ; |
| 304 | + } else if ( $replace_template ) { # Do not generate <template> sections, but rather replace the template call with the template text |
| 305 | + |
| 306 | + # Get template text |
| 307 | + $between = trim ( $content_provider->get_template_text ( $target ) ) ; |
| 308 | + add_authors ( $content_provider->authors ) ; |
301 | 309 | |
302 | | -# if ( $a > 0 && explode ( "\n" , $between , 2 ) > 1 ) # Multi-lined templates get leading newline |
303 | | -# $between = "\n" . $between ; |
304 | | - |
305 | 310 | # Removing <noinclude> stuff |
306 | 311 | $between = preg_replace( '?<noinclude>.*</noinclude>?msU', '', $between); |
307 | 312 | $between = str_replace ( "<include>" , "" , $between ) ; |
308 | 313 | $between = str_replace ( "</include>" , "" , $between ) ; |
309 | 314 | $between = str_replace ( "<includeonly>" , "" , $between ) ; |
310 | 315 | $between = str_replace ( "</includeonly>" , "" , $between ) ; |
311 | | - |
| 316 | + |
| 317 | + # Remove HTML comments |
| 318 | + $between = preg_replace( '?<!--.*-->?msU', '', $between) ; |
| 319 | + |
312 | 320 | # Replacing template variables. |
313 | 321 | # ATTENTION: Template variables within <nowiki> sections of templates will be replaced as well! |
314 | 322 | |
| 323 | + if ( $a > 0 && substr ( $between , 0 , 2 ) == '{|' ) |
| 324 | + $between = "\n" . $between ; |
| 325 | + |
315 | 326 | $this->replace_template_variables ( $between , $variables ) ; |
316 | 327 | |
317 | 328 | # Change source (!) |
— | — | @@ -324,7 +335,31 @@ |
325 | 336 | } |
326 | 337 | return true ; |
327 | 338 | } |
| 339 | + |
| 340 | + function process_template_logic ( $title , $variables ) { |
328 | 341 | |
| 342 | + # TODO : Process title and variables for sub-template-replacements |
| 343 | + |
| 344 | + if ( substr ( $title , 0 , 4 ) == "#if:" ) { |
| 345 | + $title = trim ( substr ( $title , 4 ) ) ; |
| 346 | + if ( $title == '' ) return array_pop ( $variables ) ; # ELSE |
| 347 | + return array_shift ( $variables ) ; # THEN |
| 348 | + } |
| 349 | + |
| 350 | + if ( substr ( $title , 0 , 8 ) == "#switch:" ) { |
| 351 | + $title = trim ( array_pop ( explode ( ':' , $title , 2 ) ) ) ; |
| 352 | + foreach ( $variables AS $v ) { |
| 353 | + $v = explode ( '=' , $v , 2 ) ; |
| 354 | + $key = trim ( array_shift ( $v ) ) ; |
| 355 | + if ( $key != $title ) continue ; # Wrong key |
| 356 | + return array_pop ( $v ) ; # Correct key, return value |
| 357 | + } |
| 358 | + } |
| 359 | + |
| 360 | + # BAD PARSER FUNCTION! Ignoring... |
| 361 | + return $title ; |
| 362 | + } |
| 363 | + |
329 | 364 | function replace_template_variables ( &$text , &$variables ) { |
330 | 365 | for ( $a = 0 ; $a+3 < strlen ( $text ) ; $a++ ) { |
331 | 366 | if ( $text[$a] != '{' ) continue ; |
Index: trunk/wiki2xml/php/w2x.php |
— | — | @@ -255,6 +255,7 @@ |
256 | 256 | } |
257 | 257 | |
258 | 258 | if ( $whatsthis == "wikitext" ) { |
| 259 | + $content_provider->first_title = "Raw wikitext page" ; |
259 | 260 | $wiki2xml_authors = array () ; |
260 | 261 | $xml = $converter->article2xml ( "" , $wikitext , $xmlg ) ; |
261 | 262 | } else { |