r95681 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95680‎ | r95681 | r95682 >
Date:17:56, 29 August 2011
Author:neilk
Status:ok
Tags:
Comment:
MFT of r79749 - needed to make other fixes for fatals in UploadStash work
Modified paths:
  • /branches/wmf/1.17wmf1/RELEASE-NOTES (modified) (history)
  • /branches/wmf/1.17wmf1/includes/DefaultSettings.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/specials/SpecialUpload.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/upload/UploadBase.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/upload/UploadFromFile.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/upload/UploadFromStash.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/upload/UploadFromUrl.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/includes/upload/UploadFromStash.php
@@ -70,6 +70,8 @@
7171 $this->mVirtualTempPath = $metadata['us_path'];
7272 $this->mFileProps = $this->stash->getFileProps( $key );
7373 $this->mSourceType = $metadata['us_source_type'];
 74+ $this->mSourceType = isset( $sessionData['mSourceType'] ) ?
 75+ $sessionData['mSourceType'] : null;
7476 }
7577
7678 public function initializeFromRequest( &$request ) {
@@ -82,6 +84,10 @@
8385 return $this->initialize( $fileKey, $desiredDestName );
8486 }
8587
 88+ public function getSourceType() {
 89+ return $this->mSourceType;
 90+ }
 91+
8692 /**
8793 * File has been previously verified so no need to do so again.
8894 */
Index: branches/wmf/1.17wmf1/includes/upload/UploadFromUrl.php
@@ -81,6 +81,7 @@
8282 && $wgUser->isAllowed( 'upload_by_url' );
8383 }
8484
 85+ public function getSourceType() { return 'url'; }
