IndexPager: Introduce constants for values of $mDefaultDirection
authorBartosz Dziewoński <matma.rex@gmail.com>
Mon, 25 Aug 2014 15:26:58 +0000 (17:26 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Wed, 3 Sep 2014 17:54:34 +0000 (19:54 +0200)
I've spent several hours looking at related code and I still can't
remember which direction is 'true' and which is 'false'.

Change-Id: I58694f7a0892c986e7215f59b56b014cece8d40d

includes/pager/IndexPager.php
includes/pager/ReverseChronologicalPager.php
includes/pager/TablePager.php
includes/specials/SpecialAllMessages.php
includes/specials/SpecialBlockList.php
includes/specials/SpecialContributions.php
includes/specials/SpecialDeletedContributions.php
includes/specials/SpecialListfiles.php
includes/specials/SpecialListusers.php

index 5972296..ce6dc50 100644 (file)
  * @ingroup Pager
  */
 abstract class IndexPager extends ContextSource implements Pager {
+       /**
+        * Constants for the $mDefaultDirection field.
+        *
+        * These are boolean for historical reasons and should stay boolean for backwards-compatibility.
+        */
+       const DIR_ASCENDING = false;
+       const DIR_DESCENDING = true;
+
        public $mRequest;
        public $mLimitsShown = array( 20, 50, 100, 250, 500 );
        public $mDefaultLimit = 50;
@@ -87,7 +95,7 @@ abstract class IndexPager extends ContextSource implements Pager {
        protected $mOrderType;
        /**
         * $mDefaultDirection gives the direction to use when sorting results:
-        * false for ascending, true for descending.  If $mIsBackwards is set, we
+        * DIR_ASCENDING or DIR_DESCENDING.  If $mIsBackwards is set, we
         * start from the opposite end, but we still sort the page itself according
         * to $mDefaultDirection.  E.g., if $mDefaultDirection is false but we're
         * going backwards, we'll display the last page of results, but the last
@@ -190,6 +198,7 @@ abstract class IndexPager extends ContextSource implements Pager {
                $fname = __METHOD__ . ' (' . get_class( $this ) . ')';
                wfProfileIn( $fname );
 
+               // @todo This should probably compare to DIR_DESCENDING and DIR_ASCENDING constants
                $descending = ( $this->mIsBackwards == $this->mDefaultDirection );
                # Plus an extra row so that we can tell the "next" link should be shown
                $queryLimit = $this->mLimit + 1;
@@ -709,8 +718,8 @@ abstract class IndexPager extends ContextSource implements Pager {
        }
 
        /**
-        * Return the default sorting direction: false for ascending, true for
-        * descending.  You can also have an associative array of ordertype => dir,
+        * Return the default sorting direction: DIR_ASCENDING or DIR_DESCENDING.
+        * You can also have an associative array of ordertype => dir,
         * if multiple order types are supported.  In this case getIndexField()
         * must return an array, and the keys of that must exactly match the keys
         * of this.
@@ -728,6 +737,6 @@ abstract class IndexPager extends ContextSource implements Pager {
         * @return bool
         */
        protected function getDefaultDirections() {
-               return false;
+               return IndexPager::DIR_ASCENDING;
        }
 }
index 3f96382..4f8c438 100644 (file)
@@ -26,7 +26,7 @@
  * @ingroup Pager
  */
 abstract class ReverseChronologicalPager extends IndexPager {
-       public $mDefaultDirection = true;
+       public $mDefaultDirection = IndexPager::DIR_DESCENDING;
        public $mYear;
        public $mMonth;
 
index 2218787..c5141a9 100644 (file)
@@ -42,9 +42,9 @@ abstract class TablePager extends IndexPager {
                        $this->mSort = $this->getDefaultSort();
                }
                if ( $this->getRequest()->getBool( 'asc' ) ) {
-                       $this->mDefaultDirection = false;
+                       $this->mDefaultDirection = IndexPager::DIR_ASCENDING;
                } elseif ( $this->getRequest()->getBool( 'desc' ) ) {
-                       $this->mDefaultDirection = true;
+                       $this->mDefaultDirection = IndexPager::DIR_DESCENDING;
                } /* Else leave it at whatever the class default is */
 
                parent::__construct();
@@ -128,7 +128,7 @@ abstract class TablePager extends IndexPager {
                                if ( $this->mSort == $field ) {
                                        // The table is sorted by this field already, make a link to sort in the other direction
                                        // We don't actually know in which direction other fields will be sorted by default…
-                                       if ( $this->mDefaultDirection ) {
+                                       if ( $this->mDefaultDirection == IndexPager::DIR_DESCENDING ) {
                                                $linkType = 'asc';
                                                $class = "$sortClass TablePager_sort-descending";
                                                $query['asc'] = '1';
index 6ecb121..760b41b 100644 (file)
@@ -101,7 +101,7 @@ class AllMessagesTablePager extends TablePager {
                $this->mIndexField = 'am_title';
                $this->mPage = $page;
                $this->mConds = $conds;
-               $this->mDefaultDirection = true; // always sort ascending
+               $this->mDefaultDirection = IndexPager::DIR_ASCENDING;
                $this->mLimitsShown = array( 20, 50, 100, 250, 500, 5000 );
 
                global $wgContLang;
index 0123972..842a25a 100644 (file)
@@ -224,7 +224,7 @@ class BlockListPager extends TablePager {
        function __construct( $page, $conds ) {
                $this->page = $page;
                $this->conds = $conds;
-               $this->mDefaultDirection = true;
+               $this->mDefaultDirection = IndexPager::DIR_ASCENDING;
                parent::__construct( $page->getContext() );
        }
 
index af8ab58..2f06bea 100644 (file)
@@ -652,7 +652,7 @@ class SpecialContributions extends IncludableSpecialPage {
  * @ingroup SpecialPage Pager
  */
 class ContribsPager extends ReverseChronologicalPager {
-       public $mDefaultDirection = true;
+       public $mDefaultDirection = IndexPager::DIR_ASCENDING;
        public $messages;
        public $target;
        public $namespace = '';
index 934b7a3..79eaa8c 100644 (file)
@@ -26,7 +26,7 @@
  * @ingroup SpecialPage
  */
 class DeletedContribsPager extends IndexPager {
-       public $mDefaultDirection = true;
+       public $mDefaultDirection = IndexPager::DIR_ASCENDING;
        public $messages;
        public $target;
        public $namespace = '';
index 3eee43a..ef04280 100644 (file)
@@ -108,12 +108,12 @@ class ImageListPager extends TablePager {
 
                if ( !$including ) {
                        if ( $context->getRequest()->getText( 'sort', 'img_date' ) == 'img_date' ) {
-                               $this->mDefaultDirection = true;
+                               $this->mDefaultDirection = IndexPager::DIR_ASCENDING;
                        } else {
-                               $this->mDefaultDirection = false;
+                               $this->mDefaultDirection = IndexPager::DIR_DESCENDING;
                        }
                } else {
-                       $this->mDefaultDirection = true;
+                       $this->mDefaultDirection = IndexPager::DIR_ASCENDING;
                }
 
                parent::__construct( $context );
index 993285f..cc3226d 100644 (file)
@@ -69,7 +69,9 @@ class UsersPager extends AlphabeticPager {
                $this->editsOnly = $request->getBool( 'editsOnly' );
                $this->creationSort = $request->getBool( 'creationSort' );
                $this->including = $including;
-               $this->mDefaultDirection = $request->getBool( 'desc' );
+               $this->mDefaultDirection = $request->getBool( 'desc' )
+                       ? IndexPager::DIR_DESCENDING
+                       : IndexPager::DIR_ASCENDING;
 
                $this->requestedUser = '';