MediaWiki
REL1_19
|
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. More...
Public Member Functions | |
__construct (IContextSource $context=null) | |
doQuery () | |
Do the query, using information from the object context. | |
extractResultInfo ($offset, $limit, ResultWrapper $res) | |
Extract some useful data from the result object for use by the navigation bar, put it into $this. | |
formatRow ($row) | |
Abstract formatting function. | |
getBody () | |
Get the formatted result list. | |
getDefaultQuery () | |
Get an array of query parameters that should be put into self-links. | |
getIndexField () | |
This function should be overridden to return the name of the index fi- eld. | |
getLimitLinks () | |
getNumRows () | |
Get the number of rows in the result set. | |
getPagingLinks ($linkTexts, $disabledTexts=array()) | |
Get paging links. | |
getPagingQueries () | |
Get a URL query array for the prev, next, first and last links. | |
getQueryInfo () | |
This function should be overridden to provide all parameters needed for the main paged query. | |
getResult () | |
getSqlComment () | |
Get some text to go in brackets in the "function name" part of the SQL comment. | |
isNavigationBarShown () | |
Returns whether to show the "navigation bar". | |
makeLink ($text, $query=null, $type=null) | |
Make a self-link. | |
reallyDoQuery ($offset, $limit, $descending) | |
Do a query with specified parameters, rather than using the object context. | |
setLimit ($limit) | |
Set the limit from an other source than the request. | |
setOffset ($offset) | |
Set the offset from an other source than the request. | |
Public Attributes | |
$mDb | |
$mDefaultDirection | |
$mDefaultDirection gives the direction to use when sorting results: false for ascending, true for descending. | |
$mDefaultLimit = 50 | |
$mDefaultQuery | |
$mFirstShown | |
$mIsBackwards | |
$mIsFirst | |
True if the current result set is the first one. | |
$mIsLast | |
$mLimit | |
$mLimitsShown = array( 20, 50, 100, 250, 500 ) | |
$mNavigationBar | |
$mOffset | |
$mPastTheEndIndex | |
$mPastTheEndRow | |
$mQueryDone = false | |
$mRequest | |
$mResult | |
Protected Member Functions | |
doBatchLookups () | |
Called from getBody(), before getStartBody() is called and after doQuery() was called. | |
getDefaultDirections () | |
Return the default sorting direction: false for ascending, true for de- scending. | |
getEmptyBody () | |
Hook into getBody(), for the bit between the start and the end when there are no rows. | |
getEndBody () | |
Hook into getBody() for the end of the list. | |
getExtraSortFields () | |
This function should be overridden to return the names of secondary columns to order by in addition to the column in getIndexField(). | |
getStartBody () | |
Hook into getBody(), allows text to be inserted at the start. | |
preprocessResults ($result) | |
Pre-process results; useful for performing batch existence checks, etc. | |
Protected Attributes | |
$mExtraSortFields | |
An array of secondary columns to order by. | |
$mIndexField | |
The index to actually be used for ordering. | |
$mLastShown | |
$mOrderType | |
For pages that support multiple types of ordering, which one to use. |
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.
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 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.
* 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 HistoryPage.php and SpecialBlockList.php. You just need to override formatRow(), getQueryInfo() and getIndexField(). Don't forget to call the parent constructor if you override it.
IndexPager::__construct | ( | IContextSource $ | context = null | ) |
Reimplemented in TablePager.
Definition at line 109 of file Pager.php.
References ContextSource\$context, $dir, getDefaultDirections(), getExtraSortFields(), getIndexField(), ContextSource\getRequest(), ContextSource\getUser(), ContextSource\setContext(), and wfGetDB().
IndexPager::doBatchLookups | ( | ) | [protected] |
Called from getBody(), before getStartBody() is called and after doQuery() was called.
This will be called only if there are rows in the result set.
Reimplemented in ContribsPager, and HistoryPager.
Definition at line 400 of file Pager.php.
Referenced by getBody().
Do the query, using information from the object context.
This function has been kept minimal to make it overridable if necessary, to allow for result sets formed from multiple DB queries.
Reimplemented in ImageHistoryPseudoPager, and LogPager.
Definition at line 164 of file Pager.php.
References $fname, extractResultInfo(), preprocessResults(), reallyDoQuery(), wfProfileIn(), and wfProfileOut().
Referenced by UsersPager\getBody(), getBody(), getNumRows(), getPagingQueries(), and isNavigationBarShown().
IndexPager::extractResultInfo | ( | $ | offset, |
$ | limit, | ||
ResultWrapper $ | res | ||
) |
Extract some useful data from the result object for use by the navigation bar, put it into $this.
$offset | String: index offset, inclusive |
$limit | Integer: exact query limit |
$res | ResultWrapper |
Definition at line 219 of file Pager.php.
References $limit, ResultWrapper\fetchObject(), ResultWrapper\fetchRow(), ResultWrapper\numRows(), and ResultWrapper\seek().
Referenced by doQuery().
IndexPager::formatRow | ( | $ | row | ) | [abstract] |
Abstract formatting function.
This should return an HTML string representing the result row $row. Rows will be concatenated and returned by getBody()
$row | Object: database row |
Reimplemented in ImageHistoryPseudoPager, TablePager, ContribsPager, NewPagesPager, MergeHistoryPager, AllmessagesTablePager, HistoryPager, ProtectedPagesPager, LogPager, ProtectedTitlesPager, DeletedContribsPager, UsersPager, ActiveUsersPager, CategoryPager, and NewFilesPager.
Referenced by getBody().
Get the formatted result list.
Calls getStartBody(), formatRow() and getEndBody(), concatenates the results and returns them.
Implements Pager.
Reimplemented in ImageHistoryPseudoPager, UsersPager, and CategoryPager.
Definition at line 328 of file Pager.php.
References doBatchLookups(), doQuery(), formatRow(), getEmptyBody(), getEndBody(), and getStartBody().
IndexPager::getDefaultDirections | ( | ) | [protected] |
Return the default sorting direction: false for ascending, true for de- scending.
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.
For backward compatibility, this method's return value will be ignored if $this->mDefaultDirection is already set when the constructor is called, for instance if it's statically initialized. In that case the value of that variable (which must be a boolean) will be used.
Note that despite its name, this does not return the value of the $this->mDefaultDirection member variable. That's the default for this particular instantiation, which is a single value. This is the set of all defaults for the class.
Reimplemented in CategoryPager.
Definition at line 637 of file Pager.php.
Referenced by __construct().
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 short blacklist.
Reimplemented in ContribsPager, ImageListPager, UsersPager, CategoryPager, LogPager, and DeletedContribsPager.
Definition at line 438 of file Pager.php.
References ContextSource\getRequest().
Referenced by makeLink().
IndexPager::getEmptyBody | ( | ) | [protected] |
Hook into getBody(), for the bit between the start and the end when there are no rows.
Reimplemented in TablePager.
Definition at line 427 of file Pager.php.
Referenced by getBody().
IndexPager::getEndBody | ( | ) | [protected] |
Hook into getBody() for the end of the list.
Reimplemented in TablePager, ContribsPager, NewPagesPager, HistoryPager, NewFilesPager, and DeletedContribsPager.
Definition at line 417 of file Pager.php.
Referenced by getBody().
IndexPager::getExtraSortFields | ( | ) | [protected] |
This function should be overridden to return the names of secondary columns to order by in addition to the column in getIndexField().
These fields will 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 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 page_len,page_id avoids temp tables (given a page_len index). This would also work if page_id was non-unique but we had a page_len,page_id index.
Definition at line 616 of file Pager.php.
Referenced by __construct().
IndexPager::getIndexField | ( | ) | [abstract] |
This function should be overridden to return the name of the index fi- eld.
If the pager supports multiple orders, it may return an array of 'querykey' => 'indexfield' pairs, so that a request with &count=querykey will use indexfield to sort. In this case, the first returned key is the default.
Needless to say, it's really not a good idea to use a non-unique index for this! That won't page right.
Reimplemented in ImageHistoryPseudoPager, TablePager, ContribsPager, NewPagesPager, MergeHistoryPager, BlockListPager, HistoryPager, ProtectedPagesPager, LogPager, ProtectedTitlesPager, NewFilesPager, ActiveUsersPager, CategoryPager, DeletedContribsPager, and UsersPager.
Referenced by __construct(), and AlphabeticPager\getNavigationBar().
Definition at line 545 of file Pager.php.
References $limit, ContextSource\getLanguage(), and makeLink().
Referenced by DeletedContribsPager\getNavigationBar(), AlphabeticPager\getNavigationBar(), and ReverseChronologicalPager\getNavigationBar().
Get the number of rows in the result set.
Definition at line 457 of file Pager.php.
References doQuery().
Referenced by HistoryPager\diffButtons(), HistoryPager\getEndBody(), LogPager\getStartBody(), and HistoryPager\submitButton().
IndexPager::getPagingLinks | ( | $ | linkTexts, |
$ | disabledTexts = array() |
||
) |
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.
$linkTexts | Array |
$disabledTexts | Array |
Definition at line 526 of file Pager.php.
References getPagingQueries(), and makeLink().
Referenced by DeletedContribsPager\getNavigationBar(), AlphabeticPager\getNavigationBar(), ReverseChronologicalPager\getNavigationBar(), and TablePager\getNavigationBar().
Get a URL query array for the prev, next, first and last links.
Reimplemented in ImageListPager.
Definition at line 469 of file Pager.php.
References doQuery().
Referenced by getPagingLinks().
IndexPager::getQueryInfo | ( | ) | [abstract] |
This function should be overridden to provide all parameters needed for the main paged query.
It returns an associative array with the following elements: tables => Table(s) for passing to Database::select() fields => Field(s) for passing to Database::select(), may be * conds => WHERE conditions options => option array join_conds => JOIN conditions
Reimplemented in ImageHistoryPseudoPager, ContribsPager, NewPagesPager, MergeHistoryPager, AllmessagesTablePager, BlockListPager, HistoryPager, ProtectedPagesPager, ProtectedTitlesPager, LogPager, ImageListPager, ActiveUsersPager, UsersPager, CategoryPager, NewFilesPager, and DeletedContribsPager.
Referenced by reallyDoQuery().
Get some text to go in brackets in the "function name" part of the SQL comment.
Reimplemented in ContribsPager, and HistoryPager.
Definition at line 274 of file Pager.php.
Referenced by reallyDoQuery().
IndexPager::getStartBody | ( | ) | [protected] |
Hook into getBody(), allows text to be inserted at the start.
This will be called even if there are no rows in the result set.
Reimplemented in TablePager, ContribsPager, NewPagesPager, MergeHistoryPager, HistoryPager, AllmessagesTablePager, ProtectedPagesPager, LogPager, ProtectedTitlesPager, ImageListPager, NewFilesPager, and DeletedContribsPager.
Definition at line 408 of file Pager.php.
Referenced by getBody().
Returns whether to show the "navigation bar".
Definition at line 508 of file Pager.php.
References doQuery().
Referenced by AlphabeticPager\getNavigationBar(), ReverseChronologicalPager\getNavigationBar(), and TablePager\getNavigationBar().
IndexPager::makeLink | ( | $ | text, |
$ | query = null , |
||
$ | type = null |
||
) |
Make a self-link.
$text | String: text displayed on the link |
$query | Array: associative array of paramter to be in the query string |
$type | String: value of the "rel" attribute |
Definition at line 371 of file Pager.php.
References getDefaultQuery(), ContextSource\getTitle(), and Linker\linkKnown().
Referenced by getLimitLinks(), AlphabeticPager\getNavigationBar(), getPagingLinks(), and TablePager\getStartBody().
IndexPager::preprocessResults | ( | $ | result | ) | [protected] |
Pre-process results; useful for performing batch existence checks, etc.
$result | ResultWrapper |
Reimplemented in BlockListPager.
Definition at line 320 of file Pager.php.
Referenced by doQuery().
IndexPager::reallyDoQuery | ( | $ | offset, |
$ | limit, | ||
$ | descending | ||
) |
Do a query with specified parameters, rather than using the object context.
$offset | String: index offset, inclusive |
$limit | Integer: exact query limit |
$descending | Boolean: query direction, false for ascending, true for descending |
Reimplemented in AllmessagesTablePager.
Definition at line 287 of file Pager.php.
References $fname, $limit, $options, $res, getQueryInfo(), and getSqlComment().
Referenced by doQuery().
IndexPager::setLimit | ( | $ | limit | ) |
IndexPager::setOffset | ( | $ | offset | ) |
Set the offset from an other source than the request.
$offset | Int|String |
Definition at line 199 of file Pager.php.
Referenced by CategoryPager\__construct().
IndexPager::$mDb |
Reimplemented in ContribsPager, and DeletedContribsPager.
IndexPager::$mDefaultDirection |
$mDefaultDirection gives the direction to use when sorting results: false for ascending, true for 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 result will be at the bottom, not the top.
Like $mIndexField, $mDefaultDirection will be a single value even if the class supports multiple default directions for different order types.
Reimplemented in ReverseChronologicalPager, ContribsPager, and DeletedContribsPager.
IndexPager::$mExtraSortFields [protected] |
IndexPager::$mIndexField [protected] |
IndexPager::$mIsFirst |
IndexPager::$mLimitsShown = array( 20, 50, 100, 250, 500 ) |
Reimplemented in AllmessagesTablePager.
IndexPager::$mOrderType [protected] |