Sort result of FileRepo::findBySha1
authorumherirrender <umherirrender_de.wp@web.de>
Sun, 8 Jul 2012 08:45:21 +0000 (10:45 +0200)
committerAaron <aschulz@wikimedia.org>
Fri, 13 Jul 2012 18:11:39 +0000 (11:11 -0700)
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

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 065679a..d7c7533 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
         *