From: Brion Vibber Date: Thu, 29 Mar 2007 20:57:12 +0000 (+0000) Subject: * (bug 2979) Import now gracefully skips invalid titles with a warning X-Git-Tag: 1.31.0-rc.0~53532 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=849186be7872292d427ec1f90657411e7021316f;p=lhc%2Fweb%2Fwiklou.git * (bug 2979) Import now gracefully skips invalid titles with a warning Should help with Jeff Merkey's problems with import of very long titles with mismatched local namespaces. Instead of crashing the script, the particular problem pages will be skipped. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 351b62bc51..5a435b89ce 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -310,6 +310,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN and importTextFile.php scripts * (bug 8933) Fix maintenance/reassignEdits.php script * (bug 9440) Added "mediawikiwiki" interwiki prefix to MediaWiki.org +* (bug 2979) Import now gracefully skips invalid titles with a warning + == Languages updated == diff --git a/includes/SpecialImport.php b/includes/SpecialImport.php index 10ab239628..3466943fb5 100644 --- a/includes/SpecialImport.php +++ b/includes/SpecialImport.php @@ -443,7 +443,7 @@ class WikiImporter { print "$data\n"; } else { global $wgOut; - $wgOut->addHTML( "
  • $data
  • \n" ); + $wgOut->addHTML( "
  • " . htmlspecialchars( $data ) . "
  • \n" ); } } @@ -624,9 +624,14 @@ class WikiImporter { xml_set_character_data_handler( $parser, "char_append" ); break; case "revision": - $this->workRevision = new WikiRevision; - $this->workRevision->setTitle( $this->pageTitle ); - $this->workRevisionCount++; + if( is_object( $this->pageTitle ) ) { + $this->workRevision = new WikiRevision; + $this->workRevision->setTitle( $this->pageTitle ); + $this->workRevisionCount++; + } else { + // Skipping items due to invalid page title + $this->workRevision = null; + } xml_set_element_handler( $parser, "in_revision", "out_revision" ); break; default: @@ -678,30 +683,42 @@ class WikiImporter { } else { $this->pageTitle = Title::newFromText( $this->workTitle ); } - $this->pageCallback( $this->workTitle ); + if( is_null( $this->pageTitle ) ) { + // Invalid page title? Ignore the page + $this->notice( "Skipping invalid page title '$this->workTitle'" ); + } else { + $this->pageCallback( $this->workTitle ); + } break; case "id": if ( $this->parenttag == 'revision' ) { - $this->workRevision->setID( $this->appenddata ); + if( $this->workRevision ) + $this->workRevision->setID( $this->appenddata ); } break; case "text": - $this->workRevision->setText( $this->appenddata ); + if( $this->workRevision ) + $this->workRevision->setText( $this->appenddata ); break; case "username": - $this->workRevision->setUsername( $this->appenddata ); + if( $this->workRevision ) + $this->workRevision->setUsername( $this->appenddata ); break; case "ip": - $this->workRevision->setUserIP( $this->appenddata ); + if( $this->workRevision ) + $this->workRevision->setUserIP( $this->appenddata ); break; case "timestamp": - $this->workRevision->setTimestamp( $this->appenddata ); + if( $this->workRevision ) + $this->workRevision->setTimestamp( $this->appenddata ); break; case "comment": - $this->workRevision->setComment( $this->appenddata ); + if( $this->workRevision ) + $this->workRevision->setComment( $this->appenddata ); break; case "minor": - $this->workRevision->setMinor( true ); + if( $this->workRevision ) + $this->workRevision->setMinor( true ); break; default: $this->debug( "Bad append: {$this->appendfield}" ); @@ -738,10 +755,12 @@ class WikiImporter { } xml_set_element_handler( $parser, "in_page", "out_page" ); - $ok = call_user_func_array( $this->mRevisionCallback, - array( &$this->workRevision, &$this ) ); - if( $ok ) { - $this->workSuccessCount++; + if( $this->workRevision ) { + $ok = call_user_func_array( $this->mRevisionCallback, + array( &$this->workRevision, &$this ) ); + if( $ok ) { + $this->workSuccessCount++; + } } }