MediaWiki  master
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 (UserIdentity $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 34 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 192 of file UploadFromUrl.php.

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

◆ getSourceType()

UploadFromUrl::getSourceType ( )
Returns
string

Definition at line 181 of file UploadFromUrl.php.

◆ initialize()

UploadFromUrl::initialize (   $name,
  $url 
)

Entry point for API upload.

Parameters
string$name
string$url
Exceptions
MWException

Definition at line 140 of file UploadFromUrl.php.

References makeTemporaryFile().

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

◆ initializeFromRequest()

UploadFromUrl::initializeFromRequest ( $request)

Entry point for SpecialUpload.

Parameters
WebRequest&$request

Definition at line 152 of file UploadFromUrl.php.

References initialize().

◆ isAllowed()

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

Definition at line 50 of file UploadFromUrl.php.

References getPermissionManager().

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

References $wgCopyUploadsDomains, 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 123 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 65 of file UploadFromUrl.php.

References $wgAllowCopyUploads.

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

◆ isValidRequest()

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

Definition at line 167 of file UploadFromUrl.php.

◆ makeTemporaryFile()

UploadFromUrl::makeTemporaryFile ( )
protected

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

Returns
string Path to the file

Definition at line 211 of file UploadFromUrl.php.

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

References $wgCopyUploadProxy, $wgCopyUploadTimeout, MWHttpRequest\factory(), 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 226 of file UploadFromUrl.php.

References wfDebugLog().

Member Data Documentation

◆ $allowedUrls

UploadFromUrl::$allowedUrls = []
staticprotected

Definition at line 39 of file UploadFromUrl.php.

◆ $mTempPath

UploadFromUrl::$mTempPath
protected

Definition at line 37 of file UploadFromUrl.php.

◆ $mTmpHandle

UploadFromUrl::$mTmpHandle

Definition at line 37 of file UploadFromUrl.php.

◆ $mUrl

UploadFromUrl::$mUrl
protected

Definition at line 35 of file UploadFromUrl.php.


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