9b297db1d90fd75614a71bdc4e8838c2916eaa98
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
{
14 public function __construct( $title, $params, $id = 0 ) {
15 parent
::__construct( 'uploadFromUrl', $title, $params, $id );
18 public function run() {
19 # Initialize this object and the upload object
20 $upload = new UploadFromUrl();
22 $this->title
->getText(),
26 $this->user
= User
::newFromName( $this->params
['userName'] );
29 $status = $upload->fetchFile();
30 if ( !$status->isOk() ) {
31 $this->leaveMessage( $status );
36 if ( !$this->params
['ignoreWarnings'] ) {
37 $warnings = $this->checkWarnings();
39 if ( $this->params
['leaveMessage'] ) {
40 $this->user
->leaveUserMessage(
41 wfMsg( 'upload-warning-subj' ),
42 wfMsg( 'upload-warning-msg', $this->params
['sessionKey'] )
45 $this->storeResultInSession( 'Warning',
46 'warnings', $warnings );
53 $status = $upload->performUpload(
54 $this->params
['comment'],
55 $this->params
['pageText'],
56 $this->params
['watch']
58 $this->leaveMessage( $status );
62 * Leave a message on the user talk page or in the session according to
63 * $params['leaveMessage'].
65 * @param $status Status
67 protected function leaveMessage( $status ) {
68 if ( $this->params
['leaveMessage'] ) {
69 if ( $status->isGood() ) {
70 $file = $this->getLocalFile();
72 $this->user
->leaveUserMessage( wfMsg( 'successfulupload' ),
73 wfMsg( 'upload-success-msg', $file->getDescriptionUrl() ) );
75 $this->user
->leaveUserMessage( wfMsg( 'upload-failure-subj' ),
76 wfMsg( 'upload-failure-msg', $status->getWikiText() ) );
79 if ( $status->isOk() ) {
80 $this->storeResultInSession( 'Success',
81 'filename', $this->getLocalFile()->getName() );
83 $this->storeResultInSession( 'Failure',
84 'errors', $status->getErrorsArray() );
91 * Store a result in the session data
93 * @param $result string The result (Success|Warning|Failure)
94 * @param $dataKey string The key of the extra data
95 * @param $dataKey mixed The extra data itself
97 protected function storeResultInSession( $result, $dataKey, $dataValue ) {
98 $session &= $_SESSION[UploadBase
::getSessionKeyname()][$this->params
['sessionKey']];
99 $session['result'] = $result;
100 $session[$dataKey] = $dataValue;