MediaWiki  master
QueryPage Class Reference

This is a class for doing query pages; since they're almost all the same, we factor out some of the functionality into a superclass, and let subclasses derive from it. More...

Inheritance diagram for QueryPage:
Collaboration diagram for QueryPage:

Public Member Functions

 closeList ()
 
 doQuery ( $offset=false, $limit=false)
 Somewhat deprecated, you probably want to be using execute() More...
 
 execute ( $par)
 This is the actual workhorse. More...
 
 fetchFromCache ( $limit, $offset=false)
 Fetch the query results from the query cache. More...
 
 formatResult ( $skin, $result)
 Formats the results of the query for display. More...
 
 getCachedTimestamp ()
 
 getCacheOrderFields ()
 Return the order fields for fetchFromCache. More...
 
 getOrderFields ()
 Subclasses return an array of fields to order by here. More...
 
 getPageHeader ()
 The content returned by this function will be output before any result. More...
 
 getQueryInfo ()
 Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s) for passing to Database::select() fields => Field(s) for passing to Database::select(), may be * conds => WHERE conditions options => options join_conds => JOIN conditions. More...
 
 getRecacheDB ()
 Get a DB connection to be used for slow recache queries. More...
 
 getSQL ()
 For back-compat, subclasses may return a raw SQL query here, as a string. More...
 
 isCacheable ()
 Is the output of this query cacheable? Non-cacheable expensive pages will be disabled in miser mode and will not have their results written to the querycache table. More...
 
 isCached ()
 Whether or not the output of the page in question is retrieved from the database cache. More...
 
 isExpensive ()
 Is this query expensive (for some definition of expensive)? Then we don't let it run in miser mode. More...
 
 isSyndicated ()
 Sometime we don't want to build rss / atom feeds. More...
 
 linkParameters ()
 If using extra form wheely-dealies, return a set of parameters here as an associative array. More...
 
 openList ( $offset)
 
 preprocessResults ( $db, $res)
 Do any necessary preprocessing of the result object. More...
 
 reallyDoQuery ( $limit, $offset=false)
 Run the query and return the result. More...
 
 recache ( $limit, $ignoreErrors=true)
 Clear the cache and save new results. More...
 
 setListoutput ( $bool)
 A mutator for $this->listoutput;. More...
 
 sortDescending ()
 Override to sort by increasing values. More...
 
 tryLastResult ()
 Some special pages (for example SpecialListusers used to) might not return the current object formatted, but return the previous one instead. More...
 
 usesTimestamps ()
 Does this query return timestamps rather than integers in its 'value' field? If true, this class will convert 'value' to a UNIX timestamp for caching. More...
 
