Improve sorting on SpecialWanted*-Pages
authorEddie Greiner-Petter <git@eddie-sh.de>
Tue, 21 Feb 2017 12:58:47 +0000 (13:58 +0100)
committer20after4 <mmodell@wikimedia.org>
Wed, 8 Mar 2017 17:13:55 +0000 (17:13 +0000)
Change the SpecialWanted*-Pages so that they do sort
1. by the number of links to a site (as is now) and
2. alphabetically for entries which have the same number of links (new)

Bug: T4335
Change-Id: If54cd52b69007ee81af4733a14be3fd893c4abfe

includes/specialpage/QueryPage.php
includes/specialpage/WantedQueryPage.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
                );
        }
 
index 9d92cbd..7a18342 100644 (file)
@@ -119,4 +119,26 @@ abstract class WantedQueryPage extends QueryPage {
                $label = $this->msg( 'nlinks' )->numParams( $result->value )->escaped();
                return Linker::link( $wlh, $label );
        }
+
+       /**
+        * Order by title, overwrites QueryPage::getOrderFields
+        *
+        * @return array
+        */
+       function getOrderFields() {
+               return [ 'value DESC', 'namespace', 'title' ];
+       }
+
+       /**
+        * Do not order descending for all order fields.  We will use DESC only on one field, see
+        *  getOrderFields above. This overwrites sortDescending from QueryPage::getOrderFields().
+        *  Do NOT change this to true unless you remove the phrase DESC in getOrderFiels above.
+        *  If you do a database error will be thrown due to double adding DESC to query!
+        *
+        * @return bool
+        */
+       function sortDescending() {
+               return false;
+       }
+
 }