MediaWiki  master
UploadBase Class Reference

UploadBase and subclasses are the backend of MediaWiki's file uploads. More...

Inheritance diagram for UploadBase:
Collaboration diagram for UploadBase:

Public Member Functions

 __construct ()
 
 checkSvgScriptCallback ( $element, $attribs, $data=null)
 
 checkWarnings ()
 Check for non fatal problems with the file. More...
 
 cleanupTempFile ()
 If we've modified the upload file we need to manually remove it on exit to clean up. More...
 
 convertVerifyErrorToStatus ( $error)
 
 fetchFile ()
 Fetch the file. More...
 
 getFileSize ()
 Return the file size. More...
 
 getImageInfo ( $result)
 Gets image info about the file just uploaded. More...
 
 getLocalFile ()
 Return the local file and initializes if necessary. More...
 
 getRealPath ( $srcPath)
 
 getSourceType ()
 Returns the upload type. More...
 
 getStashFile ()
 
 getTempFileSha1Base36 ()
 Get the base 36 SHA1 of the file. More...
 
 getTempPath ()
 
 getTitle ()
 Returns the title of the file to be uploaded. More...
 
 getVerificationErrorCode ( $error)
 
 initializeFromRequest (&$request)
 Initialize from a WebRequest. More...
 
 initializePathInfo ( $name, $tempPath, $fileSize, $removeTempFile=false)
 Initialize the path information. More...
 
 isEmptyFile ()
 Return true if the file is empty. More...
 
 performUpload ( $comment, $pageText, $watch, $user, $tags=[])
 Really perform the upload. More...
 
 postProcessUpload ()
 Perform extra steps after a successful upload. More...
 
 stashFile (User $user=null)
 If the user does not supply all necessary information in the first upload form submission (either by accident or by design) then we may want to stash the file temporarily, get more information, and publish the file later. More...
 
 tryStashFile (User $user, $isPartial=false)
 Like stashFile(), but respects extensions' wishes to prevent the stashing. More...
 
 validateName ()
 Verify that the name is valid and, if necessary, that we can overwrite. More...
 
 verifyPermissions ( $user)
 Alias for verifyTitlePermissions. More...
 
 verifyTitlePermissions ( $user)
 Check whether the user can edit, upload and create the image. More...
 
 verifyUpload ()
 Verify whether the upload is sane. More...
 
 zipEntryCallback ( $entry)
 Callback for ZipDirectoryReader to detect Java class files. More...
 

Static Public Member Functions

static checkFileExtension ( $ext, $list)
 Perform case-insensitive match against a list of file extensions. More...
 
static checkFileExtensionList ( $ext, $list)
 Perform case-insensitive match against a list of file extensions. More...
 
static checkSvgExternalDTD ( $type, $publicId, $systemId)
 Verify that DTD urls referenced are only the standard dtds. More...
 
static checkSvgPICallback ( $target, $data)
 Callback to filter SVG Processing Instructions. More...
 
static checkXMLEncodingMissmatch ( $file)
 Check a whitelist of xml encodings that are known not to be interpreted differently by the server's xml parser (expat) and some common browsers. More...
 
static createFromRequest (&$request, $type=null)
 Create a form of UploadBase depending on wpSourceType and initializes it. More...
 
static detectScript ( $file, $mime, $extension)
 Heuristic for detecting files that could contain JavaScript instructions or things that may look like HTML to a browser and are thus potentially harmful. More...
 
static detectVirus ( $file)
 Generic wrapper function for a virus scanner program. More...
 
static getExistsWarning ( $file)
 Helper function that does various existence checks for a file. More...
 
static getFilenamePrefixBlacklist ()
 Get a list of blacklisted filename prefixes from [[MediaWiki:Filename-prefix-blacklist]]. More...
 
static getMaxPhpUploadSize ()
 Get the PHP maximum uploaded file size, based on ini settings. More...
 
static getMaxUploadSize ( $forType=null)
 Get the MediaWiki maximum uploaded file size for given type of upload, based on $wgMaxUploadSize. More...
 
static getSessionStatus (User $user, $statusKey)
 Get the current status of a chunked upload (used for polling) More...
 
static isAllowed ( $user)
 Returns true if the user can use this upload module or else a string identifying the missing permission. More...
 
static isEnabled ()
 Returns true if uploads are enabled. More...
 
static isThrottled ( $user)
 Returns true if the user has surpassed the upload rate limit, false otherwise. More...
 
static isThumbName ( $filename)
 Helper function that checks whether the filename looks like a thumbnail. More...
 
static isValidRequest ( $request)
 Check whether a request if valid for this handler. More...
 
static setSessionStatus (User $user, $statusKey, $value)
 Set the current status of a chunked upload (used for polling) More...
 
static splitExtensions ( $filename)
 Split a file into a base name and all dot-delimited 'extensions' on the end. More...
 
static userCanReUpload (User $user, File $img)
 Check if a user is the last uploader. More...
 
static verifyExtension ( $mime, $extension)
 Checks if the MIME type of the uploaded file matches the file extension. More...
 

Public Attributes

const EMPTY_FILE = 3
 
