BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
IndexPager Class Reference
Inheritance diagram for IndexPager:
Collaboration diagram for IndexPager:

Public Member Functions

 __construct (IContextSource $context=null)
 
 getDatabase ()
 
 doQuery ()
 
 getResult ()
 
 setOffset ($offset)
 
 setLimit ($limit)
 
 getLimit ()
 
 setIncludeOffset ($include)
 
 extractResultInfo ($isFirst, $limit, ResultWrapper $res)
 
 getSqlComment ()
 
 reallyDoQuery ($offset, $limit, $descending)
 
 getBody ()
 
 makeLink ($text, array $query=null, $type=null)
 
 getDefaultQuery ()
 
 getNumRows ()
 
 getPagingQueries ()
 
 isNavigationBarShown ()
 
 getPagingLinks ($linkTexts, $disabledTexts=[])
 
 getLimitLinks ()
 
 formatRow ($row)
 
 getQueryInfo ()
 
 getIndexField ()
 
- Public Member Functions inherited from ContextSource
 getContext ()
 
 setContext (IContextSource $context)
 
 getConfig ()
 
 getRequest ()
 
 getTitle ()
 
 canUseWikiPage ()
 
 getWikiPage ()
 
 getOutput ()
 
 getUser ()
 
 getLanguage ()
 
 getSkin ()
 
 getTiming ()
 
 getStats ()
 
 msg ()
 
 exportSession ()
 
- Public Member Functions inherited from Pager
 getNavigationBar ()
 

Public Attributes

const DIR_ASCENDING = false
 
const DIR_DESCENDING = true
 
 $mRequest
 
 $mLimitsShown = [ 20, 50, 100, 250, 500 ]
 
 $mDefaultLimit = 50
 
 $mOffset
 
 $mLimit
 
 $mQueryDone = false
 
 $mDb
 
 $mPastTheEndRow
 
 $mDefaultDirection
 
 $mIsBackwards
 
 $mIsFirst
 
 $mIsLast
 
 $mFirstShown
 
 $mPastTheEndIndex
 
 $mDefaultQuery
 
 $mNavigationBar
 
 $mResult
 

Protected Member Functions

 buildQueryInfo ($offset, $limit, $descending)
 
 preprocessResults ($result)
 
 doBatchLookups ()
 
 getStartBody ()
 
 getEndBody ()
 
 getEmptyBody ()
 
 getExtraSortFields ()
 
 getDefaultDirections ()
 

Protected Attributes

 $mIndexField
 
 $mExtraSortFields
 
 $mOrderType
 
 $mLastShown
 
 $mIncludeOffset = false
 

Detailed Description

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.

Member Function Documentation

IndexPager::buildQueryInfo (   $offset,
  $limit,
  $descending 
)
protected

Build variables to use by the database wrapper.

Parameters
string$offsetIndex offset, inclusive
int$limitExact query limit
bool$descendingQuery direction, false for ascending, true for descending
Returns
array
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.

Returns
void
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.

IndexPager::extractResultInfo (   $isFirst,
  $limit,
ResultWrapper  $res 
)

Extract some useful data from the result object for use by the navigation bar, put it into $this

Parameters
bool$isFirstFalse if there are rows before those fetched (i.e. if a "previous" link would make sense)
int$limitExact query limit
ResultWrapper$res
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()

Parameters
array | stdClass$rowDatabase row
Returns
string
IndexPager::getBody ( )

Get the formatted result list. Calls getStartBody(), formatRow() and getEndBody(), concatenates the results and returns them.

Returns
string

Implements Pager.

IndexPager::getDatabase ( )

Get the Database object in use

Returns
IDatabase
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.

Returns
bool
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.

Returns
array Associative array
IndexPager::getEmptyBody ( )
protected

Hook into getBody(), for the bit between the start and the end when there are no rows

Returns
string
IndexPager::getEndBody ( )
protected

Hook into getBody() for the end of the list

Returns
string
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.

Returns
array
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.

Returns
string|array
IndexPager::getLimit ( )

Get the current limit

Returns
int
IndexPager::getNumRows ( )

Get the number of rows in the result set

Returns
int
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.

Parameters
array$linkTexts
array$disabledTexts
Returns
array
IndexPager::getPagingQueries ( )

Get a URL query array for the prev, next, first and last links.

Returns
array
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

Returns
array
IndexPager::getResult ( )
Returns
ResultWrapper The result wrapper.
IndexPager::getSqlComment ( )

Get some text to go in brackets in the "function name" part of the SQL comment

Returns
string
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.

Returns
string
IndexPager::isNavigationBarShown ( )

Returns whether to show the "navigation bar"

Returns
bool
IndexPager::makeLink (   $text,
array  $query = null,
  $type = null 
)

Make a self-link

Parameters
string$textText displayed on the link
array$queryAssociative array of parameter to be in the query string
string$typeLink type used to create additional attributes, like "rel", "class" or "title". Valid values (non-exhaustive list): 'first', 'last', 'prev', 'next', 'asc', 'desc'.
Returns
string HTML fragment
IndexPager::preprocessResults (   $result)
protected

Pre-process results; useful for performing batch existence checks, etc.

Parameters
ResultWrapper$result
IndexPager::reallyDoQuery (   $offset,
  $limit,
  $descending 
)

Do a query with specified parameters, rather than using the object context

Parameters
string$offsetIndex offset, inclusive
int$limitExact query limit
bool$descendingQuery direction, false for ascending, true for descending
Returns
ResultWrapper
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.

Parameters
bool$include
IndexPager::setLimit (   $limit)

Set the limit from an other source than the request

Verifies limit is between 1 and 5000

Parameters
int | string$limit
IndexPager::setOffset (   $offset)

Set the offset from an other source than the request

Parameters
int | string$offset

Member Data Documentation

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.

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.

IndexPager::$mIncludeOffset = false
protected

Whether to include the offset in the query

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.

IndexPager::$mIsFirst

True if the current result set is the first one

IndexPager::$mOrderType
protected

For pages that support multiple types of ordering, which one to use.

const IndexPager::DIR_ASCENDING = false

Constants for the $mDefaultDirection field.

These are boolean for historical reasons and should stay boolean for backwards-compatibility.


The documentation for this class was generated from the following file: