24 use Wikimedia\ScopedCallback;
35 $this->removeDuplicates =
true;
38 public function run() {
41 ScopedCallback::consume( $scope );
45 $user = $context->getUser();
47 if ( !$user->isRegistered() ) {
48 $this->
setLastError(
"Could not load the author user from session." );
55 $this->params[
'filekey'],
56 [
'result' =>
'Poll',
'stage' =>
'publish',
'status' =>
Status::newGood() ]
64 $upload->initialize( $this->params[
'filekey'], $this->params[
'filename'] );
67 $verification = $upload->verifyUpload();
70 $status->value = [
'verification' => $verification ];
73 $this->params[
'filekey'],
74 [
'result' =>
'Failure',
'stage' =>
'publish',
'status' => $status ]
82 $status = $upload->performUpload(
83 $this->params[
'comment'],
84 $this->params[
'text'],
85 $this->params[
'watch'],
87 $this->params[
'tags'] ?? [],
88 $this->params[
'watchlistexpiry'] ??
null
90 if ( !$status->isGood() ) {
93 $this->params[
'filekey'],
94 [
'result' =>
'Failure',
'stage' =>
'publish',
'status' => $status ]
96 $this->
setLastError( $status->getWikiText(
false,
false,
'en' ) );
103 $imageInfo = $upload->getImageInfo( $apiMain->getResult() );
106 $upload->cleanupTempFile();
111 $this->params[
'filekey'],
113 'result' =>
'Success',
114 'stage' =>
'publish',
115 'filename' => $upload->getLocalFile()->getName(),
116 'imageinfo' => $imageInfo,
120 }
catch ( Exception $e ) {
123 $this->params[
'filekey'],
125 'result' =>
'Failure',
126 'stage' =>
'publish',
130 $this->
setLastError( get_class( $e ) .
": " . $e->getMessage() );
142 $info = parent::getDeduplicationInfo();
143 if ( is_array( $info[
'params'] ) ) {
144 $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 an 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.
Represents a title within MediaWiki.
static setSessionStatus(UserIdentity $user, $statusKey, $value)
Set the current status of a chunked upload (used for polling)
Implements uploading from previously stored file.