const FILE_TOO_LARGE = 12
 
const FILENAME_TOO_LONG = 14
 
const FILETYPE_BADTYPE = 9
 
const FILETYPE_MISSING = 8
 
const HOOK_ABORTED = 11
 
const ILLEGAL_FILENAME = 5
 
const MIN_LENGTH_PARTNAME = 4
 
const OK = 0
 
const OVERWRITE_EXISTING_FILE = 7
 
const SUCCESS = 0
 
const VERIFICATION_ERROR = 10
 
const WINDOWS_NONASCII_FILENAME = 13
 

Protected Member Functions

 detectScriptInSvg ( $filename, $partial)
 
 doStashFile (User $user=null)
 Implementation for stashFile() and tryStashFile(). More...
 
 runUploadStashFileHook (User $user)
 
 setTempFile ( $tempPath, $fileSize=null)
 
 verifyFile ()
 Verifies that it's ok to include the uploaded file. More...
 
 verifyMimeType ( $mime)
 Verify the MIME type. More...
 
 verifyPartialFile ()
 A verification routine suitable for partial files. More...
 

Protected Attributes

string [] $mBlackListedExtensions
 
string null $mDesiredDestName
 
string null $mDestName
 
array null $mFileProps
 
int null $mFileSize
 
string null $mFilteredName
 
string null $mFinalExtension
 
bool null $mJavaDetected
 
LocalFile $mLocalFile
 
string null $mRemoveTempFile
 
string null $mSourceType
 
UploadStashFile $mStashFile
 
string null $mSVGNSError
 
string $mTempPath
 Local file system path to the file to upload (or a local copy) More...
 
Title bool $mTitle = false
 
int $mTitleError = 0
 
TempFSFile null $tempFileObj
 Wrapper to handle deleting the temp file. More...
 

Static Protected Attributes

static $safeXmlEncodings
 

Private Member Functions

 checkAgainstArchiveDupes ( $hash)
 
 checkAgainstExistingDupes ( $hash, $ignoreLocalDupes)
 
 checkBadFileName ( $filename, $desiredFileName)
 Check whether the resulting filename is different from the desired one, but ignore things like ucfirst() and spaces/underscore things. More...
 
 checkFileSize ( $fileSize)
 
 checkLocalFileExists (LocalFile $localFile, $hash)
 
 checkLocalFileWasDeleted (LocalFile $localFile)
 
 checkOverwrite ( $user)
 Check if there's an overwrite conflict and, if so, if restrictions forbid this user from performing the upload. More...
 
 checkUnwantedFileExtensions ( $fileExtension)
 
 stripXmlNamespace ( $name)
 

Static Private Member Functions

static checkCssFragment ( $value)
 Check a block of CSS or CSS fragment for anything that looks like it is bringing in remote code. More...
 
static getUploadSessionKey (BagOStuff $store, User $user, $statusKey)
 
static getUploadSessionStore ()
 
static splitXmlNamespace ( $element)
 Divide the element name passed by the xml parser to the callback into URI and prifix. More...
 

Static Private Attributes

static $uploadHandlers = [ 'Stash', 'File', 'Url' ]
 

Detailed Description

UploadBase and subclasses are the backend of MediaWiki's file uploads.

The frontends are formed by ApiUpload and SpecialUpload.

Author
Brion Vibber
Bryan Tong Minh
Michael Dale

Definition at line 39 of file UploadBase.php.

Constructor & Destructor Documentation

◆ __construct()

UploadBase::__construct ( )

Definition at line 229 of file UploadBase.php.

Member Function Documentation

◆ checkAgainstArchiveDupes()

UploadBase::checkAgainstArchiveDupes (   $hash)
private
Parameters
string$hashsha1 hash of the file to check
Returns
string|null Name of the dupe or empty string if discovered (depending on visibility) null if the check discovered no dupes.

Definition at line 835 of file UploadBase.php.

References File\DELETED_FILE, and null.

Referenced by checkWarnings().

◆ checkAgainstExistingDupes()

UploadBase::checkAgainstExistingDupes (   $hash,
  $ignoreLocalDupes 
)
private
Parameters
string$hashsha1 hash of the file to check
bool$ignoreLocalDupesTrue to ignore local duplicates
Returns
File[] Duplicate files, if found.

Definition at line 813 of file UploadBase.php.

References $title, as, getTitle(), and RepoGroup\singleton().

Referenced by checkWarnings().

◆ checkBadFileName()

UploadBase::checkBadFileName (   $filename,
  $desiredFileName 
)
private

Check whether the resulting filename is different from the desired one, but ignore things like ucfirst() and spaces/underscore things.

Parameters
string$filename
string$desiredFileName
Returns
string|null String that was determined to be bad or null if the filename is okay

Definition at line 716 of file UploadBase.php.

References Title\capitalize(), NS_FILE, and null.

Referenced by checkWarnings().

◆ checkCssFragment()

static UploadBase::checkCssFragment (   $value)
staticprivate

Check a block of CSS or CSS fragment for anything that looks like it is bringing in remote code.