- Public Member Functions inherited from SpecialPage
 __construct ( $name='', $restriction='', $listed=true, $function=false, $file='', $includable=false)
 Default constructor for special pages Derivative classes should call this from their constructor Note that if the user does not have the required level, an error message will be displayed by the default execute() method, without the global function ever being called. More...
 
 addHelpLink ( $to, $overrideBaseUrl=false)
 Adds help link with an icon via page indicators. More...
 
 checkPermissions ()
 Checks if userCanExecute, and if not throws a PermissionsError. More...
 
 checkReadOnly ()
 If the wiki is currently in readonly mode, throws a ReadOnlyError. More...
 
 displayRestrictionError ()
 Output an error message telling the user what access level they have to have. More...
 
 doesWrites ()
 Indicates whether this special page may perform database writes. More...
 
 execute ( $subPage)
 Default execute method Checks user permissions. More...
 
 getConfig ()
 Shortcut to get main config object. More...
 
 getContext ()
 Gets the context this SpecialPage is executed in. More...
 
 getDescription ()
 Returns the name that goes in the \<h1\> in the special page itself, and also the name that will be listed in Special:Specialpages. More...
 
 getFinalGroupName ()
 Get the group that the special page belongs in on Special:SpecialPage Use this method, instead of getGroupName to allow customization of the group name from the wiki side. More...
 
 getFullTitle ()
 Return the full title, including $par. More...
 
 getLanguage ()
 Shortcut to get user's language. More...
 
 getLinkRenderer ()
 
 getLocalName ()
 Get the localised name of the special page. More...
 
 getName ()
 Get the name of this Special Page. More...
 
 getOutput ()
 Get the OutputPage being used for this instance. More...
 
 getPageTitle ( $subpage=false)
 Get a self-referential title object. More...
 
 getRequest ()
 Get the WebRequest being used for this instance. More...
 
 getRestriction ()
 Get the permission that a user must have to execute this page. More...
 
 getSkin ()
 Shortcut to get the skin being used for this instance. More...
 
 getTitle ( $subpage=false)
 Get a self-referential title object. More...
 
 getUser ()
 Shortcut to get the User executing this instance. More...
 
 including ( $x=null)
 Whether the special page is being evaluated via transclusion. More...
 
 isCached ()
 Is this page cached? Expensive pages are cached or disabled in miser mode. More...
 
 isExpensive ()
 Is this page expensive (for some definition of expensive)? Expensive pages are disabled or cached in miser mode. More...
 
 isIncludable ()
 Whether it's allowed to transclude the special page via {{Special:Foo/params}}. More...
 
 isListed ()
 Whether this special page is listed in Special:SpecialPages. More...
 
 isRestricted ()
 Can be overridden by subclasses with more complicated permissions schemes. More...
 
 listed ( $x=null)
 Get or set whether this special page is listed in Special:SpecialPages. More...
 
 maxIncludeCacheTime ()
 How long to cache page when it is being included. More...
 
 msg ( $key)
 Wrapper around wfMessage that sets the current context. More...
 
 outputHeader ( $summaryMessageKey='')
 Outputs a summary message on top of special pages Per default the message key is the canonical name of the special page May be overridden, i.e. More...
 
 prefixSearchSubpages ( $search, $limit, $offset)
 Return an array of subpages beginning with $search that this special page will accept. More...
 
 requireLogin ( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
 If the user is not logged in, throws UserNotLoggedIn error. More...
 
 run ( $subPage)
 Entry point. More...
 
 setContext ( $context)
 Sets the context this SpecialPage is executed in. More...
 
 setHeaders ()
 Sets headers - this should be called from the execute() method of all derived classes! More...
 
 setLinkRenderer (LinkRenderer $linkRenderer)
 
 setListed ( $listed)
 Set whether this page is listed in Special:Specialpages, at run-time. More...
 
 userCanExecute (User $user)
 Checks if the given user (identified by an object) can execute this special page (as defined by $mRestriction). More...
 

Static Public Member Functions

static getPages ()
 Get a list of query page classes and their associated special pages, for periodic updates. More...
 
- Static Public Member Functions inherited from SpecialPage
static getSafeTitleFor ( $name, $subpage=false)
 Get a localised Title object for a page name with a possibly unvalidated subpage. More...
 
static getTitleFor ( $name, $subpage=false, $fragment='')
 Get a localised Title object for a specified special page name If you don't need a full Title object, consider using TitleValue through getTitleValueFor() below. More...
 
static getTitleValueFor ( $name, $subpage=false, $fragment='')
 Get a localised TitleValue object for a specified special page name. More...
 

Protected Member Functions

 executeLBFromResultWrapper (IResultWrapper $res, $ns=null)
 Creates a new LinkBatch object, adds all pages from the passed ResultWrapper (MUST include title and optional the namespace field) and executes the batch. More...
 
 getDBLimit ( $uiLimit, $uiOffset)
 What is limit to fetch from DB. More...
 
 getLimitOffset ()
 Returns limit and offset, as returned by $this->getRequest()->getLimitOffset(). More...
 
 getMaxResults ()
 Get max number of results we can return in miser mode. More...
 
 outputResults ( $out, $skin, $dbr, $res, $num, $offset)
 Format and output report results using the given information plus OutputPage. More...
 
 showEmptyText ()
 Outputs some kind of an informative message (via OutputPage) to let the user know that the query returned nothing and thus there's nothing to show. More...
 
- Protected Member Functions inherited from SpecialPage
 addFeedLinks ( $params)
 Adds RSS/atom links. More...
 
 afterExecute ( $subPage)
 Gets called after. More...
 
 beforeExecute ( $subPage)
 Gets called before. More...
 
 buildPrevNextNavigation ( $offset, $limit, array $query=[], $atend=false, $subpage=false)
 Generate (prev x| next x) (20|50|100...) type links for paging. More...
 
 checkLoginSecurityLevel ( $level=null)
 Verifies that the user meets the security level, possibly reauthenticating them in the process. More...
 
 getCacheTTL ()
 
 getGroupName ()
 Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-group-*' for valid names This method defaults to group 'other'. More...
 
 getLoginSecurityLevel ()
 Tells if the special page does something security-sensitive and needs extra defense against a stolen account (e.g. More...
 
 getRobotPolicy ()
 Return the robot policy. More...
 
 getSubpagesForPrefixSearch ()
 Return an array of subpages that this special page will accept for prefix searches. More...
 
 prefixSearchString ( $search, $limit, $offset)
 Perform a regular substring search for prefixSearchSubpages. More...
 
 setReauthPostData (array $data)
 Record preserved POST data after a reauthentication. More...
 
 useTransactionalTimeLimit ()
 Call wfTransactionalTimeLimit() if this request was POSTed. More...
 

Protected Attributes

string null $cachedTimestamp = null
 
int $limit = 0
 
bool $listoutput = false
 Whether or not we want plain listoutput rather than an ordered list. More...
 
int $numRows
 The number of rows returned by the query. More...
 
int $offset = 0
 The offset and limit in use, as passed to the query() function. More...
 
bool $shownavigation = true
 Whether to show prev/next links. More...
 
- Protected Attributes inherited from SpecialPage
IContextSource $mContext
 Current request context. More...
 
 $mIncludable
 
 $mIncluding
 
 $mName
 
 $mRestriction
 

Additional Inherited Members

- Static Protected Member Functions inherited from SpecialPage
static prefixSearchArray ( $search, $limit, array $subpages, $offset)
 Helper function for implementations of prefixSearchSubpages() that filter the values in memory (as opposed to making a query). More...
 

Detailed Description

This is a class for doing query pages; since they're almost all the same, we factor out some of the functionality into a superclass, and let subclasses derive from it.

Definition at line 35 of file QueryPage.php.

Member Function Documentation

◆ closeList()

QueryPage::closeList ( )
Returns
string

Definition at line 754 of file QueryPage.php.

Referenced by outputResults(), and FileDuplicateSearchPage\showList().

◆ doQuery()

QueryPage::doQuery (   $offset = false,
  $limit = false 
)

Somewhat deprecated, you probably want to be using execute()

Parameters
int | bool$offset
int | bool$limit
Returns
IResultWrapper

Definition at line 451 of file QueryPage.php.

References fetchFromCache(), isCacheable(), isCached(), and reallyDoQuery().

◆ execute()

◆ executeLBFromResultWrapper()

QueryPage::executeLBFromResultWrapper ( IResultWrapper  $res,
  $ns = null 
)
protected

Creates a new LinkBatch object, adds all pages from the passed ResultWrapper (MUST include title and optional the namespace field) and executes the batch.

This operation will pre-cache LinkCache information like page existence and information for stub color and redirect hints.

Parameters
IResultWrapper$resThe ResultWrapper object to process. Needs to include the title field and namespace field, if the $ns parameter isn't set.
null$nsUse this namespace for the given titles in the ResultWrapper object, instead of the namespace value of $res.

Definition at line 776 of file QueryPage.php.

References $batch, as, Wikimedia\Rdbms\IResultWrapper\numRows(), and Wikimedia\Rdbms\IResultWrapper\seek().

Referenced by PageQueryPage\preprocessResults(), WantedQueryPage\preprocessResults(), MostlinkedCategoriesPage\preprocessResults(), MostcategoriesPage\preprocessResults(), MostinterwikisPage\preprocessResults(), ListDuplicatedFilesPage\preprocessResults(), MostlinkedPage\preprocessResults(), AncientPagesPage\preprocessResults(), MostlinkedTemplatesPage\preprocessResults(), UnusedCategoriesPage\preprocessResults(), ShortPagesPage\preprocessResults(), BrokenRedirectsPage\preprocessResults(), LinkSearchPage\preprocessResults(), MIMEsearchPage\preprocessResults(), and MediaStatisticsPage\preprocessResults().

◆ fetchFromCache()

QueryPage::fetchFromCache (   $limit,
  $offset = false 
)

Fetch the query results from the query cache.

Parameters
int | bool$limitNumerical limit or false for no limit
int | bool$offsetNumerical offset or false for no offset
Returns
IResultWrapper
Since
1.18

Definition at line 466 of file QueryPage.php.

References $dbr, $options, as, DB_REPLICA, getCacheOrderFields(), SpecialPage\getName(), sortDescending(), and wfGetDB().

Referenced by doQuery(), and execute().

◆ formatResult()

QueryPage::formatResult (   $skin,
  $result 
)
abstract

Formats the results of the query for display.

The skin is the current skin; you can use it for making links. The result is a single row of result data. You should be able to grab SQL results off of it. If the function returns false, the line output will be skipped.

Parameters
Skin$skin
object$resultResult row
Returns
string|bool String or false to skip

Referenced by isSyndicated(), and outputResults().

◆ getCachedTimestamp()

QueryPage::getCachedTimestamp ( )
Returns
string

Definition at line 512 of file QueryPage.php.

References $cachedTimestamp, $dbr, $fname, class, DB_REPLICA, SpecialPage\getName(), and wfGetDB().

Referenced by execute().

◆ getCacheOrderFields()

QueryPage::getCacheOrderFields ( )

Return the order fields for fetchFromCache.

Default is to always use "ORDER BY value" which was the default prior to this function.

Returns
array
Since
1.29

Definition at line 505 of file QueryPage.php.

Referenced by fetchFromCache().

◆ getDBLimit()

QueryPage::getDBLimit (   $uiLimit,
  $uiOffset 
)
protected

What is limit to fetch from DB.

Used to make it appear the DB stores less results then it actually does

Parameters
int$uiLimitLimit from UI
int$uiOffsetOffset from UI
Returns
int Limit to use for DB (not including extra row to see if at end)

Definition at line 554 of file QueryPage.php.

References SpecialPage\getConfig(), and getMaxResults().

Referenced by execute().

◆ getLimitOffset()

QueryPage::getLimitOffset ( )
protected

Returns limit and offset, as returned by $this->getRequest()->getLimitOffset().

Subclasses may override this to further restrict or modify limit and offset.

Note
Restricts the offset parameter, as most query pages have inefficient paging

Its generally expected that the returned limit will not be 0, and the returned offset will be less than the max results.

Since
1.26
Returns
int[] list( $limit, $offset )

Definition at line 534 of file QueryPage.php.

References $limit, $offset, SpecialPage\getConfig(), getMaxResults(), SpecialPage\getRequest(), and list.

Referenced by execute().

◆ getMaxResults()

QueryPage::getMaxResults ( )
protected

Get max number of results we can return in miser mode.

Most QueryPage subclasses use inefficient paging, so limit the max amount we return This matters for uncached query pages that might otherwise accept an offset of 3 million

Since
1.27
Returns
int

Definition at line 573 of file QueryPage.php.

References SpecialPage\getConfig().

Referenced by execute(), getDBLimit(), and getLimitOffset().

◆ getOrderFields()

QueryPage::getOrderFields ( )

Subclasses return an array of fields to order by here.

Don't append DESC to the field names, that'll be done automatically if sortDescending() returns true.

Returns
string[]
Since
1.18

Definition at line 178 of file QueryPage.php.

Referenced by reallyDoQuery().

◆ getPageHeader()

QueryPage::getPageHeader ( )

The content returned by this function will be output before any result.

Returns
string

Definition at line 262 of file QueryPage.php.

Referenced by execute().

◆ getPages()

static QueryPage::getPages ( )
static

Get a list of query page classes and their associated special pages, for periodic updates.

DO NOT CHANGE THIS LIST without testing that maintenance/updateSpecialPages.php still works.

Returns
string[][]

Definition at line 73 of file QueryPage.php.

References class, null, and Hooks\run().

Referenced by QueryAllSpecialPagesTest\__construct(), ApiQueryQueryPage\__construct(), and UpdateSpecialPages\execute().

◆ getQueryInfo()

QueryPage::getQueryInfo ( )

Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s) for passing to Database::select() fields => Field(s) for passing to Database::select(), may be * conds => WHERE conditions options => options join_conds => JOIN conditions.

Note that the query itself should return the following three columns: 'namespace', 'title', and 'value'. 'value' is used for sorting.

These may be stored in the querycache table for expensive queries, and that cached data will be returned sometimes, so the presence of extra fields can't be relied upon. The cached 'value' column will be an integer; non-numeric values are useful only for sorting the initial query (except if they're timestamps, see usesTimestamps()).

