+ /**
+ * 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 $mLimitsShown = array( 20, 50, 100, 250, 500 );
+ public $mLimitsShown = [ 20, 50, 100, 250, 500 ];
public $mDefaultLimit = 50;
public $mOffset, $mLimit;
public $mQueryDone = false;
public $mDefaultLimit = 50;
public $mOffset, $mLimit;
public $mQueryDone = false;
* 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
* 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
$this->mIndexField = $index[$order];
$this->mExtraSortFields = isset( $extraSort[$order] )
? (array)$extraSort[$order]
$this->mIndexField = $index[$order];
$this->mExtraSortFields = isset( $extraSort[$order] )
? (array)$extraSort[$order]
} elseif ( is_array( $index ) ) {
# First element is the default
reset( $index );
list( $this->mOrderType, $this->mIndexField ) = each( $index );
$this->mExtraSortFields = isset( $extraSort[$this->mOrderType] )
? (array)$extraSort[$this->mOrderType]
} elseif ( is_array( $index ) ) {
# First element is the default
reset( $index );
list( $this->mOrderType, $this->mIndexField ) = each( $index );
$this->mExtraSortFields = isset( $extraSort[$this->mOrderType] )
? (array)$extraSort[$this->mOrderType]
public function doQuery() {
# Use the child class name for profiling
$fname = __METHOD__ . ' (' . get_class( $this ) . ')';
public function doQuery() {
# Use the child class name for profiling
$fname = __METHOD__ . ' (' . get_class( $this ) . ')';
$descending = ( $this->mIsBackwards == $this->mDefaultDirection );
# Plus an extra row so that we can tell the "next" link should be shown
$queryLimit = $this->mLimit + 1;
$descending = ( $this->mIsBackwards == $this->mDefaultDirection );
# Plus an extra row so that we can tell the "next" link should be shown
$queryLimit = $this->mLimit + 1;
$info = $this->getQueryInfo();
$tables = $info['tables'];
$fields = $info['fields'];
$info = $this->getQueryInfo();
$tables = $info['tables'];
$fields = $info['fields'];
- $conds = isset( $info['conds'] ) ? $info['conds'] : array();
- $options = isset( $info['options'] ) ? $info['options'] : array();
- $join_conds = isset( $info['join_conds'] ) ? $info['join_conds'] : array();
- $sortColumns = array_merge( array( $this->mIndexField ), $this->mExtraSortFields );
+ $conds = isset( $info['conds'] ) ? $info['conds'] : [];
+ $options = isset( $info['options'] ) ? $info['options'] : [];
+ $join_conds = isset( $info['join_conds'] ) ? $info['join_conds'] : [];
+ $sortColumns = array_merge( [ $this->mIndexField ], $this->mExtraSortFields );
$conds[] = $this->mIndexField . $operator . $this->mDb->addQuotes( $offset );
}
$options['LIMIT'] = intval( $limit );
$conds[] = $this->mIndexField . $operator . $this->mDb->addQuotes( $offset );
}
$options['LIMIT'] = intval( $limit );
- return array( $tables, $fields, $conds, $fname, $options, $join_conds );
+ return [ $tables, $fields, $conds, $fname, $options, $join_conds ];
*
* @param string $text Text displayed on the link
* @param array $query Associative array of parameter to be in the query string
*
* @param string $text Text displayed on the link
* @param array $query Associative array of parameter to be in the query string
- * @param string $type Value of the "rel" attribute
- *
+ * @param string $type Link type used to create additional attributes, like "rel", "class" or
+ * "title". Valid values (non-exhaustive list): 'first', 'last', 'prev', 'next', 'asc', 'desc'.
* @return string HTML fragment
*/
function makeLink( $text, array $query = null, $type = null ) {
* @return string HTML fragment
*/
function makeLink( $text, array $query = null, $type = null ) {
- $attrs = array();
- if ( in_array( $type, array( 'first', 'prev', 'next', 'last' ) ) ) {
- # HTML5 rel attributes
+ $attrs = [];
+ if ( in_array( $type, [ 'prev', 'next' ] ) ) {
- $next = array( 'offset' => $this->mLastShown, 'limit' => $urlLimit );
- $last = array( 'dir' => 'prev', 'limit' => $urlLimit );
+ $next = [ 'offset' => $this->mLastShown, 'limit' => $urlLimit ];
+ $last = [ 'dir' => 'prev', 'limit' => $urlLimit ];
foreach ( $this->mLimitsShown as $limit ) {
$links[] = $this->makeLink(
$this->getLanguage()->formatNum( $limit ),
foreach ( $this->mLimitsShown as $limit ) {
$links[] = $this->makeLink(
$this->getLanguage()->formatNum( $limit ),
* not be used in the pager offset or in any links for users.
*
* If getIndexField() returns an array of 'querykey' => 'indexfield' pairs then
* not be used in the pager offset or in any links for users.
*
* If getIndexField() returns an array of 'querykey' => 'indexfield' pairs then
- * this must return a corresponding array of 'querykey' => array( fields...) pairs
- * in order for a request with &count=querykey to use array( fields...) to sort.
+ * this must return a corresponding array of 'querykey' => [ fields... ] pairs
+ * in order for a request with &count=querykey to use [ fields... ] to sort.
*
* This is useful for pagers that GROUP BY a unique column (say page_id)
* and ORDER BY another (say page_len). Using GROUP BY and ORDER BY both on
*
* This is useful for pagers that GROUP BY a unique column (say page_id)
* and ORDER BY another (say page_len). Using GROUP BY and ORDER BY both on
- * 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.
* 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.