Parameters
string$valuea string of CSS
bool$propOnlyonly check css properties (start regex with :)
Returns
bool true if the CSS contains an illegal string, false if otherwise

Definition at line 1742 of file UploadBase.php.

References $matches, $value, and as.

◆ checkFileExtension()

static UploadBase::checkFileExtension (   $ext,
  $list 
)
static

Perform case-insensitive match against a list of file extensions.

Returns true if the extension is in the list.

Parameters
string$ext
array$list
Returns
bool

Definition at line 1184 of file UploadBase.php.

References $ext.

Referenced by checkUnwantedFileExtensions(), getTitle(), and verifyMimeType().

◆ checkFileExtensionList()

static UploadBase::checkFileExtensionList (   $ext,
  $list 
)
static

Perform case-insensitive match against a list of file extensions.

Returns an array of matching extensions.

Parameters
string[]$ext
string[]$list
Returns
string[]

Definition at line 1196 of file UploadBase.php.

References $ext.

Referenced by StreamFile\contentTypeFromPath(), and getTitle().

◆ checkFileSize()

UploadBase::checkFileSize (   $fileSize)
private
Parameters
int$fileSize
Returns
array warnings

Definition at line 757 of file UploadBase.php.

References $wgUploadSizeWarning.

Referenced by checkWarnings().

◆ checkLocalFileExists()

UploadBase::checkLocalFileExists ( LocalFile  $localFile,
  $hash 
)
private
Parameters
LocalFile$localFile
string$hashsha1 hash of the file to check
Returns
array warnings

Definition at line 779 of file UploadBase.php.

References as, LocalFile\getHistory(), and LocalFile\getSha1().

Referenced by checkWarnings().

◆ checkLocalFileWasDeleted()

UploadBase::checkLocalFileWasDeleted ( LocalFile  $localFile)
private

Definition at line 803 of file UploadBase.php.

References LocalFile\exists(), and File\wasDeleted().

Referenced by checkWarnings().

◆ checkOverwrite()

UploadBase::checkOverwrite (   $user)
private

Check if there's an overwrite conflict and, if so, if restrictions forbid this user from performing the upload.

Parameters
User$user
Returns
bool|array

Definition at line 1915 of file UploadBase.php.

Referenced by verifyTitlePermissions().

◆ checkSvgExternalDTD()

static UploadBase::checkSvgExternalDTD (   $type,
  $publicId,
  $systemId 
)
static

Verify that DTD urls referenced are only the standard dtds.

Browsers seem to ignore external dtds. However just to be on the safe side, only allow dtds from the svg standard.

Parameters
string$typePUBLIC or SYSTEM
string$publicIdThe well-known public identifier for the dtd
string$systemIdThe url for the external dtd
Returns
bool|array

Definition at line 1481 of file UploadBase.php.

References $type.

◆ checkSvgPICallback()

static UploadBase::checkSvgPICallback (   $target,
  $data 
)
static

Callback to filter SVG Processing Instructions.

Parameters
string$targetProcessing instruction name
string$dataProcessing instruction attribute and value
Returns
bool|array

Definition at line 1461 of file UploadBase.php.

◆ checkSvgScriptCallback()

UploadBase::checkSvgScriptCallback (   $element,
  $attribs,
  $data = null 
)
Todo:
Replace this with a whitelist filter!
Parameters
string$element
array$attribs
string | null$data
Returns
bool|array

Definition at line 1508 of file UploadBase.php.

References $attribs, $value, as, list, Sanitizer\normalizeCss(), splitXmlNamespace(), stripXmlNamespace(), and wfDebug().

◆ checkUnwantedFileExtensions()

UploadBase::checkUnwantedFileExtensions (   $fileExtension)
private
Parameters
string$fileExtensionThe file extension to check
Returns
array|null array with the following keys: 0 => string The final extension being used 1 => string[] The extensions that are allowed 2 => int The number of extensions that are allowed.

Definition at line 735 of file UploadBase.php.

References $wgCheckFileExtensions, $wgFileExtensions, $wgLang, checkFileExtension(), and null.

Referenced by checkWarnings().

◆ checkWarnings()

UploadBase::checkWarnings ( )

Check for non fatal problems with the file.

This should not assume that mTempPath is set.

Returns
mixed[] Array of warnings

Definition at line 659 of file UploadBase.php.

References checkAgainstArchiveDupes(), checkAgainstExistingDupes(), checkBadFileName(), checkFileSize(), checkLocalFileExists(), checkLocalFileWasDeleted(), checkUnwantedFileExtensions(), getLocalFile(), getTempFileSha1Base36(), and null.

◆ checkXMLEncodingMissmatch()

static UploadBase::checkXMLEncodingMissmatch (   $file)
static

Check a whitelist of xml encodings that are known not to be interpreted differently by the server's xml parser (expat) and some common browsers.

Parameters
string$filePathname to the temporary upload file
Returns
bool True if the file contains an encoding that could be misinterpreted

Definition at line 1371 of file UploadBase.php.

References $file, $matches, $wgSVGMetadataCutoff, as, null, and wfDebug().

Referenced by UploadBaseTest\testCheckXMLEncodingMissmatch().

