| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\Status\Status; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
class UploadFromUrlJob extends Job implements GenericParameterJob { |
| 28 |
use UploadJobTrait; |
| 29 |
|
| 30 |
public function __construct( array $params ) { |
| 31 |
|
| 32 |
parent::__construct( 'UploadFromUrl', $params ); |
| 33 |
$this->removeDuplicates = true; |
| 34 |
$this->user = null; |
| 35 |
$this->cacheKey = UploadFromUrl::getCacheKey( $this->params ); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public function getDeduplicationInfo() { |
| 49 |
$info = parent::getDeduplicationInfo(); |
| 50 |
if ( is_array( $info['params'] ) ) { |
| 51 |
$info['params'] = [ 'url' => $info['params']['url'], 'title' => $info['params']['filename'] ]; |
| 52 |
} |
| 53 |
|
| 54 |
return $info; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
protected function getUpload(): UploadBase { |
| 63 |
if ( $this->upload === null ) { |
| 64 |
$this->upload = new UploadFromUrl; |
| 65 |
$this->upload->initialize( $this->params['filename'], $this->params['url'] ); |
| 66 |
} |
| 67 |
return $this->upload; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public function logJobParams( $status ): array { |
| 77 |
return [ |
| 78 |
'stage' => $status['stage'] ?? '-', |
| 79 |
'result' => $status['result'] ?? '-', |
| 80 |
'status' => (string)( $status['status'] ?? '-' ), |
| 81 |
'url' => $this->params['url'], |
| 82 |
'filename' => $this->params['filename'], |
| 83 |
'user' => $this->user->getName(), |
| 84 |
]; |
| 85 |
} |
| 86 |
|
| 87 |
} |