Don't include an ORDER or LIMIT clause, they will be added.

If this function is not overridden or returns something other than an array, getSQL() will be used instead. This is for backwards compatibility only and is strongly deprecated.

Returns
array
Since
1.18

Definition at line 155 of file QueryPage.php.

References null.

Referenced by reallyDoQuery().

◆ getRecacheDB()

QueryPage::getRecacheDB ( )

Get a DB connection to be used for slow recache queries.

Returns
IDatabase

Definition at line 389 of file QueryPage.php.

References DB_REPLICA, SpecialPage\getName(), and wfGetDB().

Referenced by execute(), ShortPagesPage\reallyDoQuery(), and reallyDoQuery().

◆ getSQL()

QueryPage::getSQL ( )

For back-compat, subclasses may return a raw SQL query here, as a string.

This is strongly deprecated; getQueryInfo() should be overridden instead.

Exceptions
MWException
Returns
string

Definition at line 165 of file QueryPage.php.

Referenced by reallyDoQuery().

◆ isCacheable()

QueryPage::isCacheable ( )

Is the output of this query cacheable? Non-cacheable expensive pages will be disabled in miser mode and will not have their results written to the querycache table.

Returns
bool
Since
1.18

Definition at line 223 of file QueryPage.php.

Referenced by doQuery(), execute(), and recache().

