MediaWiki  master
TablePager Class Reference

Table-based display with a user-selectable sort order Stable to extend. More...

Inheritance diagram for TablePager:
Collaboration diagram for TablePager:

Public Member Functions

 __construct (IContextSource $context=null, LinkRenderer $linkRenderer=null)
 Stable to call. More...
 
 formatRow ( $row)
 Stable to override. More...
 
 formatValue ( $name, $value)
 Format a table cell. More...
 
 getBody ()
 Get the formatted result list. More...
 
 getBodyOutput ()
 Get the formatted result list. More...
 
 getDefaultSort ()
 The database field name used as a default sort order. More...
 
 getFullOutput ()
 Get the formatted result list, with navigation bars. More...
 
 getHiddenFields ( $blacklist=[])
 Get \<input type="hidden"\> elements for use in a method="get" form. More...
 
 getIndexField ()
 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:

  • Always paginate on the user field: 'user'
  • Paginate on either the user or the timestamp field (default to user): [ 'name' => 'user', 'time' => 'timestamp', ]
  • Always paginate on the combination of user and timestamp: [ [ 'user', 'timestamp' ] ]
  • Paginate on the user then timestamp, or the timestamp then user: [ 'nametime' => [ 'user', 'timestamp' ], 'timename' => [ 'timestamp', 'user' ], ]
Returns
string|string[]|array[]
Stable to override More...
 
 getLimitForm ()
 Get a form containing a limit selection dropdown. More...
 
 getLimitSelect ( $attribs=[])
 Get a "<select>" element which has options for each of the allowed limits. More...
 
 getLimitSelectList ()
 Get a list of items to show in a "<select>" element of limits. More...
 
 getModuleStyles ()
 ResourceLoader modules that must be loaded to provide correct styling for this pager. More...
 
 getNavigationBar ()
 A navigation bar with images. More...
 
- Public Member Functions inherited from IndexPager
 doQuery ()
 Do the query, using information from the object context. More...
 
 getDatabase ()
 Get the Database object in use. More...
 
 getDefaultQuery ()
 Get an array of query parameters that should be put into self-links. More...
 
 getLimit ()
 Get the current limit. More...
 
 getNumRows ()
 Get the number of rows in the result set. 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 ()
 
 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...
 
- Public Member Functions inherited from ContextSource
 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...
 
 getConfig ()
 
 getContext ()
 Get the base IContextSource object. More...
 
 getLanguage ()
 
 getOutput ()
 
 getRequest ()
 
 getSkin ()
 
 getStats ()
 
 getTiming ()
 
 getTitle ()
 
 getUser ()
 Stable to override. More...
 
 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)
 

Protected Member Functions

 getCellAttrs ( $field, $value)
 Get any extra attributes to be applied to the given cell. More...
 
 getCurrentRow ()
 
 getEmptyBody ()
 
 getEndBody ()
 Stable to override. More...
 
 getFieldNames ()
 An array mapping database field names to a textual description of the field name, for use in the table header. More...
 
 getNavClass ()
 Stable to override. More...
 
 getRowAttrs ( $row)
 Get attributes to be applied to the given row. More...
 
 getRowClass ( $row)
 Get a class name to be applied to the given row. More...
 
 getSortHeaderClass ()
 Stable to override. More...
 
 getStartBody ()
 Stable to override. More...
 
 getTableClass ()
 TablePager relies on mw-datatable for styling, see T214208. More...
 
 isFieldSortable ( $field)
 Return true if the named field should be sortable by the UI, false otherwise. More...
 
- Protected Member Functions inherited from IndexPager
 buildPrevNextNavigation (Title $title, $offset, $limit, array $query=[], $atend=false)
 Generate (prev x| next x) (20|50|100...) type links for paging. More...
 
 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...
 
 getExtraSortFields ()
 Returns the names of secondary columns to order by in addition to the column in getIndexField(). More...
 
 getLimitLinks ()
 
 getLinkRenderer ()
 
 getPagingLinks ( $linkTexts, $disabledTexts=[])
 Get paging links. More...
 
 getSqlComment ()
 Get some text to go in brackets in the "function name" part of the SQL comment. More...
 
 isNavigationBarShown ()
 Returns whether to show the "navigation bar" @stable to override. 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...
 

Protected Attributes

stdClass $mCurrentRow
 
string $mSort
 
- Protected Attributes inherited from IndexPager
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
 

Private Member Functions

 getLimitDropdown ()
 Gets a limit selection dropdown. More...
 

Additional Inherited Members

- Public Attributes inherited from IndexPager
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...
 
- Static Protected Member Functions inherited from IndexPager
static oppositeOrder ( $order)
 

Detailed Description

Table-based display with a user-selectable sort order Stable to extend.

Definition at line 31 of file TablePager.php.

Constructor & Destructor Documentation

◆ __construct()

TablePager::__construct ( IContextSource  $context = null,
LinkRenderer  $linkRenderer = null 
)

Stable to call.

Parameters
IContextSource | null$context
LinkRenderer | null$linkRenderer

