MediaWiki master
MediaWiki\Upload\UploadFromUrl Class Reference

Implements uploading from a HTTP resource. More...

Inherits MediaWiki\Upload\UploadBase.

Collaboration diagram for MediaWiki\Upload\UploadFromUrl:

Public Member Functions

 canFetchFile ()
 Verify we can actually download the file.
 fetchFile ( $httpOptions=[])
 Download the file if allowed.
 getSourceType ()
 getUrl ()
 Get the URL of the file to be uploaded.
 initialize ( $name, $url, $initTempFile=true)
 Entry point for API upload.
 initializeFromRequest (&$request)
 Entry point for SpecialUpload.
 saveTempFileChunk ( $req, $buffer)
 Callback: save a chunk of the result of a HTTP request to the temporary file.
Public Member Functions inherited from MediaWiki\Upload\UploadBase
 __construct ()
 authorizeUpload (Authority $performer)
 Check whether the user can upload the image.
 checkWarnings (Authority $performer)
 Check for non fatal problems with the file.
 cleanupTempFile ()
 If we've modified the upload file, then we need to manually remove it on exit to clean up.
 convertVerifyErrorToStatus (array $error)
 fetchFile ()
 Fetch the file.
 getDesiredDestName ()
 Get the desired destination name.
 getFileSize ()
 Return the file size.
 getImageInfo ( $result=null)
 Gets image info about the file just uploaded.
 getLocalFile ()
 Return the local file and initializes if necessary.
 getRealPath ( $srcPath)
 getStashFile ()
 getTempFileSha1Base36 ()
 Get the base 36 SHA1 of the file.
 getTempPath ()
 getTitle ()
 Returns the title of the file to be uploaded.
 getVerificationErrorCode ( $error)
 initializePathInfo ( $name, $tempPath, $fileSize, $removeTempFile=false)
 isEmptyFile ()
 Return true if the file is empty.
 performUpload ( $comment, $pageText, $watch, $user, $tags=[], ?string $watchlistExpiry=null)
 Really perform the upload.
 postProcessUpload ()
 Perform extra steps after a successful upload.
 skipStashFileAttempt ()
 Check, if stash file attempt should be skipped, for example when the file is already known to stash.
 tryStashFile (User $user, $isPartial=false)
 Attempt to temporarily stash the uploaded file for later resumption of the upload.
 validateName ()
 Verify that the name is valid and, if necessary, that we can overwrite.
 verifyUpload ()
 Verify whether the upload is sensible.

Static Public Member Functions

static getAllowedHosts ()
static getCacheKey ( $params)
 Provides a caching key for an upload-from-URL set of parameters.
static getCacheKeyFromRequest (&$request)
 Get the caching key from a web request.
static isAllowed (Authority $performer)
 Checks if the user is allowed to use the upload-by-URL feature.
static isAllowedHost ( $url)
 Checks whether the URL is for an allowed host The domains in the allowlist can include wildcard characters (*) in place of any of the domain levels, e.g.
static isAllowedUrl ( $url)
 Checks whether the URL is not allowed.
static isEnabled ()
 Checks if the upload from URL feature is enabled.
static isValidRequest ( $request)
Static Public Member Functions inherited from MediaWiki\Upload\UploadBase
static checkFileExtension ( $ext, $list)
 Perform case-insensitive match against a list of file extensions.
static checkFileExtensionList ( $ext, $list)
 Perform case-insensitive match against a list of file extensions.
static createFromRequest (&$request, $type=null)
 Create a form of UploadBase depending on wpSourceType and initializes it.
static getExistsWarning ( $file)
 Helper function that does various existence checks for a file.
static getFilenamePrefixBlacklist ()
 Get a list of disallowed filename prefixes from [[MediaWiki:Filename-prefix-blacklist]].
static getMaxPhpUploadSize ()
 Get the PHP maximum uploaded file size, based on ini settings.
static getMaxUploadSize ( $forType=null)
 Get MediaWiki's maximum uploaded file size for a given type of upload, based on $wgMaxUploadSize.
static getSessionStatus (UserIdentity $user, $statusKey)
 Get the current status of a chunked upload (used for polling).
static isThumbName ( $filename)
 Helper function that checks whether the filename looks like a thumbnail.
static makeWarningsSerializable ( $warnings)
 Convert the warnings array returned by checkWarnings() to something that can be serialized, and that is suitable for inclusion directly in action API results.
static setSessionStatus (UserIdentity $user, $statusKey, $value)
 Set the current status of a chunked upload (used for polling).
static splitExtensions ( $filename)
 Split a file into a base name and all dot-delimited 'extensions' on the end.
static unserializeWarnings ( $warnings)
 Convert the serialized warnings array created by makeWarningsSerializable() back to the output of checkWarnings().
