4 * Job for asynchronous upload-by-url.
6 * This job is in fact an interface to UploadFromUrl, which is designed such
7 * that it does not require any globals. If it does, fix it elsewhere, do not
12 class UploadFromUrlJob
extends Job
{
16 public function __construct( $title, $params, $id = 0 ) {
17 parent
::__construct( 'uploadFromUrl', $title, $params, $id );
20 public function run() {
21 # Initialize this object and the upload object
22 $this->upload
= new UploadFromUrl();
23 $this->upload
->initialize(
24 $this->title
->getText(),
28 $this->user
= User
::newFromName( $this->params
['userName'] );
31 $status = $this->upload
->fetchFile();
32 if ( !$status->isOk() ) {
33 $this->leaveMessage( $status );
38 $result = $this->upload
->verifyUpload();
39 if ( $result['status'] != UploadBase
::OK
) {
40 $status = $this->upload
->convertVerifyErrorToStatus( $result );
41 $this->leaveMessage( $status );
46 if ( !$this->params
['ignoreWarnings'] ) {
47 $warnings = $this->upload
->checkWarnings();
49 if ( $this->params
['leaveMessage'] ) {
50 $this->user
->leaveUserMessage(
51 wfMsg( 'upload-warning-subj' ),
52 wfMsg( 'upload-warning-msg',
53 $this->params
['sessionKey'],
54 $this->params
['url'] )
57 $this->storeResultInSession( 'Warning',
58 'warnings', $warnings );
61 // FIXME: stash in session
67 $status = $this->upload
->performUpload(
68 $this->params
['comment'],
69 $this->params
['pageText'],
70 $this->params
['watch'],
73 $this->leaveMessage( $status );
77 * Leave a message on the user talk page or in the session according to
78 * $params['leaveMessage'].
80 * @param $status Status
82 protected function leaveMessage( $status ) {
83 if ( $this->params
['leaveMessage'] ) {
84 if ( $status->isGood() ) {
85 $this->user
->leaveUserMessage( wfMsg( 'upload-success-subj' ),
86 wfMsg( 'upload-success-msg',
87 $this->upload
->getTitle()->getText(),
91 $this->user
->leaveUserMessage( wfMsg( 'upload-failure-subj' ),
92 wfMsg( 'upload-failure-msg',
93 $status->getWikiText(),
98 if ( $status->isOk() ) {
99 $this->storeResultInSession( 'Success',
100 'filename', $this->getLocalFile()->getName() );
102 $this->storeResultInSession( 'Failure',
103 'errors', $status->getErrorsArray() );
110 * Store a result in the session data
111 * THIS IS BROKEN. $_SESSION does not exist when using runJobs.php
113 * @param $result string The result (Success|Warning|Failure)
114 * @param $dataKey string The key of the extra data
115 * @param $dataKey mixed The extra data itself
117 protected function storeResultInSession( $result, $dataKey, $dataValue ) {
118 $session &= $_SESSION[UploadBase
::getSessionKeyname()][$this->params
['sessionKey']];
119 $session['result'] = $result;
120 $session[$dataKey] = $dataValue;