8586
8687 public function fetchFile() {
8788 if ( !Http::isValidURI( $this->mUrl ) ) {
Index: branches/wmf/1.17wmf1/includes/upload/UploadBase.php
@@ -135,6 +135,14 @@
136136 }
137137
138138 public function __construct() {}
 139+
 140+ /**
 141+ * Returns the upload type. Should be overridden by child classes
 142+ *
 143+ * @since 1.18
 144+ * @return string
 145+ */
 146+ public function getSourceType() { return null; }
139147
140148 /**
141149 * Initialize the path information
@@ -219,11 +227,11 @@
220228 /**
221229 * Honor $wgMaxUploadSize
222230 */
223 - global $wgMaxUploadSize;
224 - if( $this->mFileSize > $wgMaxUploadSize ) {
 231+ $maxSize = self::getMaxUploadSize( $this->getSourceType() );
 232+ if( $this->mFileSize > $maxSize ) {
225233 return array(
226234 'status' => self::FILE_TOO_LARGE,
227 - 'max' => $wgMaxUploadSize,
 235+ 'max' => $maxSize,
228236 );
229237 }
230238
@@ -1230,4 +1238,19 @@
12311239 unset( $code['status'] );
12321240 return Status::newFatal( $this->getVerificationErrorCode( $code ), $error );
12331241 }
 1242+
 1243+ public static function getMaxUploadSize( $forType = null ) {
 1244+ global $wgMaxUploadSize;
 1245+
 1246+ if ( is_array( $wgMaxUploadSize ) ) {
 1247+ if ( !is_null( $forType) && isset( $wgMaxUploadSize[$forType] ) ) {
 1248+ return $wgMaxUploadSize[$forType];
 1249+ } else {
 1250+ return $wgMaxUploadSize['*'];
 1251+ }
 1252+ } else {
 1253+ return intval( $wgMaxUploadSize );
 1254+ }
 1255+
 1256+ }
12341257 }
Property changes on: branches/wmf/1.17wmf1/includes/upload/UploadBase.php
___________________________________________________________________
Modified: svn:mergeinfo
12351258 Merged /trunk/phase3/includes/upload/UploadBase.php:r79749
Index: branches/wmf/1.17wmf1/includes/upload/UploadFromFile.php
@@ -45,11 +45,10 @@
4646 # proper error can be shown to the user
4747 if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
4848 if ( $this->mUpload->isIniSizeOverflow() ) {
49 - global $wgMaxUploadSize;
5049 return array(
5150 'status' => self::FILE_TOO_LARGE,
5251 'max' => min(
53 - $wgMaxUploadSize,
 52+ self::getMaxUploadSize( $this->getSourceType() ),
5453 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
5554 wfShorthandToInteger( ini_get( 'post_max_size' ) )
5655 ),
Property changes on: branches/wmf/1.17wmf1/includes/upload/UploadFromFile.php
___________________________________________________________________
Modified: svn:mergeinfo
5756 Merged /trunk/phase3/includes/upload/UploadFromFile.php:r79749
Index: branches/wmf/1.17wmf1/includes/DefaultSettings.php
@@ -454,7 +454,19 @@
455455 $wgAllowAsyncCopyUploads = false;
456456
457457 /**
458 - * Max size for uploads, in bytes. Applies to all uploads.
 458+ * Max size for uploads, in bytes. If not set to an array, applies to all
 459+ * uploads. If set to an array, per upload type maximums can be set, using the
 460+ * file and url keys. If the * key is set this value will be used as maximum
 461+ * for non-specified types.
 462+ *
 463+ * For example:
 464+ * $wgUploadSize = array(
 465+ * '*' => 250 * 1024,
 466+ * 'url' => 500 * 1024,
 467+ * );
 468+ * Sets the maximum for all uploads to 250 kB except for upload-by-url, which
 469+ * will have a maximum of 500 kB.
 470+ *
459471 */
460472 $wgMaxUploadSize = 1024*1024*100; # 100MB
461473
Property changes on: branches/wmf/1.17wmf1/includes/DefaultSettings.php
___________________________________________________________________
Modified: svn:mergeinfo
462474 Merged /trunk/phase3/includes/DefaultSettings.php:r79749
Index: branches/wmf/1.17wmf1/includes/specials/SpecialUpload.php
@@ -812,7 +812,6 @@
813813 */
814814 protected function getSourceSection() {
815815 global $wgLang, $wgUser, $wgRequest;
816 - global $wgMaxUploadSize;
817816
818817 if ( $this->mSessionKey ) {
819818 return array(
@@ -855,7 +854,7 @@
856855 wfShorthandToInteger( min(
857856 wfShorthandToInteger(
858857 ini_get( 'upload_max_filesize' )
859 - ), $wgMaxUploadSize
 858+ ), UploadBase::getMaxUploadSize( 'file' )
860859 ) )
861860 )
862861 ) . ' ' . wfMsgHtml( 'upload_source_file' ),
@@ -871,7 +870,7 @@
872871 'radio' => &$radio,
873872 'help' => wfMsgExt( 'upload-maxfilesize',
874873 array( 'parseinline', 'escapenoentities' ),
875 - $wgLang->formatSize( $wgMaxUploadSize )
 874+ $wgLang->formatSize( UploadBase::getMaxUploadSize( 'url' ) )
876875 ) . ' ' . wfMsgHtml( 'upload_source_url' ),
877876 'checked' => $selectedSourceType == 'url',
878877 );
Property changes on: branches/wmf/1.17wmf1/includes/specials/SpecialUpload.php
___________________________________________________________________
Modified: svn:mergeinfo
879878 Merged /trunk/phase3/includes/specials/SpecialUpload.php:r79749
Index: branches/wmf/1.17wmf1/RELEASE-NOTES
@@ -23,6 +23,8 @@
2424 a lot of outstanding bugs, cleanup the code quality, and make it easier to
2525 use. Notably, you can now run upgrades from the web without having to move
2626 LocalSettings.php. The specific bugs are listed below in the general notes.
 27+* $wgMaxUploadSize may now be set to an array to specify the upload size limit
 28+ per upload type.
2729
2830 === Configuration changes in 1.17 ===
2931 * DatabaseFunctions.php that was needed for compatibility with pre-1.3
Property changes on: branches/wmf/1.17wmf1/RELEASE-NOTES
___________________________________________________________________
Modified: svn:mergeinfo
3032 Merged /trunk/phase3/RELEASE-NOTES:r79749

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r79749$wgMaxUploadSize may now be set to an array to specify the upload size limit ...btongminh19:42, 6 January 2011

Status & tagging log