MediaWiki
REL1_21
|
00001 <?php 00029 class PublishStashedFileJob extends Job { 00030 public function __construct( $title, $params, $id = 0 ) { 00031 parent::__construct( 'PublishStashedFile', $title, $params, $id ); 00032 $this->removeDuplicates = true; 00033 } 00034 00035 public function run() { 00036 $scope = RequestContext::importScopedSession( $this->params['session'] ); 00037 $context = RequestContext::getMain(); 00038 try { 00039 $user = $context->getUser(); 00040 if ( !$user->isLoggedIn() ) { 00041 $this->setLastError( "Could not load the author user from session." ); 00042 return false; 00043 } 00044 00045 UploadBase::setSessionStatus( 00046 $this->params['filekey'], 00047 array( 'result' => 'Poll', 'stage' => 'publish', 'status' => Status::newGood() ) 00048 ); 00049 00050 $upload = new UploadFromStash( $user ); 00051 // @TODO: initialize() causes a GET, ideally we could frontload the antivirus 00052 // checks and anything else to the stash stage (which includes concatenation and 00053 // the local file is thus already there). That way, instead of GET+PUT, there could 00054 // just be a COPY operation from the stash to the public zone. 00055 $upload->initialize( $this->params['filekey'], $this->params['filename'] ); 00056 00057 // Check if the local file checks out (this is generally a no-op) 00058 $verification = $upload->verifyUpload(); 00059 if ( $verification['status'] !== UploadBase::OK ) { 00060 $status = Status::newFatal( 'verification-error' ); 00061 $status->value = array( 'verification' => $verification ); 00062 UploadBase::setSessionStatus( 00063 $this->params['filekey'], 00064 array( 'result' => 'Failure', 'stage' => 'publish', 'status' => $status ) 00065 ); 00066 $this->setLastError( "Could not verify upload." ); 00067 return false; 00068 } 00069 00070 // Upload the stashed file to a permanent location 00071 $status = $upload->performUpload( 00072 $this->params['comment'], 00073 $this->params['text'], 00074 $this->params['watch'], 00075 $user 00076 ); 00077 if ( !$status->isGood() ) { 00078 UploadBase::setSessionStatus( 00079 $this->params['filekey'], 00080 array( 'result' => 'Failure', 'stage' => 'publish', 'status' => $status ) 00081 ); 00082 $this->setLastError( $status->getWikiText() ); 00083 return false; 00084 } 00085 00086 // Build the image info array while we have the local reference handy 00087 $apiMain = new ApiMain(); // dummy object (XXX) 00088 $imageInfo = $upload->getImageInfo( $apiMain->getResult() ); 00089 00090 // Cleanup any temporary local file 00091 $upload->cleanupTempFile(); 00092 00093 // Cache the info so the user doesn't have to wait forever to get the final info 00094 UploadBase::setSessionStatus( 00095 $this->params['filekey'], 00096 array( 00097 'result' => 'Success', 00098 'stage' => 'publish', 00099 'filename' => $upload->getLocalFile()->getName(), 00100 'imageinfo' => $imageInfo, 00101 'status' => Status::newGood() 00102 ) 00103 ); 00104 } catch ( MWException $e ) { 00105 UploadBase::setSessionStatus( 00106 $this->params['filekey'], 00107 array( 00108 'result' => 'Failure', 00109 'stage' => 'publish', 00110 'status' => Status::newFatal( 'api-error-publishfailed' ) 00111 ) 00112 ); 00113 $this->setLastError( get_class( $e ) . ": " . $e->getText() ); 00114 return false; 00115 } 00116 return true; 00117 } 00118 00119 public function getDeduplicationInfo() { 00120 $info = parent::getDeduplicationInfo(); 00121 if ( is_array( $info['params'] ) ) { 00122 $info['params'] = array( 'filekey' => $info['params']['filekey'] ); 00123 } 00124 return $info; 00125 } 00126 00127 public function allowRetries() { 00128 return false; 00129 } 00130 }