Index: trunk/phase3/maintenance/importDump.php |
— | — | @@ -150,6 +150,10 @@ |
151 | 151 | array( &$this, 'handleUpload' ) ); |
152 | 152 | $this->logItemCallback = $importer->setLogItemCallback( |
153 | 153 | array( &$this, 'handleLogItem' ) ); |
| 154 | + |
| 155 | + if ( $this->dryRun ) { |
| 156 | + $importer->setPageOutCallback( null ); |
| 157 | + } |
154 | 158 | |
155 | 159 | return $importer->doImport(); |
156 | 160 | } |
Index: trunk/phase3/includes/ImportXMLReader.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | * Creates an ImportXMLReader drawing from the source provided |
15 | 15 | */ |
16 | 16 | function __construct( $source ) { |
17 | | - $this->reader = new XMLReader(); |
| 17 | + $this->reader = new XMLReader2(); |
18 | 18 | |
19 | 19 | stream_wrapper_register( 'uploadsource', 'UploadSourceAdapter' ); |
20 | 20 | $id = UploadSourceAdapter::registerSource( $source ); |
— | — | @@ -23,6 +23,7 @@ |
24 | 24 | $this->setRevisionCallback( array( $this, "importRevision" ) ); |
25 | 25 | $this->setUploadCallback( array( $this, 'importUpload' ) ); |
26 | 26 | $this->setLogItemCallback( array( $this, 'importLogItem' ) ); |
| 27 | + $this->setPageOutCallback( array( $this, 'finishImportPage' ) ); |
27 | 28 | } |
28 | 29 | |
29 | 30 | private function throwXmlError( $err ) { |
— | — | @@ -168,6 +169,13 @@ |
169 | 170 | //return $dbw->deadlockLoop( array( $revision, 'importUpload' ) ); |
170 | 171 | return false; |
171 | 172 | } |
| 173 | + |
| 174 | + /** |
| 175 | + * Mostly for hook use |
| 176 | + */ |
| 177 | + public function finishImportPage( $title, $origTitle, $revCount, $sRevCount, $pageInfo ) { |
| 178 | + return wfRunHooks( 'AfterImportPage', func_get_args() ); |
| 179 | + } |
172 | 180 | |
173 | 181 | /** |
174 | 182 | * Alternate per-revision callback, for debugging. |
— | — | @@ -203,10 +211,9 @@ |
204 | 212 | * @param $revisionCount int |
205 | 213 | * @param $successCount Int: number of revisions for which callback returned true |
206 | 214 | */ |
207 | | - private function pageOutCallback( $title, $origTitle, $revisionCount, $successCount ) { |
| 215 | + private function pageOutCallback( $title, $origTitle, $revCount, $sucCount, $pageInfo ) { |
208 | 216 | if( isset( $this->mPageOutCallback ) ) { |
209 | | - call_user_func_array( $this->mPageOutCallback, |
210 | | - array( $title, $origTitle, $revisionCount, $successCount ) ); |
| 217 | + call_user_func_array( $this->mPageOutCallback, func_get_args() ); |
211 | 218 | } |
212 | 219 | } |
213 | 220 | |
— | — | @@ -244,21 +251,7 @@ |
245 | 252 | * @access private |
246 | 253 | */ |
247 | 254 | private function nodeContents() { |
248 | | - if( $this->reader->isEmptyElement ) { |
249 | | - return ""; |
250 | | - } |
251 | | - $buffer = ""; |
252 | | - while( $this->reader->read() ) { |
253 | | - switch( $this->reader->nodeType ) { |
254 | | - case XmlReader::TEXT: |
255 | | - case XmlReader::SIGNIFICANT_WHITESPACE: |
256 | | - $buffer .= $this->reader->value; |
257 | | - break; |
258 | | - case XmlReader::END_ELEMENT: |
259 | | - return $buffer; |
260 | | - } |
261 | | - } |
262 | | - return $this->close(); |
| 255 | + return $this->reader->nodeContents(); |
263 | 256 | } |
264 | 257 | |
265 | 258 | # -------------- |
— | — | @@ -378,7 +371,7 @@ |
379 | 372 | if ( !wfRunHooks( 'ImportHandleLogItemXMLTag', |
380 | 373 | $this->reader, $logInfo ) ) { |
381 | 374 | // Do nothing |
382 | | - } if ( in_array( $tag, $normalFields ) ) { |
| 375 | + } elseif ( in_array( $tag, $normalFields ) ) { |
383 | 376 | $logInfo[$tag] = $this->nodeContents(); |
384 | 377 | } elseif ( $tag == 'contributor' ) { |
385 | 378 | $logInfo['contributor'] = $this->handleContributor(); |
— | — | @@ -436,10 +429,10 @@ |
437 | 430 | if ( $badTitle ) { |
438 | 431 | // The title is invalid, bail out of this page |
439 | 432 | $skip = true; |
440 | | - } elseif ( !wfRunHooks( 'ImportHandlePageXMLTag', $this->reader, |
441 | | - $pageInfo ) ) { |
| 433 | + } elseif ( !wfRunHooks( 'ImportHandlePageXMLTag', array( $this->reader, |
| 434 | + &$pageInfo ) ) ) { |
442 | 435 | // Do nothing |
443 | | - } if ( in_array( $tag, $normalFields ) ) { |
| 436 | + } elseif ( in_array( $tag, $normalFields ) ) { |
444 | 437 | $pageInfo[$tag] = $this->nodeContents(); |
445 | 438 | if ( $tag == 'title' ) { |
446 | 439 | $title = $this->processTitle( $pageInfo['title'] ); |
— | — | @@ -464,7 +457,8 @@ |
465 | 458 | |
466 | 459 | $this->pageOutCallback( $pageInfo['_title'], $origTitle, |
467 | 460 | $pageInfo['revisionCount'], |
468 | | - $pageInfo['successfulRevisionCount'] ); |
| 461 | + $pageInfo['successfulRevisionCount'], |
| 462 | + $pageInfo ); |
469 | 463 | } |
470 | 464 | |
471 | 465 | private function handleRevision( &$pageInfo ) { |
— | — | @@ -486,7 +480,7 @@ |
487 | 481 | if ( !wfRunHooks( 'ImportHandleRevisionXMLTag', $this->reader, |
488 | 482 | $pageInfo, $revisionInfo ) ) { |
489 | 483 | // Do nothing |
490 | | - } if ( in_array( $tag, $normalFields ) ) { |
| 484 | + } elseif ( in_array( $tag, $normalFields ) ) { |
491 | 485 | $revisionInfo[$tag] = $this->nodeContents(); |
492 | 486 | } elseif ( $tag == 'contributor' ) { |
493 | 487 | $revisionInfo['contributor'] = $this->handleContributor(); |
— | — | @@ -547,7 +541,7 @@ |
548 | 542 | if ( !wfRunHooks( 'ImportHandleUploadXMLTag', $this->reader, |
549 | 543 | $pageInfo, $revisionInfo ) ) { |
550 | 544 | // Do nothing |
551 | | - } if ( in_array( $tag, $normalFields ) ) { |
| 545 | + } elseif ( in_array( $tag, $normalFields ) ) { |
552 | 546 | $uploadInfo[$tag] = $this->nodeContents(); |
553 | 547 | } elseif ( $tag == 'contributor' ) { |
554 | 548 | $uploadInfo['contributor'] = $this->handleContributor(); |
— | — | @@ -712,3 +706,23 @@ |
713 | 707 | return $result; |
714 | 708 | } |
715 | 709 | } |
| 710 | + |
| 711 | +class XMLReader2 extends XMLReader { |
| 712 | + function nodeContents() { |
| 713 | + if( $this->isEmptyElement ) { |
| 714 | + return ""; |
| 715 | + } |
| 716 | + $buffer = ""; |
| 717 | + while( $this->read() ) { |
| 718 | + switch( $this->nodeType ) { |
| 719 | + case XmlReader::TEXT: |
| 720 | + case XmlReader::SIGNIFICANT_WHITESPACE: |
| 721 | + $buffer .= $this->value; |
| 722 | + break; |
| 723 | + case XmlReader::END_ELEMENT: |
| 724 | + return $buffer; |
| 725 | + } |
| 726 | + } |
| 727 | + return $this->close(); |
| 728 | + } |
| 729 | +} |
Index: trunk/phase3/includes/specials/SpecialImport.php |
— | — | @@ -275,10 +275,12 @@ |
276 | 276 | class ImportReporter { |
277 | 277 | private $reason=false; |
278 | 278 | private $mOriginalLogCallback = null; |
| 279 | + private $mOriginalPageOutCallback = null; |
279 | 280 | private $mLogItemCount = 0; |
280 | 281 | |
281 | 282 | function __construct( $importer, $upload, $interwiki , $reason=false ) { |
282 | | - $importer->setPageOutCallback( array( $this, 'reportPage' ) ); |
| 283 | + $this->mOriginalPageOutCallback = |
| 284 | + $importer->setPageOutCallback( array( $this, 'reportPage' ) ); |
283 | 285 | $this->mOriginalLogCallback = |
284 | 286 | $importer->setLogItemCallback( array( $this, 'reportLogItem' ) ); |
285 | 287 | $this->mPageCount = 0; |
— | — | @@ -301,6 +303,8 @@ |
302 | 304 | |
303 | 305 | function reportPage( $title, $origTitle, $revisionCount, $successCount ) { |
304 | 306 | global $wgOut, $wgUser, $wgLang, $wgContLang; |
| 307 | + |
| 308 | + call_user_func_array( $this->mOriginalPageOutCallback, func_get_args() ); |
305 | 309 | |
306 | 310 | $skin = $wgUser->getSkin(); |
307 | 311 | |