◆ isCached()

QueryPage::isCached ( )

◆ isExpensive()

QueryPage::isExpensive ( )

Is this query expensive (for some definition of expensive)? Then we don't let it run in miser mode.

$wgDisableQueryPages causes all query pages to be declared expensive. Some query pages are always expensive.

Returns
bool

Definition at line 212 of file QueryPage.php.

References SpecialPage\getConfig().

Referenced by isCached().

◆ isSyndicated()

QueryPage::isSyndicated ( )

Sometime we don't want to build rss / atom feeds.

Returns
bool

Definition at line 242 of file QueryPage.php.

References $skin, and formatResult().

Referenced by execute().

◆ linkParameters()

QueryPage::linkParameters ( )

If using extra form wheely-dealies, return a set of parameters here as an associative array.

They will be encoded and added to the paging links (prev/next/lengths).

Returns
array

Definition at line 284 of file QueryPage.php.

Referenced by execute().

◆ openList()

QueryPage::openList (   $offset)
Parameters
int$offset
Returns
string

Definition at line 747 of file QueryPage.php.

Referenced by outputResults(), and FileDuplicateSearchPage\showList().

◆ outputResults()

QueryPage::outputResults (   $out,
  $skin,
  $dbr,
  $res,
  $num,
  $offset 
)
protected

