From: umherirrender Date: Sun, 8 Jul 2012 08:45:21 +0000 (+0200) Subject: Sort result of FileRepo::findBySha1 X-Git-Tag: 1.31.0-rc.0~23050^2 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=d6e31f68b168d49c6382654055955744625d936c;p=lhc%2Fweb%2Fwiklou.git Sort result of FileRepo::findBySha1 This sorts the result on Special:FileDuplicateSearch, which is unsorted, when merged from different repos. Adding File::compare similar to Title::compare for this Change-Id: I32e8be92c6067f9e13f3ecd1039c337b0fc3e840 --- diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index c616e162b7..dd0c947554 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -235,7 +235,8 @@ class LocalRepo extends FileRepo { 'image', LocalFile::selectFields(), array( 'img_sha1' => $hash ), - __METHOD__ + __METHOD__, + array( 'ORDER BY' => 'img_name' ) ); $result = array(); diff --git a/includes/filerepo/RepoGroup.php b/includes/filerepo/RepoGroup.php index 709655af69..6b31b7e54d 100644 --- a/includes/filerepo/RepoGroup.php +++ b/includes/filerepo/RepoGroup.php @@ -259,6 +259,7 @@ class RepoGroup { foreach ( $this->foreignRepos as $repo ) { $result = array_merge( $result, $repo->findBySha1( $hash ) ); } + usort( $result, 'File::compare' ); return $result; } diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 065679a87a..d7c75333ce 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -245,6 +245,18 @@ abstract class File { } } + /** + * Callback for usort() to do file sorts by title + * + * @param $a File + * @param $b File + * + * @return Integer: result of title comparison + */ + public static function compare( File $a, File $b ) { + return Title::compare( $a->getTitle(), $b->getTitle() ); + } + /** * Return the name of this file *