protected $mLastShown, $mFirstShown, $mPastTheEndIndex, $mDefaultQuery, $mNavigationBar;
+ /**
+ * Whether to include the offset in the query
+ */
+ protected $mIncludeOffset = false;
+
/**
* Result object for the query. Warning: seek before use.
*
# Use consistent behavior for the limit options
$this->mDefaultLimit = intval( $this->getUser()->getOption( 'rclimit' ) );
- list( $this->mLimit, /* $offset */ ) = $this->mRequest->getLimitOffset();
+ if ( !$this->mLimit ) {
+ // Don't override if a subclass calls $this->setLimit() in its constructor.
+ list( $this->mLimit, /* $offset */ ) = $this->mRequest->getLimitOffset();
+ }
$this->mIsBackwards = ( $this->mRequest->getVal( 'dir' ) == 'prev' );
$this->mDb = wfGetDB( DB_SLAVE );
/**
* Set the limit from an other source than the request
*
+ * Verifies limit is between 1 and 5000
+ *
* @param $limit Int|String
*/
function setLimit( $limit ) {
- $this->mLimit = $limit;
+ $limit = (int) $limit;
+ // WebRequest::getLimitOffset() puts a cap of 5000, so do same here.
+ if ( $limit > 5000 ) {
+ $limit = 5000;
+ }
+ if ( $limit > 0 ) {
+ $this->mLimit = $limit;
+ }
+ }
+
+ /**
+ * Set whether a row matching exactly the offset should be also included
+ * in the result or not. By default this is not the case, but when the
+ * offset is user-supplied this might be wanted.
+ *
+ * @param $include bool
+ */
+ public function setIncludeOffset( $include ) {
+ $this->mIncludeOffset = $include;
}
/**
if ( $numRows > $this->mLimit && $numRows > 1 ) {
$res->seek( $numRows - 1 );
$this->mPastTheEndRow = $res->fetchObject();
- $indexField = $this->mIndexField;
- $this->mPastTheEndIndex = $this->mPastTheEndRow->$indexField;
+ $this->mPastTheEndIndex = $this->mPastTheEndRow->$indexColumn;
$res->seek( $numRows - 2 );
$row = $res->fetchRow();
$lastIndex = $row[$indexColumn];
$sortColumns = array_merge( array( $this->mIndexField ), $this->mExtraSortFields );
if ( $descending ) {
$options['ORDER BY'] = $sortColumns;
- $operator = '>';
+ $operator = $this->mIncludeOffset ? '>=' : '>';
} else {
$orderBy = array();
foreach ( $sortColumns as $col ) {
$orderBy[] = $col . ' DESC';
}
$options['ORDER BY'] = $orderBy;
- $operator = '<';
+ $operator = $this->mIncludeOffset ? '<=' : '<';
}
if ( $offset != '' ) {
$conds[] = $this->mIndexField . $operator . $this->mDb->addQuotes( $offset );
$tableClass = htmlspecialchars( $this->getTableClass() );
$sortClass = htmlspecialchars( $this->getSortHeaderClass() );
- $s = "<table style='border:1;' class=\"mw-datatable $tableClass\"><thead><tr>\n";
+ $s = "<table style='border:1px;' class=\"mw-datatable $tableClass\"><thead><tr>\n";
$fields = $this->getFieldNames();
# Make table header