/**
* Basic pager interface.
+ * @addtogroup Pager
*/
interface Pager {
function getNavigationBar();
/**
* IndexPager is an efficient pager which uses a (roughly unique) index in the
* data set to implement paging, rather than a "LIMIT offset,limit" clause.
- * In MySQL, such a limit/offset clause requires counting through the specified number
- * of offset rows to find the desired data, which can be expensive for large offsets.
+ * In MySQL, such a limit/offset clause requires counting through the
+ * specified number of offset rows to find the desired data, which can be
+ * expensive for large offsets.
*
- * ReverseChronologicalPager is a child class of the abstract IndexPager, and contains
- * some formatting and display code which is specific to the use of timestamps as
- * indexes. Here is a synopsis of its operation:
+ * ReverseChronologicalPager is a child class of the abstract IndexPager, and
+ * contains some formatting and display code which is specific to the use of
+ * timestamps as indexes. Here is a synopsis of its operation:
*
- * * The query is specified by the offset, limit and direction (dir) parameters, in
- * addition to any subclass-specific parameters.
+ * * The query is specified by the offset, limit and direction (dir)
+ * parameters, in addition to any subclass-specific parameters.
+ * * The offset is the non-inclusive start of the DB query. A row with an
+ * index value equal to the offset will never be shown.
+ * * The query may either be done backwards, where the rows are returned by
+ * the database in the opposite order to which they are displayed to the
+ * user, or forwards. This is specified by the "dir" parameter, dir=prev
+ * means backwards, anything else means forwards. The offset value
+ * specifies the start of the database result set, which may be either
+ * the start or end of the displayed data set. This allows "previous"
+ * links to be implemented without knowledge of the index value at the
+ * start of the previous page.
+ * * An additional row beyond the user-specified limit is always requested.
+ * This allows us to tell whether we should display a "next" link in the
+ * case of forwards mode, or a "previous" link in the case of backwards
+ * mode. Determining whether to display the other link (the one for the
+ * page before the start of the database result set) can be done
+ * heuristically by examining the offset.
*
- * * The offset is the non-inclusive start of the DB query. A row with an index value
- * equal to the offset will never be shown.
+ * * An empty offset indicates that the offset condition should be omitted
+ * from the query. This naturally produces either the first page or the
+ * last page depending on the dir parameter.
*
- * * The query may either be done backwards, where the rows are returned by the database
- * in the opposite order to which they are displayed to the user, or forwards. This is
- * specified by the "dir" parameter, dir=prev means backwards, anything else means
- * forwards. The offset value specifies the start of the database result set, which
- * may be either the start or end of the displayed data set. This allows "previous"
- * links to be implemented without knowledge of the index value at the start of the
- * previous page.
+ * Subclassing the pager to implement concrete functionality should be fairly
+ * simple, please see the examples in PageHistory.php and
+ * SpecialIpblocklist.php. You just need to override formatRow(),
+ * getQueryInfo() and getIndexField(). Don't forget to call the parent
+ * constructor if you override it.
*
- * * An additional row beyond the user-specified limit is always requested. This allows
- * us to tell whether we should display a "next" link in the case of forwards mode,
- * or a "previous" link in the case of backwards mode. Determining whether to
- * display the other link (the one for the page before the start of the database
- * result set) can be done heuristically by examining the offset.
- *
- * * An empty offset indicates that the offset condition should be omitted from the query.
- * This naturally produces either the first page or the last page depending on the
- * dir parameter.
- *
- * Subclassing the pager to implement concrete functionality should be fairly simple,
- * please see the examples in PageHistory.php and SpecialIpblocklist.php. You just need
- * to override formatRow(), getQueryInfo() and getIndexField(). Don't forget to call the
- * parent constructor if you override it.
+ * @addtogroup Pager
*/
abstract class IndexPager implements Pager {
public $mRequest;
public $mResult;
function __construct() {
- global $wgRequest;
+ global $wgRequest, $wgUser;
$this->mRequest = $wgRequest;
-
- # NB: the offset is quoted, not validated. It is treated as an arbitrary string
- # to support the widest variety of index types. Be careful outputting it into
- # HTML!
+
+ # NB: the offset is quoted, not validated. It is treated as an
+ # arbitrary string to support the widest variety of index types. Be
+ # careful outputting it into HTML!
$this->mOffset = $this->mRequest->getText( 'offset' );
- $this->mLimit = $this->mRequest->getInt( 'limit', $this->mDefaultLimit );
- if ( $this->mLimit <= 0 || $this->mLimit > 50000 ) {
- $this->mLimit = $this->mDefaultLimit;
- }
+
+ # Use consistent behavior for the limit options
+ $this->mDefaultLimit = intval( $wgUser->getOption( 'rclimit' ) );
+ list( $this->mLimit, /* $offset */ ) = $this->mRequest->getLimitOffset();
+
$this->mIsBackwards = ( $this->mRequest->getVal( 'dir' ) == 'prev' );
$this->mIndexField = $this->getIndexField();
$this->mDb = wfGetDB( DB_SLAVE );
$lastIndex = $row[$this->mIndexField];
} else {
$this->mPastTheEndRow = null;
- # Setting indexes to an empty string means that they will be omitted
- # if they would otherwise appear in URLs. It just so happens that this
- # is the right thing to do in the standard UI, in all the relevant cases.
+ # Setting indexes to an empty string means that they will be
+ # omitted if they would otherwise appear in URLs. It just so
+ # happens that this is the right thing to do in the standard
+ # UI, in all the relevant cases.
$this->mPastTheEndIndex = '';
$res->seek( $numRows - 1 );
$row = $res->fetchRow();
}
/**
- * Do a query with specified parameters, rather than using the object context
+ * Do a query with specified parameters, rather than using the object
+ * context
*
* @param string $offset Index offset, inclusive
* @param integer $limit Exact query limit
* @param boolean $descending Query direction, false for ascending, true for descending
* @return ResultWrapper
*/
- function reallyDoQuery( $offset, $limit, $ascending ) {
+ function reallyDoQuery( $offset, $limit, $descending ) {
$fname = __METHOD__ . ' (' . get_class( $this ) . ')';
$info = $this->getQueryInfo();
$tables = $info['tables'];
$fields = $info['fields'];
$conds = isset( $info['conds'] ) ? $info['conds'] : array();
$options = isset( $info['options'] ) ? $info['options'] : array();
- if ( $ascending ) {
+ if ( $descending ) {
$options['ORDER BY'] = $this->mIndexField;
$operator = '>';
} else {
if ( $query === null ) {
return $text;
} else {
- return Linker::makeKnownLinkObj( $this->getTitle(), $text,
+ return $this->getSkin()->makeKnownLinkObj( $this->getTitle(), $text,
wfArrayToCGI( $query, $this->getDefaultQuery() ) );
}
}
return $GLOBALS['wgTitle'];
}
+ /**
+ * Get the current skin. This can be overridden if necessary.
+ */
+ function getSkin() {
+ if ( !isset( $this->mSkin ) ) {
+ global $wgUser;
+ $this->mSkin = $wgUser->getSkin();
+ }
+ return $this->mSkin;
+ }
+
/**
* Get an array of query parameters that should be put into self-links.
* By default, all parameters passed in the URL are used, except for a
$next = array( 'offset' => $this->mLastShown, 'limit' => $urlLimit );
$last = array( 'dir' => 'prev', 'limit' => $urlLimit );
}
- return compact( 'prev', 'next', 'first', 'last' );
+ return array( 'prev' => $prev, 'next' => $next, 'first' => $first, 'last' => $last );
}
/**
- * Get paging links. If a link is disabled, the item from $disabledTexts will
- * be used. If there is no such item, the unlinked text from $linkTexts will
- * be used. Both $linkTexts and $disabledTexts are arrays of HTML.
+ * Get paging links. If a link is disabled, the item from $disabledTexts
+ * will be used. If there is no such item, the unlinked text from
+ * $linkTexts will be used. Both $linkTexts and $disabledTexts are arrays
+ * of HTML.
*/
function getPagingLinks( $linkTexts, $disabledTexts = array() ) {
$queries = $this->getPagingQueries();
abstract function getIndexField();
}
+
+/**
+ * IndexPager with an alphabetic list and a formatted navigation bar
+ * @addtogroup Pager
+ */
+abstract class AlphabeticPager extends IndexPager {
+ public $mDefaultDirection = false;
+
+ function __construct() {
+ parent::__construct();
+ }
+
+ /**
+ * Shamelessly stolen bits from ReverseChronologicalPager, d
+ * didn't want to do class magic as may be still revamped
+ */
+ function getNavigationBar() {
+ global $wgLang;
+
+ $linkTexts = array(
+ 'prev' => wfMsgHtml( "prevn", $this->mLimit ),
+ 'next' => wfMsgHtml( 'nextn', $this->mLimit ),
+ 'first' => wfMsgHtml('page_first'), /* Introduced the message */
+ 'last' => wfMsgHtml( 'page_last' ) /* Introduced the message */
+ );
+
+ $pagingLinks = $this->getPagingLinks( $linkTexts );
+ $limitLinks = $this->getLimitLinks();
+ $limits = implode( ' | ', $limitLinks );
+
+ $this->mNavigationBar = "({$pagingLinks['first']} | {$pagingLinks['last']}) " . wfMsgHtml("viewprevnext", $pagingLinks['prev'], $pagingLinks['next'], $limits);
+ return $this->mNavigationBar;
+
+ }
+}
+
/**
* IndexPager with a formatted navigation bar
+ * @addtogroup Pager
*/
abstract class ReverseChronologicalPager extends IndexPager {
public $mDefaultDirection = true;
$limitLinks = $this->getLimitLinks();
$limits = implode( ' | ', $limitLinks );
- $this->mNavigationBar = "({$pagingLinks['first']} | {$pagingLinks['last']}) " . wfMsgHtml("viewprevnext", $pagingLinks['prev'], $pagingLinks['next'], $limits);
+ $this->mNavigationBar = "({$pagingLinks['first']} | {$pagingLinks['last']}) " .
+ wfMsgHtml("viewprevnext", $pagingLinks['prev'], $pagingLinks['next'], $limits);
return $this->mNavigationBar;
}
}
/**
* Table-based display with a user-selectable sort order
+ * @addtogroup Pager
*/
abstract class TablePager extends IndexPager {
var $mSort;
}
function getEndBody() {
- return '</tbody></table>';
+ return "</tbody></table>\n";
}
function getEmptyBody() {
'next' => $wgContLang->isRTL() ? 'arrow_disabled_left_25.png' : 'arrow_disabled_right_25.png',
'last' => $wgContLang->isRTL() ? 'arrow_disabled_first_25.png' : 'arrow_disabled_last_25.png',
);
-
+
$linkTexts = array();
$disabledTexts = array();
foreach ( $labels as $type => $label ) {
$links = $this->getPagingLinks( $linkTexts, $disabledTexts );
$navClass = htmlspecialchars( $this->getNavClass() );
- $s = "<table class=\"$navClass\" align=\"center\" cellpadding=\"3\"><tr>";
+ $s = "<table class=\"$navClass\" align=\"center\" cellpadding=\"3\"><tr>\n";
$cellAttrs = 'valign="top" align="center" width="' . 100 / count( $links ) . '%"';
foreach ( $labels as $type => $label ) {
$s .= "<td $cellAttrs>{$links[$type]}</td>\n";
}
- $s .= '</tr></table>';
+ $s .= "</tr></table>\n";
return $s;
}
}
/**
- * Return true if the named field should be sortable by the UI, false otherwise
+ * Return true if the named field should be sortable by the UI, false
+ * otherwise
+ *
* @param string $field
*/
abstract function isFieldSortable( $field );
/**
- * Format a table cell. The return value should be HTML, but use an empty string
- * not for empty cells. Do not include the <td> and </td>.
+ * Format a table cell. The return value should be HTML, but use an empty
+ * string not for empty cells. Do not include the <td> and </td>.
+ *
+ * The current result row is available as $this->mCurrentRow, in case you
+ * need more context.
*
* @param string $name The database field name
* @param string $value The value retrieved from the database
- *
- * The current result row is available as $this->mCurrentRow, in case you need
- * more context.
*/
abstract function formatValue( $name, $value );
abstract function getDefaultSort();
/**
- * An array mapping database field names to a textual description of the field
- * name, for use in the table header. The description should be plain text, it
- * will be HTML-escaped later.
+ * An array mapping database field names to a textual description of the
+ * field name, for use in the table header. The description should be plain
+ * text, it will be HTML-escaped later.
*/
abstract function getFieldNames();
}
-?>
+