MediaWiki
REL1_24
|
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 ($isFirst, $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. | |
getDatabase () | |
Get the Database object in use. | |
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. | |
getLimit () | |
Get the current limit. | |
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, array $query=null, $type=null) | |
Make a self-link. | |
reallyDoQuery ($offset, $limit, $descending) | |
Do a query with specified parameters, rather than using the object context. | |
setIncludeOffset ($include) | |
Set whether a row matching exactly the offset should be also included in the result or not. | |
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: DIR_ASCENDING or DIR_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 | |
ResultWrapper | $mResult |
Result object for the query. | |
const | DIR_ASCENDING = false |
Constants for the $mDefaultDirection field. | |
const | DIR_DESCENDING = true |
Protected Member Functions | |
buildQueryInfo ($offset, $limit, $descending) | |
Build variables to use by the database wrapper. | |
doBatchLookups () | |
Called from getBody(), before getStartBody() is called and after doQuery() was called. | |
getDefaultDirections () | |
Return the default sorting direction: DIR_ASCENDING or DIR_DESCENDING. | |
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. | |
$mIncludeOffset = false | |
Whether to include the offset in the query. | |
$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 HistoryAction.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.
Definition at line 66 of file IndexPager.php.
IndexPager::__construct | ( | IContextSource $ | context = null | ) |
Reimplemented in TablePager.
Definition at line 127 of file IndexPager.php.
References ContextSource\$context, $dir, array(), getDefaultDirections(), getExtraSortFields(), getIndexField(), ContextSource\getRequest(), ContextSource\getUser(), list, ContextSource\setContext(), and wfGetDB().
IndexPager::buildQueryInfo | ( | $ | offset, |
$ | limit, | ||
$ | descending | ||
) | [protected] |
Build variables to use by the database wrapper.
string | $offset | Index offset, inclusive |
int | $limit | Exact query limit |
bool | $descending | Query direction, false for ascending, true for descending |
Definition at line 377 of file IndexPager.php.
Referenced by ImageListPager\reallyDoQuery().
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, HistoryPager, ImageListPager, UsersPager, and ActiveUsersPager.
Definition at line 496 of file IndexPager.php.
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 195 of file IndexPager.php.
IndexPager::extractResultInfo | ( | $ | isFirst, |
$ | limit, | ||
ResultWrapper $ | res | ||
) |
Extract some useful data from the result object for use by the navigation bar, put it into $this.
bool | $isFirst | False if there are rows before those fetched (i.e. if a "previous" link would make sense) |
int | $limit | Exact query limit |
ResultWrapper | $res |
Definition at line 295 of file IndexPager.php.
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()
array | stdClass | $row | Database row |
Reimplemented in ImageHistoryPseudoPager, ContribsPager, NewPagesPager, MergeHistoryPager, HistoryPager, AllMessagesTablePager, LogPager, ProtectedTitlesPager, TablePager, CategoryPager, UsersPager, NewFilesPager, DeletedContribsPager, and ActiveUsersPager.
Get the formatted result list.
Calls getStartBody(), formatRow() and getEndBody(), concatenates the results and returns them.
Implements Pager.
Reimplemented in ImageHistoryPseudoPager, CategoryPager, and TablePager.
Definition at line 418 of file IndexPager.php.
Get the Database object in use.
Reimplemented in DeletedContribsPager.
Definition at line 186 of file IndexPager.php.
IndexPager::getDefaultDirections | ( | ) | [protected] |
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.
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 738 of file IndexPager.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 535 of file IndexPager.php.
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 524 of file IndexPager.php.
IndexPager::getEndBody | ( | ) | [protected] |
Hook into getBody() for the end of the list.
Reimplemented in ContribsPager, NewPagesPager, HistoryPager, TablePager, NewFilesPager, and DeletedContribsPager.
Definition at line 514 of file IndexPager.php.
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 715 of file IndexPager.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, ContribsPager, NewPagesPager, ProtectedPagesPager, MergeHistoryPager, HistoryPager, BlockListPager, LogPager, ProtectedTitlesPager, TablePager, CategoryPager, NewFilesPager, UsersPager, DeletedContribsPager, and ActiveUsersPager.
Referenced by __construct(), and AlphabeticPager\getNavigationBar().
Definition at line 644 of file IndexPager.php.
References $limit, array(), as, ContextSource\getLanguage(), and makeLink().
Referenced by ReverseChronologicalPager\getNavigationBar(), AlphabeticPager\getNavigationBar(), and DeletedContribsPager\getNavigationBar().
Get the number of rows in the result set.
Definition at line 554 of file IndexPager.php.
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.
array | $linkTexts | |
array | $disabledTexts |
Definition at line 623 of file IndexPager.php.
Referenced by ReverseChronologicalPager\getNavigationBar(), AlphabeticPager\getNavigationBar(), DeletedContribsPager\getNavigationBar(), and TablePager\getNavigationBar().
Get a URL query array for the prev, next, first and last links.
Reimplemented in ImageListPager.
Definition at line 566 of file IndexPager.php.
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, MergeHistoryPager, NewPagesPager, ProtectedPagesPager, AllMessagesTablePager, HistoryPager, BlockListPager, ProtectedTitlesPager, LogPager, ImageListPager, CategoryPager, UsersPager, ActiveUsersPager, NewFilesPager, and DeletedContribsPager.
Definition at line 235 of file IndexPager.php.
Get some text to go in brackets in the "function name" part of the SQL comment.
Reimplemented in ContribsPager, and HistoryPager.
Definition at line 349 of file IndexPager.php.
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 ContribsPager, NewPagesPager, MergeHistoryPager, HistoryPager, AllMessagesTablePager, LogPager, ProtectedTitlesPager, NewFilesPager, TablePager, and DeletedContribsPager.
Definition at line 505 of file IndexPager.php.
Returns whether to show the "navigation bar".
Definition at line 605 of file IndexPager.php.
Referenced by ReverseChronologicalPager\getNavigationBar(), AlphabeticPager\getNavigationBar(), and TablePager\getNavigationBar().
IndexPager::makeLink | ( | $ | text, |
array $ | query = null , |
||
$ | type = null |
||
) |
Make a self-link.
string | $text | Text displayed on the link |
array | $query | Associative array of parameter to be in the query string |
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'. |
Definition at line 462 of file IndexPager.php.
Referenced by getLimitLinks(), AlphabeticPager\getNavigationBar(), and TablePager\getStartBody().
IndexPager::preprocessResults | ( | $ | result | ) | [protected] |
Pre-process results; useful for performing batch existence checks, etc.
ResultWrapper | $result |
Reimplemented in BlockListPager, and ProtectedPagesPager.
Definition at line 409 of file IndexPager.php.
IndexPager::reallyDoQuery | ( | $ | offset, |
$ | limit, | ||
$ | descending | ||
) |
Do a query with specified parameters, rather than using the object context.
string | $offset | Index offset, inclusive |
int | $limit | Exact query limit |
bool | $descending | Query direction, false for ascending, true for descending |
Reimplemented in ContribsPager, ImageListPager, and AllMessagesTablePager.
Definition at line 362 of file IndexPager.php.
IndexPager::setIncludeOffset | ( | $ | include | ) |
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.
bool | $include |
Definition at line 282 of file IndexPager.php.
IndexPager::setLimit | ( | $ | limit | ) |
Set the limit from an other source than the request.
Verifies limit is between 1 and 5000
int | string | $limit |
Definition at line 255 of file IndexPager.php.
Referenced by NewFilesPager\__construct().
IndexPager::setOffset | ( | $ | offset | ) |
Set the offset from an other source than the request.
int | string | $offset |
Definition at line 244 of file IndexPager.php.
IndexPager::$mDb |
Reimplemented in ContribsPager, and DeletedContribsPager.
Definition at line 80 of file IndexPager.php.
IndexPager::$mDefaultDirection |
$mDefaultDirection gives the direction to use when sorting results: 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 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 ContribsPager, ReverseChronologicalPager, and DeletedContribsPager.
Definition at line 107 of file IndexPager.php.
IndexPager::$mDefaultLimit = 50 |
Definition at line 77 of file IndexPager.php.
IndexPager::$mDefaultQuery |
Definition at line 114 of file IndexPager.php.
IndexPager::$mExtraSortFields [protected] |
An array of secondary columns to order by.
These fields are not part of the offset. This is a column list for one ordering, even if multiple orderings are supported.
Definition at line 92 of file IndexPager.php.
IndexPager::$mFirstShown |
Definition at line 114 of file IndexPager.php.
IndexPager::$mIncludeOffset = false [protected] |
Whether to include the offset in the query.
Definition at line 119 of file IndexPager.php.
IndexPager::$mIndexField [protected] |
The index to actually be used for ordering.
This is a single column, for one ordering, even if multiple orderings are supported.
Definition at line 87 of file IndexPager.php.
IndexPager::$mIsBackwards |
Definition at line 108 of file IndexPager.php.
IndexPager::$mIsFirst |
True if the current result set is the first one.
Definition at line 111 of file IndexPager.php.
IndexPager::$mIsLast |
Definition at line 112 of file IndexPager.php.
IndexPager::$mLastShown [protected] |
Definition at line 114 of file IndexPager.php.
IndexPager::$mLimit |
Definition at line 78 of file IndexPager.php.
IndexPager::$mLimitsShown = array( 20, 50, 100, 250, 500 ) |
Reimplemented in AllMessagesTablePager.
Definition at line 76 of file IndexPager.php.
IndexPager::$mNavigationBar |
Reimplemented in DeletedContribsPager.
Definition at line 114 of file IndexPager.php.
IndexPager::$mOffset |
Definition at line 78 of file IndexPager.php.
IndexPager::$mOrderType [protected] |
For pages that support multiple types of ordering, which one to use.
Definition at line 95 of file IndexPager.php.
IndexPager::$mPastTheEndIndex |
Definition at line 114 of file IndexPager.php.
IndexPager::$mPastTheEndRow |
Definition at line 81 of file IndexPager.php.
IndexPager::$mQueryDone = false |
Definition at line 79 of file IndexPager.php.
IndexPager::$mRequest |
Definition at line 75 of file IndexPager.php.
ResultWrapper IndexPager::$mResult |
Result object for the query.
Warning: seek before use.
Definition at line 125 of file IndexPager.php.
const IndexPager::DIR_ASCENDING = false |
Constants for the $mDefaultDirection field.
These are boolean for historical reasons and should stay boolean for backwards-compatibility.
Definition at line 72 of file IndexPager.php.
Referenced by TablePager\__construct(), UsersPager\__construct(), and ImageListPager\__construct().
const IndexPager::DIR_DESCENDING = true |
Definition at line 73 of file IndexPager.php.
Referenced by TablePager\__construct(), UsersPager\__construct(), ImageListPager\__construct(), BlockListPager\__construct(), and TablePager\getStartBody().