Converted ImportStreamSource functions to return a Status object rather than ImportSt...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sun, 5 Dec 2010 14:22:49 +0000 (14:22 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sun, 5 Dec 2010 14:22:49 +0000 (14:22 +0000)
This is a breaking change since the ImportStreamSource object is in the value member of the Status object; I will fix the extensions in my next commit

includes/Import.php
includes/api/ApiImport.php
includes/specials/SpecialImport.php

index 29c1e27..533d538 100644 (file)
@@ -414,27 +414,27 @@ class ImportStreamSource {
        static function newFromFile( $filename ) {
                $file = @fopen( $filename, 'rt' );
                if( !$file ) {
-                       return new WikiErrorMsg( "importcantopen" );
+                       return Status::newFatal( "importcantopen" );
                }
-               return new ImportStreamSource( $file );
+               return Status::newGood( new ImportStreamSource( $file ) );
        }
 
        static function newFromUpload( $fieldname = "xmlimport" ) {
                $upload =& $_FILES[$fieldname];
 
                if( !isset( $upload ) || !$upload['name'] ) {
-                       return new WikiErrorMsg( 'importnofile' );
+                       return Status::newFatal( 'importnofile' );
                }
                if( !empty( $upload['error'] ) ) {
                        switch($upload['error']){
                                case 1: # The uploaded file exceeds the upload_max_filesize directive in php.ini.
-                                       return new WikiErrorMsg( 'importuploaderrorsize' );
+                                       return Status::newFatal( 'importuploaderrorsize' );
                                case 2: # The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
-                                       return new WikiErrorMsg( 'importuploaderrorsize' );
+                                       return Status::newFatal( 'importuploaderrorsize' );
                                case 3: # The uploaded file was only partially uploaded
-                                       return new WikiErrorMsg( 'importuploaderrorpartial' );
+                                       return Status::newFatal( 'importuploaderrorpartial' );
                                case 6: #Missing a temporary folder.
-                                       return new WikiErrorMsg( 'importuploaderrortemp' );
+                                       return Status::newFatal( 'importuploaderrortemp' );
                                # case else: # Currently impossible
                        }
 
@@ -443,7 +443,7 @@ class ImportStreamSource {
                if( is_uploaded_file( $fname ) ) {
                        return ImportStreamSource::newFromFile( $fname );
                } else {
-                       return new WikiErrorMsg( 'importnofile' );
+                       return Status::newFatal( 'importnofile' );
                }
        }
 
@@ -459,19 +459,19 @@ class ImportStreamSource {
                        fwrite( $file, $data );
                        fflush( $file );
                        fseek( $file, 0 );
-                       return new ImportStreamSource( $file );
+                       return Status::newGood( new ImportStreamSource( $file ) );
                } else {
-                       return new WikiErrorMsg( 'importcantopen' );
+                       return Status::newFatal( 'importcantopen' );
                }
        }
 
        public static function newFromInterwiki( $interwiki, $page, $history = false, $templates = false, $pageLinkDepth = 0 ) {
                if( $page == '' ) {
-                       return new WikiErrorMsg( 'import-noarticle' );
+                       return Status::newFatal( 'import-noarticle' );
                }
                $link = Title::newFromText( "$interwiki:Special:Export/$page" );
                if( is_null( $link ) || $link->getInterwiki() == '' ) {
-                       return new WikiErrorMsg( 'importbadinterwiki' );
+                       return Status::newFatal( 'importbadinterwiki' );
                } else {
                        $params = array();
                        if ( $history ) $params['history'] = 1;
index d6bf328..7b3fe8e 100644 (file)
@@ -65,16 +65,11 @@ class ApiImport extends ApiBase {
                        }
                        $source = ImportStreamSource::newFromUpload( 'xml' );
                }
-               if ( $source instanceof WikiErrorMsg ) {
-                       $this->dieUsageMsg( array_merge(
-                               array( $source->getMessageKey() ),
-                               $source->getMessageArgs() ) );
-               } elseif ( WikiError::isError( $source ) ) {
-                       // This shouldn't happen
-                       $this->dieUsageMsg( array( 'import-unknownerror', $source->getMessage() ) );
+               if ( !$source->isOK() ) {
+                       $this->dieUsageMsg( $source->getErrorsArray() );
                }
 
-               $importer = new WikiImporter( $source );
+               $importer = new WikiImporter( $source->value );
                if ( isset( $params['namespace'] ) ) {
                        $importer->setTargetNamespace( $params['namespace'] );
                }
index 4f28744..a9001df 100644 (file)
@@ -81,7 +81,7 @@ class SpecialImport extends SpecialPage {
                $this->pageLinkDepth = $wgExportMaxLinkDepth == 0 ? 0 : $wgRequest->getIntOrNull( 'pagelink-depth' );
 
                if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'editToken' ) ) ) {
-                       $source = new WikiErrorMsg( 'import-token-mismatch' );
+                       $source = Status::newFatal( 'import-token-mismatch' );
                } elseif ( $sourceName == 'upload' ) {
                        $isUpload = true;
                        if( $wgUser->isAllowed( 'importupload' ) ) {
@@ -92,7 +92,7 @@ class SpecialImport extends SpecialPage {
                } elseif ( $sourceName == "interwiki" ) {
                        $this->interwiki = $wgRequest->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" );
@@ -105,15 +105,15 @@ class SpecialImport extends SpecialPage {
                                        $this->pageLinkDepth );
                        }
                } else {
-                       $source = new WikiErrorMsg( "importunknownsource" );
+                       $source = Status::newFatal( "importunknownsource" );
                }
 
-               if( WikiError::isError( $source ) ) {
-                       $wgOut->wrapWikiMsg( "<p class=\"error\">\n$1\n</p>", array( 'importfailed', $source->getMessage() ) );
+               if( !$source->isGood() ) {
+                       $wgOut->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 );
                        }