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
21 use MediaWiki\Status\Status
;
24 * Upload a file by URL, via the jobqueue.
27 class UploadFromUrlJob
extends Job
implements GenericParameterJob
{
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;
35 $this->cacheKey
= UploadFromUrl
::getCacheKey( $this->params
);
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
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'] ];
58 * getter for the upload
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'] );
71 * Get the parameters for job logging
73 * @param Status[] $status
76 public function logJobParams( $status ): array {
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(),