static userCanReUpload (Authority $performer, File $img)
 Check if a user is the last uploader.

Protected Member Functions

 makeTemporaryFile ()
 Create a new temporary file.
 reallyFetchFile ( $httpOptions=[])
 Download the file with no domain name validation.
Protected Member Functions inherited from MediaWiki\Upload\UploadBase
 doStashFile (?User $user=null)
 Implementation for tryStashFile().
 getFileProps ()
 File props is very expensive on large files (due to SHA-1 calc) so it is important we save the result to reuse.
 runUploadStashFileHook (User $user)
 setTempFile ( $tempPath, $fileSize=null)
 verifyFile ()
 Verifies that it's OK to include the uploaded file.
 verifyMimeType ( $mime)
 Verify the MIME type.
 verifyPartialFile ()
 A verification routine suitable for partial files.

Protected Attributes

resource null false $mTmpHandle
string $mUrl
Protected Attributes inherited from MediaWiki\Upload\UploadBase
string[] $mBlackListedExtensions
string null $mDesiredDestName
string null $mDestName
array null $mFileProps
int null $mFileSize
string null $mFilteredName
string null $mFinalExtension
LocalFile null $mLocalFile
bool null $mRemoveTempFile
string null $mSourceType
UploadStashFile null $mStashFile
string null $mTempPath
 Local file system path to the file to upload (or a local copy).
Title false null $mTitle = false
int $mTitleError = 0
TempFSFile null $tempFileObj
 Wrapper to handle deleting the temp file.

Static Protected Attributes

static array< string, bool > $allowedUrls = []

Additional Inherited Members

Public Attributes inherited from MediaWiki\Upload\UploadBase
const EMPTY_FILE = 3
const FILE_TOO_LARGE = 12
const FILENAME_TOO_LONG = 14
const FILETYPE_BADTYPE = 9
const FILETYPE_MISSING = 8
const ILLEGAL_FILENAME = 5
const MIN_LENGTH_PARTNAME = 4
const OK = 0
const SUCCESS = 0
const VERIFICATION_ERROR = 10
const WINDOWS_NONASCII_FILENAME = 13

Detailed Description

Implements uploading from a HTTP resource.

Author
Bryan Tong Minh
Michael Dale

Definition at line 28 of file UploadFromUrl.php.

Member Function Documentation

◆ canFetchFile()

MediaWiki\Upload\UploadFromUrl::canFetchFile ( )

Verify we can actually download the file.

Returns
Status

Reimplemented from MediaWiki\Upload\UploadBase.

Definition at line 273 of file UploadFromUrl.php.

Referenced by fetchFile().

◆ fetchFile()

MediaWiki\Upload\UploadFromUrl::fetchFile ( $httpOptions = [])

Download the file if allowed.

Parameters
array$httpOptionsArray of options for MWHttpRequest. This could be used to override the timeout on the HTTP request.
Returns
Status

Definition at line 260 of file UploadFromUrl.php.

References canFetchFile(), and reallyFetchFile().

◆ getAllowedHosts()

MediaWiki\Upload\UploadFromUrl::getAllowedHosts ( )
static
Since
1.45 public
Returns
string[]

Definition at line 153 of file UploadFromUrl.php.

References MediaWiki\MainConfigNames\CopyUploadAllowOnWikiDomainConfig, and MediaWiki\MainConfigNames\CopyUploadsDomains.

Referenced by isAllowedHost().

◆ getCacheKey()

MediaWiki\Upload\UploadFromUrl::getCacheKey ( $params)
static

Provides a caching key for an upload-from-URL set of parameters.

Used to set the status of an async job in UploadFromUrlJob and retrieve it in frontend clients like ApiUpload. Will return the empty string if not all parameters are present.

Parameters
array$params
Returns
string

Definition at line 115 of file UploadFromUrl.php.

Referenced by getCacheKeyFromRequest().

◆ getCacheKeyFromRequest()

MediaWiki\Upload\UploadFromUrl::getCacheKeyFromRequest ( & $request)
static

Get the caching key from a web request.

Parameters
WebRequest&$request
Returns
string

Definition at line 132 of file UploadFromUrl.php.

References $request, and getCacheKey().

Referenced by MediaWiki\Specials\SpecialUpload\loadRequest().

◆ getSourceType()

MediaWiki\Upload\UploadFromUrl::getSourceType ( )
Returns
string

Reimplemented from MediaWiki\Upload\UploadBase.

Definition at line 249 of file UploadFromUrl.php.

◆ getUrl()

MediaWiki\Upload\UploadFromUrl::getUrl ( )

Get the URL of the file to be uploaded.

Returns
string

Definition at line 196 of file UploadFromUrl.php.

◆ initialize()

MediaWiki\Upload\UploadFromUrl::initialize ( $name,
$url,
$initTempFile = true )

