MediaWiki  1.30.0
UploadFromUrl Class Reference

Implements uploading from a HTTP resource. More...

Inheritance diagram for UploadFromUrl:
Collaboration diagram for UploadFromUrl:

Public Member Functions

 fetchFile ( $httpOptions=[])
 Download the file. More...
 
 getSourceType ()
 
 initialize ( $name, $url)
 Entry point for API upload. More...
 
 initializeFromRequest (&$request)
 Entry point for SpecialUpload. More...
 
 saveTempFileChunk ( $req, $buffer)
 Callback: save a chunk of the result of a HTTP request to the temporary file. More...
 

Static Public Member Functions

static isAllowed ( $user)
 Checks if the user is allowed to use the upload-by-URL feature. More...
 
static isAllowedHost ( $url)
 Checks whether the URL is for an allowed host The domains in the whitelist can include wildcard characters (*) in place of any of the domain levels, e.g. More...
 
static isAllowedUrl ( $url)
 Checks whether the URL is not allowed. More...
 
static isEnabled ()
 Checks if the upload from URL feature is enabled. More...
 
static isValidRequest ( $request)
 

Public Attributes

 $mTmpHandle
 

Protected Member Functions

 makeTemporaryFile ()
 Create a new temporary file in the URL subdirectory of wfTempDir(). More...
 
 reallyFetchFile ( $httpOptions=[])
 Download the file, save it to the temporary file and update the file size and set $mRemoveTempFile to true. More...
 

Protected Attributes

 $mTempPath
 
 $mUrl
 

Static Protected Attributes

static $allowedUrls = []
 

Detailed Description

Implements uploading from a HTTP resource.

Author
Bryan Tong Minh
Michael Dale

Definition at line 31 of file UploadFromUrl.php.

Member Function Documentation

◆ fetchFile()

UploadFromUrl::fetchFile (   $httpOptions = [])

Download the file.

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

Definition at line 185 of file UploadFromUrl.php.

References Http\isValidURI(), StatusValue\newFatal(), and reallyFetchFile().

◆ getSourceType()

UploadFromUrl::getSourceType ( )
Returns
string

Definition at line 174 of file UploadFromUrl.php.

◆ initialize()

UploadFromUrl::initialize (   $name,
  $url 
)

Entry point for API upload.

Parameters
string$name
string$url
Exceptions
MWException

Definition at line 134 of file UploadFromUrl.php.

References $name, and makeTemporaryFile().

Referenced by initializeFromRequest(), and ApiUpload\selectUploadModule().

◆ initializeFromRequest()

UploadFromUrl::initializeFromRequest ( $request)

Entry point for SpecialUpload.

Parameters
WebRequest&$request

Definition at line 146 of file UploadFromUrl.php.

References $request, and initialize().

◆ isAllowed()

static UploadFromUrl::isAllowed (   $user)
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
User$user
Returns
bool|string

Definition at line 47 of file UploadFromUrl.php.

References $user.

Referenced by UploadForm\getSourceSection().

◆ isAllowedHost()

static UploadFromUrl::isAllowedHost (   $url)
static

Checks whether the URL is for an allowed host The domains in the whitelist 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 $wgCopyUploadsDomains, as, captcha-old\count, global, and wfParseUrl().

Referenced by ApiUpload\selectUploadModule().

◆ isAllowedUrl()

static UploadFromUrl::isAllowedUrl (   $url)
static

Checks whether the URL is not allowed.

Parameters
string$url
Returns
bool

Definition at line 117 of file UploadFromUrl.php.

References Hooks\run().

Referenced by ApiUpload\selectUploadModule().

◆ isEnabled()

static UploadFromUrl::isEnabled ( )
static

Checks if the upload from URL feature is enabled.

Returns
bool

Definition at line 59 of file UploadFromUrl.php.

References $wgAllowCopyUploads, and global.

Referenced by UploadForm\getSourceSection(), and ApiUpload\selectUploadModule().

◆ isValidRequest()

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

Definition at line 162 of file UploadFromUrl.php.

References $request, $wgUser, and global.

◆ makeTemporaryFile()

UploadFromUrl::makeTemporaryFile ( )
protected

Create a new temporary file in the URL subdirectory of wfTempDir().

Returns
string Path to the file

Definition at line 204 of file UploadFromUrl.php.

References TempFSFile\factory(), and wfTempDir().

Referenced by initialize().

◆ reallyFetchFile()

UploadFromUrl::reallyFetchFile (   $httpOptions = [])
protected

Download the file, save it to the temporary file and update the file size and set $mRemoveTempFile to true.

Parameters
array$httpOptionsArray of options for MWHttpRequest
Returns
Status

Definition at line 245 of file UploadFromUrl.php.

References $options, $req, $wgCopyUploadProxy, $wgCopyUploadTimeout, MWHttpRequest\factory(), global, StatusValue\newFatal(), true, and wfDebugLog().

Referenced by fetchFile().

◆ saveTempFileChunk()

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 218 of file UploadFromUrl.php.

References $buffer, and wfDebugLog().

Member Data Documentation

◆ $allowedUrls

UploadFromUrl::$allowedUrls = []
staticprotected

Definition at line 36 of file UploadFromUrl.php.

◆ $mTempPath

UploadFromUrl::$mTempPath
protected

Definition at line 34 of file UploadFromUrl.php.

◆ $mTmpHandle

UploadFromUrl::$mTmpHandle

Definition at line 34 of file UploadFromUrl.php.

◆ $mUrl

UploadFromUrl::$mUrl
protected

Definition at line 32 of file UploadFromUrl.php.


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