Update core usage of getLanguageName[s].
[lhc/web/wiklou.git] / includes / specials / SpecialImport.php
index 165e337..dea2bac 100644 (file)
@@ -60,10 +60,6 @@ class SpecialImport extends SpecialPage {
                        throw new PermissionsError( 'import' );
                }
 
-               if ( wfReadOnly() ) {
-                       throw new ReadOnlyError;
-               }
-
                # @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'
@@ -78,11 +74,12 @@ class SpecialImport extends SpecialPage {
                        )
                );
 
-               if( $errors ){
-                       $this->getOutput()->showPermissionsErrorPage( $errors );
-                       return;
+               if ( $errors ) {
+                       throw new PermissionsError( 'import', $errors );
                }
 
+               $this->checkReadOnly();
+
                $request = $this->getRequest();
                if ( $request->wasPosted() && $request->getVal( 'action' ) == 'submit' ) {
                        $this->doImport();
@@ -112,11 +109,11 @@ class SpecialImport extends SpecialPage {
                        if( $user->isAllowed( 'importupload' ) ) {
                                $source = ImportStreamSource::newFromUpload( "xmlimport" );
                        } else {
-                               return $this->getOutput()->permissionRequired( 'importupload' );
+                               throw new PermissionsError( 'importupload' );
                        }
                } elseif ( $sourceName == "interwiki" ) {
                        if( !$user->isAllowed( 'import' ) ){
-                               return $this->getOutput()->permissionRequired( 'import' );
+                               throw new PermissionsError( 'import' );
                        }
                        $this->interwiki = $request->getVal( 'interwiki' );
                        if ( !in_array( $this->interwiki, $wgImportSources ) ) {
@@ -182,7 +179,7 @@ class SpecialImport extends SpecialPage {
                if( $user->isAllowed( 'importupload' ) ) {
                        $out->addWikiMsg( "importtext" );
                        $out->addHTML(
-                               Xml::fieldset( wfMsg( 'import-upload' ) ).
+                               Xml::fieldset( $this->msg( 'import-upload' )->text() ).
                                Xml::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post',
                                        'action' => $action, 'id' => 'mw-import-upload-form' ) ) .
                                Html::hidden( 'action', 'submit' ) .
@@ -191,7 +188,7 @@ class SpecialImport extends SpecialPage {
 
                                "<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' ) ) . ' ' .
@@ -199,7 +196,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, '',
@@ -209,11 +206,11 @@ class SpecialImport extends SpecialPage {
                                <tr>
                                        <td></td>
                                        <td class='mw-submit'>" .
-                                               Xml::submitButton( wfMsg( 'uploadbtn' ) ) .
+                                               Xml::submitButton( $this->msg( 'uploadbtn' )->text() ) .
                                        "</td>
                                </tr>" .
                                Xml::closeElement( 'table' ).
-                               Html::hidden( 'editToken', $user->editToken() ) .
+                               Html::hidden( 'editToken', $user->getEditToken() ) .
                                Xml::closeElement( 'form' ) .
                                Xml::closeElement( 'fieldset' )
                        );
@@ -229,7 +226,7 @@ class SpecialImport extends SpecialPage {
                        if( $wgExportMaxLinkDepth > 0 ) {
                                $importDepth = "<tr>
                                                        <td class='mw-label'>" .
-                                                               wfMsgExt( 'export-pagelinks', 'parseinline' ) .
+                                                               $this->msg( 'export-pagelinks' )->parse() .
                                                        "</td>
                                                        <td class='mw-input'>" .
                                                                Xml::input( 'pagelink-depth', 3, 0 ) .
@@ -238,16 +235,16 @@ class SpecialImport extends SpecialPage {
                        }
 
                        $out->addHTML(
-                               Xml::fieldset(  wfMsg( 'importinterwiki' ) ) .
+                               Xml::fieldset( $this->msg( 'importinterwiki' )->text() ) .
                                Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'mw-import-interwiki-form' ) ) .
-                               wfMsgExt( 'import-interwiki-text', array( 'parse' ) ) .
+                               $this->msg( 'import-interwiki-text' )->parseAsBlock() .
                                Html::hidden( 'action', 'submit' ) .
                                Html::hidden( 'source', 'interwiki' ) .
-                               Html::hidden( 'editToken', $user->editToken() ) .
+                               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' ) )
@@ -266,20 +263,20 @@ 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 class='mw-label'>" .
-                                               Xml::label( wfMsg( 'import-interwiki-namespace' ), 'namespace' ) .
+                                               Xml::label( $this->msg( 'import-interwiki-namespace' )->text(), 'namespace' ) .
                                        "</td>
                                        <td class='mw-input'>" .
                                                Xml::namespaceSelector( $this->namespace, '' ) .
@@ -287,7 +284,7 @@ class SpecialImport extends SpecialPage {
                                </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, '',
@@ -298,7 +295,7 @@ class SpecialImport extends SpecialPage {
                                        <td>
                                        </td>
                                        <td class='mw-submit'>" .
-                                               Xml::submitButton( wfMsg( 'import-interwiki-submit' ), Linker::tooltipAndAccesskeyAttribs( 'import' ) ) .
+                                               Xml::submitButton( $this->msg( 'import-interwiki-submit' )->text(), Linker::tooltipAndAccesskeyAttribs( 'import' ) ) .
                                        "</td>
                                </tr>" .
                                Xml::closeElement( 'table' ).
@@ -324,6 +321,7 @@ class ImportReporter extends ContextSource {
                                $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;
@@ -334,6 +332,10 @@ class ImportReporter extends ContextSource {
                $this->getOutput()->addHTML( "<ul>\n" );
        }
 
+       function reportNotice( $msg, array $params ) {
+               $this->getOutput()->addHTML( Html::element( 'li', array(), $this->msg( $msg, $params )->text() ) );
+       }
+
        function reportLogItem( /* ... */ ) {
                $this->mLogItemCount++;
                if ( is_callable( $this->mOriginalLogCallback ) ) {
@@ -350,37 +352,37 @@ class ImportReporter extends ContextSource {
         * @return void
         */
        function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo ) {
-               global $wgContLang;
-
                $args = func_get_args();
                call_user_func_array( $this->mOriginalPageOutCallback, $args );
 
-               $this->mPageCount++;
+               if ( $title === null ) {
+                       # Invalid or non-importable title; a notice is already displayed
+                       return;
+               }
 
-               $localCount = $this->getLang()->formatNum( $successCount );
-               $contentCount = $wgContLang->formatNum( $successCount );
+               $this->mPageCount++;
 
                if( $successCount > 0 ) {
                        $this->getOutput()->addHTML( "<li>" . Linker::linkKnown( $title ) . " " .
-                               wfMsgExt( 'import-revision-count', array( 'parsemag', 'escape' ), $localCount ) .
+                               $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 );
                        }
@@ -391,22 +393,21 @@ class ImportReporter extends ContextSource {
                        $nullRevision = Revision::newNullRevision( $dbw, $title->getArticleId(), $comment, true );
                        if (!is_null($nullRevision)) {
                                $nullRevision->insertOn( $dbw );
-                               $article = new Article( $title );
+                               $page = WikiPage::factory( $title );
                                # Update page record
-                               $article->updateRevisionOn( $dbw, $nullRevision );
-                               wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $this->getUser() ) );
+                               $page->updateRevisionOn( $dbw, $nullRevision );
+                               wfRunHooks( 'NewRevisionFromEditComplete', array( $page, $nullRevision, $latest, $this->getUser() ) );
                        }
                } else {
                        $this->getOutput()->addHTML( "<li>" . Linker::linkKnown( $title ) . " " .
-                               wfMsgHtml( 'import-nonewrevisions' ) . "</li>\n" );
+                               $this->msg( 'import-nonewrevisions' )->escaped() . "</li>\n" );
                }
        }
 
        function close() {
                $out = $this->getOutput();
                if ( $this->mLogItemCount > 0 ) {
-                       $msg = wfMsgExt( 'imported-log-entries', 'parseinline',
-                                               $this->getLang()->formatNum( $this->mLogItemCount ) );
+                       $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" );