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 # Until we find a way to store data in sessions, set leaveMessage to
22 # true unconditionally
23 $this->params
['leaveMessage'] = true;
24 # Similar for ignorewarnings. This is not really a good fallback, but
25 # there is no easy way to get a wikitext formatted warning message to
27 $this->params
['ignoreWarnings'] = true;
29 # Initialize this object and the upload object
30 $this->upload
= new UploadFromUrl();
31 $this->upload
->initialize(
32 $this->title
->getText(),
36 $this->user
= User
::newFromName( $this->params
['userName'] );
39 $status = $this->upload
->fetchFile();
40 if ( !$status->isOk() ) {
41 $this->leaveMessage( $status );
46 $result = $this->upload
->verifyUpload();
47 if ( $result['status'] != UploadBase
::OK
) {
48 $status = $this->upload
->convertVerifyErrorToStatus( $result );
49 $this->leaveMessage( $status );
54 if ( !$this->params
['ignoreWarnings'] ) {
55 $warnings = $this->upload
->checkWarnings();
57 if ( $this->params
['leaveMessage'] ) {
58 $this->user
->leaveUserMessage(
59 wfMsg( 'upload-warning-subj' ),
60 wfMsg( 'upload-warning-msg',
61 $this->params
['sessionKey'],
62 $this->params
['url'] )
65 $this->storeResultInSession( 'Warning',
66 'warnings', $warnings );
69 // FIXME: stash in session
75 $status = $this->upload
->performUpload(
76 $this->params
['comment'],
77 $this->params
['pageText'],
78 $this->params
['watch'],
81 $this->leaveMessage( $status );
87 * Leave a message on the user talk page or in the session according to
88 * $params['leaveMessage'].
90 * @param $status Status
92 protected function leaveMessage( $status ) {
93 if ( $this->params
['leaveMessage'] ) {
94 if ( $status->isGood() ) {
95 $this->user
->leaveUserMessage( wfMsg( 'upload-success-subj' ),
96 wfMsg( 'upload-success-msg',
97 $this->upload
->getTitle()->getText(),
101 $this->user
->leaveUserMessage( wfMsg( 'upload-failure-subj' ),
102 wfMsg( 'upload-failure-msg',
103 $status->getWikiText(),
108 if ( $status->isOk() ) {
109 $this->storeResultInSession( 'Success',
110 'filename', $this->getLocalFile()->getName() );
112 $this->storeResultInSession( 'Failure',
113 'errors', $status->getErrorsArray() );
120 * Store a result in the session data
121 * THIS IS BROKEN. $_SESSION does not exist when using runJobs.php
123 * @param $result string The result (Success|Warning|Failure)
124 * @param $dataKey string The key of the extra data
125 * @param $dataKey mixed The extra data itself
127 protected function storeResultInSession( $result, $dataKey, $dataValue ) {
128 $session &= $_SESSION[UploadBase
::getSessionKeyname()][$this->params
['sessionKey']];
129 $session['result'] = $result;
130 $session[$dataKey] = $dataValue;