Reimplemented from IndexPager.

Definition at line 44 of file TablePager.php.

References ContextSource\$context, IndexPager\$linkRenderer, IndexPager\DIR_ASCENDING, IndexPager\DIR_DESCENDING, getDefaultSort(), getFieldNames(), ContextSource\getRequest(), isFieldSortable(), and ContextSource\setContext().

Member Function Documentation

◆ formatRow()

TablePager::formatRow (   $row)

Stable to override.

Parameters
stdClass$row
Returns
string HTML

Reimplemented from IndexPager.

Reimplemented in AllMessagesTablePager.

Definition at line 196 of file TablePager.php.

References $s, Html\closeElement(), formatValue(), getCellAttrs(), getFieldNames(), getRowAttrs(), Html\openElement(), and Html\rawElement().

◆ formatValue()

TablePager::formatValue (   $name,
  $value 
)
abstract

Format a table cell.

The return value should be HTML, but use an empty string not &#160; for empty cells. Do not include the

and .

The current result row is available as $this->mCurrentRow, in case you need more context.

Parameters
string$nameThe database field name
string$valueThe value retrieved from the database

Reimplemented in BlockListPager, ImageListPager, AllMessagesTablePager, and ProtectedPagesPager.

Referenced by formatRow().

◆ getBody()

TablePager::getBody ( )
final

Get the formatted result list.

Calls getStartBody(), formatRow() and getEndBody(), concatenates the results and returns them.

