r77800 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77799‎ | r77800 | r77801 >
Date:14:22, 5 December 2010
Author:ialex
Status:ok (Comments)
Tags:
Comment:
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
Modified paths:
  • /trunk/phase3/includes/Import.php (modified) (history)
  • /trunk/phase3/includes/api/ApiImport.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialImport.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiImport.php
@@ -65,16 +65,11 @@
6666 }
6767 $source = ImportStreamSource::newFromUpload( 'xml' );
6868 }
69 - if ( $source instanceof WikiErrorMsg ) {
70 - $this->dieUsageMsg( array_merge(
71 - array( $source->getMessageKey() ),
72 - $source->getMessageArgs() ) );
73 - } elseif ( WikiError::isError( $source ) ) {
74 - // This shouldn't happen
75 - $this->dieUsageMsg( array( 'import-unknownerror', $source->getMessage() ) );
 69+ if ( !$source->isOK() ) {
 70+ $this->dieUsageMsg( $source->getErrorsArray() );
7671 }
7772
78 - $importer = new WikiImporter( $source );
 73+ $importer = new WikiImporter( $source->value );
7974 if ( isset( $params['namespace'] ) ) {
8075 $importer->setTargetNamespace( $params['namespace'] );
8176 }
Index: trunk/phase3/includes/specials/SpecialImport.php
@@ -81,7 +81,7 @@
8282 $this->pageLinkDepth = $wgExportMaxLinkDepth == 0 ? 0 : $wgRequest->getIntOrNull( 'pagelink-depth' );
8383
8484 if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'editToken' ) ) ) {
85 - $source = new WikiErrorMsg( 'import-token-mismatch' );
 85+ $source = Status::newFatal( 'import-token-mismatch' );
8686 } elseif ( $sourceName == 'upload' ) {
8787 $isUpload = true;
8888 if( $wgUser->isAllowed( 'importupload' ) ) {
@@ -92,7 +92,7 @@
9393 } elseif ( $sourceName == "interwiki" ) {
9494 $this->interwiki = $wgRequest->getVal( 'interwiki' );
9595 if ( !in_array( $this->interwiki, $wgImportSources ) ) {
96 - $source = new WikiErrorMsg( "import-invalid-interwiki" );
 96+ $source = Status::newFatal( "import-invalid-interwiki" );
9797 } else {
9898 $this->history = $wgRequest->getCheck( 'interwikiHistory' );
9999 $this->frompage = $wgRequest->getText( "frompage" );
@@ -105,15 +105,15 @@
106106 $this->pageLinkDepth );
107107 }
108108 } else {
109 - $source = new WikiErrorMsg( "importunknownsource" );
 109+ $source = Status::newFatal( "importunknownsource" );
110110 }
111111
112 - if( WikiError::isError( $source ) ) {
113 - $wgOut->wrapWikiMsg( "<p class=\"error\">\n$1\n</p>", array( 'importfailed', $source->getMessage() ) );
 112+ if( !$source->isGood() ) {
 113+ $wgOut->wrapWikiMsg( "<p class=\"error\">\n$1\n</p>", array( 'importfailed', $source->getWikiText() ) );
114114 } else {
115115 $wgOut->addWikiMsg( "importstart" );
116116
117 - $importer = new WikiImporter( $source );
 117+ $importer = new WikiImporter( $source->value );
118118 if( !is_null( $this->namespace ) ) {
119119 $importer->setTargetNamespace( $this->namespace );
120120 }
Index: trunk/phase3/includes/Import.php
@@ -414,27 +414,27 @@
415415 static function newFromFile( $filename ) {
416416 $file = @fopen( $filename, 'rt' );
417417 if( !$file ) {
418 - return new WikiErrorMsg( "importcantopen" );
 418+ return Status::newFatal( "importcantopen" );
419419 }
420 - return new ImportStreamSource( $file );
 420+ return Status::newGood( new ImportStreamSource( $file ) );
421421 }
422422
423423 static function newFromUpload( $fieldname = "xmlimport" ) {
424424 $upload =& $_FILES[$fieldname];
425425
426426 if( !isset( $upload ) || !$upload['name'] ) {
427 - return new WikiErrorMsg( 'importnofile' );
 427+ return Status::newFatal( 'importnofile' );
428428 }
429429 if( !empty( $upload['error'] ) ) {
430430 switch($upload['error']){
431431 case 1: # The uploaded file exceeds the upload_max_filesize directive in php.ini.
432 - return new WikiErrorMsg( 'importuploaderrorsize' );
 432+ return Status::newFatal( 'importuploaderrorsize' );
433433 case 2: # The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
434 - return new WikiErrorMsg( 'importuploaderrorsize' );
 434+ return Status::newFatal( 'importuploaderrorsize' );
435435 case 3: # The uploaded file was only partially uploaded
436 - return new WikiErrorMsg( 'importuploaderrorpartial' );
 436+ return Status::newFatal( 'importuploaderrorpartial' );
437437 case 6: #Missing a temporary folder.
438 - return new WikiErrorMsg( 'importuploaderrortemp' );
 438+ return Status::newFatal( 'importuploaderrortemp' );
439439 # case else: # Currently impossible
440440 }
441441
@@ -443,7 +443,7 @@
444444 if( is_uploaded_file( $fname ) ) {
445445 return ImportStreamSource::newFromFile( $fname );
446446 } else {
447 - return new WikiErrorMsg( 'importnofile' );
 447+ return Status::newFatal( 'importnofile' );
448448 }
449449 }
450450
@@ -459,19 +459,19 @@
460460 fwrite( $file, $data );
461461 fflush( $file );
462462 fseek( $file, 0 );
463 - return new ImportStreamSource( $file );
 463+ return Status::newGood( new ImportStreamSource( $file ) );
464464 } else {
465 - return new WikiErrorMsg( 'importcantopen' );
 465+ return Status::newFatal( 'importcantopen' );
466466 }
467467 }
468468
469469 public static function newFromInterwiki( $interwiki, $page, $history = false, $templates = false, $pageLinkDepth = 0 ) {
470470 if( $page == '' ) {
471 - return new WikiErrorMsg( 'import-noarticle' );
 471+ return Status::newFatal( 'import-noarticle' );
472472 }
473473 $link = Title::newFromText( "$interwiki:Special:Export/$page" );
474474 if( is_null( $link ) || $link->getInterwiki() == '' ) {
475 - return new WikiErrorMsg( 'importbadinterwiki' );
 475+ return Status::newFatal( 'importbadinterwiki' );
476476 } else {
477477 $params = array();
478478 if ( $history ) $params['history'] = 1;

Follow-up revisions

RevisionCommit summaryAuthorDate
r77801Follow-up r77800: fix extensions using static methods from ImportSourceStream...ialex14:31, 5 December 2010
r77870* (bug 23119) WikiError class and subclasses are now marked as deprecated...ialex10:09, 6 December 2010

Comments

#Comment by Werdna (talk | contribs)   00:32, 6 December 2010

Looks fine.

#Comment by QuestPC (talk | contribs)   06:26, 24 December 2010

With newer revisions of 1.18a I've begin to get the error in UploadSourceAdapter::stream_read() in ImportXMLReader.php at line 664: while ( !$leave && !$this->mSource->atEnd() &&

stating that atEnd() is not a member of mSource. Switched back to 1.16, everything is fine.

when using ImportStreamSource::newFromUpload('xml'); in my extension's API.

I wonder, whether that has a relationship to this change.

I can provide exact error case and investigate further, if that information is not enough (apache error_log is not locally available right now, but I can get it later).

#Comment by IAlex (talk | contribs)   10:03, 24 December 2010

As stated in the commit summary, ImportStreamSource::newFromUpload() now returns a Status object, with the ImportStreamSource object in the "value" member of the Status object instead of returning directly an ImportStreamSource object.

Status & tagging log