◆ cleanupTempFile()

UploadBase::cleanupTempFile ( )

If we've modified the upload file we need to manually remove it on exit to clean up.

Definition at line 1148 of file UploadBase.php.

References wfDebug().

◆ convertVerifyErrorToStatus()

UploadBase::convertVerifyErrorToStatus (   $error)
Parameters
array$error
Returns
Status

Definition at line 2131 of file UploadBase.php.

References $code, getVerificationErrorCode(), and StatusValue\newFatal().

◆ createFromRequest()

static UploadBase::createFromRequest ( $request,
  $type = null 
)
static

Create a form of UploadBase depending on wpSourceType and initializes it.

Parameters
WebRequest&$request
string | null$type
Returns
null|UploadBase

Definition at line 181 of file UploadBase.php.

References $handler, $request, $type, null, Hooks\run(), and wfDebug().

Referenced by SpecialUpload\loadRequest().

◆ detectScript()

static UploadBase::detectScript (   $file,
  $mime,
  $extension 
)
static

Heuristic for detecting files that could contain JavaScript instructions or things that may look like HTML to a browser and are thus potentially harmful.

The present implementation will produce false positives in some situations.

Parameters
string$filePathname to the temporary upload file
string$mimeThe MIME type of the file
string$extensionThe extension of the file
Returns
bool True if the file contains something looking like embedded scripts

Definition at line 1260 of file UploadBase.php.

References $file, as, Sanitizer\decodeCharReferences(), in, null, and wfDebug().

◆ detectScriptInSvg()

UploadBase::detectScriptInSvg (   $filename,
  $partial 
)
protected
Parameters
string$filename
bool$partial
Returns
bool|array

Definition at line 1429 of file UploadBase.php.

References $mSVGNSError, and false.

Referenced by verifyFile(), and verifyPartialFile().

◆ detectVirus()

static UploadBase::detectVirus (   $file)
static

Generic wrapper function for a virus scanner program.

This relies on the $wgAntivirus and $wgAntivirusSetup variables. $wgAntivirusRequired may be used to deny upload if the scan fails.

Parameters
string$filePathname to the temporary upload file
Returns
bool|null|string False if not virus is found, null if the scan fails or is disabled, or a string containing feedback from the virus scanner if a virus was found. If textual feedback is missing but a virus was found, this function returns true.

Definition at line 1821 of file UploadBase.php.

References $command, $file, $output, $wgAntivirus, $wgAntivirusRequired, $wgAntivirusSetup, $wgOut, AV_NO_VIRUS, AV_SCAN_ABORTED, AV_SCAN_FAILED, null, there, wfDebug(), wfMessage(), and wfShellExecWithStderr().

Referenced by verifyPartialFile().

◆ doStashFile()

UploadBase::doStashFile ( User  $user = null)
protected

Implementation for stashFile() and tryStashFile().

Parameters
User | null$user
Returns
UploadStashFile Stashed file

Definition at line 1136 of file UploadBase.php.

References $file, $user, getSourceType(), and RepoGroup\singleton().

Referenced by stashFile(), and tryStashFile().

◆ fetchFile()

UploadBase::fetchFile ( )

Fetch the file.

Usually a no-op

Returns
Status

Definition at line 288 of file UploadBase.php.

References StatusValue\newGood().

◆ getExistsWarning()

static UploadBase::getExistsWarning (   $file)
static

Helper function that does various existence checks for a file.

The following checks are performed:

  • The file exists
  • Article with the same name as the file exists
  • File exists with normalized extension
  • The file looks like a thumbnail and the original exists
Parameters
File$fileThe File object to check
Returns
mixed False if the file does not exists, else an array

Definition at line 1972 of file UploadBase.php.

Referenced by ApiQueryImageInfo\getInfo().

◆ getFilenamePrefixBlacklist()

static UploadBase::getFilenamePrefixBlacklist ( )
static

Get a list of blacklisted filename prefixes from [[MediaWiki:Filename-prefix-blacklist]].

Returns
array List of prefixes

Definition at line 2077 of file UploadBase.php.

References $line, $lines, as, and wfMessage().

◆ getFileSize()

UploadBase::getFileSize ( )

Return the file size.

Returns
int

Definition at line 304 of file UploadBase.php.

References $mFileSize.

◆ getImageInfo()

UploadBase::getImageInfo (   $result)

Gets image info about the file just uploaded.

Also has the effect of setting metadata to be an 'indexed tag name' in returned API result if 'metadata' was requested. Oddly, we have to pass the "result" object down just so it can do that with the appropriate format, presumably.

Parameters
ApiResult$result
Returns
array Image info

Definition at line 2111 of file UploadBase.php.

References ApiQueryImageInfo\getInfo(), getLocalFile(), ApiQueryImageInfo\getPropertyNames(), and getStashFile().

◆ getLocalFile()

UploadBase::getLocalFile ( )

Return the local file and initializes if necessary.

Returns
LocalFile|null

Definition at line 1049 of file UploadBase.php.

References $mLocalFile, getTitle(), null, and wfLocalFile().

Referenced by checkWarnings(), getImageInfo(), performUpload(), and validateName().

