From e6bba17c9f9f5a637dff1cf551591ab416852188 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sun, 5 Dec 2010 14:22:49 +0000 Subject: [PATCH] Converted ImportStreamSource functions to return a Status object rather than ImportStreamSource-or-WikiError 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 | 24 ++++++++++++------------ includes/api/ApiImport.php | 11 +++-------- includes/specials/SpecialImport.php | 12 ++++++------ 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/includes/Import.php b/includes/Import.php index 29c1e27ac7..533d538192 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -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; diff --git a/includes/api/ApiImport.php b/includes/api/ApiImport.php index d6bf328f0e..7b3fe8e47a 100644 --- a/includes/api/ApiImport.php +++ b/includes/api/ApiImport.php @@ -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'] ); } diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index 4f28744676..a9001df1b1 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -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( "

\n$1\n

", array( 'importfailed', $source->getMessage() ) ); + if( !$source->isGood() ) { + $wgOut->wrapWikiMsg( "

\n$1\n

", 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 ); } -- 2.20.1