(bug 40326) Check if files exist with a different extension during
[lhc/web/wiklou.git] / includes / filerepo / LocalRepo.php
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