(bug 30202) Restrict file names on upload to 240 bytes, because wfTimestamp( TS_MW...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 29 Sep 2011 19:00:45 +0000 (19:00 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 29 Sep 2011 19:00:45 +0000 (19:00 +0000)
Commit to fix UploadTest to use @dataProvider will follow

RELEASE-NOTES-1.19
includes/upload/UploadBase.php
tests/phpunit/includes/upload/UploadTest.php

index 08dc004..60df92b 100644 (file)
@@ -107,6 +107,8 @@ production.
 * Per page edit-notices now work in namespaces without subpages enabled.
 * (bug 30245) Use the correct way to construct a log page title
 * (bug 31081) $wgEnotifUseJobQ causes many unnecessary jobs to be queued
+* (bug 30202) File names are now restricted on upload to 240 bytes, because of
+  restrictions on some of the database fields.
 
 === API changes in 1.19 ===
 * (bug 19838) siprop=interwikimap can now use the interwiki cache.
index 6fa72f8..3c66086 100644 (file)
@@ -631,6 +631,14 @@ abstract class UploadBase {
                }
                $this->mFilteredName = $nt->getDBkey();
 
+               # oi_archive_name is max 255 bytes, which include a timestamp and an
+               # exclamation mark, so restrict file name to 240 bytes. Return
+               # ILLEGAL_FILENAME, just like would have happened for >255 bytes
+               if ( strlen( $this->mFilteredName ) > 240 ) {
+                       $this->mTitleError = self::ILLEGAL_FILENAME;
+                       return $this->mTitle = null;                    
+               }
+               
                /**
                 * We'll want to blacklist against *any* 'extension', and use
                 * only the final one for the whitelist.
index 69c2903..f74018a 100644 (file)
@@ -60,6 +60,16 @@ class UploadTest extends MediaWikiTestCase {
                $this->assertUploadTitleAndCode( '.jpg',
                        null, UploadBase::MIN_LENGTH_PARTNAME,
                        'upload title without basename' );
+               
+               /* A title that is longer than 255 bytes */
+               $this->assertUploadTitleAndCode( str_repeat( 'a', 255 ) . '.jpg',
+                       null, UploadBase::ILLEGAL_FILENAME,
+                       'upload title longer than 255 bytes' );
+                       
+               /* A title that is longer than 240 bytes */
+               $this->assertUploadTitleAndCode( str_repeat( 'a', 240 ) . '.jpg',
+                       null, UploadBase::ILLEGAL_FILENAME,
+                       'upload title longer than 240 bytes' );
 
        }
        /**
@@ -134,6 +144,7 @@ class UploadTestHandler extends UploadBase {
                public function testTitleValidation( $name ) {
                        $this->mTitle = false;
                        $this->mDesiredDestName = $name;
+                       $this->mTitleError = UploadBase::OK;
                        $this->getTitle();
                        return $this->mTitleError;
                }