◆ getMaxPhpUploadSize()

static UploadBase::getMaxPhpUploadSize ( )
static

Get the PHP maximum uploaded file size, based on ini settings.

If there is no limit or the limit can't be guessed, returns a very large number (PHP_INT_MAX).

Since
1.27
Returns
int

Definition at line 2166 of file UploadBase.php.

References wfShorthandToInteger().

Referenced by UploadForm\getSourceSection().

◆ getMaxUploadSize()

static UploadBase::getMaxUploadSize (   $forType = null)
static

Get the MediaWiki maximum uploaded file size for given type of upload, based on $wgMaxUploadSize.

Parameters
null | string$forType
Returns
int

Definition at line 2145 of file UploadBase.php.

References $wgMaxUploadSize.

Referenced by UploadFromChunks\addChunk(), UploadForm\addUploadJS(), ApiQuerySiteinfo\appendGeneralInfo(), ApiUpload\execute(), ApiUpload\getAllowedParams(), and UploadForm\getSourceSection().

◆ getRealPath()

UploadBase::getRealPath (   $srcPath)
Parameters
string$srcPathThe source path
Returns
string|bool The real path if it was a virtual URL Returns false on failure

Definition at line 320 of file UploadBase.php.

References $path, FileRepo\isVirtualUrl(), and RepoGroup\singleton().

Referenced by UploadFromChunks\continueChunks(), and UploadFromStash\initialize().

◆ getSessionStatus()

static UploadBase::getSessionStatus ( User  $user,
  $statusKey 
)
static

Get the current status of a chunked upload (used for polling)

The value will be read from cache.

Parameters
User$user
string$statusKey
Returns
Status[]|bool

Definition at line 2187 of file UploadBase.php.

Referenced by ApiUpload\getChunkResult(), ApiUpload\performUpload(), and ApiUpload\selectUploadModule().

◆ getSourceType()

UploadBase::getSourceType ( )

Returns the upload type.

Should be overridden by child classes

Since
1.18
Returns
string

Definition at line 238 of file UploadBase.php.

References null.

Referenced by doStashFile(), and verifyUpload().

◆ getStashFile()

UploadBase::getStashFile ( )
Returns
UploadStashFile|null

Definition at line 1061 of file UploadBase.php.

References $mStashFile.

Referenced by getImageInfo().

◆ getTempFileSha1Base36()

UploadBase::getTempFileSha1Base36 ( )

Get the base 36 SHA1 of the file.

Returns
string

Definition at line 312 of file UploadBase.php.

References FSFile\getSha1Base36FromPath().

Referenced by checkWarnings().

◆ getTempPath()

UploadBase::getTempPath ( )

Definition at line 1156 of file UploadBase.php.

References $mTempPath.

◆ getTitle()

◆ getUploadSessionKey()

static UploadBase::getUploadSessionKey ( BagOStuff  $store,
User  $user,
  $statusKey 
)
staticprivate
Parameters
BagOStuff$store
User$user
string$statusKey
Returns
string

Definition at line 2223 of file UploadBase.php.

References User\getId(), User\getName(), and BagOStuff\makeKey().

◆ getUploadSessionStore()

static UploadBase::getUploadSessionStore ( )
staticprivate
Returns
BagOStuff

Definition at line 2234 of file UploadBase.php.

References ObjectCache\getInstance().

◆ getVerificationErrorCode()

UploadBase::getVerificationErrorCode (   $error)
Parameters
int$error
Returns
string

Definition at line 110 of file UploadBase.php.

Referenced by UploadFromChunks\concatenateChunks(), and convertVerifyErrorToStatus().

◆ initializeFromRequest()

UploadBase::initializeFromRequest ( $request)
abstract

Initialize from a WebRequest.

Override this in a subclass.

Parameters
WebRequest&$request

Referenced by initializePathInfo().

◆ initializePathInfo()

UploadBase::initializePathInfo (   $name,
  $tempPath,
  $fileSize,
  $removeTempFile = false 
)

Initialize the path information.

Parameters
string$nameThe desired destination name
string$tempPathThe temporary path
int$fileSizeThe file size
bool$removeTempFile(false) remove the temporary file?
Exceptions
MWException

Definition at line 250 of file UploadBase.php.

References $name, $request, initializeFromRequest(), FileBackend\isStoragePath(), and setTempFile().

Referenced by UploadFromChunks\continueChunks(), UploadFromFile\initialize(), UploadFromStash\initialize(), and UploadFromUrl\initialize().

◆ isAllowed()

static UploadBase::isAllowed (   $user)
static

Returns true if the user can use this upload module or else a string identifying the missing permission.

Can be overridden by subclasses.

Parameters
User$user
Returns
bool|string

Definition at line 151 of file UploadBase.php.

References $user, and as.

Referenced by SkinTemplate\buildNavUrls(), and SpecialUpload\execute().

◆ isEmptyFile()

UploadBase::isEmptyFile ( )

Return true if the file is empty.

Returns
bool

Definition at line 296 of file UploadBase.php.

Referenced by UploadFromFile\verifyUpload(), and verifyUpload().

