Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / jobqueue / jobs / UploadFromUrlJob.php
blob1e936e375a153d4ae90fda2b31117305d60c99ce
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
21 use MediaWiki\Status\Status;
23 /**
24 * Upload a file by URL, via the jobqueue.
27 class UploadFromUrlJob extends Job implements GenericParameterJob {
28 use UploadJobTrait;
30 public function __construct( array $params ) {
31 // @TODO: fix the invokation of Job::__construct in the parent class
32 parent::__construct( 'UploadFromUrl', $params );
33 $this->removeDuplicates = true;
34 $this->user = null;
35 $this->cacheKey = UploadFromUrl::getCacheKey( $this->params );
38 /**
39 * Deduplicate on title, url alone.
41 * Please note that this could cause some
42 * edge case failure, when the image at the
43 * same remote url is changed before the first upload
44 * is ran.
46 * @return array
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'] ];
54 return $info;
57 /**
58 * getter for the upload
60 * @return UploadBase
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'] );
67 return $this->upload;
70 /**
71 * Get the parameters for job logging
73 * @param Status[] $status
74 * @return array
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(),