From 6a637fb0bcbfdf27d00b6f31a0cab19a1d932e1f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 25 Aug 2014 17:26:58 +0200 Subject: [PATCH] IndexPager: Introduce constants for values of $mDefaultDirection 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 | 17 +++++++++++++---- includes/pager/ReverseChronologicalPager.php | 2 +- includes/pager/TablePager.php | 6 +++--- includes/specials/SpecialAllMessages.php | 2 +- includes/specials/SpecialBlockList.php | 2 +- includes/specials/SpecialContributions.php | 2 +- .../specials/SpecialDeletedContributions.php | 2 +- includes/specials/SpecialListfiles.php | 6 +++--- includes/specials/SpecialListusers.php | 4 +++- 9 files changed, 27 insertions(+), 16 deletions(-) diff --git a/includes/pager/IndexPager.php b/includes/pager/IndexPager.php index 5972296f39..ce6dc50cbf 100644 --- a/includes/pager/IndexPager.php +++ b/includes/pager/IndexPager.php @@ -64,6 +64,14 @@ * @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; } } diff --git a/includes/pager/ReverseChronologicalPager.php b/includes/pager/ReverseChronologicalPager.php index 3f96382db0..4f8c438db0 100644 --- a/includes/pager/ReverseChronologicalPager.php +++ b/includes/pager/ReverseChronologicalPager.php @@ -26,7 +26,7 @@ * @ingroup Pager */ abstract class ReverseChronologicalPager extends IndexPager { - public $mDefaultDirection = true; + public $mDefaultDirection = IndexPager::DIR_DESCENDING; public $mYear; public $mMonth; diff --git a/includes/pager/TablePager.php b/includes/pager/TablePager.php index 221878700d..c5141a9347 100644 --- a/includes/pager/TablePager.php +++ b/includes/pager/TablePager.php @@ -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'; diff --git a/includes/specials/SpecialAllMessages.php b/includes/specials/SpecialAllMessages.php index 6ecb121155..760b41b5cf 100644 --- a/includes/specials/SpecialAllMessages.php +++ b/includes/specials/SpecialAllMessages.php @@ -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; diff --git a/includes/specials/SpecialBlockList.php b/includes/specials/SpecialBlockList.php index 012397280d..842a25a2cf 100644 --- a/includes/specials/SpecialBlockList.php +++ b/includes/specials/SpecialBlockList.php @@ -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() ); } diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index af8ab58283..2f06bead5b 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -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 = ''; diff --git a/includes/specials/SpecialDeletedContributions.php b/includes/specials/SpecialDeletedContributions.php index 934b7a3c47..79eaa8c985 100644 --- a/includes/specials/SpecialDeletedContributions.php +++ b/includes/specials/SpecialDeletedContributions.php @@ -26,7 +26,7 @@ * @ingroup SpecialPage */ class DeletedContribsPager extends IndexPager { - public $mDefaultDirection = true; + public $mDefaultDirection = IndexPager::DIR_ASCENDING; public $messages; public $target; public $namespace = ''; diff --git a/includes/specials/SpecialListfiles.php b/includes/specials/SpecialListfiles.php index 3eee43a9ef..ef04280bbd 100644 --- a/includes/specials/SpecialListfiles.php +++ b/includes/specials/SpecialListfiles.php @@ -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 ); diff --git a/includes/specials/SpecialListusers.php b/includes/specials/SpecialListusers.php index 993285f27a..cc3226dd38 100644 --- a/includes/specials/SpecialListusers.php +++ b/includes/specials/SpecialListusers.php @@ -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 = ''; -- 2.20.1