Index: trunk/phase3/maintenance/language/messages.inc |
— | — | @@ -2355,6 +2355,7 @@ |
2356 | 2356 | 'import-error-create', |
2357 | 2357 | 'import-error-interwiki', |
2358 | 2358 | 'import-error-special', |
| 2359 | + 'import-error-invalid', |
2359 | 2360 | ), |
2360 | 2361 | 'importlog' => array( |
2361 | 2362 | 'importlogpage', |
Index: trunk/phase3/includes/specials/SpecialImport.php |
— | — | @@ -321,6 +321,7 @@ |
322 | 322 | $importer->setPageOutCallback( array( $this, 'reportPage' ) ); |
323 | 323 | $this->mOriginalLogCallback = |
324 | 324 | $importer->setLogItemCallback( array( $this, 'reportLogItem' ) ); |
| 325 | + $importer->setNoticeCallback( array( $this, 'reportNotice' ) ); |
325 | 326 | $this->mPageCount = 0; |
326 | 327 | $this->mIsUpload = $upload; |
327 | 328 | $this->mInterwiki = $interwiki; |
— | — | @@ -331,6 +332,10 @@ |
332 | 333 | $this->getOutput()->addHTML( "<ul>\n" ); |
333 | 334 | } |
334 | 335 | |
| 336 | + function reportNotice( $msg, array $params ) { |
| 337 | + $this->getOutput()->addHTML( Html::element( 'li', array(), $this->msg( $msg, $params )->text() ) ); |
| 338 | + } |
| 339 | + |
335 | 340 | function reportLogItem( /* ... */ ) { |
336 | 341 | $this->mLogItemCount++; |
337 | 342 | if ( is_callable( $this->mOriginalLogCallback ) ) { |
— | — | @@ -352,6 +357,11 @@ |
353 | 358 | $args = func_get_args(); |
354 | 359 | call_user_func_array( $this->mOriginalPageOutCallback, $args ); |
355 | 360 | |
| 361 | + if ( $title === null ) { |
| 362 | + # Invalid or non-importable title; a notice is already displayed |
| 363 | + return; |
| 364 | + } |
| 365 | + |
356 | 366 | $this->mPageCount++; |
357 | 367 | |
358 | 368 | $localCount = $this->getLanguage()->formatNum( $successCount ); |
Index: trunk/phase3/includes/Import.php |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | private $reader = null; |
36 | 36 | private $mLogItemCallback, $mUploadCallback, $mRevisionCallback, $mPageCallback; |
37 | 37 | private $mSiteInfoCallback, $mTargetNamespace, $mPageOutCallback; |
38 | | - private $mDebug; |
| 38 | + private $mNoticeCallback, $mDebug; |
39 | 39 | private $mImportUploads, $mImageBasePath; |
40 | 40 | private $mNoUpdates = false; |
41 | 41 | |
— | — | @@ -75,13 +75,14 @@ |
76 | 76 | wfDebug( "IMPORT: $data\n" ); |
77 | 77 | } |
78 | 78 | |
79 | | - private function notice( $data ) { |
80 | | - global $wgCommandLineMode; |
81 | | - if( $wgCommandLineMode ) { |
82 | | - print "$data\n"; |
83 | | - } else { |
84 | | - global $wgOut; |
85 | | - $wgOut->addHTML( "<li>" . htmlspecialchars( $data ) . "</li>\n" ); |
| 79 | + private function notice( $msg /*, $param, ...*/ ) { |
| 80 | + $params = func_get_args(); |
| 81 | + array_shift( $params ); |
| 82 | + |
| 83 | + if ( is_callable( $this->mNoticeCallback ) ) { |
| 84 | + call_user_func( $this->mNoticeCallback, $msg, $params ); |
| 85 | + } else { # No ImportReporter -> CLI |
| 86 | + echo wfMessage( $msg, $params )->text() . "\n"; |
86 | 87 | } |
87 | 88 | } |
88 | 89 | |
— | — | @@ -102,6 +103,16 @@ |
103 | 104 | } |
104 | 105 | |
105 | 106 | /** |
| 107 | + * Set a callback that displays notice messages |
| 108 | + * |
| 109 | + * @param $callback callback |
| 110 | + * @return callback |
| 111 | + */ |
| 112 | + public function setNoticeCallback( $callback ) { |
| 113 | + return wfSetVar( $this->mNoticeCallback, $callback ); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
106 | 117 | * Sets the action to perform as each new page in the stream is reached. |
107 | 118 | * @param $callback callback |
108 | 119 | * @return callback |
— | — | @@ -780,21 +791,21 @@ |
781 | 792 | |
782 | 793 | if( is_null( $title ) ) { |
783 | 794 | # Invalid page title? Ignore the page |
784 | | - $this->notice( "Skipping invalid page title '$workTitle'" ); |
| 795 | + $this->notice( 'import-error-invalid', $workTitle ); |
785 | 796 | return false; |
786 | 797 | } elseif( $title->isExternal() ) { |
787 | | - $this->notice( wfMessage( 'import-error-interwiki', $title->getText() )->text() ); |
| 798 | + $this->notice( 'import-error-interwiki', $title->getPrefixedText() ); |
788 | 799 | return false; |
789 | 800 | } elseif( !$title->canExist() ) { |
790 | | - $this->notice( wfMessage( 'import-error-special', $title->getText() )->text() ); |
| 801 | + $this->notice( 'import-error-special', $title->getPrefixedText() ); |
791 | 802 | return false; |
792 | 803 | } elseif( !$title->userCan( 'edit' ) && !$wgCommandLineMode ) { |
793 | 804 | # Do not import if the importing wiki user cannot edit this page |
794 | | - $this->notice( wfMessage( 'import-error-edit', $title->getText() )->text() ); |
| 805 | + $this->notice( 'import-error-edit', $title->getPrefixedText() ); |
795 | 806 | return false; |
796 | 807 | } elseif( !$title->exists() && !$title->userCan( 'create' ) && !$wgCommandLineMode ) { |
797 | 808 | # Do not import if the importing wiki user cannot create this page |
798 | | - $this->notice( wfMessage( 'import-error-create', $title->getText() )->text() ); |
| 809 | + $this->notice( 'import-error-create', $title->getPrefixedText() ); |
799 | 810 | return false; |
800 | 811 | } |
801 | 812 | |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -3400,6 +3400,7 @@ |
3401 | 3401 | 'import-error-create' => 'Page "$1" is not imported because you are not allowed to create it.', |
3402 | 3402 | 'import-error-interwiki' => 'Page "$1" is not imported because its name is reserved for external linking (interwiki).', |
3403 | 3403 | 'import-error-special' => 'Page "$1" is not imported because it belongs to a special namespace that does not allow pages.', |
| 3404 | +'import-error-invalid' => 'Page "$1" is not imported because its name is invalid.', |
3404 | 3405 | |
3405 | 3406 | # Import log |
3406 | 3407 | 'importlogpage' => 'Import log', |