Improve sorting on SpecialWanted*-Pages
[lhc/web/wiklou.git] / includes / specialpage / QueryPage.php
index 40f82f5..c495f93 100644 (file)
@@ -407,7 +407,7 @@ abstract class QueryPage extends SpecialPage {
                        $options = isset( $query['options'] ) ? (array)$query['options'] : [];
                        $join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : [];
 
-                       if ( count( $order ) ) {
+                       if ( $order ) {
                                $options['ORDER BY'] = $order;
                        }
 
@@ -460,20 +460,28 @@ abstract class QueryPage extends SpecialPage {
                if ( $limit !== false ) {
                        $options['LIMIT'] = intval( $limit );
                }
+
                if ( $offset !== false ) {
                        $options['OFFSET'] = intval( $offset );
                }
-               if ( $this->sortDescending() ) {
-                       $options['ORDER BY'] = 'qc_value DESC';
-               } else {
-                       $options['ORDER BY'] = 'qc_value ASC';
+
+               $orderFields = $this->getOrderFields();
+               $order = [];
+               $DESC = $this->sortDescending() ? ' DESC' : '';
+               foreach ( $orderFields as $field ) {
+                       $order[] = "qc_${field}${DESC}";
+               }
+               if ( $order ) {
+                       $options['ORDER BY'] = $order;
                }
+
                return $dbr->select( 'querycache', [ 'qc_type',
                                'namespace' => 'qc_namespace',
                                'title' => 'qc_title',
                                'value' => 'qc_value' ],
                                [ 'qc_type' => $this->getName() ],
-                               __METHOD__, $options
+                               __METHOD__,
+                               $options
                );
        }