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
}
if( is_uploaded_file( $fname ) ) {
return ImportStreamSource::newFromFile( $fname );
} else {
- return new WikiErrorMsg( 'importnofile' );
+ return Status::newFatal( 'importnofile' );
}
}
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;
}
$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'] );
}
$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' ) ) {
} 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" );
$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 );
}