MediaWiki
master
|
Efficient paging for SQL queries that use a (roughly unique) index. More...
Public Member Functions | |
__construct (IContextSource $context=null, LinkRenderer $linkRenderer=null) | |
doQuery () | |
Do the query, using information from the object context. More... | |
formatRow ( $row) | |
Returns an HTML string representing the result row $row. More... | |
getBody () | |
Get the formatted result list. More... | |
getDatabase () | |
Get the Database object in use. More... | |
getDefaultQuery () | |
Get an array of query parameters that should be put into self-links. More... | |
getIndexField () | |
Returns the name of the index field. More... | |
getLimit () | |
Get the current limit. More... | |
getModuleStyles () | |
ResourceLoader modules that must be loaded to provide correct styling for this pager. More... | |
getNavigationBuilder () | |
@stable to override More... | |
getNumRows () | |
Get the number of rows in the result set. More... | |
getOffsetQuery () | |
Get the current offset for the URL query parameter. More... | |
getPagingQueries () | |
Get a URL query array for the prev, next, first and last links. More... | |
getQueryInfo () | |
Provides all parameters needed for the main paged query. More... | |
getResult () | |
getResultOffset () | |
reallyDoQuery ( $offset, $limit, $order) | |
Do a query with specified parameters, rather than using the object context. More... | |
setIncludeOffset ( $include) | |
Set whether a row matching exactly the offset should be also included in the result or not. More... | |
setLimit ( $limit) | |
Set the limit from an other source than the request. More... | |
setOffset ( $offset) | |
Set the offset from an other source than the request. More... | |
![]() | |
canUseWikiPage () | |
Check whether a WikiPage object can be get with getWikiPage(). More... | |
exportSession () | |
Export the resolved user IP, HTTP headers, user ID, and session ID. More... | |
getActionName () | |
Get the action name for the current web request. More... | |
getAuthority () | |
getConfig () | |
getContext () | |
Get the base IContextSource object. More... | |
getCsrfTokenSet () | |
Get a repository to obtain and match CSRF tokens. More... | |
getLanguage () | |
getOutput () | |
getRequest () | |
getSkin () | |
getTiming () | |
getTitle () | |
getUser () | |
getWikiPage () | |
Get the WikiPage object. More... | |
msg ( $key,... $params) | |
Get a Message object with context set Parameters are the same as wfMessage() More... | |
setContext (IContextSource $context) | |
![]() | |
getNavigationBar () | |
Public Attributes | |
IDatabase | $mDb |
bool | $mDefaultDirection |
$mDefaultDirection gives the direction to use when sorting results: DIR_ASCENDING or DIR_DESCENDING. More... | |
int | $mDefaultLimit = 50 |
The default entry limit choosen for clients. More... | |
bool | $mIsBackwards |
bool | $mIsFirst |
True if the current result set is the first one. More... | |
bool | $mIsLast |
int | $mLimit |
The maximum number of entries to show. More... | |
int[] | $mLimitsShown = [ 20, 50, 100, 250, 500 ] |
List of default entry limit options to be presented to clients. More... | |
mixed | $mOffset |
The starting point to enumerate entries. More... | |
stdClass bool null | $mPastTheEndRow |
Extra row fetched at the end to see if the end was reached. More... | |
bool | $mQueryDone = false |
Whether the listing query completed. More... | |
WebRequest | $mRequest |
IResultWrapper | $mResult |
Result object for the query. More... | |
const | DIR_ASCENDING = false |
Backwards-compatible constant for $mDefaultDirection field (do not change) More... | |
const | DIR_DESCENDING = true |
Backwards-compatible constant for $mDefaultDirection field (do not change) More... | |
const | QUERY_ASCENDING = true |
Backwards-compatible constant for reallyDoQuery() (do not change) More... | |
const | QUERY_DESCENDING = false |
Backwards-compatible constant for reallyDoQuery() (do not change) More... | |
Protected Member Functions | |
buildQueryInfo ( $offset, $limit, $order) | |
Build variables to use by the database wrapper. More... | |
doBatchLookups () | |
Called from getBody(), before getStartBody() is called and after doQuery() was called. More... | |
extractResultInfo ( $isFirst, $limit, IResultWrapper $res) | |
Extract some useful data from the result object for use by the navigation bar, put it into $this. More... | |
getDefaultDirections () | |
Return the default sorting direction: DIR_ASCENDING or DIR_DESCENDING. More... | |
getEmptyBody () | |
Hook into getBody(), for the bit between the start and the end when there are no rows. More... | |
getEndBody () | |
Hook into getBody() for the end of the list. More... | |
getExtraSortFields () | |
Returns the names of secondary columns to order by in addition to the column in getIndexField(). More... | |
getFooter () | |
Classes can extend to output a footer at the bottom of the pager list. More... | |
getHookContainer () | |
getLinkRenderer () | |
getRow ( $row) | |
Get the HTML of a pager row. More... | |
getSqlComment () | |
Get some text to go in brackets in the "function name" part of the SQL comment. More... | |
getStartBody () | |
Hook into getBody(), allows text to be inserted at the start. More... | |
isNavigationBarShown () | |
Returns whether to show the "navigation bar". More... | |
makeLink ( $text, array $query=null, $type=null) | |
Make a self-link. More... | |
preprocessResults ( $result) | |
Pre-process results; useful for performing batch existence checks, etc. More... | |
Static Protected Member Functions | |
static | oppositeOrder ( $order) |
Protected Attributes | |
array | $mDefaultQuery |
string[] | $mExtraSortFields |
An array of secondary columns to order by. More... | |
array | $mFirstShown |
bool | $mIncludeOffset = false |
Whether to include the offset in the query. More... | |
string string[] | $mIndexField |
The index to actually be used for ordering. More... | |
array | $mLastShown |
string | $mNavigationBar |
string null | $mOrderType |
For pages that support multiple types of ordering, which one to use. More... | |
array | $mPastTheEndIndex |
Efficient paging for SQL queries that use a (roughly unique) index.
This is for paging through data sets stored in tables with a unique index, instead of a naive "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 75 of file IndexPager.php.
IndexPager::__construct | ( | IContextSource | $context = null , |
LinkRenderer | $linkRenderer = null |
||
) |
IContextSource | null | $context | |
LinkRenderer | null | $linkRenderer |
Reimplemented in TablePager.
Definition at line 175 of file IndexPager.php.
References $mLimit, $mOrderType, DB_REPLICA, getDefaultDirections(), getExtraSortFields(), getIndexField(), ContextSource\getRequest(), ContextSource\getUser(), ContextSource\setContext(), and wfGetDB().
|
protected |
Build variables to use by the database wrapper.
int | string | $offset | Index offset, inclusive |
int | $limit | Exact query limit |
bool | $order | IndexPager::QUERY_ASCENDING or IndexPager::QUERY_DESCENDING |
Reimplemented in ActiveUsersPager, ReverseChronologicalPager, and RangeChronologicalPager.
Definition at line 474 of file IndexPager.php.
References 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.
@stable to override
Reimplemented in UsersPager, NewFilesPager, MergeHistoryPager, ImageListPager, DeletedContribsPager, ContribsPager, ActiveUsersPager, and HistoryPager.
Definition at line 665 of file IndexPager.php.
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 ImageHistoryPseudoPager.
Definition at line 259 of file IndexPager.php.
References $mIncludeOffset, DIR_ASCENDING, extractResultInfo(), oppositeOrder(), preprocessResults(), and reallyDoQuery().
|
protected |
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 377 of file IndexPager.php.
References $res.
Referenced by doQuery().
|
abstract |
Returns an HTML string representing the result row $row.
Rows will be concatenated and returned by getBody()
array | stdClass | $row | Database row |
Reimplemented in UsersPager, ProtectedTitlesPager, NewPagesPager, NewFilesPager, MergeHistoryPager, DeletedContribsPager, ContribsPager, AllMessagesTablePager, ActiveUsersPager, TablePager, ImageHistoryPseudoPager, LogPager, HistoryPager, and CategoryPager.
IndexPager::getBody | ( | ) |
Get the formatted result list.
Calls getStartBody(), formatRow() and getEndBody(), concatenates the results and returns them.
Implements Pager.
Reimplemented in CategoryPager, TablePager, and ImageHistoryPseudoPager.
Definition at line 560 of file IndexPager.php.
Referenced by MediaWiki\Specials\SpecialContributions\execute().
IndexPager::getDatabase | ( | ) |
Get the Database object in use.
Definition at line 248 of file IndexPager.php.
References $mDb.
Referenced by ActiveUsersPager\buildQueryInfo(), ActiveUsersPager\doBatchLookups(), UsersPager\doBatchLookups(), ActiveUsersPager\getQueryInfo(), BlockListPager\getQueryInfo(), DeletedContribsPager\getQueryInfo(), MergeHistoryPager\getQueryInfo(), NewFilesPager\getQueryInfo(), ProtectedPagesPager\getQueryInfo(), ProtectedTitlesPager\getQueryInfo(), UsersPager\getQueryInfo(), ImageListPager\getQueryInfoReal(), BlockListPager\getTotalAutoblocks(), AllMessagesTablePager\reallyDoQuery(), ContribsPager\reallyDoQuery(), and ImageListPager\reallyDoQuery().
|
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 945 of file IndexPager.php.
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, apart from a few exceptions.
@stable to override
Reimplemented in UsersPager, ImageListPager, DeletedContribsPager, ContribsPager, CategoryPager, and LogPager.
Definition at line 710 of file IndexPager.php.
References MediaWiki\Rest\Handler\getRequest().
|
protected |
Hook into getBody(), for the bit between the start and the end when there are no rows.
@stable to override
Reimplemented in TablePager, and HistoryPager.
Definition at line 697 of file IndexPager.php.
|
protected |
Hook into getBody() for the end of the list.
@stable to override
Reimplemented in NewPagesPager, NewFilesPager, MergeHistoryPager, DeletedContribsPager, ContribsPager, AllMessagesTablePager, TablePager, and HistoryPager.
Definition at line 685 of file IndexPager.php.
|
protected |
Returns 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 &order=querykey to use [ fields... ] to sort.
If getIndexField() returns a string with the field to sort by, this must either: 1 - return an associative array like above, but only the elements for the current field will be used. 2 - return a non-associative array, for secondary keys to use always.
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 DeletedContribsPager, and ContribsPager.
Definition at line 920 of file IndexPager.php.
Referenced by __construct().
|
protected |
Classes can extend to output a footer at the bottom of the pager list.
Reimplemented in ReverseChronologicalPager.
Definition at line 614 of file IndexPager.php.
|
protected |
Definition at line 965 of file IndexPager.php.
References wfDeprecated().
|
abstract |
Returns the name of the index field.
If the pager supports multiple orders, it may return an array of 'querykey' => 'indexfield' pairs, so that a request with &order=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.
The pager may paginate on multiple fields in combination. If paginating on multiple fields, they should be unique in combination (e.g. when paginating on user and timestamp, rows may have the same user, rows may have the same timestamp, but rows should all have a different combination of user and timestamp).
Examples:
Reimplemented in UsersPager, ProtectedTitlesPager, ProtectedPagesPager, NewPagesPager, NewFilesPager, MergeHistoryPager, ImageListPager, DeletedContribsPager, ContribsPager, CategoryPager, BlockListPager, ActiveUsersPager, TablePager, ImageHistoryPseudoPager, LogPager, and HistoryPager.
Referenced by __construct().
IndexPager::getLimit | ( | ) |
Get the current limit.
Definition at line 351 of file IndexPager.php.
References $mLimit.
|
protected |
Definition at line 953 of file IndexPager.php.
Referenced by CategoryPager\formatRow(), HistoryPager\formatRow(), NewFilesPager\formatRow(), AllMessagesTablePager\formatValue(), ProtectedPagesPager\formatValue(), and BlockListPager\formatValue().
IndexPager::getModuleStyles | ( | ) |
ResourceLoader modules that must be loaded to provide correct styling for this pager.
@stable to override
Reimplemented in TablePager.
Definition at line 604 of file IndexPager.php.
IndexPager::getNavigationBuilder | ( | ) |
@stable to override
Definition at line 798 of file IndexPager.php.
Referenced by AlphabeticPager\getNavigationBar().
IndexPager::getNumRows | ( | ) |
Get the number of rows in the result set.
Definition at line 729 of file IndexPager.php.
Referenced by MediaWiki\Specials\SpecialContributions\execute(), HistoryPager\getEndBody(), HistoryPager\getStartBody(), LogPager\getStartBody(), HistoryPager\isNavigationBarShown(), MediaWiki\Specials\SpecialAutoblockList\showList(), and MediaWiki\Specials\SpecialBlockList\showList().
IndexPager::getOffsetQuery | ( | ) |
Get the current offset for the URL query parameter.
@stable to override
Definition at line 785 of file IndexPager.php.
IndexPager::getPagingQueries | ( | ) |
Get a URL query array for the prev, next, first and last links.
@stable to override
Reimplemented in ImageListPager.
Definition at line 743 of file IndexPager.php.
Referenced by TablePager\getNavigationBar().
|
abstract |
Provides 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 UsersPager, ProtectedTitlesPager, ProtectedPagesPager, NewPagesPager, NewFilesPager, MergeHistoryPager, ImageListPager, DeletedContribsPager, ContribsPager, CategoryPager, BlockListPager, AllMessagesTablePager, ImageHistoryPseudoPager, LogPager, and HistoryPager.
Referenced by buildQueryInfo().
IndexPager::getResult | ( | ) |
Definition at line 306 of file IndexPager.php.
References $mResult.
IndexPager::getResultOffset | ( | ) |
Definition at line 313 of file IndexPager.php.
Referenced by HistoryPager\formatRow(), ProtectedPagesPager\formatValue(), and BlockListPager\formatValue().
|
protected |
Get the HTML of a pager row.
stdClass | $row |
Reimplemented in ReverseChronologicalPager.
Definition at line 548 of file IndexPager.php.
|
protected |
Get some text to go in brackets in the "function name" part of the SQL comment.
Reimplemented in ContribsPager, and HistoryPager.
Definition at line 439 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 ProtectedTitlesPager, NewPagesPager, NewFilesPager, MergeHistoryPager, DeletedContribsPager, ContribsPager, AllMessagesTablePager, TablePager, LogPager, and HistoryPager.
Definition at line 674 of file IndexPager.php.
|
protected |
Returns whether to show the "navigation bar".
Reimplemented in HistoryPager.
Definition at line 829 of file IndexPager.php.
Referenced by AlphabeticPager\getNavigationBar(), and TablePager\getNavigationBar().
|
protected |
Make a self-link.
@stable to call (since 1.39)
string | $text | Text displayed on the link |
array | null | $query | Associative array of parameter to be in the query string. If null, no link is generated. |
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 630 of file IndexPager.php.
References $type, and getTitle().
Referenced by TablePager\getStartBody().
|
staticfinalprotected |
bool | $order | One of the IndexPager::QUERY_* class constants |
Definition at line 297 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 ProtectedPagesPager, and BlockListPager.
Definition at line 537 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 ImageListPager, DeletedContribsPager, ContribsPager, and AllMessagesTablePager.
Definition at line 455 of file IndexPager.php.
References buildQueryInfo().
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 362 of file IndexPager.php.
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 335 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 322 of file IndexPager.php.
Referenced by CategoryPager\__construct().
IDatabase IndexPager::$mDb |
Definition at line 100 of file IndexPager.php.
Referenced by getDatabase().
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 133 of file IndexPager.php.
Referenced by UsersPager\getPageHeader().
int IndexPager::$mDefaultLimit = 50 |
The default entry limit choosen for clients.
Definition at line 92 of file IndexPager.php.
|
protected |
Definition at line 149 of file IndexPager.php.
Referenced by 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 116 of file IndexPager.php.
|
protected |
Definition at line 145 of file IndexPager.php.
|
protected |
Whether to include the offset in the query.
Definition at line 157 of file IndexPager.php.
Referenced by doQuery().
|
protected |
The index to actually be used for ordering.
This can be a single column, an array of single columns, or an array of arrays of columns. See getIndexField for more details.
Definition at line 110 of file IndexPager.php.
Referenced by ImageListPager\reallyDoQuery().
bool IndexPager::$mIsBackwards |
Definition at line 135 of file IndexPager.php.
bool IndexPager::$mIsFirst |
True if the current result set is the first one.
Definition at line 138 of file IndexPager.php.
bool IndexPager::$mIsLast |
Definition at line 140 of file IndexPager.php.
|
protected |
Definition at line 143 of file IndexPager.php.
int IndexPager::$mLimit |
The maximum number of entries to show.
Definition at line 96 of file IndexPager.php.
Referenced by ImageHistoryPseudoPager\__construct(), __construct(), getLimit(), TablePager\getLimitSelectList(), UsersPager\getPageHeader(), 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 90 of file IndexPager.php.
|
protected |
Definition at line 151 of file IndexPager.php.
Referenced by AlphabeticPager\getNavigationBar().
mixed IndexPager::$mOffset |
The starting point to enumerate entries.
Definition at line 94 of file IndexPager.php.
|
protected |
For pages that support multiple types of ordering, which one to use.
Definition at line 120 of file IndexPager.php.
Referenced by __construct().
|
protected |
Definition at line 147 of file IndexPager.php.
stdClass bool null IndexPager::$mPastTheEndRow |
Extra row fetched at the end to see if the end was reached.
Definition at line 102 of file IndexPager.php.
bool IndexPager::$mQueryDone = false |
Whether the listing query completed.
Definition at line 98 of file IndexPager.php.
WebRequest IndexPager::$mRequest |
Definition at line 88 of file IndexPager.php.
IResultWrapper IndexPager::$mResult |
Result object for the query.
Warning: seek before use.
Definition at line 164 of file IndexPager.php.
Referenced by getResult().
const IndexPager::DIR_ASCENDING = false |
Backwards-compatible constant for $mDefaultDirection field (do not change)
Definition at line 78 of file IndexPager.php.
Referenced by ImageListPager\__construct(), UsersPager\__construct(), TablePager\__construct(), and doQuery().
const IndexPager::DIR_DESCENDING = true |
Backwards-compatible constant for $mDefaultDirection field (do not change)
Definition at line 80 of file IndexPager.php.
Referenced by BlockListPager\__construct(), ImageListPager\__construct(), UsersPager\__construct(), AllMessagesTablePager\__construct(), TablePager\__construct(), and TablePager\getStartBody().
const IndexPager::QUERY_ASCENDING = true |
Backwards-compatible constant for reallyDoQuery() (do not change)
Definition at line 83 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 85 of file IndexPager.php.
Referenced by oppositeOrder().