◆ isEnabled()

static UploadBase::isEnabled ( )
static

Returns true if uploads are enabled.

Can be override by subclasses.

Returns
bool

Definition at line 132 of file UploadBase.php.

References $wgEnableUploads, wfIniGetBool(), and wfIsHHVM().

Referenced by ApiQuerySiteinfo\appendGeneralInfo(), SkinTemplate\buildNavUrls(), ApiUpload\execute(), SpecialUpload\execute(), and SpecialUpload\userCanExecute().

◆ isThrottled()

static UploadBase::isThrottled (   $user)
static

Returns true if the user has surpassed the upload rate limit, false otherwise.

Parameters
User$user
Returns
bool

Definition at line 167 of file UploadBase.php.

References $user.

Referenced by ApiUpload\getContextResult(), and SpecialUpload\processUpload().

◆ isThumbName()

static UploadBase::isThumbName (   $filename)
static

Helper function that checks whether the filename looks like a thumbnail.

Parameters
string$filename
Returns
bool

Definition at line 2061 of file UploadBase.php.

◆ isValidRequest()

static UploadBase::isValidRequest (   $request)
static

Check whether a request if valid for this handler.

Parameters
WebRequest$request
Returns
bool

Definition at line 225 of file UploadBase.php.

◆ performUpload()

UploadBase::performUpload (   $comment,
  $pageText,
  $watch,
  $user,
  $tags = [] 
)

Really perform the upload.

Stores the file in the local repo, watches if necessary and runs the UploadComplete hook.

Parameters
string$comment
string$pageText
bool$watchWhether the file page should be added to user's watchlist. (This doesn't check $user's permissions.)
User$user
string[]$tags Change tags to add to the log entry and page revision. (This doesn't check $user's permissions.)
Returns
Status Indicating the whether the upload succeeded.

Definition at line 861 of file UploadBase.php.

References $mFileProps, $user, File\DELETE_SOURCE, WatchAction\doWatch(), getLocalFile(), getTitle(), User\IGNORE_USER_RIGHTS, StatusValue\newFatal(), null, postProcessUpload(), and Hooks\run().

◆ postProcessUpload()

UploadBase::postProcessUpload ( )

Perform extra steps after a successful upload.

Since
1.25

Definition at line 908 of file UploadBase.php.

Referenced by performUpload().

◆ runUploadStashFileHook()

UploadBase::runUploadStashFileHook ( User  $user)
protected
Parameters
User$user
Returns
array|null Error message and parameters, null if there's no error

Definition at line 1095 of file UploadBase.php.

References $mFileProps, null, and Hooks\run().

Referenced by UploadFromChunks\concatenateChunks(), and tryStashFile().

◆ setSessionStatus()

static UploadBase::setSessionStatus ( User  $user,
  $statusKey,
  $value 
)
static

Set the current status of a chunked upload (used for polling)

The value will be set in cache for 1 day

Avoid triggering this method on HTTP GET/HEAD requests

Parameters
User$user
string$statusKey
array | bool$value
Returns
void

Definition at line 2206 of file UploadBase.php.

References $value.

Referenced by ApiUpload\getChunkResult(), ApiUpload\performUpload(), AssembleUploadChunksJob\run(), and PublishStashedFileJob\run().

◆ setTempFile()

UploadBase::setTempFile (   $tempPath,
  $fileSize = null 
)
protected
Parameters
string$tempPathFile system path to temporary file containing the upload
int | null$fileSize

Definition at line 271 of file UploadBase.php.

References null.

Referenced by UploadFromChunks\concatenateChunks(), and initializePathInfo().

◆ splitExtensions()

static UploadBase::splitExtensions (   $filename)
static

Split a file into a base name and all dot-delimited 'extensions' on the end.

Some web server configurations will fall back to earlier pseudo-'extensions' to determine type and execute scripts, so the blacklist needs to check them all.

Parameters
string$filename
Returns
array [ string, string[] ]

Definition at line 1169 of file UploadBase.php.

Referenced by StreamFile\contentTypeFromPath(), and getTitle().

◆ splitXmlNamespace()

static UploadBase::splitXmlNamespace (   $element)
staticprivate

Divide the element name passed by the xml parser to the callback into URI and prifix.

Parameters
string$element
Returns
array Containing the namespace URI and prefix

Definition at line 1791 of file UploadBase.php.

References $name.

Referenced by checkSvgScriptCallback().

◆ stashFile()

UploadBase::stashFile ( User  $user = null)

If the user does not supply all necessary information in the first upload form submission (either by accident or by design) then we may want to stash the file temporarily, get more information, and publish the file later.

This method will stash a file in a temporary directory for later processing, and save the necessary descriptive info into the database. This method returns the file object, which also has a 'fileKey' property which can be passed through a form or API request to find this stashed file again.

Deprecated:
since 1.28 Use tryStashFile() instead
Parameters
User | null$user
Returns
UploadStashFile Stashed file
Exceptions
UploadStashBadPathException
UploadStashFileException
UploadStashNotLoggedInException

Definition at line 1124 of file UploadBase.php.

References $user, doStashFile(), and wfDeprecated().