Entry point for API upload.

Parameters
string$name
string$url
bool$initTempFile

Definition at line 207 of file UploadFromUrl.php.

References $url, MediaWiki\Upload\UploadBase\initializePathInfo(), and makeTemporaryFile().

Referenced by MediaWiki\JobQueue\Jobs\UploadFromUrlJob\getUpload(), initializeFromRequest(), and MediaWiki\Api\ApiUpload\selectUploadModule().

◆ initializeFromRequest()

MediaWiki\Upload\UploadFromUrl::initializeFromRequest ( & $request)

Entry point for SpecialUpload.

Parameters
WebRequest&$request

Reimplemented from MediaWiki\Upload\UploadBase.

Definition at line 220 of file UploadFromUrl.php.

References $request, and initialize().

◆ isAllowed()

MediaWiki\Upload\UploadFromUrl::isAllowed ( Authority $performer)
static

Checks if the user is allowed to use the upload-by-URL feature.

If the user is not allowed, return the name of the user right as a string. If the user is allowed, have the parent do further permissions checking.

Parameters
Authority$performer
Returns
bool|string

Reimplemented from MediaWiki\Upload\UploadBase.

Definition at line 47 of file UploadFromUrl.php.

References MediaWiki\Permissions\Authority\isAllowed().

◆ isAllowedHost()

MediaWiki\Upload\UploadFromUrl::isAllowedHost ( $url)
static

Checks whether the URL is for an allowed host The domains in the allowlist can include wildcard characters (*) in place of any of the domain levels, e.g.

'.flickr.com' or 'upload..gov.uk'.

Parameters
string$url
Returns
bool

Definition at line 73 of file UploadFromUrl.php.

References $url, getAllowedHosts(), and MediaWiki\MediaWikiServices\getInstance().

◆ isAllowedUrl()

MediaWiki\Upload\UploadFromUrl::isAllowedUrl ( $url)
static

Checks whether the URL is not allowed.

Parameters
string$url
Returns
bool

Definition at line 181 of file UploadFromUrl.php.

References $url, and MediaWiki\MediaWikiServices\getInstance().

◆ isEnabled()

MediaWiki\Upload\UploadFromUrl::isEnabled ( )
static

Checks if the upload from URL feature is enabled.

Returns
bool

Reimplemented from MediaWiki\Upload\UploadBase.

Definition at line 59 of file UploadFromUrl.php.

References MediaWiki\MainConfigNames\AllowCopyUploads, and MediaWiki\MediaWikiServices\getInstance().

◆ isValidRequest()

MediaWiki\Upload\UploadFromUrl::isValidRequest ( $request)
static
Parameters
WebRequest$request
Returns
bool

Reimplemented from MediaWiki\Upload\UploadBase.

Definition at line 235 of file UploadFromUrl.php.

References $request, $url, and MediaWiki\MediaWikiServices\getInstance().

◆ makeTemporaryFile()

MediaWiki\Upload\UploadFromUrl::makeTemporaryFile ( )
protected

Create a new temporary file.

Returns
string Path to the file

Definition at line 295 of file UploadFromUrl.php.

References MediaWiki\MediaWikiServices\getInstance().

Referenced by initialize().

◆ reallyFetchFile()

MediaWiki\Upload\UploadFromUrl::reallyFetchFile ( $httpOptions = [])
protected

Download the file with no domain name validation.

Parameters
array$httpOptionsArray of options for MWHttpRequest
Returns
Status

Definition at line 336 of file UploadFromUrl.php.

References MediaWiki\MainConfigNames\CopyUploadProxy, MediaWiki\MainConfigNames\CopyUploadTimeout, MediaWiki\MediaWikiServices\getInstance(), saveTempFileChunk(), and wfDebugLog().

Referenced by fetchFile().

◆ saveTempFileChunk()

MediaWiki\Upload\UploadFromUrl::saveTempFileChunk ( $req,
$buffer )

Callback: save a chunk of the result of a HTTP request to the temporary file.

Parameters
mixed$req
string$buffer
Returns
int Number of bytes handled

Definition at line 310 of file UploadFromUrl.php.

References wfDebugLog().

Referenced by reallyFetchFile().

Member Data Documentation

◆ $allowedUrls

array<string,bool> MediaWiki\Upload\UploadFromUrl::$allowedUrls = []
staticprotected

Definition at line 36 of file UploadFromUrl.php.

◆ $mTmpHandle

resource null false MediaWiki\Upload\UploadFromUrl::$mTmpHandle
protected

Definition at line 33 of file UploadFromUrl.php.

◆ $mUrl

string MediaWiki\Upload\UploadFromUrl::$mUrl
protected

Definition at line 30 of file UploadFromUrl.php.


The documentation for this class was generated from the following file: