protected $mTextAfterSummary;
protected $mSourceIds;
+
+ protected $mMaxFileSize = array();
public function __construct( $options = array() ) {
$this->mWatch = !empty( $options['watch'] );
);
}
+ $this->mMaxUploadSize['file'] = min(
+ wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
+ UploadBase::getMaxUploadSize( 'file' ) );
+
$descriptor['UploadFile'] = array(
'class' => 'UploadSourceField',
'section' => 'source',
'radio' => &$radio,
'help' => wfMsgExt( 'upload-maxfilesize',
array( 'parseinline', 'escapenoentities' ),
- $wgLang->formatSize(
- wfShorthandToInteger( min(
- wfShorthandToInteger(
- ini_get( 'upload_max_filesize' )
- ), UploadBase::getMaxUploadSize( 'file' )
- ) )
- )
+ $wgLang->formatSize( $this->mMaxUploadSize['file'] )
) . ' ' . wfMsgHtml( 'upload_source_file' ),
'checked' => $selectedSourceType == 'file',
);
if ( $canUploadByUrl ) {
+ $this->mMaxUploadSize['url'] = UploadBase::getMaxUploadSize( 'url' );
$descriptor['UploadFileURL'] = array(
'class' => 'UploadSourceField',
'section' => 'source',
'radio' => &$radio,
'help' => wfMsgExt( 'upload-maxfilesize',
array( 'parseinline', 'escapenoentities' ),
- $wgLang->formatSize( UploadBase::getMaxUploadSize( 'url' ) )
+ $wgLang->formatSize( $this->mMaxUploadSize['url'] )
) . ' ' . wfMsgHtml( 'upload_source_url' ),
'checked' => $selectedSourceType == 'url',
);
$useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
$useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI;
+ $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize();
$scriptVars = array(
'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
'wgUploadSourceIds' => $this->mSourceIds,
'wgStrictFileExtensions' => $wgStrictFileExtensions,
'wgCapitalizeUploads' => MWNamespace::isCapitalized( NS_FILE ),
+ 'wgMaxUploadSize' => $this->mMaxUploadSize,
);
$wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) );
$( '#mw-upload-thumbnail' ).remove();
}
-
+ /**
+ * Check if the file does not exceed the maximum size
+ */
+ function checkMaxUploadSize( file ) {
+ function getMaxUploadSize( type ) {
+ sizes = mw.config.get( 'wgMaxUploadSize' );
+ if ( sizes[type] !== undefined ) {
+ return sizes[type];
+ }
+ return sizes['*'];
+ }
+ $( '.mw-upload-source-error' ).remove();
+
+ maxSize = getMaxUploadSize( 'file' );
+ if ( file.size > maxSize ) {
+ error = $( '<p class="error mw-upload-source-error" id="wpSourceTypeFile-error">' +
+ mw.msg( 'largefileserver', file.size, maxSize ) + '</p>' );
+ $( '#wpUploadFile' ).after( error );
+ return false;
+ }
+ return true;
+ }
+
+
+ /**
+ * Initialization
+ */
if ( hasFileAPI() ) {
// Update thumbnail when the file selection control is updated.
$( '#wpUploadFile' ).change( function() {
if ( this.files && this.files.length ) {
// Note: would need to be updated to handle multiple files.
var file = this.files[0];
+
+ if ( !checkMaxUploadSize( file ) ) {
+ return;
+ }
+
if ( fileIsPreviewable( file ) ) {
showPreview( file );
}
$( 'input[name="wpSourceType"]', row ).change( function () {
var currentRow = row; // Store current row in our own scope
return function () {
+ $( '.mw-upload-source-error' ).remove();
if ( this.checked ) {
// Disable all inputs
$( 'input[name!="wpSourceType"]', rows ).attr( 'disabled', true );
}() );
}
} );
+