Bartosz Dziewoński has uploaded a new change for review.
https://gerrit.wikimedia.org/r/156128
Change subject: IndexPager: Introduce constants for values of $mDefaultDirection
......................................................................
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
---
M includes/pager/IndexPager.php
M includes/pager/ReverseChronologicalPager.php
M includes/pager/TablePager.php
M includes/specials/SpecialAllMessages.php
M includes/specials/SpecialBlockList.php
M includes/specials/SpecialContributions.php
M includes/specials/SpecialDeletedContributions.php
M includes/specials/SpecialListfiles.php
M includes/specials/SpecialListusers.php
9 files changed, 27 insertions(+), 16 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/28/156128/1
diff --git a/includes/pager/IndexPager.php b/includes/pager/IndexPager.php
index 5972296..ebb3108 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 @@
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 @@
$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 @@
}
/**
- * 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 @@
* @return bool
*/
protected function getDefaultDirections() {
- return false;
+ return IndexPager::DIR_ASCENDING;
}
}
diff --git a/includes/pager/ReverseChronologicalPager.php
b/includes/pager/ReverseChronologicalPager.php
index 3f96382..4f8c438 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 39b7036..7eaf6c0 100644
--- a/includes/pager/TablePager.php
+++ b/includes/pager/TablePager.php
@@ -42,9 +42,9 @@
$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();
@@ -127,7 +127,7 @@
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 6ecb121..760b41b 100644
--- a/includes/specials/SpecialAllMessages.php
+++ b/includes/specials/SpecialAllMessages.php
@@ -101,7 +101,7 @@
$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 0123972..842a25a 100644
--- a/includes/specials/SpecialBlockList.php
+++ b/includes/specials/SpecialBlockList.php
@@ -224,7 +224,7 @@
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 af8ab58..2f06bea 100644
--- a/includes/specials/SpecialContributions.php
+++ b/includes/specials/SpecialContributions.php
@@ -652,7 +652,7 @@
* @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 934b7a3..79eaa8c 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 3eee43a..ef04280 100644
--- a/includes/specials/SpecialListfiles.php
+++ b/includes/specials/SpecialListfiles.php
@@ -108,12 +108,12 @@
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 993285f..cc3226d 100644
--- a/includes/specials/SpecialListusers.php
+++ b/includes/specials/SpecialListusers.php
@@ -69,7 +69,9 @@
$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 = '';
--
To view, visit https://gerrit.wikimedia.org/r/156128
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I58694f7a0892c986e7215f59b56b014cece8d40d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits