23 use Wikimedia\ScopedCallback;
34 $this->removeDuplicates =
true;
37 public function run() {
40 ScopedCallback::consume( $scope );
44 $user = $context->getUser();
46 if ( !$user->isRegistered() ) {
47 $this->
setLastError(
"Could not load the author user from session." );
54 $this->params[
'filekey'],
55 [
'result' =>
'Poll',
'stage' =>
'publish',
'status' => Status::newGood() ]
63 $upload->initialize( $this->params[
'filekey'], $this->params[
'filename'] );
66 $verification = $upload->verifyUpload();
68 $status = Status::newFatal(
'verification-error' );
69 $status->value = [
'verification' => $verification ];
72 $this->params[
'filekey'],
73 [
'result' =>
'Failure',
'stage' =>
'publish',
'status' => $status ]
81 $status = $upload->performUpload(
82 $this->params[
'comment'],
83 $this->params[
'text'],
84 $this->params[
'watch'],
86 $this->params[
'tags'] ?? [],
87 $this->params[
'watchlistexpiry'] ??
null
89 if ( !$status->isGood() ) {
92 $this->params[
'filekey'],
93 [
'result' =>
'Failure',
'stage' =>
'publish',
'status' => $status ]
95 $this->
setLastError( $status->getWikiText(
false,
false,
'en' ) );
102 $imageInfo = $upload->getImageInfo( $apiMain->getResult() );
105 $upload->cleanupTempFile();
110 $this->params[
'filekey'],
112 'result' =>
'Success',
113 'stage' =>
'publish',
114 'filename' => $upload->getLocalFile()->getName(),
115 'imageinfo' => $imageInfo,
116 'status' => Status::newGood()
119 }
catch ( Exception $e ) {
122 $this->params[
'filekey'],
124 'result' =>
'Failure',
125 'stage' =>
'publish',
126 'status' => Status::newFatal(
'api-error-publishfailed' )
129 $this->
setLastError( get_class( $e ) .
": " . $e->getMessage() );
141 $info = parent::getDeduplicationInfo();
142 if ( is_array( $info[
'params'] ) ) {
143 $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 setSessionStatus(UserIdentity $user, $statusKey, $value)
Set the current status of a chunked upload (used for polling).
Implements uploading from previously stored file.