Also adds the required styles to our OutputPage object (this means that if context wasn't passed to constructor or otherwise set up, you will get a pager with missing styles).

This method has been made 'final' in 1.24. There's no reason to override it, and if there exist any subclasses that do, the style loading hack is probably broken in them. Let's fail fast rather than mysteriously render things wrong.

Deprecated:
since 1.24, use getBodyOutput() or getFullOutput() instead
Returns
string

Reimplemented from IndexPager.

Definition at line 79 of file TablePager.php.

References getModuleStyles(), and ContextSource\getOutput().

◆ getBodyOutput()

TablePager::getBodyOutput ( )

Get the formatted result list.

Calls getBody() and getModuleStyles() and builds a ParserOutput object. (This is a bit hacky but works well.)

Since
1.24
Returns
ParserOutput

Definition at line 93 of file TablePager.php.

References getModuleStyles(), and ParserOutput\setText().

◆ getCellAttrs()

TablePager::getCellAttrs (   $field,
  $value 
)
protected

Get any extra attributes to be applied to the given cell.

Don't take this as an excuse to hardcode styles; use classes and CSS instead. Row context is available in $this->mCurrentRow

Stable to override

Parameters
string$fieldThe column
string$valueThe cell contents
Returns
array Array of attr => value

Reimplemented in AllMessagesTablePager.

Definition at line 265 of file TablePager.php.

Referenced by formatRow().

◆ getCurrentRow()

TablePager::getCurrentRow ( )
protected
Returns
stdClass

Definition at line 250 of file TablePager.php.

References $mCurrentRow.

◆ getDefaultSort()

TablePager::getDefaultSort ( )
abstract

The database field name used as a default sort order.

Note that this field will only be sorted on if isFieldSortable returns true for this field. If not (e.g. paginating on multiple columns), this should return empty string, and getIndexField should be overridden.

Returns
string

Reimplemented in ImageListPager, BlockListPager, AllMessagesTablePager, and ProtectedPagesPager.

Referenced by __construct().

◆ getEmptyBody()

TablePager::getEmptyBody ( )
protected
Returns
string

Reimplemented from IndexPager.

Definition at line 184 of file TablePager.php.

References Html\element(), getFieldNames(), ContextSource\msg(), and Html\rawElement().

◆ getEndBody()

TablePager::getEndBody ( )
protected

Stable to override.

Returns
string

Reimplemented from IndexPager.

Reimplemented in AllMessagesTablePager.

Definition at line 177 of file TablePager.php.

◆ getFieldNames()

TablePager::getFieldNames ( )
abstractprotected

An array mapping database field names to a textual description of the field name, for use in the table header.

The description should be plain text, it will be HTML-escaped later.

Returns
array

Reimplemented in AllMessagesTablePager, ImageListPager, ProtectedPagesPager, and BlockListPager.

Referenced by __construct(), formatRow(), getEmptyBody(), and getStartBody().

◆ getFullOutput()

TablePager::getFullOutput ( )

Get the formatted result list, with navigation bars.

Calls getBody(), getNavigationBar() and getModuleStyles() and builds a ParserOutput object. (This is a bit hacky but works well.)

Since
1.24
Returns
ParserOutput

Definition at line 111 of file TablePager.php.

References getModuleStyles(), getNavigationBar(), and ParserOutput\setText().

Referenced by SpecialAutoblockList\showList(), and SpecialBlockList\showList().

◆ getHiddenFields()

TablePager::getHiddenFields (   $blacklist = [])

Get \<input type="hidden"\> elements for use in a method="get" form.

Resubmits all defined elements of the query string, except for a blacklist, passed in the $blacklist parameter.

Parameters
array$blacklistParameters from the request query which should not be resubmitted
Returns
string HTML fragment

Definition at line 413 of file TablePager.php.

References $s, ContextSource\getRequest(), and Html\hidden().

Referenced by getLimitDropdown().

◆ getIndexField()

TablePager::getIndexField ( )

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:

  • Always paginate on the user field: 'user'
  • Paginate on either the user or the timestamp field (default to user): [ 'name' => 'user', 'time' => 'timestamp', ]
  • Always paginate on the combination of user and timestamp: [ [ 'user', 'timestamp' ] ]
  • Paginate on the user then timestamp, or the timestamp then user: [ 'nametime' => [ 'user', 'timestamp' ], 'timename' => [ 'timestamp', 'user' ], ]
Returns
string|string[]|array[]
Stable to override

Reimplemented from IndexPager.

Reimplemented in ImageListPager, BlockListPager, and ProtectedPagesPager.

Definition at line 273 of file TablePager.php.

References $mSort.

◆ getLimitDropdown()

TablePager::getLimitDropdown ( )
private

Gets a limit selection dropdown.

Returns
string

Definition at line 447 of file TablePager.php.

References getHiddenFields(), getLimitSelect(), and ContextSource\msg().

Referenced by getLimitForm().

◆ getLimitForm()

TablePager::getLimitForm ( )

Get a form containing a limit selection dropdown.

Returns
string HTML fragment

Definition at line 431 of file TablePager.php.

References getLimitDropdown(), Html\rawElement(), and wfScript().

◆ getLimitSelect()

TablePager::getLimitSelect (   $attribs = [])

Get a "<select>" element which has options for each of the allowed limits.

Parameters
string[]$attribsExtra attributes to set
Returns
string HTML fragment

Definition at line 365 of file TablePager.php.

References getLimitSelectList().

Referenced by getLimitDropdown().

◆ getLimitSelectList()

TablePager::getLimitSelectList ( )

Get a list of items to show in a "<select>" element of limits.

This can be passed directly to XmlSelect::addOptions().

Since
1.22
Returns
array

Definition at line 381 of file TablePager.php.

References IndexPager\$mLimit, and ContextSource\getLanguage().

Referenced by getLimitSelect().

◆ getModuleStyles()

TablePager::getModuleStyles ( )

ResourceLoader modules that must be loaded to provide correct styling for this pager.

Stable to override

Since
1.24
Returns
string[]

Definition at line 355 of file TablePager.php.

Referenced by getBody(), getBodyOutput(), and getFullOutput().

◆ getNavClass()

TablePager::getNavClass ( )
protected

Stable to override.

Returns
string

Reimplemented in ImageListPager.

Definition at line 291 of file TablePager.php.

Referenced by getNavigationBar().

◆ getNavigationBar()

TablePager::getNavigationBar ( )

A navigation bar with images.

Stable to override

Returns
string HTML

Implements Pager.

Definition at line 309 of file TablePager.php.

References $title, $type, getNavClass(), ContextSource\getOutput(), IndexPager\getPagingQueries(), ContextSource\getTitle(), IndexPager\isNavigationBarShown(), and ContextSource\msg().

Referenced by getFullOutput().

◆ getRowAttrs()

TablePager::getRowAttrs (   $row)
protected

Get attributes to be applied to the given row.

Stable to override

Parameters
object$rowThe database result row
Returns
array Array of attribute => value

Reimplemented in AllMessagesTablePager.

Definition at line 237 of file TablePager.php.

References getRowClass().

Referenced by formatRow().

◆ getRowClass()

TablePager::getRowClass (   $row)
protected

Get a class name to be applied to the given row.

Stable to override

Parameters
object$rowThe database result row
Returns
string

Definition at line 225 of file TablePager.php.

Referenced by getRowAttrs().

◆ getSortHeaderClass()

TablePager::getSortHeaderClass ( )
protected

Stable to override.

Returns
string

Reimplemented in ImageListPager.

Definition at line 299 of file TablePager.php.

Referenced by getStartBody().

◆ getStartBody()

TablePager::getStartBody ( )
protected

◆ getTableClass()

TablePager::getTableClass ( )
protected

TablePager relies on mw-datatable for styling, see T214208.

Stable to override

Returns
string

Reimplemented in ImageListPager, BlockListPager, and ProtectedPagesPager.

Definition at line 283 of file TablePager.php.

Referenced by getStartBody(), and AllMessagesTablePager\getStartBody().

◆ isFieldSortable()

TablePager::isFieldSortable (   $field)
abstractprotected

Return true if the named field should be sortable by the UI, false otherwise.

Parameters
string$field

Reimplemented in AllMessagesTablePager, BlockListPager, ProtectedPagesPager, and ImageListPager.

Referenced by __construct(), and getStartBody().

Member Data Documentation

◆ $mCurrentRow

stdClass TablePager::$mCurrentRow
protected

◆ $mSort

string TablePager::$mSort
protected

Definition at line 33 of file TablePager.php.

Referenced by getIndexField().


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