Backwards compatible, if not set to an array, applies to all uploads. If set to an array, per upload type maximums can be set, using the file and url keys. If the * key is set this value will be used as maximum for non-specified types.
note that this changes the cache key making all old entries in the parser cache invalid you
can set $wgUseEditSectionTokens to false to disable this and keep your old parser cache entries.
Note that this feature should reduce parser cache fragmentation when enabled.
+* $wgMaxUploadSize may now be set to an array to specify the upload size limit
+ per upload type.
=== New features in 1.18 ===
* Added a special page, disabled by default, that allows users with the
$wgAllowAsyncCopyUploads = false;
/**
- * Max size for uploads, in bytes. Applies to all uploads.
+ * Max size for uploads, in bytes. If not set to an array, applies to all
+ * uploads. If set to an array, per upload type maximums can be set, using the
+ * file and url keys. If the * key is set this value will be used as maximum
+ * for non-specified types.
+ *
+ * For example:
+ * $wgUploadSize = array(
+ * '*' => 250 * 1024,
+ * 'url' => 500 * 1024,
+ * );
+ * Sets the maximum for all uploads to 250 kB except for upload-by-url, which
+ * will have a maximum of 500 kB.
+ *
*/
$wgMaxUploadSize = 1024*1024*100; # 100MB
*/
protected function getSourceSection() {
global $wgLang, $wgUser, $wgRequest;
- global $wgMaxUploadSize;
if ( $this->mSessionKey ) {
return array(
wfShorthandToInteger( min(
wfShorthandToInteger(
ini_get( 'upload_max_filesize' )
- ), $wgMaxUploadSize
+ ), UploadBase::getMaxUploadSize( 'file' )
) )
)
) . ' ' . wfMsgHtml( 'upload_source_file' ),
'radio' => &$radio,
'help' => wfMsgExt( 'upload-maxfilesize',
array( 'parseinline', 'escapenoentities' ),
- $wgLang->formatSize( $wgMaxUploadSize )
+ $wgLang->formatSize( UploadBase::getMaxUploadSize( 'url' ) )
) . ' ' . wfMsgHtml( 'upload_source_url' ),
'checked' => $selectedSourceType == 'url',
);
}
public function __construct() {}
+
+ /**
+ * Returns the upload type. Should be overridden by child classes
+ *
+ * @since 1.18
+ * @return string
+ */
+ public function getSourceType() { return null; }
/**
* Initialize the path information
/**
* Honor $wgMaxUploadSize
*/
- global $wgMaxUploadSize;
- if( $this->mFileSize > $wgMaxUploadSize ) {
+ $maxSize = self::getMaxUploadSize( $this->getSourceType() );
+ if( $this->mFileSize > $maxSize ) {
return array(
'status' => self::FILE_TOO_LARGE,
- 'max' => $wgMaxUploadSize,
+ 'max' => $maxSize,
);
}
public function stashSessionFile( $key = null ) {
$stash = new UploadStash();
$data = array(
- 'mFileProps' => $this->mFileProps
+ 'mFileProps' => $this->mFileProps,
+ 'mSourceType' => $this->getSourceType(),
);
$file = $stash->stashFile( $this->mTempPath, $data, $key );
$this->mLocalFile = $file;
unset( $code['status'] );
return Status::newFatal( $this->getVerificationErrorCode( $code ), $error );
}
+
+ public static function getMaxUploadSize( $forType = null ) {
+ global $wgMaxUploadSize;
+
+ if ( is_array( $wgMaxUploadSize ) ) {
+ if ( !is_null( $forType) && isset( $wgMaxUploadSize[$forType] ) ) {
+ return $wgMaxUploadSize[$forType];
+ } else {
+ return $wgMaxUploadSize['*'];
+ }
+ } else {
+ return intval( $wgMaxUploadSize );
+ }
+
+ }
}
return true;
}
+ public function getSourceType() { return 'file'; }
+
public function verifyUpload() {
# Check for a post_max_size or upload_max_size overflow, so that a
# proper error can be shown to the user
if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
if ( $this->mUpload->isIniSizeOverflow() ) {
- global $wgMaxUploadSize;
return array(
'status' => UploadBase::FILE_TOO_LARGE,
'max' => min(
- $wgMaxUploadSize,
+ self::getMaxUploadSize( $this->getSourceType() ),
wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
wfShorthandToInteger( ini_get( 'post_max_size' ) )
),
$this->mSessionKey = $sessionKey;
$this->mVirtualTempPath = $sessionData['mTempPath'];
$this->mFileProps = $sessionData['mFileProps'];
+ $this->mSourceType = isset( $sessionData['mSourceType'] ) ?
+ $sessionData['mSourceType'] : null;
}
public function initializeFromRequest( &$request ) {
return $this->initialize( $desiredDestName, $sessionKey, $sessionData[$sessionKey] );
}
+ public function getSourceType() {
+ return $this->mSourceType;
+ }
+
/**
* File has been previously verified so no need to do so again.
*/
&& $wgUser->isAllowed( 'upload_by_url' );
}
+ public function getSourceType() { return 'url'; }
public function fetchFile() {
if ( !Http::isValidURI( $this->mUrl ) ) {