X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Ffilerepo%2FLocalRepo.php;h=229f8bf668ea4fc3cb9f0673d6c92f3401bdfaf6;hb=c5c8b3145015f24bfcb21dca9e581e0c7df2d9bc;hp=0fbaeef8a0aae852485059737cc5ebeac02abc53;hpb=154a0a03aa545762663c98eeea40417425f8c430;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index 0fbaeef8a0..229f8bf668 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -281,6 +281,34 @@ class LocalRepo extends FileRepo { return $result; } + /** + * Return an array of files where the name starts with $prefix. + * + * @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 ) { + $selectOptions = array( 'ORDER BY' => 'img_name', 'LIMIT' => intval( $limit ) ); + + // Query database + $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; + } + /** * Get a connection to the slave DB * @return DatabaseBase