50use Psr\Log\LoggerInterface;
52use Wikimedia\Message\MessageSpecifier;
53use Wikimedia\ParamValidator\ParamValidator;
54use Wikimedia\ParamValidator\TypeDef\IntegerDef;
55use Wikimedia\Timestamp\TimestampFormat as TS;
72 private LoggerInterface $log;
83 parent::__construct( $mainModule, $moduleName );
88 $this->watchlistMaxDuration =
90 $this->watchlistManager = $watchlistManager;
91 $this->watchedItemStore = $watchedItemStore;
92 $this->userOptionsLookup = $userOptionsLookup;
93 $this->log = LoggerFactory::getInstance(
'upload' );
98 if ( !UploadBase::isEnabled() ) {
108 $this->mParams[
'async'] = $this->mParams[
'async'] &&
113 if ( !$this->mParams[
'filekey'] && $this->mParams[
'sessionkey'] ) {
114 $this->mParams[
'filekey'] = $this->mParams[
'sessionkey'];
120 if ( $this->mParams[
'stash'] && $this->mParams[
'text'] !==
null ) {
121 $this->
addWarning(
'apiwarn-upload-textwithstash' );
126 if ( $this->mParams[
'stash'] && $this->mParams[
'autotext'] ) {
127 $this->
addWarning(
'apiwarn-upload-autotextwithstash' );
130 if ( !$this->mParams[
'checkstatus'] ) {
139 } elseif ( !$this->mUpload ) {
153 if ( $this->mParams[
'async'] && $this->mParams[
'url'] ) {
154 $status = $this->mUpload->canFetchFile();
156 $status = $this->mUpload->fetchFile();
159 if ( !$status->isGood() ) {
160 $this->log->info(
"Unable to fetch file {filename} for {user} because {status}",
162 'user' => $this->
getUser()->getName(),
163 'status' => (
string)$status,
164 'filename' => $this->mParams[
'filename'] ??
'-',
176 if ( !$this->mParams[
'stash'] ) {
177 $status = $this->mUpload->authorizeUpload( $user );
178 if ( !$status->isGood() ) {
179 $this->dieRecoverableError( $status->getMessages(),
'filename' );
185 $result = $this->getContextResult();
194 if ( $result[
'result'] ===
'Success' ) {
200 $this->mUpload->cleanupTempFile();
214 $services->getJobQueueGroup(),
215 $services->getWatchlistManager(),
216 $services->getWatchedItemStore(),
217 $services->getUserOptionsLookup(),
218 $services->getRepoGroup(),
235 $stashFile = $upload->getStashFile();
237 $info = $this->getUploadImageInfoInternal( $stashFile,
true );
240 $info = $this->getUploadImageInfoInternal( $localFile,
false );
246 private function getUploadImageInfoInternal( File $file,
bool $stashedImageInfos ): array {
247 $result = $this->getResult();
273 if ( $stashedImageInfos ) {
275 $info = ApiQueryStashImageInfo::getInfo(
277 array_fill_keys( $imParam,
true ),
290 $info = ApiQueryImageInfo::getInfo(
292 array_fill_keys( $imParam,
true ),
304 private function getContextResult() {
305 $warnings = $this->getApiWarnings();
306 if ( $warnings && !$this->mParams[
'ignorewarnings'] ) {
308 return $this->getWarningsResult( $warnings );
309 } elseif ( $this->mParams[
'chunk'] ) {
311 return $this->getChunkResult( $warnings );
312 } elseif ( $this->mParams[
'stash'] ) {
314 return $this->getStashResult( $warnings );
319 return $this->performUpload( $warnings );
327 private function getStashResult( $warnings ) {
328 $result = [
'result' =>
'Success' ];
329 if ( $warnings && count( $warnings ) > 0 ) {
330 $result[
'warnings'] = $warnings;
334 $this->performStash(
'critical', $result );
344 private function getWarningsResult( $warnings ) {
346 'result' =>
'Warning',
347 'warnings' => $warnings,
352 $this->performStash(
'optional', $result );
369 ini_get(
'post_max_size' ),
378 UploadBase::getMaxUploadSize(
'file' ),
379 UploadBase::getMaxPhpUploadSize(),
389 private function getChunkResult( $warnings ) {
392 if ( $warnings && count( $warnings ) > 0 ) {
393 $result[
'warnings'] = $warnings;
396 $chunkUpload = $this->getMain()->getUpload(
'chunk' );
397 $chunkPath = $chunkUpload->getTempName();
398 $chunkSize = $chunkUpload->getSize();
399 $totalSoFar = $this->mParams[
'offset'] + $chunkSize;
400 $minChunkSize = self::getMinUploadChunkSize( $this->getConfig() );
403 if ( $totalSoFar > $this->mParams[
'filesize'] ) {
404 $this->dieWithError(
'apierror-invalid-chunk' );
408 if ( $totalSoFar != $this->mParams[
'filesize'] && $chunkSize < $minChunkSize ) {
409 $this->dieWithError( [
'apierror-chunk-too-small', Message::numParam( $minChunkSize ) ] );
412 if ( $this->mParams[
'offset'] == 0 ) {
413 $this->log->debug(
"Started first chunk of chunked upload of {filename} for {user}",
416 'filename' => $this->mParams[
'filename'] ??
'-',
417 'filesize' => $this->mParams[
'filesize'],
418 'chunkSize' => $chunkSize
421 $filekey = $this->performStash(
'critical' );
423 $filekey = $this->mParams[
'filekey'];
426 $progress = UploadBase::getSessionStatus( $this->
getUser(), $filekey );
429 $this->log->info(
"Stash failed due to no session for {user}",
432 'filename' => $this->mParams[
'filename'] ??
'-',
433 'filekey' => $this->mParams[
'filekey'] ??
'-',
434 'filesize' => $this->mParams[
'filesize'],
435 'chunkSize' => $chunkSize
438 $this->dieWithError(
'apierror-stashfailed-nosession',
'stashfailed' );
439 } elseif ( $progress[
'result'] !==
'Continue' || $progress[
'stage'] !==
'uploading' ) {
440 $this->dieWithError(
'apierror-stashfailed-complete',
'stashfailed' );
443 $status = $this->mUpload->addChunk(
444 $chunkPath, $chunkSize, $this->mParams[
'offset'] );
445 if ( !$status->isGood() ) {
447 'offset' => $this->mUpload->getOffset(),
449 $this->log->info(
"Chunked upload stash failure {status} for {user}",
451 'status' => (
string)$status,
453 'filename' => $this->mParams[
'filename'] ??
'-',
454 'filekey' => $this->mParams[
'filekey'] ??
'-',
455 'filesize' => $this->mParams[
'filesize'],
456 'chunkSize' => $chunkSize,
457 'offset' => $this->mUpload->getOffset()
460 $this->dieStatusWithCode( $status,
'stashfailed', $extradata );
462 $this->log->debug(
"Got chunk for {filename} with offset {offset} for {user}",
465 'filename' => $this->mParams[
'filename'] ??
'-',
466 'filekey' => $this->mParams[
'filekey'] ??
'-',
467 'filesize' => $this->mParams[
'filesize'],
468 'chunkSize' => $chunkSize,
469 'offset' => $this->mUpload->getOffset()
476 if ( $totalSoFar == $this->mParams[
'filesize'] ) {
477 if ( $this->mParams[
'async'] ) {
478 UploadBase::setSessionStatus(
481 [
'result' =>
'Poll',
482 'stage' =>
'queued',
'status' => Status::newGood() ]
488 $this->jobQueueGroup->lazyPush(
new AssembleUploadChunksJob( [
489 'filename' => $this->mParams[
'filename'],
490 'filekey' => $filekey,
491 'filesize' => $this->mParams[
'filesize'],
492 'session' => $this->
getContext()->exportSession()
494 $this->log->info(
"Received final chunk of {filename} for {user}, queuing assemble job",
497 'filename' => $this->mParams[
'filename'] ??
'-',
498 'filekey' => $this->mParams[
'filekey'] ??
'-',
499 'filesize' => $this->mParams[
'filesize'],
500 'chunkSize' => $chunkSize,
503 $result[
'result'] =
'Poll';
504 $result[
'stage'] =
'queued';
506 $this->log->info(
"Received final chunk of {filename} for {user}, assembling immediately",
509 'filename' => $this->mParams[
'filename'] ??
'-',
510 'filekey' => $this->mParams[
'filekey'] ??
'-',
511 'filesize' => $this->mParams[
'filesize'],
512 'chunkSize' => $chunkSize,
515 UploadBase::setSessionStatus(
518 [
'result' =>
'Poll',
'stage' =>
'assembling',
'status' => Status::newGood() ]
522 $status = $this->mUpload->concatenateChunks();
523 if ( !$status->isGood() ) {
524 UploadBase::setSessionStatus(
527 [
'result' =>
'Failure',
'stage' =>
'assembling',
'status' => $status ]
529 $this->log->info(
"Non jobqueue assembly of {filename} failed because {status}",
532 'filename' => $this->mParams[
'filename'] ??
'-',
533 'filekey' => $this->mParams[
'filekey'] ??
'-',
534 'filesize' => $this->mParams[
'filesize'],
535 'chunkSize' => $chunkSize,
536 'status' => (
string)$status
539 $this->dieStatusWithCode( $status,
'stashfailed' );
543 $warnings = $this->getApiWarnings();
545 $result[
'warnings'] = $warnings;
550 $this->mUpload->stash->removeFile( $filekey );
551 $uploadFilekey = $filekey;
552 $filekey = $this->mUpload->getStashFile()->getFileKey();
554 $result[
'result'] =
'Success';
555 UploadBase::setSessionStatus(
559 'result' =>
'Success',
560 'stage' =>
'assembling',
561 'filekey' => $filekey,
565 }
catch ( ApiUsageException $e ) {
568 }
catch ( Exception $e ) {
570 'Non jobqueue assembly of {filename} failed: ' . get_class( $e ) .
' ' . $e->getMessage(),
572 'user' => $this->getUser()->getName(),
573 'filename' => $this->mParams[
'filename'] ??
'-',
574 'filekey' => $this->mParams[
'filekey'] ??
'-',
575 'filesize' => $this->mParams[
'filesize'],
576 'chunkSize' => $chunkSize,
581 $status = Status::newFatal( $this->getErrorFormatter()->getMessageFromException(
582 $e, [
'wrap' =>
new ApiMessage(
'apierror-stashexception',
'stashfailed' ) ]
584 UploadBase::setSessionStatus(
587 [
'result' =>
'Failure',
'stage' =>
'assembling',
'status' => $status ]
593 UploadBase::setSessionStatus(
597 'result' =>
'Continue',
598 'stage' =>
'uploading',
599 'offset' => $totalSoFar,
600 'status' => Status::newGood(),
603 $result[
'result'] =
'Continue';
604 $result[
'offset'] = $totalSoFar;
607 $result[
'filekey'] = $filekey;
624 private function performStash( $failureMode, &$data = [] ) {
625 if ( $failureMode ===
'optional' && $this->mUpload->skipStashFileAttempt() ) {
629 $isPartial = (bool)$this->mParams[
'chunk'];
631 $status = $this->mUpload->tryStashFile( $this->
getUser(), $isPartial );
633 if ( $status->isGood() && !$status->getValue() ) {
635 $status->fatal(
new ApiMessage(
'apierror-stashinvalidfile',
'stashfailed' ) );
637 }
catch ( Exception $e ) {
638 $debugMessage =
'Stashing temporary file failed: ' . get_class( $e ) .
' ' . $e->getMessage();
639 $this->log->info( $debugMessage,
642 'filename' => $this->mParams[
'filename'] ??
'-',
643 'filekey' => $this->mParams[
'filekey'] ??
'-'
647 $status = Status::newFatal( $this->getErrorFormatter()->getMessageFromException(
648 $e, [
'wrap' =>
new ApiMessage(
'apierror-stashexception',
'stashfailed' ) ]
652 if ( $status->isGood() ) {
653 $stashFile = $status->getValue();
654 $data[
'filekey'] = $stashFile->getFileKey();
656 $data[
'sessionkey'] = $data[
'filekey'];
657 return $data[
'filekey'];
660 if ( $status->getMessage()->getKey() ===
'uploadstash-exception' ) {
663 [ $exceptionType, $message ] = $status->getMessage()->getParams();
664 $debugMessage =
'Stashing temporary file failed: ' . $exceptionType .
' ' . $message;
665 $this->log->info( $debugMessage,
668 'filename' => $this->mParams[
'filename'] ??
'-',
669 'filekey' => $this->mParams[
'filekey'] ??
'-'
674 $this->log->info(
"Stash upload failure {status}",
676 'status' => (
string)$status,
678 'filename' => $this->mParams[
'filename'] ??
'-',
679 'filekey' => $this->mParams[
'filekey'] ??
'-'
683 if ( $failureMode !==
'optional' ) {
684 $this->dieStatus( $status );
686 $data[
'stasherrors'] = $this->getErrorFormatter()->arrayFromStatus( $status );
700 private function dieRecoverableError( $errors, $parameter =
null ): never {
702 $this->performStash(
'optional', $data );
705 $data[
'invalidparameter'] = $parameter;
709 foreach ( $errors as $error ) {
710 $msg = ApiMessage::create( $error );
711 $msg->setApiData( $msg->getApiData() + $data );
714 $this->dieStatus( $sv );
728 $sv = StatusValue::newGood();
729 foreach ( $status->getMessages() as $error ) {
730 $msg = ApiMessage::create( $error, $overrideCode );
731 if ( $moreExtraData ) {
732 $msg->setApiData( $msg->getApiData() + $moreExtraData );
736 $this->dieStatus( $sv );
748 if ( !$this->mParams[
'chunk'] ) {
750 'filekey',
'file',
'url' );
754 if ( $this->mParams[
'checkstatus'] &&
755 ( $this->mParams[
'filekey'] || ( $this->mParams[
'url'] && $this->mParams[
'filename'] ) )
757 $statusKey = $this->mParams[
'filekey'] ?: UploadFromUrl::getCacheKey( $this->mParams );
758 $progress = UploadBase::getSessionStatus( $this->
getUser(), $statusKey );
760 $this->log->info(
"Cannot check upload status due to missing upload session for {user}",
762 'user' => $this->
getUser()->getName(),
763 'url' => $this->mParams[
'url'] ??
'-',
764 'filename' => $this->mParams[
'filename'] ??
'-',
765 'filekey' => $this->mParams[
'filekey'] ??
'-'
768 $this->
dieWithError(
'apierror-upload-missingresult',
'missingresult' );
769 } elseif ( !$progress[
'status']->isGood() ) {
772 if ( isset( $progress[
'status']->value[
'verification'] ) ) {
775 if ( isset( $progress[
'status']->value[
'warnings'] ) ) {
778 $progress[
'warnings'] = $warnings;
782 unset( $progress[
'status'] );
784 if ( $progress[
'result'] ===
'Success' ) {
785 if ( isset( $progress[
'filekey'] ) ) {
788 $file = $this->localRepo->getUploadStash( $this->
getUser() )->getFile( $progress[
'filekey'] );
789 $imageinfo = $this->getUploadImageInfoInternal( $file,
true );
793 } elseif ( isset( $progress[
'filename'] ) && isset( $progress[
'timestamp'] ) ) {
795 $file = $this->localRepo->findFile(
796 $progress[
'filename'],
797 [
'time' => $progress[
'timestamp'],
'latest' =>
true ]
800 $imageinfo = $this->getUploadImageInfoInternal( $file,
false );
816 if ( $this->mParams[
'filename'] ===
null ) {
817 $this->
dieWithError( [
'apierror-missingparam',
'filename' ] );
820 if ( $this->mParams[
'chunk'] ) {
823 if ( isset( $this->mParams[
'filekey'] ) ) {
824 if ( $this->mParams[
'offset'] === 0 ) {
825 $this->
dieWithError(
'apierror-upload-filekeynotallowed',
'filekeynotallowed' );
829 $this->mUpload->continueChunks(
830 $this->mParams[
'filename'],
831 $this->mParams[
'filekey'],
832 $this->
getMain()->getUpload(
'chunk' )
835 if ( $this->mParams[
'offset'] !== 0 ) {
836 $this->
dieWithError(
'apierror-upload-filekeyneeded',
'filekeyneeded' );
840 $this->mUpload->initialize(
841 $this->mParams[
'filename'],
842 $this->
getMain()->getUpload(
'chunk' )
845 } elseif ( isset( $this->mParams[
'filekey'] ) ) {
854 $this->mUpload->initialize(
855 $this->mParams[
'filekey'], $this->mParams[
'filename'], !$this->mParams[
'async']
857 } elseif ( isset( $this->mParams[
'file'] ) ) {
861 if ( $this->mParams[
'async'] ) {
862 $this->
dieWithError(
'apierror-cannot-async-upload-file' );
866 $this->mUpload->initialize(
867 $this->mParams[
'filename'],
868 $this->
getMain()->getUpload(
'file' )
870 } elseif ( isset( $this->mParams[
'url'] ) ) {
872 if ( !UploadFromUrl::isEnabled() ) {
876 if ( !UploadFromUrl::isAllowedHost( $this->mParams[
'url'] ) ) {
880 if ( !UploadFromUrl::isAllowedUrl( $this->mParams[
'url'] ) ) {
887 $this->mUpload->
initialize( $this->mParams[
'filename'],
888 $this->mParams[
'url'], !$this->mParams[
'async'] );
901 $permission = $this->mUpload->isAllowed( $user );
903 if ( $permission !==
true ) {
904 if ( !$user->isNamed() ) {
905 $this->
dieWithError( [
'apierror-mustbeloggedin', $this->
msg(
'action-upload' ) ] );
908 $this->
dieStatus( User::newFatalPermissionDeniedStatus( $permission ) );
912 if ( $user->isBlockedFromUpload() ) {
922 if ( $this->mParams[
'chunk'] ) {
923 $maxSize = UploadBase::getMaxUploadSize(
'file' );
924 if ( $this->mParams[
'filesize'] > $maxSize ) {
927 if ( !$this->mUpload->getTitle() ) {
932 $verification = $this->mUpload->validateName();
933 if ( $verification ===
true ) {
936 } elseif ( $this->mParams[
'async'] && ( $this->mParams[
'filekey'] || $this->mParams[
'url'] ) ) {
940 $verification = $this->mUpload->validateName();
941 if ( $verification ===
true ) {
945 wfDebug( __METHOD__ .
" about to verify" );
947 $verification = $this->mUpload->verifyUpload();
949 if ( $verification[
'status'] === UploadBase::OK ) {
952 $this->log->info(
"File verification of {filename} failed for {user} because {result}",
954 'user' => $this->
getUser()->getName(),
955 'resultCode' => $verification[
'status'],
956 'result' => $this->mUpload->getVerificationErrorCode( $verification[
'status'] ),
957 'filename' => $this->mParams[
'filename'] ??
'-',
958 'details' => $verification[
'details'] ??
''
973 $status = $this->mUpload->convertVerifyErrorToStatus( $verification );
974 if ( $status->isRecoverableError() ) {
975 $this->dieRecoverableError( [ $status->asApiMessage() ], $status->getInvalidParameter() );
978 $this->dieWithError( $status->asApiMessage() );
990 $warnings = UploadBase::makeWarningsSerializable(
991 $this->mUpload->checkWarnings( $this->getUser() )
1002 if ( isset( $warnings[
'duplicate'] ) ) {
1003 $dupes = array_column( $warnings[
'duplicate'],
'fileName' );
1005 $warnings[
'duplicate'] = $dupes;
1008 if ( isset( $warnings[
'exists'] ) ) {
1009 $warning = $warnings[
'exists'];
1010 unset( $warnings[
'exists'] );
1011 $localFile = $warning[
'normalizedFile'] ?? $warning[
'file'];
1012 $warnings[$warning[
'warning']] = $localFile[
'fileName'];
1015 if ( isset( $warnings[
'no-change'] ) ) {
1016 $file = $warnings[
'no-change'];
1017 unset( $warnings[
'no-change'] );
1019 $warnings[
'nochange'] = [
1020 'timestamp' =>
wfTimestamp( TS::ISO_8601, $file[
'timestamp'] )
1024 if ( isset( $warnings[
'duplicate-version'] ) ) {
1026 foreach ( $warnings[
'duplicate-version'] as $dupe ) {
1028 'timestamp' =>
wfTimestamp( TS::ISO_8601, $dupe[
'timestamp'] )
1031 unset( $warnings[
'duplicate-version'] );
1034 $warnings[
'duplicateversions'] = $dupes;
1048 $this->log->info(
"Upload stashing of {filename} failed for {user} because {error}",
1050 'user' => $this->
getUser()->getName(),
1051 'error' => get_class( $e ),
1052 'filename' => $this->mParams[
'filename'] ??
'-',
1053 'filekey' => $this->mParams[
'filekey'] ??
'-'
1057 switch ( get_class( $e ) ) {
1058 case UploadStashFileNotFoundException::class:
1059 $wrap =
'apierror-stashedfilenotfound';
1061 case UploadStashBadPathException::class:
1062 $wrap =
'apierror-stashpathinvalid';
1064 case UploadStashFileException::class:
1065 $wrap =
'apierror-stashfilestorage';
1067 case UploadStashZeroLengthFileException::class:
1068 $wrap =
'apierror-stashzerolength';
1070 case UploadStashNotLoggedInException::class:
1072 [
'apierror-mustbeloggedin', $this->
msg(
'action-upload' ) ],
'stashnotloggedin'
1074 case UploadStashWrongOwnerException::class:
1075 $wrap =
'apierror-stashwrongowner';
1077 case UploadStashNoSuchKeyException::class:
1078 $wrap =
'apierror-stashnosuchfilekey';
1081 $wrap = [
'uploadstash-exception', get_class( $e ) ];
1084 return StatusValue::newFatal(
1097 if ( $this->mParams[
'autotext'] ) {
1102 $this->mParams[
'text'] = SpecialUpload::getInitialPageText(
1103 $this->mParams[
'comment'],
1104 $this->mParams[
'license'],
1105 $this->mParams[
'copystatus'],
1106 $this->mParams[
'source'],
1111 $this->mParams[
'text'] ??= $this->mParams[
'comment'];
1115 $file = $this->mUpload->getLocalFile();
1117 $title = $file->getTitle();
1125 $this->mParams[
'watchlist'], $title, $user,
'watchdefault'
1128 if ( !$watch && $this->mParams[
'watchlist'] ==
'preferences' && !$file->exists() ) {
1134 $expiryOption = $file->exists() ?
'watchdefault-expiry' :
'watchcreations-expiry';
1135 $watchlistExpiry = $this->
getExpiryFromParams( $this->mParams, $title, $user, $expiryOption );
1138 if ( $this->mParams[
'watch'] ) {
1142 if ( $this->mParams[
'tags'] ) {
1143 $status = ChangeTags::canAddTagsAccompanyingChange( $this->mParams[
'tags'], $this->
getAuthority() );
1144 if ( !$status->isOK() ) {
1151 if ( $this->mParams[
'async'] ) {
1153 if ( $this->mParams[
'filekey'] ) {
1156 'filename' => $this->mParams[
'filename'],
1157 'filekey' => $this->mParams[
'filekey'],
1158 'comment' => $this->mParams[
'comment'],
1159 'tags' => $this->mParams[
'tags'] ?? [],
1160 'text' => $this->mParams[
'text'],
1162 'watchlistexpiry' => $watchlistExpiry,
1164 'ignorewarnings' => $this->mParams[
'ignorewarnings']
1167 } elseif ( $this->mParams[
'url'] ) {
1170 'filename' => $this->mParams[
'filename'],
1171 'url' => $this->mParams[
'url'],
1172 'comment' => $this->mParams[
'comment'],
1173 'tags' => $this->mParams[
'tags'] ?? [],
1174 'text' => $this->mParams[
'text'],
1176 'watchlistexpiry' => $watchlistExpiry,
1178 'ignorewarnings' => $this->mParams[
'ignorewarnings']
1182 $this->
dieWithError(
'apierror-no-async-support',
'publishfailed' );
1188 $cacheKey =
$job->getCacheKey();
1191 $progress = UploadBase::getSessionStatus( $this->
getUser(), $cacheKey );
1192 if ( $progress && $progress[
'result'] ===
'Poll' ) {
1193 $this->
dieWithError(
'apierror-upload-inprogress',
'publishfailed' );
1195 UploadBase::setSessionStatus(
1198 [
'result' =>
'Poll',
'stage' =>
'queued',
'status' => Status::newGood() ]
1201 $this->jobQueueGroup->push(
$job );
1202 $this->log->info(
"Sending publish job of {filename} for {user}",
1204 'user' => $this->
getUser()->getName(),
1205 'filename' => $this->mParams[
'filename'] ??
'-'
1208 $result[
'result'] =
'Poll';
1209 $result[
'stage'] =
'queued';
1211 $status = $this->mUpload->performUpload(
1212 $this->mParams[
'comment'],
1213 $this->mParams[
'text'],
1216 $this->mParams[
'tags'] ?? [],
1220 if ( !$status->isGood() ) {
1221 $this->log->info(
"Non-async API upload publish failed for {user} because {status}",
1223 'user' => $this->
getUser()->getName(),
1224 'filename' => $this->mParams[
'filename'] ??
'-',
1225 'filekey' => $this->mParams[
'filekey'] ??
'-',
1226 'status' => (
string)$status
1229 $this->dieRecoverableError( $status->getMessages() );
1231 $result[
'result'] =
'Success';
1234 $result[
'filename'] = $file->getName();
1235 if ( $warnings && count( $warnings ) > 0 ) {
1236 $result[
'warnings'] = $warnings;
1256 ParamValidator::PARAM_TYPE =>
'string',
1259 ParamValidator::PARAM_DEFAULT =>
''
1262 ParamValidator::PARAM_TYPE =>
'tags',
1263 ParamValidator::PARAM_ISMULTI =>
true,
1266 ParamValidator::PARAM_TYPE =>
'text',
1269 ParamValidator::PARAM_DEFAULT =>
false,
1270 ParamValidator::PARAM_DEPRECATED =>
true,
1283 'ignorewarnings' =>
false,
1285 ParamValidator::PARAM_TYPE =>
'upload',
1290 ParamValidator::PARAM_DEPRECATED =>
true,
1295 ParamValidator::PARAM_TYPE =>
'integer',
1296 IntegerDef::PARAM_MIN => 0,
1297 IntegerDef::PARAM_MAX => UploadBase::getMaxUploadSize(
'file' ),
1300 ParamValidator::PARAM_TYPE =>
'integer',
1301 IntegerDef::PARAM_MIN => 0,
1304 ParamValidator::PARAM_TYPE =>
'upload',
1308 'checkstatus' =>
false,
1311 ParamValidator::PARAM_TYPE =>
'boolean',
1312 ParamValidator::PARAM_DEFAULT =>
false,
1315 ParamValidator::PARAM_TYPE =>
'string',
1316 ParamValidator::PARAM_DEFAULT =>
''
1323 ParamValidator::PARAM_TYPE =>
'string',
1324 ParamValidator::PARAM_DEFAULT =>
''
1327 ParamValidator::PARAM_TYPE =>
'string',
1328 ParamValidator::PARAM_DEFAULT =>
''
1344 'action=upload&filename=Wiki.png' .
1345 '&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png&token=123ABC'
1346 =>
'apihelp-upload-example-url',
1347 'action=upload&filename=Wiki.png&filekey=filekey&ignorewarnings=1&token=123ABC'
1348 =>
'apihelp-upload-example-filekey',
1354 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Upload';
1359class_alias( ApiUpload::class,
'ApiUpload' );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfShorthandToInteger(?string $string='', int $default=-1)
Converts shorthand byte notation to integer form.
wfTimestamp( $outputtype=TS::UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(!defined('MW_SETUP_CALLBACK'))
This is the main API class, used for both external and internal processing.
exportSession()
Export the resolved user IP, HTTP headers, user ID, and session ID.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage().
A class containing constants representing the names of configuration variables.
const EnableAsyncUploads
Name constant for the EnableAsyncUploads setting, for use with Config\get().
const WatchlistExpiry
Name constant for the WatchlistExpiry setting, for use with Config\get().
const MinUploadChunkSize
Name constant for the MinUploadChunkSize setting, for use with Config\get().
const UseCopyrightUpload
Name constant for the UseCopyrightUpload setting, for use with Config\get().
const EnableAsyncUploadsByURL
Name constant for the EnableAsyncUploadsByURL setting, for use with Config\get().
const WatchlistExpiryMaxDuration
Name constant for the WatchlistExpiryMaxDuration setting, for use with Config\get().
static newGood( $value=null)
Factory function for good results.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
if(count( $args)< 1) $job