(bug 40326) Check if files exist with a different extension during
[lhc/web/wiklou.git] / includes / upload / UploadBase.php
index 4eb30ee..9d756f8 100644 (file)
@@ -239,7 +239,7 @@ abstract class UploadBase {
         * Get the base 36 SHA1 of the file
         * @return string
         */
-       protected function getTempFileSha1Base36() {
+       public function getTempFileSha1Base36() {
                return FSFile::getSha1Base36FromPath( $this->mTempPath );
        }
 
@@ -360,7 +360,7 @@ abstract class UploadBase {
                global $wgVerifyMimeType;
                wfProfileIn( __METHOD__ );
                if ( $wgVerifyMimeType ) {
-                       wfDebug ( "\n\nmime: <$mime> extension: <{$this->mFinalExtension}>\n\n");
+                       wfDebug ( "\n\nmime: <$mime> extension: <{$this->mFinalExtension}>\n\n" );
                        global $wgMimeTypeBlacklist;
                        if ( $this->checkFileExtension( $mime, $wgMimeTypeBlacklist ) ) {
                                wfProfileOut( __METHOD__ );
@@ -1377,6 +1377,17 @@ abstract class UploadBase {
                        }
                }
 
+               // Check for files with the same name but a different extension
+               $similarFiles = RepoGroup::singleton()->getLocalRepo()->findFilesByPrefix(
+                               "{$partname}.", 1 );
+               if ( count( $similarFiles ) ) {
+                       return array(\r
+                               'warning' => 'exists-normalized',\r
+                               'file' => $file,\r
+                               'normalizedFile' => $similarFiles[0],\r
+                       );
+               }
+
                if ( self::isThumbName( $file->getName() ) ) {
                        # Check for filenames like 50px- or 180px-, these are mostly thumbnails
                        $nt_thb = Title::newFromText( substr( $partname, strpos( $partname, '-' ) + 1 ) . '.' . $extension, NS_FILE );