* 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 );
$this->setRevisionCallback( array( $this, "importRevision" ) );
$this->setUploadCallback( array( $this, 'importUpload' ) );
$this->setLogItemCallback( array( $this, 'importLogItem' ) );
+ $this->setPageOutCallback( array( $this, 'finishImportPage' ) );
}
private function throwXmlError( $err ) {
//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.
* @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() );
}
}
* @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();
}
# --------------
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();
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'] );
$this->pageOutCallback( $pageInfo['_title'], $origTitle,
$pageInfo['revisionCount'],
- $pageInfo['successfulRevisionCount'] );
+ $pageInfo['successfulRevisionCount'],
+ $pageInfo );
}
private function handleRevision( &$pageInfo ) {
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();
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();
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();
+ }
+}
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;
function reportPage( $title, $origTitle, $revisionCount, $successCount ) {
global $wgOut, $wgUser, $wgLang, $wgContLang;
+
+ call_user_func_array( $this->mOriginalPageOutCallback, func_get_args() );
$skin = $wgUser->getSkin();