Index: trunk/phase3/includes/Import.php |
— | — | @@ -383,6 +383,7 @@ |
384 | 384 | var $mLogItemCallback = null; |
385 | 385 | var $mUploadCallback = null; |
386 | 386 | var $mTargetNamespace = null; |
| 387 | + var $mXmlNamespace = false; |
387 | 388 | var $lastfield; |
388 | 389 | var $tagStack = array(); |
389 | 390 | |
— | — | @@ -398,6 +399,22 @@ |
399 | 400 | wfDebug( "WikiImporter XML error: $err\n" ); |
400 | 401 | } |
401 | 402 | |
| 403 | + function handleXmlNamespace ( $parser, $data, $prefix=false, $uri=false ) { |
| 404 | + if( preg_match( '/www.mediawiki.org/',$prefix ) ) { |
| 405 | + $prefix = str_replace( '/','\/',$prefix ); |
| 406 | + $this->mXmlNamespace='/^'.$prefix.':/'; |
| 407 | + } |
| 408 | + } |
| 409 | + |
| 410 | + function stripXmlNamespace($name) { |
| 411 | + if( $this->mXmlNamespace ) { |
| 412 | + return(preg_replace($this->mXmlNamespace,'',$name,1)); |
| 413 | + } |
| 414 | + else { |
| 415 | + return($name); |
| 416 | + } |
| 417 | + } |
| 418 | + |
402 | 419 | # -------------- |
403 | 420 | |
404 | 421 | function doImport() { |
— | — | @@ -405,13 +422,14 @@ |
406 | 423 | return new WikiErrorMsg( "importnotext" ); |
407 | 424 | } |
408 | 425 | |
409 | | - $parser = xml_parser_create( "UTF-8" ); |
| 426 | + $parser = xml_parser_create_ns( "UTF-8" ); |
410 | 427 | |
411 | 428 | # case folding violates XML standard, turn it off |
412 | 429 | xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, false ); |
413 | 430 | |
414 | 431 | xml_set_object( $parser, $this ); |
415 | 432 | xml_set_element_handler( $parser, "in_start", "" ); |
| 433 | + xml_set_start_namespace_decl_handler( $parser, "handleXmlNamespace" ); |
416 | 434 | |
417 | 435 | $offset = 0; // for context extraction on error reporting |
418 | 436 | do { |
— | — | @@ -603,6 +621,7 @@ |
604 | 622 | } |
605 | 623 | |
606 | 624 | function in_start( $parser, $name, $attribs ) { |
| 625 | + $name = $this->stripXmlNamespace($name); |
607 | 626 | $this->debug( "in_start $name" ); |
608 | 627 | if( $name != "mediawiki" ) { |
609 | 628 | return $this->throwXMLerror( "Expected <mediawiki>, got <$name>" ); |
— | — | @@ -611,6 +630,7 @@ |
612 | 631 | } |
613 | 632 | |
614 | 633 | function in_mediawiki( $parser, $name, $attribs ) { |
| 634 | + $name = $this->stripXmlNamespace($name); |
615 | 635 | $this->debug( "in_mediawiki $name" ); |
616 | 636 | if( $name == 'siteinfo' ) { |
617 | 637 | xml_set_element_handler( $parser, "in_siteinfo", "out_siteinfo" ); |
— | — | @@ -630,6 +650,7 @@ |
631 | 651 | } |
632 | 652 | } |
633 | 653 | function out_mediawiki( $parser, $name ) { |
| 654 | + $name = $this->stripXmlNamespace($name); |
634 | 655 | $this->debug( "out_mediawiki $name" ); |
635 | 656 | if( $name != "mediawiki" ) { |
636 | 657 | return $this->throwXMLerror( "Expected </mediawiki>, got </$name>" ); |
— | — | @@ -640,6 +661,7 @@ |
641 | 662 | |
642 | 663 | function in_siteinfo( $parser, $name, $attribs ) { |
643 | 664 | // no-ops for now |
| 665 | + $name = $this->stripXmlNamespace($name); |
644 | 666 | $this->debug( "in_siteinfo $name" ); |
645 | 667 | switch( $name ) { |
646 | 668 | case "sitename": |
— | — | @@ -655,6 +677,7 @@ |
656 | 678 | } |
657 | 679 | |
658 | 680 | function out_siteinfo( $parser, $name ) { |
| 681 | + $name = $this->stripXmlNamespace($name); |
659 | 682 | if( $name == "siteinfo" ) { |
660 | 683 | xml_set_element_handler( $parser, "in_mediawiki", "out_mediawiki" ); |
661 | 684 | } |
— | — | @@ -662,6 +685,7 @@ |
663 | 686 | |
664 | 687 | |
665 | 688 | function in_page( $parser, $name, $attribs ) { |
| 689 | + $name = $this->stripXmlNamespace($name); |
666 | 690 | $this->debug( "in_page $name" ); |
667 | 691 | switch( $name ) { |
668 | 692 | case "id": |
— | — | @@ -702,6 +726,7 @@ |
703 | 727 | } |
704 | 728 | |
705 | 729 | function out_page( $parser, $name ) { |
| 730 | + $name = $this->stripXmlNamespace($name); |
706 | 731 | $this->debug( "out_page $name" ); |
707 | 732 | $this->pop(); |
708 | 733 | if( $name != "page" ) { |
— | — | @@ -721,6 +746,7 @@ |
722 | 747 | } |
723 | 748 | |
724 | 749 | function in_nothing( $parser, $name, $attribs ) { |
| 750 | + $name = $this->stripXmlNamespace($name); |
725 | 751 | $this->debug( "in_nothing $name" ); |
726 | 752 | return $this->throwXMLerror( "No child elements allowed here; got <$name>" ); |
727 | 753 | } |
— | — | @@ -731,6 +757,7 @@ |
732 | 758 | } |
733 | 759 | |
734 | 760 | function out_append( $parser, $name ) { |
| 761 | + $name = $this->stripXmlNamespace($name); |
735 | 762 | $this->debug( "out_append $name" ); |
736 | 763 | if( $name != $this->appendfield ) { |
737 | 764 | return $this->throwXMLerror( "Expected </{$this->appendfield}>, got </$name>" ); |
— | — | @@ -823,6 +850,7 @@ |
824 | 851 | } |
825 | 852 | |
826 | 853 | function in_revision( $parser, $name, $attribs ) { |
| 854 | + $name = $this->stripXmlNamespace($name); |
827 | 855 | $this->debug( "in_revision $name" ); |
828 | 856 | switch( $name ) { |
829 | 857 | case "id": |
— | — | @@ -844,6 +872,7 @@ |
845 | 873 | } |
846 | 874 | |
847 | 875 | function out_revision( $parser, $name ) { |
| 876 | + $name = $this->stripXmlNamespace($name); |
848 | 877 | $this->debug( "out_revision $name" ); |
849 | 878 | $this->pop(); |
850 | 879 | if( $name != "revision" ) { |
— | — | @@ -861,6 +890,7 @@ |
862 | 891 | } |
863 | 892 | |
864 | 893 | function in_logitem( $parser, $name, $attribs ) { |
| 894 | + $name = $this->stripXmlNamespace($name); |
865 | 895 | $this->debug( "in_logitem $name" ); |
866 | 896 | switch( $name ) { |
867 | 897 | case "id": |
— | — | @@ -884,6 +914,7 @@ |
885 | 915 | } |
886 | 916 | |
887 | 917 | function out_logitem( $parser, $name ) { |
| 918 | + $name = $this->stripXmlNamespace($name); |
888 | 919 | $this->debug( "out_logitem $name" ); |
889 | 920 | $this->pop(); |
890 | 921 | if( $name != "logitem" ) { |
— | — | @@ -901,6 +932,7 @@ |
902 | 933 | } |
903 | 934 | |
904 | 935 | function in_upload( $parser, $name, $attribs ) { |
| 936 | + $name = $this->stripXmlNamespace($name); |
905 | 937 | $this->debug( "in_upload $name" ); |
906 | 938 | switch( $name ) { |
907 | 939 | case "timestamp": |
— | — | @@ -923,6 +955,7 @@ |
924 | 956 | } |
925 | 957 | |
926 | 958 | function out_upload( $parser, $name ) { |
| 959 | + $name = $this->stripXmlNamespace($name); |
927 | 960 | $this->debug( "out_revision $name" ); |
928 | 961 | $this->pop(); |
929 | 962 | if( $name != "upload" ) { |
— | — | @@ -940,6 +973,7 @@ |
941 | 974 | } |
942 | 975 | |
943 | 976 | function in_contributor( $parser, $name, $attribs ) { |
| 977 | + $name = $this->stripXmlNamespace($name); |
944 | 978 | $this->debug( "in_contributor $name" ); |
945 | 979 | switch( $name ) { |
946 | 980 | case "username": |
— | — | @@ -955,6 +989,7 @@ |
956 | 990 | } |
957 | 991 | |
958 | 992 | function out_contributor( $parser, $name ) { |
| 993 | + $name = $this->stripXmlNamespace($name); |
959 | 994 | $this->debug( "out_contributor $name" ); |
960 | 995 | $this->pop(); |
961 | 996 | if( $name != "contributor" ) { |