Merge "Sort result of FileRepo::findBySha1"
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 13 Jul 2012 18:14:28 +0000 (18:14 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 13 Jul 2012 18:14:28 +0000 (18:14 +0000)
includes/filerepo/LocalRepo.php
includes/filerepo/RepoGroup.php
includes/filerepo/file/File.php

index c616e16..dd0c947 100644 (file)
@@ -235,7 +235,8 @@ class LocalRepo extends FileRepo {
                        'image',
                        LocalFile::selectFields(),
                        array( 'img_sha1' => $hash ),
-                       __METHOD__
+                       __METHOD__,
+                       array( 'ORDER BY' => 'img_name' )
                );
                
                $result = array();
index 709655a..6b31b7e 100644 (file)
@@ -259,6 +259,7 @@ class RepoGroup {
                foreach ( $this->foreignRepos as $repo ) {
                        $result = array_merge( $result, $repo->findBySha1( $hash ) );
                }
+               usort( $result, 'File::compare' );
                return $result;
        }
 
index 81536b5..3fa8166 100644 (file)
@@ -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
         *