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
This commit is contained in:
Bartosz Dziewoński 2014-08-25 17:26:58 +02:00
parent 987a860df4
commit 6a637fb0bc
9 changed files with 27 additions and 16 deletions

View file

@ -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;
}
}

View file

@ -26,7 +26,7 @@
* @ingroup Pager
*/
abstract class ReverseChronologicalPager extends IndexPager {
public $mDefaultDirection = true;
public $mDefaultDirection = IndexPager::DIR_DESCENDING;
public $mYear;
public $mMonth;

View 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';

View 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;

View 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() );
}

View 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 = '';

View 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 = '';

View 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 );

View 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 = '';