Format and output report results using the given information plus OutputPage.

Parameters
OutputPage$outOutputPage to print to
Skin$skinUser skin to use
IDatabase$dbrDatabase (read) connection to use
IResultWrapper$resResult pointer
int$numNumber of available result rows
int$offsetPaging offset

Definition at line 702 of file QueryPage.php.

References $html, $line, $out, $res, $skin, closeList(), formatResult(), null, openList(), and tryLastResult().

Referenced by execute().

◆ preprocessResults()

QueryPage::preprocessResults (   $db,
  $res 
)

Do any necessary preprocessing of the result object.

Parameters
IDatabase$db
IResultWrapper$res

Definition at line 763 of file QueryPage.php.

Referenced by execute().

◆ reallyDoQuery()

QueryPage::reallyDoQuery (   $limit,
  $offset = false 
)

Run the query and return the result.

Parameters
int | bool$limitNumerical limit or false for no limit
int | bool$offsetNumerical offset or false for no offset
Returns
IResultWrapper
Since
1.18

Definition at line 400 of file QueryPage.php.

References $dbr, $fname, $options, $query, $res, $tables, array(), as, class, getOrderFields(), getQueryInfo(), getRecacheDB(), getSQL(), and sortDescending().

Referenced by doQuery(), execute(), and recache().

