Merge "Remove broken test."
[lhc/web/wiklou.git] / includes / specials / SpecialImport.php
index 6d9b2c8..362fc5c 100644 (file)
@@ -1,7 +1,8 @@
 <?php
 /**
- * MediaWiki page data importer
- * Copyright (C) 2003,2005 Brion Vibber <brion@pobox.com>
+ * Implements Special:Import
+ *
+ * Copyright © 2003,2005 Brion Vibber <brion@pobox.com>
  * http://www.mediawiki.org/
  *
  * This program is free software; you can redistribute it and/or modify
  * @ingroup SpecialPage
  */
 
+/**
+ * MediaWiki page data importer
+ *
+ * @ingroup SpecialPage
+ */
 class SpecialImport extends SpecialPage {
-       
+
        private $interwiki = false;
        private $namespace;
+       private $rootpage = '';
        private $frompage = '';
        private $logcomment= false;
        private $history = true;
        private $includeTemplates = false;
-       
+       private $pageLinkDepth;
+
        /**
         * Constructor
         */
@@ -40,57 +48,82 @@ class SpecialImport extends SpecialPage {
                global $wgImportTargetNamespace;
                $this->namespace = $wgImportTargetNamespace;
        }
-       
+
        /**
         * Execute
         */
        function execute( $par ) {
-               global $wgRequest;
-               
                $this->setHeaders();
                $this->outputHeader();
-               
-               if ( wfReadOnly() ) {
-                       global $wgOut;
-                       $wgOut->readOnlyPage();
-                       return;
+
+               $user = $this->getUser();
+               if ( !$user->isAllowedAny( 'import', 'importupload' ) ) {
+                       throw new PermissionsError( 'import' );
+               }
+
+               # @todo Allow Title::getUserPermissionsErrors() to take an array
+               # @todo FIXME: Title::checkSpecialsAndNSPermissions() has a very wierd expectation of what
+               # getUserPermissionsErrors() might actually be used for, hence the 'ns-specialprotected'
+               $errors = wfMergeErrorArrays(
+                       $this->getTitle()->getUserPermissionsErrors(
+                               'import', $user, true,
+                               array( 'ns-specialprotected', 'badaccess-group0', 'badaccess-groups' )
+                       ),
+                       $this->getTitle()->getUserPermissionsErrors(
+                               'importupload', $user, true,
+                               array( 'ns-specialprotected', 'badaccess-group0', 'badaccess-groups' )
+                       )
+               );
+
+               if ( $errors ) {
+                       throw new PermissionsError( 'import', $errors );
                }
-               
-               if ( $wgRequest->wasPosted() && $wgRequest->getVal( 'action' ) == 'submit' ) {
+
+               $this->checkReadOnly();
+
+               $request = $this->getRequest();
+               if ( $request->wasPosted() && $request->getVal( 'action' ) == 'submit' ) {
                        $this->doImport();
                }
                $this->showForm();
        }
-       
+
        /**
         * Do the actual import
         */
        private function doImport() {
-               global $wgOut, $wgRequest, $wgUser, $wgImportSources;
+               global $wgImportSources, $wgExportMaxLinkDepth;
+
                $isUpload = false;
-               $this->namespace = $wgRequest->getIntOrNull( 'namespace' );
-               $sourceName = $wgRequest->getVal( "source" );
+               $request = $this->getRequest();
+               $this->namespace = $request->getIntOrNull( 'namespace' );
+               $sourceName = $request->getVal( "source" );
 
-               $this->logcomment = $wgRequest->getText( 'log-comment' );
-               $this->pageLinkDepth = $wgRequest->getIntOrNull( 'pagelink-depth' );
+               $this->logcomment = $request->getText( 'log-comment' );
+               $this->pageLinkDepth = $wgExportMaxLinkDepth == 0 ? 0 : $request->getIntOrNull( 'pagelink-depth' );
+               $this->rootpage = $request->getText( 'rootpage' );\r
 
-               if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'editToken' ) ) ) {
-                       $source = new WikiErrorMsg( 'import-token-mismatch' );
+               $user = $this->getUser();
+               if ( !$user->matchEditToken( $request->getVal( 'editToken' ) ) ) {
+                       $source = Status::newFatal( 'import-token-mismatch' );
                } elseif ( $sourceName == 'upload' ) {
                        $isUpload = true;
-                       if( $wgUser->isAllowed( 'importupload' ) ) {
+                       if( $user->isAllowed( 'importupload' ) ) {
                                $source = ImportStreamSource::newFromUpload( "xmlimport" );
                        } else {
-                               return $wgOut->permissionRequired( 'importupload' );
+                               throw new PermissionsError( 'importupload' );
                        }
                } elseif ( $sourceName == "interwiki" ) {
-                       $this->interwiki = $wgRequest->getVal( 'interwiki' );
+                       if( !$user->isAllowed( 'import' ) ){
+                               throw new PermissionsError( 'import' );
+                       }
+                       $this->interwiki = $request->getVal( 'interwiki' );
                        if ( !in_array( $this->interwiki, $wgImportSources ) ) {
-                               $source = new WikiErrorMsg( "import-invalid-interwiki" );
+                               $source = Status::newFatal( "import-invalid-interwiki" );
                        } else {
-                               $this->history = $wgRequest->getCheck( 'interwikiHistory' );
-                               $this->frompage = $wgRequest->getText( "frompage" );
-                               $this->includeTemplates = $wgRequest->getCheck( 'interwikiTemplates' );
+                               $this->history = $request->getCheck( 'interwikiHistory' );
+                               $this->frompage = $request->getText( "frompage" );
+                               $this->includeTemplates = $request->getCheck( 'interwikiTemplates' );
                                $source = ImportStreamSource::newFromInterwiki(
                                        $this->interwiki,
                                        $this->frompage,
@@ -99,60 +132,73 @@ class SpecialImport extends SpecialPage {
                                        $this->pageLinkDepth );
                        }
                } else {
-                       $source = new WikiErrorMsg( "importunknownsource" );
+                       $source = Status::newFatal( "importunknownsource" );
                }
 
-               if( WikiError::isError( $source ) ) {
-                       $wgOut->wrapWikiMsg( '<p class="error">$1</p>', array( 'importfailed', $source->getMessage() ) );
+               $out = $this->getOutput();
+               if( !$source->isGood() ) {
+                       $out->wrapWikiMsg( "<p class=\"error\">\n$1\n</p>", array( 'importfailed', $source->getWikiText() ) );
                } else {
-                       $wgOut->addWikiMsg( "importstart" );
-
-                       $importer = new WikiImporter( $source );
+                       $importer = new WikiImporter( $source->value );
                        if( !is_null( $this->namespace ) ) {
                                $importer->setTargetNamespace( $this->namespace );
                        }
+                       if( !is_null( $this->rootpage ) ) {
+                               $statusRootPage = $importer->setTargetRootPage( $this->rootpage );
+                               if( !$statusRootPage->isGood() ) {
+                                       $out->wrapWikiMsg( "<p class=\"error\">\n$1\n</p>", array( 'import-options-wrong', $statusRootPage->getWikiText(), count( $statusRootPage->getErrorsArray() ) ) );
+                                       return;
+                               }
+                       }
+
+                       $out->addWikiMsg( "importstart" );
+
                        $reporter = new ImportReporter( $importer, $isUpload, $this->interwiki , $this->logcomment);
+                       $reporter->setContext( $this->getContext() );
+                       $exception = false;
 
                        $reporter->open();
-                       $result = $importer->doImport();
-                       $resultCount = $reporter->close();
+                       try {
+                               $importer->doImport();
+                       } catch ( MWException $e ) {
+                               $exception = $e;
+                       }
+                       $result = $reporter->close();
 
-                       if( WikiError::isError( $result ) ) {
+                       if ( $exception ) {
                                # No source or XML parse error
-                               $wgOut->wrapWikiMsg( '<p class="error">$1</p>', array( 'importfailed', $result->getMessage() ) );
-                       } elseif( WikiError::isError( $resultCount ) ) {
+                               $out->wrapWikiMsg( "<p class=\"error\">\n$1\n</p>", array( 'importfailed', $exception->getMessage() ) );
+                       } elseif( !$result->isGood() ) {
                                # Zero revisions
-                               $wgOut->wrapWikiMsg( '<p class="error">$1</p>', array( 'importfailed', $resultCount->getMessage() ) );
+                               $out->wrapWikiMsg( "<p class=\"error\">\n$1\n</p>", array( 'importfailed', $result->getWikiText() ) );
                        } else {
                                # Success!
-                               $wgOut->addWikiMsg( 'importsuccess' );
+                               $out->addWikiMsg( 'importsuccess' );
                        }
-                       $wgOut->addWikiText( '<hr />' );
+                       $out->addHTML( '<hr />' );
                }
        }
 
        private function showForm() {
-               global $wgUser, $wgOut, $wgRequest, $wgTitle, $wgImportSources;
-               # FIXME: Quick hack to disable import for non privileged users /Raymond 
-               # Regression from 43963 
-               if( !$wgUser->isAllowed( 'import' ) && !$wgUser->isAllowed( 'importupload' ) )
-                       return $wgOut->permissionRequired( 'import' );
-
-               $action = $wgTitle->getLocalUrl( 'action=submit' );
-
-               if( $wgUser->isAllowed( 'importupload' ) ) {
-                       $wgOut->addWikiMsg( "importtext" );
-                       $wgOut->addHTML(
-                               Xml::openElement( 'fieldset' ).
-                               Xml::element( 'legend', null, wfMsg( 'import-upload' ) ) .
-                               Xml::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post', 'action' => $action ) ) .
-                               Xml::hidden( 'action', 'submit' ) .
-                               Xml::hidden( 'source', 'upload' ) .
+               global $wgImportSources, $wgExportMaxLinkDepth;
+
+               $action = $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) );
+               $user = $this->getUser();
+               $out = $this->getOutput();
+
+               if( $user->isAllowed( 'importupload' ) ) {
+                       $out->addHTML(
+                               Xml::fieldset( $this->msg( 'import-upload' )->text() ).
+                               Xml::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post',
+                                       'action' => $action, 'id' => 'mw-import-upload-form' ) ) .
+                               $this->msg( 'importtext' )->parseAsBlock() .
+                               Html::hidden( 'action', 'submit' ) .
+                               Html::hidden( 'source', 'upload' ) .
                                Xml::openElement( 'table', array( 'id' => 'mw-import-table' ) ) .
 
                                "<tr>
                                        <td class='mw-label'>" .
-                                               Xml::label( wfMsg( 'import-upload-filename' ), 'xmlimport' ) .
+                                               Xml::label( $this->msg( 'import-upload-filename' )->text(), 'xmlimport' ) .
                                        "</td>
                                        <td class='mw-input'>" .
                                                Xml::input( 'xmlimport', 50, '', array( 'type' => 'file' ) ) . ' ' .
@@ -160,7 +206,7 @@ class SpecialImport extends SpecialPage {
                                </tr>
                                <tr>
                                        <td class='mw-label'>" .
-                                               Xml::label( wfMsg( 'import-comment' ), 'mw-import-comment' ) .
+                                               Xml::label( $this->msg( 'import-comment' )->text(), 'mw-import-comment' ) .
                                        "</td>
                                        <td class='mw-input'>" .
                                                Xml::input( 'log-comment', 50, '',
@@ -168,44 +214,66 @@ class SpecialImport extends SpecialPage {
                                        "</td>
                                </tr>
                                <tr>
-                                       <td></td>
+                                       <td class='mw-label'>" .
+                                               Xml::label( $this->msg( 'import-interwiki-rootpage' )->text(), 'mw-interwiki-rootpage' ) .
+                                       "</td>
                                        <td class='mw-input'>" .
-                                               Xml::submitButton( wfMsg( 'uploadbtn' ) ) .
+                                               Xml::input( 'rootpage', 50, $this->rootpage,
+                                                       array( 'id' => 'mw-interwiki-rootpage', 'type' => 'text' ) ) . ' ' .
+                                       "</td>
+                               </tr>
+                               <tr>
+                                       <td></td>
+                                       <td class='mw-submit'>" .
+                                               Xml::submitButton( $this->msg( 'uploadbtn' )->text() ) .
                                        "</td>
                                </tr>" .
                                Xml::closeElement( 'table' ).
-                               Xml::hidden( 'editToken', $wgUser->editToken() ) .
+                               Html::hidden( 'editToken', $user->getEditToken() ) .
                                Xml::closeElement( 'form' ) .
                                Xml::closeElement( 'fieldset' )
                        );
                } else {
                        if( empty( $wgImportSources ) ) {
-                               $wgOut->addWikiMsg( 'importnosources' );
+                               $out->addWikiMsg( 'importnosources' );
                        }
                }
 
-               if( $wgUser->isAllowed( 'import' ) && !empty( $wgImportSources ) ) {
-                       $wgOut->addHTML(
-                               Xml::openElement( 'fieldset' ) .
-                               Xml::element( 'legend', null, wfMsg( 'importinterwiki' ) ) .
-                               Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action ) ) .
-                               wfMsgExt( 'import-interwiki-text', array( 'parse' ) ) .
-                               Xml::hidden( 'action', 'submit' ) .
-                               Xml::hidden( 'source', 'interwiki' ) .
-                               Xml::hidden( 'editToken', $wgUser->editToken() ) .
+               if( $user->isAllowed( 'import' ) && !empty( $wgImportSources ) ) {
+                       # Show input field for import depth only if $wgExportMaxLinkDepth > 0
+                       $importDepth = '';
+                       if( $wgExportMaxLinkDepth > 0 ) {
+                               $importDepth = "<tr>
+                                                       <td class='mw-label'>" .
+                                                               $this->msg( 'export-pagelinks' )->parse() .
+                                                       "</td>
+                                                       <td class='mw-input'>" .
+                                                               Xml::input( 'pagelink-depth', 3, 0 ) .
+                                                       "</td>
+                                               </tr>";
+                       }
+
+                       $out->addHTML(
+                               Xml::fieldset( $this->msg( 'importinterwiki' )->text() ) .
+                               Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'mw-import-interwiki-form' ) ) .
+                               $this->msg( 'import-interwiki-text' )->parseAsBlock() .
+                               Html::hidden( 'action', 'submit' ) .
+                               Html::hidden( 'source', 'interwiki' ) .
+                               Html::hidden( 'editToken', $user->getEditToken() ) .
                                Xml::openElement( 'table', array( 'id' => 'mw-import-table' ) ) .
                                "<tr>
                                        <td class='mw-label'>" .
-                                               Xml::label( wfMsg( 'import-interwiki-source' ), 'interwiki' ) .
+                                               Xml::label( $this->msg( 'import-interwiki-source' )->text(), 'interwiki' ) .
                                        "</td>
                                        <td class='mw-input'>" .
                                                Xml::openElement( 'select', array( 'name' => 'interwiki' ) )
                        );
                        foreach( $wgImportSources as $prefix ) {
                                $selected = ( $this->interwiki === $prefix ) ? ' selected="selected"' : '';
-                               $wgOut->addHTML( Xml::option( $prefix, $prefix, $selected ) );
+                               $out->addHTML( Xml::option( $prefix, $prefix, $selected ) );
                        }
-                       $wgOut->addHTML(
+
+                       $out->addHTML(
                                                Xml::closeElement( 'select' ) .
                                                Xml::input( 'frompage', 50, $this->frompage ) .
                                        "</td>
@@ -214,42 +282,57 @@ class SpecialImport extends SpecialPage {
                                        <td>
                                        </td>
                                        <td class='mw-input'>" .
-                                               Xml::checkLabel( wfMsg( 'import-interwiki-history' ), 'interwikiHistory', 'interwikiHistory', $this->history ) .
+                                               Xml::checkLabel( $this->msg( 'import-interwiki-history' )->text(), 'interwikiHistory', 'interwikiHistory', $this->history ) .
                                        "</td>
                                </tr>
                                <tr>
                                        <td>
                                        </td>
                                        <td class='mw-input'>" .
-                                               Xml::checkLabel( wfMsg( 'import-interwiki-templates' ), 'interwikiTemplates', 'interwikiTemplates', $this->includeTemplates ) .
+                                               Xml::checkLabel( $this->msg( 'import-interwiki-templates' )->text(), 'interwikiTemplates', 'interwikiTemplates', $this->includeTemplates ) .
                                        "</td>
                                </tr>
+                               $importDepth
                                <tr>
-                                       <td>".wfMsgExt( 'export-pagelinks', 'parseinline' )."</td>
-                                       <td class=\"mw-input\">" . Xml::input( 'pagelink-depth', 20, 0 ) . "<br/>
-                               </tr>
-                               <tr>
-                                       <td>" .
-                                               Xml::label( wfMsg( 'import-interwiki-namespace' ), 'namespace' ) .
+                                       <td class='mw-label'>" .
+                                               Xml::label( $this->msg( 'import-interwiki-namespace' )->text(), 'namespace' ) .
                                        "</td>
                                        <td class='mw-input'>" .
-                                               Xml::namespaceSelector( $this->namespace, '' ) .
+                                               Html::namespaceSelector(
+                                                       array(
+                                                               'selected' => $this->namespace,
+                                                               'all' => '',
+                                                       ), array(
+                                                               'name'  => 'namespace',
+                                                               'id'    => 'namespace',
+                                                               'class' => 'namespaceselector',
+                                                       )
+                                               ) .
                                        "</td>
                                </tr>
                                <tr>
                                        <td class='mw-label'>" .
-                                               Xml::label( wfMsg( 'import-comment' ), 'mw-interwiki-comment' ) .
+                                               Xml::label( $this->msg( 'import-comment' )->text(), 'mw-interwiki-comment' ) .
                                        "</td>
                                        <td class='mw-input'>" .
                                                Xml::input( 'log-comment', 50, '',
                                                        array( 'id' => 'mw-interwiki-comment', 'type' => 'text' ) ) . ' ' .
                                        "</td>
                                </tr>
+                               <tr>
+                                       <td class='mw-label'>" .
+                                               Xml::label( $this->msg( 'import-interwiki-rootpage' )->text(), 'mw-interwiki-rootpage' ) .
+                                       "</td>
+                                       <td class='mw-input'>" .
+                                               Xml::input( 'rootpage', 50, $this->rootpage,
+                                                       array( 'id' => 'mw-interwiki-rootpage', 'type' => 'text' ) ) . ' ' .
+                                       "</td>
+                               </tr>
                                <tr>
                                        <td>
                                        </td>
-                                       <td class='mw-input'>" .
-                                               Xml::submitButton( wfMsg( 'import-interwiki-submit' ), array( 'accesskey' => 's' ) ) .
+                                       <td class='mw-submit'>" .
+                                               Xml::submitButton( $this->msg( 'import-interwiki-submit' )->text(), Linker::tooltipAndAccesskeyAttribs( 'import' ) ) .
                                        "</td>
                                </tr>" .
                                Xml::closeElement( 'table' ).
@@ -264,11 +347,18 @@ class SpecialImport extends SpecialPage {
  * Reporting callback
  * @ingroup SpecialPage
  */
-class ImportReporter {
-      private $reason=false;
+class ImportReporter extends ContextSource {
+       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' ) );
+               $importer->setNoticeCallback( array( $this, 'reportNotice' ) );
                $this->mPageCount = 0;
                $this->mIsUpload = $upload;
                $this->mInterwiki = $interwiki;
@@ -276,41 +366,60 @@ class ImportReporter {
        }
 
        function open() {
-               global $wgOut;
-               $wgOut->addHTML( "<ul>\n" );
+               $this->getOutput()->addHTML( "<ul>\n" );
        }
 
-       function reportPage( $title, $origTitle, $revisionCount, $successCount ) {
-               global $wgOut, $wgUser, $wgLang, $wgContLang;
+       function reportNotice( $msg, array $params ) {
+               $this->getOutput()->addHTML( Html::element( 'li', array(), $this->msg( $msg, $params )->text() ) );
+       }
 
-               $skin = $wgUser->getSkin();
+       function reportLogItem( /* ... */ ) {
+               $this->mLogItemCount++;
+               if ( is_callable( $this->mOriginalLogCallback ) ) {
+                       call_user_func_array( $this->mOriginalLogCallback, func_get_args() );
+               }
+       }
 
-               $this->mPageCount++;
+       /**
+        * @param Title $title
+        * @param Title $origTitle
+        * @param int $revisionCount
+        * @param  $successCount
+        * @param  $pageInfo
+        * @return void
+        */
+       function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo ) {
+               $args = func_get_args();
+               call_user_func_array( $this->mOriginalPageOutCallback, $args );
 
-               $localCount = $wgLang->formatNum( $successCount );
-               $contentCount = $wgContLang->formatNum( $successCount );
+               if ( $title === null ) {
+                       # Invalid or non-importable title; a notice is already displayed
+                       return;
+               }
+
+               $this->mPageCount++;
 
                if( $successCount > 0 ) {
-                       $wgOut->addHTML( "<li>" . $skin->makeKnownLinkObj( $title ) . " " .
-                               wfMsgExt( 'import-revision-count', array( 'parsemag', 'escape' ), $localCount ) .
+                       $this->getOutput()->addHTML( "<li>" . Linker::linkKnown( $title ) . " " .
+                               $this->msg( 'import-revision-count' )->numParams( $successCount )->escaped() .
                                "</li>\n"
                        );
 
                        $log = new LogPage( 'import' );
                        if( $this->mIsUpload ) {
-                               $detail = wfMsgExt( 'import-logentry-upload-detail', array( 'content', 'parsemag' ),
-                                       $contentCount );
+                               $detail = $this->msg( 'import-logentry-upload-detail' )->numParams(
+                                       $successCount )->inContentLanguage()->text();
                                if ( $this->reason ) {
-                                       $detail .=  wfMsgForContent( 'colon-separator' ) . $this->reason;
+                                       $detail .=  $this->msg( 'colon-separator' )->inContentLanguage()->text() . $this->reason;
                                }
                                $log->addEntry( 'upload', $title, $detail );
                        } else {
                                $interwiki = '[[:' . $this->mInterwiki . ':' .
                                        $origTitle->getPrefixedText() . ']]';
-                               $detail = wfMsgExt( 'import-logentry-interwiki-detail', array( 'content', 'parsemag' ),
-                                       $contentCount, $interwiki );
+                               $detail = $this->msg( 'import-logentry-interwiki-detail' )->numParams(
+                                       $successCount )->params( $interwiki )->inContentLanguage()->text();
                                if ( $this->reason ) {
-                                       $detail .=  wfMsgForContent( 'colon-separator' ) . $this->reason;
+                                       $detail .=  $this->msg( 'colon-separator' )->inContentLanguage()->text() . $this->reason;
                                }
                                $log->addEntry( 'interwiki', $title, $detail );
                        }
@@ -318,25 +427,31 @@ class ImportReporter {
                        $comment = $detail; // quick
                        $dbw = wfGetDB( DB_MASTER );
                        $latest = $title->getLatestRevID();
-                       $nullRevision = Revision::newNullRevision( $dbw, $title->getArticleId(), $comment, true );
-                       $nullRevision->insertOn( $dbw );
-                       $article = new Article( $title );
-                       # Update page record
-                       $article->updateRevisionOn( $dbw, $nullRevision );
-                       wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $wgUser) );
+                       $nullRevision = Revision::newNullRevision( $dbw, $title->getArticleID(), $comment, true );
+                       if (!is_null($nullRevision)) {
+                               $nullRevision->insertOn( $dbw );
+                               $page = WikiPage::factory( $title );
+                               # Update page record
+                               $page->updateRevisionOn( $dbw, $nullRevision );
+                               wfRunHooks( 'NewRevisionFromEditComplete', array( $page, $nullRevision, $latest, $this->getUser() ) );
+                       }
                } else {
-                       $wgOut->addHTML( '<li>' . wfMsgHtml( 'import-nonewrevisions' ) . '</li>' );
+                       $this->getOutput()->addHTML( "<li>" . Linker::linkKnown( $title ) . " " .
+                               $this->msg( 'import-nonewrevisions' )->escaped() . "</li>\n" );
                }
        }
 
        function close() {
-               global $wgOut;
-               if( $this->mPageCount == 0 ) {
-                       $wgOut->addHTML( "</ul>\n" );
-                       return new WikiErrorMsg( "importnopages" );
+               $out = $this->getOutput();
+               if ( $this->mLogItemCount > 0 ) {
+                       $msg = $this->msg( 'imported-log-entries' )->numParams( $this->mLogItemCount )->parse();
+                       $out->addHTML( Xml::tags( 'li', null, $msg ) );
+               } elseif( $this->mPageCount == 0 && $this->mLogItemCount == 0 ) {
+                       $out->addHTML( "</ul>\n" );
+                       return Status::newFatal( 'importnopages' );
                }
-               $wgOut->addHTML( "</ul>\n" );
+               $out->addHTML( "</ul>\n" );
 
-               return $this->mPageCount;
+               return Status::newGood( $this->mPageCount );
        }
 }