22 use Wikimedia\ScopedCallback;
33 $this->removeDuplicates =
true;
36 public function run() {
39 ScopedCallback::consume( $scope );
43 $user = $context->getUser();
45 if ( !$user->isRegistered() ) {
46 $this->
setLastError(
"Could not load the author user from session." );
53 $this->params[
'filekey'],
54 [
'result' =>
'Poll',
'stage' =>
'publish',
'status' =>
Status::newGood() ]
62 $upload->initialize( $this->params[
'filekey'], $this->params[
'filename'] );
65 $verification = $upload->verifyUpload();
68 $status->value = [
'verification' => $verification ];
71 $this->params[
'filekey'],
72 [
'result' =>
'Failure',
'stage' =>
'publish',
'status' => $status ]
80 $status = $upload->performUpload(
81 $this->params[
'comment'],
82 $this->params[
'text'],
83 $this->params[
'watch'],
85 $this->params[
'tags'] ?? [],
86 $this->params[
'watchlistexpiry'] ??
null
88 if ( !$status->isGood() ) {
91 $this->params[
'filekey'],
92 [
'result' =>
'Failure',
'stage' =>
'publish',
'status' => $status ]
94 $this->
setLastError( $status->getWikiText(
false,
false,
'en' ) );
101 $imageInfo = $upload->getImageInfo( $apiMain->getResult() );
104 $upload->cleanupTempFile();
109 $this->params[
'filekey'],
111 'result' =>
'Success',
112 'stage' =>
'publish',
113 'filename' => $upload->getLocalFile()->getName(),
114 'imageinfo' => $imageInfo,
118 }
catch ( Exception $e ) {
121 $this->params[
'filekey'],
123 'result' =>
'Failure',
124 'stage' =>
'publish',
128 $this->
setLastError( get_class( $e ) .
": " . $e->getMessage() );
140 $info = parent::getDeduplicationInfo();
141 if ( is_array( $info[
'params'] ) ) {
142 $info[
'params'] = [
'filekey' => $info[
'params'][
'filekey'] ];
This is the main API class, used for both external and internal processing.
Class to both describe a background job and handle jobs.
addTeardownCallback( $callback)
array $params
Array of job parameters.
static rollbackPrimaryChangesAndLog(Throwable $e, $catcher=self::CAUGHT_BY_OTHER)
Roll back any open database transactions and log the stack trace of the throwable.
Upload a file from the upload stash into the local file repo.
allowRetries()
bool Whether this job can be retried on failure by job runners 1.21Stability: stableto override
getDeduplicationInfo()
Subclasses may need to override this to make duplication detection work.
__construct(Title $title, array $params)
static importScopedSession(array $params)
Import a client IP address, HTTP headers, user ID, and session ID.
static getMain()
Get the RequestContext object associated with the main request.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
static newGood( $value=null)
Factory function for good results.
static setSessionStatus(UserIdentity $user, $statusKey, $value)
Set the current status of a chunked upload (used for polling)
Implements uploading from previously stored file.