(bug 40326) Check if files exist with a different extension during
authorbtongminh <bryan.tongminh@gmail.com>
Wed, 6 Feb 2013 20:15:07 +0000 (21:15 +0100)
committerReedy <reedy@wikimedia.org>
Wed, 6 Mar 2013 03:52:49 +0000 (03:52 +0000)
uploading

Added FileRepo::findFilesByPrefix( $prefix ), which does a img_name LIKE
'$prefix%' search and use this in UploadBase::getExistsWarning().

Change-Id: I21eddc5d08ca3c23b342ebc1c6947e36c4201a45

RELEASE-NOTES-1.21
includes/filerepo/FileRepo.php
includes/filerepo/LocalRepo.php
includes/upload/UploadBase.php

index 4f38f3a..80c2c88 100644 (file)
@@ -189,6 +189,8 @@ production.
   "password mismatch" error.
 * (bug 44599) On Special:Version, HEADs for submodule checkouts (e.g. for
   extensions) performed using Git 1.7.8+ should now appear.
+* (bug 42184) $wgUploadSizeWarning missing second variable
+* (bug 40326) Check if files exist with a different extension during uploading
 
 === API changes in 1.21 ===
 * prop=revisions can now report the contentmodel and contentformat.
index 05e71d4..6dbe245 100644 (file)
@@ -490,6 +490,18 @@ class FileRepo {
                return $result;
        }
 
+       /**
+        * Return an array of files where the name starts with $prefix.
+        *
+        * STUB
+        * @param string $prefix The prefix to search for
+        * @param int $limit The maximum amount of files to return
+        * @return array
+        */
+       public function findFilesByPrefix( $prefix, $limit ) {
+               return array();
+       }
+
        /**
         * Get the public root URL of the repository
         *
index 0fbaeef..229f8bf 100644 (file)
@@ -281,6 +281,34 @@ class LocalRepo extends FileRepo {
                return $result;
        }
 
+       /**\r
+        * Return an array of files where the name starts with $prefix.\r
+        *\r
+        * @param string $prefix The prefix to search for\r
+        * @param int $limit The maximum amount of files to return\r
+        * @return array\r
+        */\r
+       public function findFilesByPrefix( $prefix, $limit ) {
+               $selectOptions = array( 'ORDER BY' => 'img_name', 'LIMIT' => intval( $limit ) );
+
+               // Query database\r
+               $dbr = $this->getSlaveDB();
+               $res = $dbr->select(
+                       'image',
+                       LocalFile::selectFields(),
+                       'img_name ' . $dbr->buildLike( $prefix, $dbr->anyString() ),
+                       __METHOD__,
+                       $selectOptions
+                       );
+
+               // Build file objects
+               $files = array();
+               foreach ( $res as $row ) {
+                       $files[] = $this->newFileFromRow( $row );
+               }
+               return $files;\r
+       }
+
        /**
         * Get a connection to the slave DB
         * @return DatabaseBase
index 49713fc..9d756f8 100644 (file)
@@ -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 );