MediaWiki
REL1_20
|
UploadBase and subclasses are the backend of MediaWiki's file uploads. More...
Public Member Functions | |
__construct () | |
checkSvgScriptCallback ($element, $attribs) | |
checkWarnings () | |
Check for non fatal problems with the file. | |
cleanupTempFile () | |
If we've modified the upload file we need to manually remove it on exit to clean up. | |
convertVerifyErrorToStatus ($error) | |
fetchFile () | |
Fetch the file. | |
getFileSize () | |
Return the file size. | |
getImageInfo ($result) | |
Gets image info about the file just uploaded. | |
getLocalFile () | |
Return the local file and initializes if necessary. | |
getRealPath ($srcPath) | |
getSourceType () | |
Returns the upload type. | |
getTempPath () | |
getTitle () | |
Returns the title of the file to be uploaded. | |
getVerificationErrorCode ($error) | |
initializeFromRequest (&$request) | |
Initialize from a WebRequest. | |
initializePathInfo ($name, $tempPath, $fileSize, $removeTempFile=false) | |
Initialize the path information. | |
isEmptyFile () | |
Return true if the file is empty. | |
performUpload ($comment, $pageText, $watch, $user) | |
Really perform the upload. | |
stashFile () | |
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. | |
stashFileGetKey () | |
Stash a file in a temporary directory, returning a key which can be used to find the file again. | |
stashSession () | |
alias for stashFileGetKey, for backwards compatibility | |
verifyPermissions ($user) | |
Alias for verifyTitlePermissions. | |
verifyTitlePermissions ($user) | |
Check whether the user can edit, upload and create the image. | |
verifyUpload () | |
Verify whether the upload is sane. | |
zipEntryCallback ($entry) | |
Callback for ZipDirectoryReader to detect Java class files. | |
Static Public Member Functions | |
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 | 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. | |
static | createFromRequest (&$request, $type=null) |
Create a form of UploadBase depending on wpSourceType and initializes it. | |
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. | |
static | detectVirus ($file) |
Generic wrapper function for a virus scanner program. | |
static | getExistsWarning ($file) |
Helper function that does various existence checks for a file. | |
static | getFilenamePrefixBlacklist () |
Get a list of blacklisted filename prefixes from [[MediaWiki:Filename-prefix-blacklist]]. | |
static | getMaxUploadSize ($forType=null) |
static | isAllowed ($user) |
Returns true if the user can use this upload module or else a string identifying the missing permission. | |
static | isEnabled () |
Returns true if uploads are enabled. | |
static | isThumbName ($filename) |
Helper function that checks whether the filename looks like a thumbnail. | |
static | isValidRequest ($request) |
Check whether a request if valid for this handler. | |
static | splitExtensions ($filename) |
Split a file into a base name and all dot-delimited 'extensions' on the end. | |
static | userCanReUpload (User $user, $img) |
Check if a user is the last uploader. | |
static | verifyExtension ($mime, $extension) |
Checks if the mime type of the uploaded file matches the file extension. | |
Public Attributes | |
$mDestName | |
$mFileProps | |
$mFileSize | |
$mFinalExtension | |
$mRemoveTempFile | |
$mSourceType | |
$mTitleError = 0 | |
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 | UPLOAD_VERIFICATION_ERROR = 11 |
const | VERIFICATION_ERROR = 10 |
const | WINDOWS_NONASCII_FILENAME = 13 |
Static Public Attributes | |
static | $uploadHandlers = array( 'Stash', 'File', 'Url' ) |
Protected Member Functions | |
detectScriptInSvg ($filename) | |
validateName () | |
Verify that the name is valid and, if necessary, that we can overwrite. | |
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 | |
$mBlackListedExtensions | |
$mDesiredDestName | |
$mFilteredName | |
$mJavaDetected | |
$mLocalFile | |
$mTempPath | |
$mTitle = false | |
Static Protected Attributes | |
static | $safeXmlEncodings = array( 'UTF-8', 'ISO-8859-1', 'ISO-8859-2', 'UTF-16', 'UTF-32' ) |
Private Member Functions | |
checkOverwrite ($user) | |
Check if there's an overwrite conflict and, if so, if restrictions forbid this user from performing the upload. | |
stripXmlNamespace ($name) |
UploadBase and subclasses are the backend of MediaWiki's file uploads.
The frontends are formed by ApiUpload and SpecialUpload.
See also includes/docs/upload.txt
Definition at line 40 of file UploadBase.php.
Definition at line 181 of file UploadBase.php.
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.
$ext | String |
$list | Array |
Definition at line 889 of file UploadBase.php.
References $ext.
Referenced by checkWarnings(), and verifyMimeType().
static UploadBase::checkFileExtensionList | ( | $ | ext, |
$ | list | ||
) | [static] |
Perform case-insensitive match against a list of file extensions.
Returns an array of matching extensions.
$ext | Array |
$list | Array |
Definition at line 901 of file UploadBase.php.
References $ext.
Referenced by StreamFile\contentTypeFromPath(), and getTitle().
UploadBase::checkOverwrite | ( | $ | user | ) | [private] |
Check if there's an overwrite conflict and, if so, if restrictions forbid this user from performing the upload.
$user | User |
Definition at line 1369 of file UploadBase.php.
Referenced by verifyTitlePermissions().
UploadBase::checkSvgScriptCallback | ( | $ | element, |
$ | attribs | ||
) |
$element | string |
$attribs | array |
Definition at line 1151 of file UploadBase.php.
References $matches, $value, stripXmlNamespace(), and wfDebug().
Check for non fatal problems with the file.
Reimplemented in UploadFromUrl.
Definition at line 582 of file UploadBase.php.
References $title, $wgFileExtensions, $wgLang, Title\capitalize(), checkFileExtension(), getExistsWarning(), getLocalFile(), FSFile\getSha1Base36FromPath(), getTitle(), RepoGroup\singleton(), wfProfileIn(), and wfProfileOut().
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.
string | $file | pathname to the temporary upload file |
Definition at line 1088 of file UploadBase.php.
References $file, $matches, wfDebug(), wfRestoreWarnings(), and wfSuppressWarnings().
If we've modified the upload file we need to manually remove it on exit to clean up.
Definition at line 855 of file UploadBase.php.
References wfDebug().
UploadBase::convertVerifyErrorToStatus | ( | $ | error | ) |
$error | array |
Definition at line 1571 of file UploadBase.php.
References getVerificationErrorCode(), and Status\newFatal().
static UploadBase::createFromRequest | ( | &$ | request, |
$ | type = null |
||
) | [static] |
Create a form of UploadBase depending on wpSourceType and initializes it.
$request | WebRequest |
$type |
Definition at line 135 of file UploadBase.php.
References wfDebug(), and wfRunHooks().
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.
$file | String: pathname to the temporary upload file |
$mime | String: the mime type of the file |
$extension | String: the extension of the file |
Definition at line 954 of file UploadBase.php.
References $file, $mime, Sanitizer\decodeCharReferences(), wfDebug(), wfProfileIn(), and wfProfileOut().
UploadBase::detectScriptInSvg | ( | $ | filename | ) | [protected] |
$filename | string |
Definition at line 1140 of file UploadBase.php.
Referenced by verifyPartialFile().
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.
$file | String: pathname to the temporary upload file |
Definition at line 1268 of file UploadBase.php.
References $command, $file, $output, $wgOut, wfDebug(), wfEscapeShellArg(), wfMessage(), wfProfileIn(), wfProfileOut(), and wfShellExec().
Referenced by verifyPartialFile().
Fetch the file.
Usually a no-op
Reimplemented in UploadFromUrl.
Definition at line 218 of file UploadBase.php.
References Status\newGood().
static UploadBase::getExistsWarning | ( | $ | file | ) | [static] |
Helper function that does various existence checks for a file.
The following checks are performed:
Definition at line 1426 of file UploadBase.php.
Referenced by checkWarnings().
static UploadBase::getFilenamePrefixBlacklist | ( | ) | [static] |
Get a list of blacklisted filename prefixes from [[MediaWiki:Filename-prefix-blacklist]].
Definition at line 1521 of file UploadBase.php.
References $comment, $lines, and wfMessage().
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.
$result | ApiResult: |
Definition at line 1553 of file UploadBase.php.
References $file, $result, ApiQueryImageInfo\getInfo(), getLocalFile(), and ApiQueryImageInfo\getPropertyNames().
Return the local file and initializes if necessary.
Definition at line 802 of file UploadBase.php.
References getTitle(), and wfLocalFile().
Referenced by checkWarnings(), getImageInfo(), performUpload(), and validateName().
static UploadBase::getMaxUploadSize | ( | $ | forType = null | ) | [static] |
$forType | null|string |
Definition at line 1581 of file UploadBase.php.
Referenced by UploadFromChunks\addChunk(), ApiQuerySiteinfo\appendGeneralInfo(), and verifyUpload().
UploadBase::getRealPath | ( | $ | srcPath | ) |
$srcPath | String: the source path |
Definition at line 242 of file UploadBase.php.
References RepoGroup\singleton(), wfProfileIn(), and wfProfileOut().
Referenced by UploadFromChunks\continueChunks(), and UploadFromStash\initialize().
Returns the upload type.
Should be overridden by child classes
Reimplemented in UploadFromUrl, UploadFromStash, and UploadFromFile.
Definition at line 189 of file UploadBase.php.
Referenced by stashFile(), and verifyUpload().
Definition at line 862 of file UploadBase.php.
Returns the title of the file to be uploaded.
Sets mTitleError in case the name was illegal.
Definition at line 690 of file UploadBase.php.
References $ext, $mime, $title, $wgFileExtensions, checkFileExtensionList(), FILENAME_TOO_LONG, FILETYPE_BADTYPE, FILETYPE_MISSING, ILLEGAL_FILENAME, Title\makeTitleSafe(), MIN_LENGTH_PARTNAME, Title\newFromText(), MimeMagic\singleton(), splitExtensions(), wfIsWindows(), wfStripIllegalFilenameChars(), and WINDOWS_NONASCII_FILENAME.
Referenced by checkWarnings(), getLocalFile(), UploadFromUrl\insertJob(), performUpload(), UploadTestHandler\testTitleValidation(), validateName(), verifyPartialFile(), and verifyTitlePermissions().
UploadBase::getVerificationErrorCode | ( | $ | error | ) |
$error | int |
Definition at line 72 of file UploadBase.php.
Referenced by UploadFromChunks\concatenateChunks(), and convertVerifyErrorToStatus().
UploadBase::initializeFromRequest | ( | &$ | request | ) | [abstract] |
Initialize from a WebRequest.
Override this in a subclass.
Reimplemented in UploadTestHandler, UploadFromStash, UploadFromUrl, and UploadFromFile.
UploadBase::initializePathInfo | ( | $ | name, |
$ | tempPath, | ||
$ | fileSize, | ||
$ | removeTempFile = false |
||
) |
Initialize the path information.
$name | string the desired destination name |
$tempPath | string the temporary path |
$fileSize | int the file size |
$removeTempFile | bool (false) remove the temporary file? |
MWException |
Definition at line 199 of file UploadBase.php.
References FileBackend\isStoragePath().
Referenced by UploadFromChunks\continueChunks(), UploadFromStash\initialize(), and UploadFromUrl\initialize().
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 overriden by subclasses.
$user | User |
Reimplemented in UploadFromUrl.
Definition at line 116 of file UploadBase.php.
References $user.
Referenced by SkinTemplate\buildNavUrls(), StandardTemplate\quickBar(), CologneBlueTemplate\quickBar(), and NostalgiaTemplate\topLinks().
Return true if the file is empty.
Definition at line 226 of file UploadBase.php.
Referenced by verifyUpload().
static UploadBase::isEnabled | ( | ) | [static] |
Returns true if uploads are enabled.
Can be override by subclasses.
Reimplemented in UploadFromUrl.
Definition at line 97 of file UploadBase.php.
References wfIniGetBool(), and wfIsHipHop().
Referenced by SkinTemplate\buildNavUrls(), ApiUpload\execute(), StandardTemplate\quickBar(), CologneBlueTemplate\quickBar(), and NostalgiaTemplate\topLinks().
static UploadBase::isThumbName | ( | $ | filename | ) | [static] |
Helper function that checks whether the filename looks like a thumbnail.
$filename | string |
Definition at line 1506 of file UploadBase.php.
References $n.
static UploadBase::isValidRequest | ( | $ | request | ) | [static] |
Check whether a request if valid for this handler.
$request |
Reimplemented in UploadFromUrl, UploadFromStash, and UploadFromFile.
Definition at line 177 of file UploadBase.php.
UploadBase::performUpload | ( | $ | comment, |
$ | pageText, | ||
$ | watch, | ||
$ | user | ||
) |
Really perform the upload.
Stores the file in the local repo, watches if necessary and runs the UploadComplete hook.
$comment | |
$pageText | |
$watch | |
$user | User |
Reimplemented in UploadFromUrl, UploadFromStash, and UploadFromChunks.
Definition at line 660 of file UploadBase.php.
References $comment, $user, File\DELETE_SOURCE, getLocalFile(), getTitle(), wfProfileIn(), wfProfileOut(), and wfRunHooks().
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.
$filename | string |
Definition at line 875 of file UploadBase.php.
Referenced by StreamFile\contentTypeFromPath(), and getTitle().
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.
Reimplemented in UploadFromStash, and UploadFromChunks.
Definition at line 821 of file UploadBase.php.
References $file, getSourceType(), RepoGroup\singleton(), wfProfileIn(), and wfProfileOut().
Referenced by stashFileGetKey().
Stash a file in a temporary directory, returning a key which can be used to find the file again.
See stashFile().
Definition at line 838 of file UploadBase.php.
References stashFile().
Referenced by stashSession().
alias for stashFileGetKey, for backwards compatibility
Reimplemented in UploadFromStash.
Definition at line 847 of file UploadBase.php.
References stashFileGetKey().
Referenced by UploadFromUrl\insertJob().
UploadBase::stripXmlNamespace | ( | $ | name | ) | [private] |
$name | string |
Definition at line 1252 of file UploadBase.php.
Referenced by checkSvgScriptCallback().
static UploadBase::userCanReUpload | ( | User $ | user, |
$ | img | ||
) | [static] |
Check if a user is the last uploader.
$user | User object |
$img | String: image name |
Definition at line 1398 of file UploadBase.php.
UploadBase::validateName | ( | ) | [protected] |
Verify that the name is valid and, if necessary, that we can overwrite.
Definition at line 325 of file UploadBase.php.
References $result, getLocalFile(), and getTitle().
Referenced by verifyUpload().
static UploadBase::verifyExtension | ( | $ | mime, |
$ | extension | ||
) | [static] |
Checks if the mime type of the uploaded file matches the file extension.
$mime | String: the mime type of the uploaded file |
$extension | String: the filename extension that the file is to be served with |
Definition at line 912 of file UploadBase.php.
References $mime, MimeMagic\singleton(), and wfDebug().
Referenced by verifyFile().
UploadBase::verifyFile | ( | ) | [protected] |
Verifies that it's ok to include the uploaded file.
Definition at line 389 of file UploadBase.php.
References $mime, MediaHandler\getHandler(), FSFile\getPropsFromPath(), verifyExtension(), verifyPartialFile(), wfDebug(), wfProfileIn(), wfProfileOut(), and wfRunHooks().
Referenced by verifyUpload().
UploadBase::verifyMimeType | ( | $ | mime | ) | [protected] |
Verify the mime type.
$mime | string representing the mime |
Definition at line 353 of file UploadBase.php.
References $mime, checkFileExtension(), MimeMagic\singleton(), wfDebug(), wfProfileIn(), and wfProfileOut().
Referenced by 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.
Definition at line 439 of file UploadBase.php.
References $mime, detectScriptInSvg(), detectVirus(), FSFile\getPropsFromPath(), getTitle(), ZipDirectoryReader\read(), verifyMimeType(), wfProfileIn(), and wfProfileOut().
Referenced by UploadFromChunks\verifyChunk(), and verifyFile().
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.
$user | User object to verify the permissions against |
Definition at line 532 of file UploadBase.php.
References $user, and 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.
$user | User object to verify the permissions against |
Reimplemented in UploadFromUrl.
Definition at line 547 of file UploadBase.php.
References $user, checkOverwrite(), getTitle(), and wfArrayDiff2().
Referenced by verifyPermissions().
Verify whether the upload is sane.
Reimplemented in UploadFromUrl, and UploadFromFile.
Definition at line 261 of file UploadBase.php.
References $result, getMaxUploadSize(), getSourceType(), isEmptyFile(), validateName(), verifyFile(), wfProfileIn(), wfProfileOut(), and wfRunHooks().
UploadBase::zipEntryCallback | ( | $ | entry | ) |
Callback for ZipDirectoryReader to detect Java class files.
Definition at line 505 of file UploadBase.php.
UploadBase::$mBlackListedExtensions [protected] |
Definition at line 46 of file UploadBase.php.
UploadBase::$mDesiredDestName [protected] |
Definition at line 42 of file UploadBase.php.
UploadBase::$mDestName |
Definition at line 42 of file UploadBase.php.
UploadBase::$mFileProps |
Reimplemented in UploadFromStash.
Definition at line 45 of file UploadBase.php.
UploadBase::$mFileSize |
Definition at line 45 of file UploadBase.php.
UploadBase::$mFilteredName [protected] |
Definition at line 44 of file UploadBase.php.
UploadBase::$mFinalExtension |
Definition at line 44 of file UploadBase.php.
UploadBase::$mJavaDetected [protected] |
Definition at line 47 of file UploadBase.php.
UploadBase::$mLocalFile [protected] |
Definition at line 45 of file UploadBase.php.
UploadBase::$mRemoveTempFile |
Definition at line 42 of file UploadBase.php.
UploadBase::$mSourceType |
Reimplemented in UploadFromStash.
Definition at line 42 of file UploadBase.php.
UploadBase::$mTempPath [protected] |
Reimplemented in UploadFromUrl.
Definition at line 41 of file UploadBase.php.
UploadBase::$mTitle = false [protected] |
Definition at line 43 of file UploadBase.php.
UploadBase::$mTitleError = 0 |
Definition at line 43 of file UploadBase.php.
UploadBase::$safeXmlEncodings = array( 'UTF-8', 'ISO-8859-1', 'ISO-8859-2', 'UTF-16', 'UTF-32' ) [static, protected] |
Definition at line 49 of file UploadBase.php.
UploadBase::$uploadHandlers = array( 'Stash', 'File', 'Url' ) [static] |
Definition at line 126 of file UploadBase.php.
const UploadBase::EMPTY_FILE = 3 |
Definition at line 53 of file UploadBase.php.
Referenced by UploadTest\testVerifyUpload().
const UploadBase::FILE_TOO_LARGE = 12 |
Definition at line 64 of file UploadBase.php.
const UploadBase::FILENAME_TOO_LONG = 14 |
Definition at line 66 of file UploadBase.php.
Referenced by UploadTest\dataTestTitleValidation(), and getTitle().
const UploadBase::FILETYPE_BADTYPE = 9 |
Definition at line 58 of file UploadBase.php.
Referenced by getTitle().
const UploadBase::FILETYPE_MISSING = 8 |
Definition at line 57 of file UploadBase.php.
Referenced by UploadTest\dataTestTitleValidation(), and getTitle().
const UploadBase::HOOK_ABORTED = 11 |
Definition at line 63 of file UploadBase.php.
const UploadBase::ILLEGAL_FILENAME = 5 |
Definition at line 55 of file UploadBase.php.
Referenced by UploadTest\dataTestTitleValidation(), and getTitle().
const UploadBase::MIN_LENGTH_PARTNAME = 4 |
Definition at line 54 of file UploadBase.php.
Referenced by UploadTest\dataTestTitleValidation(), and getTitle().
const UploadBase::OK = 0 |
Definition at line 52 of file UploadBase.php.
Referenced by UploadFromChunks\concatenateChunks(), UploadTest\dataTestTitleValidation(), UploadTest\testMaxUploadSize(), UploadTest\testTitleValidation(), UploadTestHandler\testTitleValidation(), and UploadFromUrl\verifyUpload().
const UploadBase::OVERWRITE_EXISTING_FILE = 7 |
Definition at line 56 of file UploadBase.php.
const UploadBase::SUCCESS = 0 |
Definition at line 51 of file UploadBase.php.
const UploadBase::UPLOAD_VERIFICATION_ERROR = 11 |
Definition at line 62 of file UploadBase.php.
const UploadBase::VERIFICATION_ERROR = 10 |
Definition at line 59 of file UploadBase.php.
const UploadBase::WINDOWS_NONASCII_FILENAME = 13 |
Definition at line 65 of file UploadBase.php.
Referenced by getTitle().