◆ recache()

QueryPage::recache (   $limit,
  $ignoreErrors = true 
)

Clear the cache and save new results.

Parameters
int | bool$limitLimit for SQL statement
bool$ignoreErrorsWhether to ignore database errors
Exceptions
DBError|Exception
Returns
bool|int

Definition at line 311 of file QueryPage.php.

References $e, $fname, $res, $value, as, class, DB_MASTER, Wikimedia\Rdbms\IDatabase\delete(), SpecialPage\getName(), Wikimedia\Rdbms\IDatabase\insert(), isCacheable(), reallyDoQuery(), Wikimedia\Rdbms\IDatabase\timestamp(), use, usesTimestamps(), wfGetDB(), and wfTimestamp().

◆ setListoutput()

QueryPage::setListoutput (   $bool)

A mutator for $this->listoutput;.

Parameters
bool$bool

Definition at line 125 of file QueryPage.php.

Referenced by WantedPagesPage\execute().

◆ showEmptyText()

QueryPage::showEmptyText ( )
protected

Outputs some kind of an informative message (via OutputPage) to let the user know that the query returned nothing and thus there's nothing to show.

Since
1.26

Definition at line 273 of file QueryPage.php.

References SpecialPage\getOutput().

Referenced by execute().

◆ sortDescending()

QueryPage::sortDescending ( )

Override to sort by increasing values.

Returns
bool

Definition at line 201 of file QueryPage.php.

Referenced by fetchFromCache(), and reallyDoQuery().

◆ tryLastResult()

QueryPage::tryLastResult ( )

Some special pages (for example SpecialListusers used to) might not return the current object formatted, but return the previous one instead.

Setting this to return true will ensure formatResult() is called one more time to make sure that the very last result is formatted as well.

Deprecated:
since 1.27
Returns
bool

Definition at line 299 of file QueryPage.php.

Referenced by outputResults().

◆ usesTimestamps()

QueryPage::usesTimestamps ( )

Does this query return timestamps rather than integers in its 'value' field? If true, this class will convert 'value' to a UNIX timestamp for caching.

NOTE: formatRow() may get timestamps in TS_MW (mysql), TS_DB (pgsql) or TS_UNIX (querycache) format, so be sure to always run them through wfTimestamp()

Returns
bool
Since
1.18

Definition at line 192 of file QueryPage.php.

Referenced by recache().

Member Data Documentation

◆ $cachedTimestamp

string null QueryPage::$cachedTimestamp = null
protected

Definition at line 57 of file QueryPage.php.

Referenced by getCachedTimestamp().

◆ $limit

◆ $listoutput

bool QueryPage::$listoutput = false
protected

Whether or not we want plain listoutput rather than an ordered list.

Definition at line 37 of file QueryPage.php.

◆ $numRows

int QueryPage::$numRows
protected

The number of rows returned by the query.

Reading this variable only makes sense in functions that are run after the query has been done, such as preprocessResults() and formatRow().

Definition at line 52 of file QueryPage.php.

Referenced by FileDuplicateSearchPage\execute().

◆ $offset

int QueryPage::$offset = 0
protected

◆ $shownavigation

bool QueryPage::$shownavigation = true
protected

Whether to show prev/next links.

Definition at line 62 of file QueryPage.php.


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