From 9688b1cc54d5e8b73466fe95a11bdcf9b05ec622 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Fri, 25 Jun 2010 21:03:48 +0000 Subject: [PATCH] Some import-related fixes for LiquidThreads dump importation. --- includes/ImportXMLReader.php | 66 +++++++++++++++++------------ includes/specials/SpecialImport.php | 6 ++- maintenance/importDump.php | 4 ++ 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/includes/ImportXMLReader.php b/includes/ImportXMLReader.php index 29536ed4bf..06f21579c2 100644 --- a/includes/ImportXMLReader.php +++ b/includes/ImportXMLReader.php @@ -13,7 +13,7 @@ class WikiImporter { * Creates an ImportXMLReader drawing from the source provided */ function __construct( $source ) { - $this->reader = new XMLReader(); + $this->reader = new XMLReader2(); stream_wrapper_register( 'uploadsource', 'UploadSourceAdapter' ); $id = UploadSourceAdapter::registerSource( $source ); @@ -23,6 +23,7 @@ class WikiImporter { $this->setRevisionCallback( array( $this, "importRevision" ) ); $this->setUploadCallback( array( $this, 'importUpload' ) ); $this->setLogItemCallback( array( $this, 'importLogItem' ) ); + $this->setPageOutCallback( array( $this, 'finishImportPage' ) ); } private function throwXmlError( $err ) { @@ -168,6 +169,13 @@ class WikiImporter { //return $dbw->deadlockLoop( array( $revision, 'importUpload' ) ); return false; } + + /** + * Mostly for hook use + */ + public function finishImportPage( $title, $origTitle, $revCount, $sRevCount, $pageInfo ) { + return wfRunHooks( 'AfterImportPage', func_get_args() ); + } /** * Alternate per-revision callback, for debugging. @@ -203,10 +211,9 @@ class WikiImporter { * @param $revisionCount int * @param $successCount Int: number of revisions for which callback returned true */ - private function pageOutCallback( $title, $origTitle, $revisionCount, $successCount ) { + private function pageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ) { if( isset( $this->mPageOutCallback ) ) { - call_user_func_array( $this->mPageOutCallback, - array( $title, $origTitle, $revisionCount, $successCount ) ); + call_user_func_array( $this->mPageOutCallback, func_get_args() ); } } @@ -244,21 +251,7 @@ class WikiImporter { * @access private */ private function nodeContents() { - if( $this->reader->isEmptyElement ) { - return ""; - } - $buffer = ""; - while( $this->reader->read() ) { - switch( $this->reader->nodeType ) { - case XmlReader::TEXT: - case XmlReader::SIGNIFICANT_WHITESPACE: - $buffer .= $this->reader->value; - break; - case XmlReader::END_ELEMENT: - return $buffer; - } - } - return $this->close(); + return $this->reader->nodeContents(); } # -------------- @@ -378,7 +371,7 @@ class WikiImporter { if ( !wfRunHooks( 'ImportHandleLogItemXMLTag', $this->reader, $logInfo ) ) { // Do nothing - } if ( in_array( $tag, $normalFields ) ) { + } elseif ( in_array( $tag, $normalFields ) ) { $logInfo[$tag] = $this->nodeContents(); } elseif ( $tag == 'contributor' ) { $logInfo['contributor'] = $this->handleContributor(); @@ -436,10 +429,10 @@ class WikiImporter { if ( $badTitle ) { // The title is invalid, bail out of this page $skip = true; - } elseif ( !wfRunHooks( 'ImportHandlePageXMLTag', $this->reader, - $pageInfo ) ) { + } elseif ( !wfRunHooks( 'ImportHandlePageXMLTag', array( $this->reader, + &$pageInfo ) ) ) { // Do nothing - } if ( in_array( $tag, $normalFields ) ) { + } elseif ( in_array( $tag, $normalFields ) ) { $pageInfo[$tag] = $this->nodeContents(); if ( $tag == 'title' ) { $title = $this->processTitle( $pageInfo['title'] ); @@ -464,7 +457,8 @@ class WikiImporter { $this->pageOutCallback( $pageInfo['_title'], $origTitle, $pageInfo['revisionCount'], - $pageInfo['successfulRevisionCount'] ); + $pageInfo['successfulRevisionCount'], + $pageInfo ); } private function handleRevision( &$pageInfo ) { @@ -486,7 +480,7 @@ class WikiImporter { if ( !wfRunHooks( 'ImportHandleRevisionXMLTag', $this->reader, $pageInfo, $revisionInfo ) ) { // Do nothing - } if ( in_array( $tag, $normalFields ) ) { + } elseif ( in_array( $tag, $normalFields ) ) { $revisionInfo[$tag] = $this->nodeContents(); } elseif ( $tag == 'contributor' ) { $revisionInfo['contributor'] = $this->handleContributor(); @@ -547,7 +541,7 @@ class WikiImporter { if ( !wfRunHooks( 'ImportHandleUploadXMLTag', $this->reader, $pageInfo, $revisionInfo ) ) { // Do nothing - } if ( in_array( $tag, $normalFields ) ) { + } elseif ( in_array( $tag, $normalFields ) ) { $uploadInfo[$tag] = $this->nodeContents(); } elseif ( $tag == 'contributor' ) { $uploadInfo['contributor'] = $this->handleContributor(); @@ -712,3 +706,23 @@ class UploadSourceAdapter { return $result; } } + +class XMLReader2 extends XMLReader { + function nodeContents() { + if( $this->isEmptyElement ) { + return ""; + } + $buffer = ""; + while( $this->read() ) { + switch( $this->nodeType ) { + case XmlReader::TEXT: + case XmlReader::SIGNIFICANT_WHITESPACE: + $buffer .= $this->value; + break; + case XmlReader::END_ELEMENT: + return $buffer; + } + } + return $this->close(); + } +} diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index d5b25db199..9abdb30b3c 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -275,10 +275,12 @@ class SpecialImport extends SpecialPage { class ImportReporter { private $reason=false; private $mOriginalLogCallback = null; + private $mOriginalPageOutCallback = null; private $mLogItemCount = 0; function __construct( $importer, $upload, $interwiki , $reason=false ) { - $importer->setPageOutCallback( array( $this, 'reportPage' ) ); + $this->mOriginalPageOutCallback = + $importer->setPageOutCallback( array( $this, 'reportPage' ) ); $this->mOriginalLogCallback = $importer->setLogItemCallback( array( $this, 'reportLogItem' ) ); $this->mPageCount = 0; @@ -301,6 +303,8 @@ class ImportReporter { function reportPage( $title, $origTitle, $revisionCount, $successCount ) { global $wgOut, $wgUser, $wgLang, $wgContLang; + + call_user_func_array( $this->mOriginalPageOutCallback, func_get_args() ); $skin = $wgUser->getSkin(); diff --git a/maintenance/importDump.php b/maintenance/importDump.php index cbe8153bbc..17c040448f 100644 --- a/maintenance/importDump.php +++ b/maintenance/importDump.php @@ -150,6 +150,10 @@ class BackupReader { array( &$this, 'handleUpload' ) ); $this->logItemCallback = $importer->setLogItemCallback( array( &$this, 'handleLogItem' ) ); + + if ( $this->dryRun ) { + $importer->setPageOutCallback( null ); + } return $importer->doImport(); } -- 2.20.1