◆ stripXmlNamespace()

UploadBase::stripXmlNamespace (   $name)
private
Parameters
string$name
Returns
string

Definition at line 1804 of file UploadBase.php.

References $name.

Referenced by checkSvgScriptCallback().

◆ tryStashFile()

UploadBase::tryStashFile ( User  $user,
  $isPartial = false 
)

Like stashFile(), but respects extensions' wishes to prevent the stashing.

verifyUpload() must be called before calling this method (unless $isPartial is true).

Upload stash exceptions are also caught and converted to an error status.

Since
1.28
Parameters
User$user
bool$isPartialPass true if this is a part of a chunked upload (not a complete file).
Returns
Status If successful, value is an UploadStashFile instance

Definition at line 1076 of file UploadBase.php.

References $e, $file, doStashFile(), StatusValue\newFatal(), StatusValue\newGood(), and runUploadStashFileHook().

◆ userCanReUpload()

static UploadBase::userCanReUpload ( User  $user,
File  $img 
)
static

Check if a user is the last uploader.

Parameters
User$user
File$img
Returns
bool

Definition at line 1945 of file UploadBase.php.

Referenced by ImagePage\uploadLinksBox().

◆ validateName()

UploadBase::validateName ( )

Verify that the name is valid and, if necessary, that we can overwrite.

Returns
mixed True if valid, otherwise and array with 'status' and other keys

Definition at line 391 of file UploadBase.php.

References $mBlackListedExtensions, $mFilteredName, $mFinalExtension, $mTitleError, getLocalFile(), and getTitle().

Referenced by verifyUpload().

◆ verifyExtension()

static UploadBase::verifyExtension (   $mime,
  $extension 
)
static

Checks if the MIME type of the uploaded file matches the file extension.

Parameters
string$mimeThe MIME type of the uploaded file
string$extensionThe filename extension that the file is to be served with
Returns
bool

Definition at line 1207 of file UploadBase.php.

References MediaWiki\MediaWikiServices\getInstance(), null, and wfDebug().

Referenced by verifyFile().

◆ verifyFile()

UploadBase::verifyFile ( )
protected

Verifies that it's ok to include the uploaded file.

Returns
mixed True of the file is verified, array otherwise.

Definition at line 455 of file UploadBase.php.

References $handler, $mFinalExtension, $wgDisableUploadScriptChecks, $wgVerifyMimeType, detectScriptInSvg(), MediaHandler\getHandler(), Hooks\run(), verifyExtension(), verifyPartialFile(), and wfDebug().

Referenced by verifyUpload().

◆ verifyMimeType()

UploadBase::verifyMimeType (   $mime)
protected

Verify the MIME type.

Note
Only checks that it is not an evil MIME. The "does it have correct extension given its MIME type?" check is in verifyFile. in verifyFile() that MIME type and file extension correlate.
Parameters
string$mimeRepresenting the MIME
Returns
mixed True if the file is verified, an array otherwise

Definition at line 421 of file UploadBase.php.

References $wgMimeTypeBlacklist, $wgVerifyMimeType, $wgVerifyMimeTypeIE, as, checkFileExtension(), MediaWiki\MediaWikiServices\getInstance(), and wfDebug().

Referenced by verifyPartialFile().

◆ verifyPartialFile()

UploadBase::verifyPartialFile ( )
protected

A verification routine suitable for partial files.

Runs the blacklist checks, but not any checks that may assume the entire file is present.

Returns
mixed True for valid or array with error message key.

Definition at line 516 of file UploadBase.php.

References $wgAllowJavaUploads, $wgDisableUploadScriptChecks, detectScriptInSvg(), detectVirus(), getTitle(), ZipDirectoryReader\read(), and verifyMimeType().

Referenced by UploadFromChunks\verifyChunk(), and verifyFile().

◆ verifyPermissions()

UploadBase::verifyPermissions (   $user)

Alias for verifyTitlePermissions.

The function was originally 'verifyPermissions', but that suggests it's checking the user, when it's really checking the title + user combination.

Parameters
User$userUser object to verify the permissions against
Returns
mixed An array as returned by getUserPermissionsErrors or true in case the user has proper permissions.

Definition at line 606 of file UploadBase.php.

References $user, and verifyTitlePermissions().

◆ verifyTitlePermissions()

UploadBase::verifyTitlePermissions (   $user)

Check whether the user can edit, upload and create the image.

This checks only against the current title; if it returns errors, it may very well be that another title will not give errors. Therefore isAllowed() should be called as well for generic is-user-blocked or can-user-upload checking.

Parameters
User$userUser object to verify the permissions against
Returns
mixed An array as returned by getUserPermissionsErrors or true in case the user has proper permissions.

Definition at line 621 of file UploadBase.php.

References $user, checkOverwrite(), getTitle(), and wfArrayDiff2().

Referenced by verifyPermissions().

◆ verifyUpload()

UploadBase::verifyUpload ( )

Verify whether the upload is sane.

Returns
mixed Const self::OK or else an array with error information

Definition at line 342 of file UploadBase.php.

References getSourceType(), isEmptyFile(), validateName(), and verifyFile().

