MediaWiki REL1_33
|
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, IResultWrapper $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=[]) | |
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, $order) | |
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 Member Functions inherited from ContextSource | |
canUseWikiPage () | |
Check whether a WikiPage object can be get with getWikiPage(). | |
exportSession () | |
Export the resolved user IP, HTTP headers, user ID, and session ID. | |
getConfig () | |
getContext () | |
Get the base IContextSource object. | |
getLanguage () | |
getOutput () | |
getRequest () | |
getSkin () | |
getStats () | |
getTiming () | |
getTitle () | |
getUser () | |
getWikiPage () | |
Get the WikiPage object. | |
msg ( $key) | |
Get a Message object with context set Parameters are the same as wfMessage() | |
setContext (IContextSource $context) | |
Public Member Functions inherited from Pager | |
getNavigationBar () | |
Public Attributes | |
IDatabase | $mDb |
bool | $mDefaultDirection |
$mDefaultDirection gives the direction to use when sorting results: DIR_ASCENDING or DIR_DESCENDING. | |
int | $mDefaultLimit = 50 |
The default entry limit choosen for clients. | |
bool | $mIsBackwards |
bool | $mIsFirst |
True if the current result set is the first one. | |
bool | $mIsLast |
int | $mLimit |
The maximum number of entries to show. | |
int[] | $mLimitsShown = [ 20, 50, 100, 250, 500 ] |
List of default entry limit options to be presented to clients. | |
mixed | $mOffset |
The starting point to enumerate entries. | |
stdClass bool null | $mPastTheEndRow |
Extra row fetched at the end to see if the end was reached. | |
bool | $mQueryDone = false |
Whether the listing query completed. | |
WebRequest | $mRequest |
IResultWrapper | $mResult |
Result object for the query. | |
const | DIR_ASCENDING = false |
Backwards-compatible constant for $mDefaultDirection field (do not change) | |
const | DIR_DESCENDING = true |
Backwards-compatible constant for $mDefaultDirection field (do not change) | |
const | QUERY_ASCENDING = true |
Backwards-compatible constant for reallyDoQuery() (do not change) | |
const | QUERY_DESCENDING = false |
Backwards-compatible constant for reallyDoQuery() (do not change) | |
Protected Member Functions | |
buildQueryInfo ( $offset, $limit, $order) | |
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. | |
Static Protected Member Functions | |
static | oppositeOrder ( $order) |
Protected Attributes | |
array | $mDefaultQuery |
string[] | $mExtraSortFields |
An array of secondary columns to order by. | |
mixed | $mFirstShown |
bool | $mIncludeOffset = false |
Whether to include the offset in the query. | |
string | $mIndexField |
The index to actually be used for ordering. | |
mixed | $mLastShown |
string | $mNavigationBar |
string null | $mOrderType |
For pages that support multiple types of ordering, which one to use. | |
mixed | $mPastTheEndIndex |
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:
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 69 of file IndexPager.php.
IndexPager::__construct | ( | IContextSource | $context = null | ) |
Reimplemented in TablePager.
Definition at line 158 of file IndexPager.php.
References ContextSource\$context, $mOrderType, and(), array(), DB_REPLICA, getDefaultDirections(), getExtraSortFields(), getIndexField(), ContextSource\getRequest(), ContextSource\getUser(), key, list, ContextSource\setContext(), and wfGetDB().
|
protected |
Build variables to use by the database wrapper.
string | $offset | Index offset, inclusive |
int | $limit | Exact query limit |
bool | $order | IndexPager::QUERY_ASCENDING or IndexPager::QUERY_DESCENDING |
Reimplemented in RangeChronologicalPager, and ActiveUsersPager.
Definition at line 424 of file IndexPager.php.
References $fname, $options, $tables, and(), getQueryInfo(), and getSqlComment().
Referenced by reallyDoQuery(), and ImageListPager\reallyDoQuery().
|
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 HistoryPager, ActiveUsersPager, ContribsPager, ImageListPager, and UsersPager.
Definition at line 542 of file IndexPager.php.
Referenced by getBody().
IndexPager::doQuery | ( | ) |
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 LogPager, and ImageHistoryPseudoPager.
Definition at line 226 of file IndexPager.php.
References $fname, $mIncludeOffset, $section, and(), DIR_ASCENDING, extractResultInfo(), oppositeOrder(), preprocessResults(), QUERY_DESCENDING, and reallyDoQuery().
Referenced by getBody(), getNumRows(), getPagingQueries(), and isNavigationBarShown().
IndexPager::extractResultInfo | ( | $isFirst, | |
$limit, | |||
IResultWrapper | $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 |
IResultWrapper | $res |
Definition at line 339 of file IndexPager.php.
Referenced by doQuery().
|
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 CategoryPager, HistoryPager, LogPager, ImageHistoryPseudoPager, TablePager, ActiveUsersPager, AllMessagesTablePager, ContribsPager, DeletedContribsPager, MergeHistoryPager, NewFilesPager, NewPagesPager, ProtectedTitlesPager, and UsersPager.
Referenced by getBody().
IndexPager::getBody | ( | ) |
Get the formatted result list.
Calls getStartBody(), formatRow() and getEndBody(), concatenates the results and returns them.
Implements Pager.
Reimplemented in ImageHistoryPseudoPager, TablePager, and CategoryPager.
Definition at line 465 of file IndexPager.php.
References $s, doBatchLookups(), doQuery(), formatRow(), getEmptyBody(), getEndBody(), and getStartBody().
IndexPager::getDatabase | ( | ) |
Get the Database object in use.
Reimplemented in DeletedContribsPager.
Definition at line 217 of file IndexPager.php.
References $mDb.
Referenced by ActiveUsersPager\doBatchLookups(), ActiveUsersPager\getQueryInfo(), BlockListPager\getQueryInfo(), and BlockListPager\getTotalAutoblocks().
|
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.
Definition at line 784 of file IndexPager.php.
References DIR_ASCENDING.
Referenced by __construct().
IndexPager::getDefaultQuery | ( | ) |
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 LogPager, CategoryPager, ContribsPager, DeletedContribsPager, ImageListPager, and UsersPager.
Definition at line 581 of file IndexPager.php.
References $mDefaultQuery, and(), and ContextSource\getRequest().
Referenced by makeLink().
|
protected |
Hook into getBody(), for the bit between the start and the end when there are no rows.
Reimplemented in TablePager.
Definition at line 570 of file IndexPager.php.
Referenced by getBody().
|
protected |
Hook into getBody() for the end of the list.
Reimplemented in HistoryPager, TablePager, AllMessagesTablePager, ContribsPager, DeletedContribsPager, NewFilesPager, and NewPagesPager.
Definition at line 560 of file IndexPager.php.
Referenced by getBody().
|
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' => [ 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 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.
Reimplemented in ContribsPager.
Definition at line 761 of file IndexPager.php.
Referenced by __construct().
|
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 HistoryPager, LogPager, ImageHistoryPseudoPager, TablePager, ActiveUsersPager, BlockListPager, CategoryPager, ContribsPager, DeletedContribsPager, MergeHistoryPager, NewFilesPager, NewPagesPager, ProtectedPagesPager, ProtectedTitlesPager, and UsersPager.
Referenced by __construct(), and AlphabeticPager\getNavigationBar().
IndexPager::getLimit | ( | ) |
Get the current limit.
Definition at line 315 of file IndexPager.php.
References $mLimit.
IndexPager::getLimitLinks | ( | ) |
Definition at line 690 of file IndexPager.php.
References $mOffset, $mPastTheEndIndex, ContextSource\getLanguage(), and makeLink().
Referenced by AlphabeticPager\getNavigationBar(), and ReverseChronologicalPager\getNavigationBar().
IndexPager::getNumRows | ( | ) |
Get the number of rows in the result set.
Definition at line 600 of file IndexPager.php.
References doQuery().
Referenced by HistoryPager\diffButtons(), HistoryPager\getEndBody(), LogPager\getStartBody(), SpecialAutoblockList\showList(), SpecialBlockList\showList(), and HistoryPager\submitButton().
IndexPager::getPagingLinks | ( | $linkTexts, | |
$disabledTexts = [] ) |
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 669 of file IndexPager.php.
References $queries, $query, $type, and(), getPagingQueries(), and makeLink().
Referenced by AlphabeticPager\getNavigationBar(), and ReverseChronologicalPager\getNavigationBar().
IndexPager::getPagingQueries | ( | ) |
Get a URL query array for the prev, next, first and last links.
Reimplemented in ImageListPager.
Definition at line 612 of file IndexPager.php.
References $last, $mFirstShown, $mLastShown, $mLimit, and(), doQuery(), and null.
Referenced by TablePager\getNavigationBar(), and getPagingLinks().
|
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 HistoryPager, LogPager, ImageHistoryPseudoPager, AllMessagesTablePager, BlockListPager, CategoryPager, ContribsPager, DeletedContribsPager, ImageListPager, MergeHistoryPager, NewFilesPager, NewPagesPager, ProtectedPagesPager, ProtectedTitlesPager, and UsersPager.
Referenced by buildQueryInfo().
IndexPager::getResult | ( | ) |
Definition at line 279 of file IndexPager.php.
References $mResult.
IndexPager::getSqlComment | ( | ) |
Get some text to go in brackets in the "function name" part of the SQL comment.
Reimplemented in HistoryPager, and ContribsPager.
Definition at line 393 of file IndexPager.php.
Referenced by buildQueryInfo(), ActiveUsersPager\buildQueryInfo(), and ActiveUsersPager\getQueryInfo().
|
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 HistoryPager, LogPager, TablePager, AllMessagesTablePager, ContribsPager, DeletedContribsPager, MergeHistoryPager, NewFilesPager, NewPagesPager, and ProtectedTitlesPager.
Definition at line 551 of file IndexPager.php.
Referenced by getBody().
IndexPager::isNavigationBarShown | ( | ) |
Returns whether to show the "navigation bar".
Definition at line 651 of file IndexPager.php.
References $mIsLast, and doQuery().
Referenced by AlphabeticPager\getNavigationBar(), ReverseChronologicalPager\getNavigationBar(), and TablePager\getNavigationBar().
Make a self-link.
string | $text | Text displayed on the link |
array | null | $query | Associative array of parameter to be in the query string |
string | null | $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 509 of file IndexPager.php.
References $query, $type, and(), getDefaultQuery(), ContextSource\getTitle(), Linker\linkKnown(), ContextSource\msg(), and text.
Referenced by getLimitLinks(), AlphabeticPager\getNavigationBar(), getPagingLinks(), and TablePager\getStartBody().
|
staticfinalprotected |
bool | $order | One of the IndexPager::QUERY_* class constants |
Definition at line 270 of file IndexPager.php.
References QUERY_ASCENDING, and QUERY_DESCENDING.
Referenced by doQuery().
|
protected |
Pre-process results; useful for performing batch existence checks, etc.
IResultWrapper | $result |
Reimplemented in BlockListPager, and ProtectedPagesPager.
Definition at line 456 of file IndexPager.php.
Referenced by doQuery().
IndexPager::reallyDoQuery | ( | $offset, | |
$limit, | |||
$order ) |
Do a query with specified parameters, rather than using the object context.
string | $offset | Index offset, inclusive |
int | $limit | Exact query limit |
bool | $order | IndexPager::QUERY_ASCENDING or IndexPager::QUERY_DESCENDING |
Reimplemented in AllMessagesTablePager, ContribsPager, DeletedContribsPager, and ImageListPager.
Definition at line 407 of file IndexPager.php.
References $fname, $options, $tables, buildQueryInfo(), and list.
Referenced by doQuery().
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 326 of file IndexPager.php.
References and().
Referenced by CategoryPager\__construct().
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 299 of file IndexPager.php.
References and().
Referenced by NewFilesPager\__construct().
IndexPager::setOffset | ( | $offset | ) |
Set the offset from an other source than the request.
int | string | $offset |
Definition at line 288 of file IndexPager.php.
Referenced by CategoryPager\__construct().
IDatabase IndexPager::$mDb |
Definition at line 93 of file IndexPager.php.
Referenced by getDatabase(), and LogPager\limitTitle().
bool 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. For example, if $mDefaultDirection is DIR_ASCENDING 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.
Definition at line 125 of file IndexPager.php.
Referenced by UsersPager\getPageHeader().
int IndexPager::$mDefaultLimit = 50 |
The default entry limit choosen for clients.
Definition at line 85 of file IndexPager.php.
|
protected |
Definition at line 141 of file IndexPager.php.
Referenced by getDefaultQuery(), and CategoryPager\getDefaultQuery().
|
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 108 of file IndexPager.php.
|
protected |
Definition at line 137 of file IndexPager.php.
Referenced by getPagingQueries().
|
protected |
Whether to include the offset in the query.
Definition at line 149 of file IndexPager.php.
Referenced by doQuery().
|
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 102 of file IndexPager.php.
Referenced by ImageListPager\reallyDoQuery().
bool IndexPager::$mIsBackwards |
Definition at line 127 of file IndexPager.php.
bool IndexPager::$mIsFirst |
True if the current result set is the first one.
Definition at line 130 of file IndexPager.php.
Referenced by HistoryPager\formatRow(), and HistoryPager\getEndBody().
bool IndexPager::$mIsLast |
Definition at line 132 of file IndexPager.php.
Referenced by isNavigationBarShown().
|
protected |
Definition at line 135 of file IndexPager.php.
Referenced by getPagingQueries().
int IndexPager::$mLimit |
The maximum number of entries to show.
Definition at line 89 of file IndexPager.php.
Referenced by getLimit(), TablePager\getLimitSelectList(), UsersPager\getPageHeader(), getPagingQueries(), and TablePager\getStartBody().
int [] IndexPager::$mLimitsShown = [ 20, 50, 100, 250, 500 ] |
List of default entry limit options to be presented to clients.
Definition at line 83 of file IndexPager.php.
|
protected |
Definition at line 143 of file IndexPager.php.
Referenced by AlphabeticPager\getNavigationBar(), and ReverseChronologicalPager\getNavigationBar().
mixed IndexPager::$mOffset |
The starting point to enumerate entries.
Definition at line 87 of file IndexPager.php.
Referenced by RangeChronologicalPager\getDateCond(), ReverseChronologicalPager\getDateCond(), and getLimitLinks().
|
protected |
For pages that support multiple types of ordering, which one to use.
Definition at line 112 of file IndexPager.php.
Referenced by __construct().
|
protected |
Definition at line 139 of file IndexPager.php.
Referenced by getLimitLinks().
stdClass bool null IndexPager::$mPastTheEndRow |
Extra row fetched at the end to see if the end was reached.
Definition at line 95 of file IndexPager.php.
Referenced by HistoryPager\getEndBody().
bool IndexPager::$mQueryDone = false |
Whether the listing query completed.
Definition at line 91 of file IndexPager.php.
WebRequest IndexPager::$mRequest |
Definition at line 81 of file IndexPager.php.
IResultWrapper IndexPager::$mResult |
Result object for the query.
Warning: seek before use.
Definition at line 156 of file IndexPager.php.
Referenced by getResult().
const IndexPager::DIR_ASCENDING = false |
Backwards-compatible constant for $mDefaultDirection field (do not change)
Definition at line 71 of file IndexPager.php.
Referenced by ImageListPager\__construct(), TablePager\__construct(), UsersPager\__construct(), doQuery(), and getDefaultDirections().
const IndexPager::DIR_DESCENDING = true |
Backwards-compatible constant for $mDefaultDirection field (do not change)
Definition at line 73 of file IndexPager.php.
Referenced by BlockListPager\__construct(), ImageListPager\__construct(), TablePager\__construct(), UsersPager\__construct(), AllMessagesTablePager\__construct(), and TablePager\getStartBody().
const IndexPager::QUERY_ASCENDING = true |
Backwards-compatible constant for reallyDoQuery() (do not change)
Definition at line 76 of file IndexPager.php.
Referenced by oppositeOrder(), and AllMessagesTablePager\reallyDoQuery().
const IndexPager::QUERY_DESCENDING = false |
Backwards-compatible constant for reallyDoQuery() (do not change)
Definition at line 78 of file IndexPager.php.
Referenced by doQuery(), and oppositeOrder().