◆ zipEntryCallback()

UploadBase::zipEntryCallback (   $entry)

Callback for ZipDirectoryReader to detect Java class files.

Parameters
array$entry

Definition at line 577 of file UploadBase.php.

Member Data Documentation

◆ $mBlackListedExtensions

string [] UploadBase::$mBlackListedExtensions
protected

Definition at line 69 of file UploadBase.php.

Referenced by validateName().

◆ $mDesiredDestName

string null UploadBase::$mDesiredDestName
protected

Definition at line 45 of file UploadBase.php.

Referenced by getTitle(), and UploadFromChunks\verifyChunk().

◆ $mDestName

string null UploadBase::$mDestName
protected

Definition at line 47 of file UploadBase.php.

◆ $mFileProps

array null UploadBase::$mFileProps
protected

Definition at line 67 of file UploadBase.php.

Referenced by performUpload(), and runUploadStashFileHook().

◆ $mFileSize

int null UploadBase::$mFileSize
protected

Definition at line 65 of file UploadBase.php.

Referenced by getFileSize().

◆ $mFilteredName

string null UploadBase::$mFilteredName
protected

Definition at line 57 of file UploadBase.php.

Referenced by validateName().

◆ $mFinalExtension

string null UploadBase::$mFinalExtension
protected

Definition at line 59 of file UploadBase.php.

Referenced by getTitle(), validateName(), and verifyFile().

◆ $mJavaDetected

bool null UploadBase::$mJavaDetected
protected

Definition at line 71 of file UploadBase.php.

◆ $mLocalFile

LocalFile UploadBase::$mLocalFile
protected

Definition at line 61 of file UploadBase.php.

Referenced by getLocalFile().

◆ $mRemoveTempFile

string null UploadBase::$mRemoveTempFile
protected

Definition at line 49 of file UploadBase.php.

◆ $mSourceType

string null UploadBase::$mSourceType
protected

Definition at line 51 of file UploadBase.php.

◆ $mStashFile

UploadStashFile UploadBase::$mStashFile
protected

Definition at line 63 of file UploadBase.php.

Referenced by UploadFromChunks\doStashFile(), and getStashFile().

◆ $mSVGNSError

string null UploadBase::$mSVGNSError
protected

Definition at line 73 of file UploadBase.php.

Referenced by detectScriptInSvg().

◆ $mTempPath

string UploadBase::$mTempPath
protected

Local file system path to the file to upload (or a local copy)

Definition at line 41 of file UploadBase.php.

Referenced by UploadFromChunks\addChunk(), and getTempPath().

◆ $mTitle

Title bool UploadBase::$mTitle = false
protected

Definition at line 53 of file UploadBase.php.

Referenced by getTitle().

◆ $mTitleError

int UploadBase::$mTitleError = 0
protected

Definition at line 55 of file UploadBase.php.

Referenced by validateName().

◆ $safeXmlEncodings

UploadBase::$safeXmlEncodings
staticprotected
Initial value:
= [
'UTF-8',
'ISO-8859-1',
'ISO-8859-2',
'UTF-16',
'UTF-32',
'WINDOWS-1250',
'WINDOWS-1251',
'WINDOWS-1252',
'WINDOWS-1253',
'WINDOWS-1254',
'WINDOWS-1255',
'WINDOWS-1256',
'WINDOWS-1257',
'WINDOWS-1258',
]

Definition at line 75 of file UploadBase.php.

◆ $tempFileObj

TempFSFile null UploadBase::$tempFileObj
protected

Wrapper to handle deleting the temp file.

Definition at line 43 of file UploadBase.php.

◆ $uploadHandlers

UploadBase::$uploadHandlers = [ 'Stash', 'File', 'Url' ]
staticprivate

Definition at line 172 of file UploadBase.php.

◆ EMPTY_FILE

const UploadBase::EMPTY_FILE = 3

◆ FILE_TOO_LARGE

const UploadBase::FILE_TOO_LARGE = 12

◆ FILENAME_TOO_LONG

const UploadBase::FILENAME_TOO_LONG = 14

◆ FILETYPE_BADTYPE

const UploadBase::FILETYPE_BADTYPE = 9

◆ FILETYPE_MISSING

const UploadBase::FILETYPE_MISSING = 8

◆ HOOK_ABORTED

const UploadBase::HOOK_ABORTED = 11

◆ ILLEGAL_FILENAME

const UploadBase::ILLEGAL_FILENAME = 5

◆ MIN_LENGTH_PARTNAME

const UploadBase::MIN_LENGTH_PARTNAME = 4

◆ OK

◆ OVERWRITE_EXISTING_FILE

const UploadBase::OVERWRITE_EXISTING_FILE = 7

Definition at line 97 of file UploadBase.php.

◆ SUCCESS

const UploadBase::SUCCESS = 0

Definition at line 92 of file UploadBase.php.

◆ VERIFICATION_ERROR

const UploadBase::VERIFICATION_ERROR = 10

◆ WINDOWS_NONASCII_FILENAME

const UploadBase::WINDOWS_NONASCII_FILENAME = 13

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