MediaWiki  REL1_23
ApiQueryBase Class Reference

This is a base class for all Query modules. More...

Inheritance diagram for ApiQueryBase:
Collaboration diagram for ApiQueryBase:

List of all members.

Public Member Functions

 __construct (ApiBase $query, $moduleName, $paramPrefix= '')
 getCacheMode ($params)
 Get the cache mode for the data generated by this module.
 getDirectionDescription ($p= '', $extraDirText= '')
 Gets the personalised direction parameter description.
 getPossibleErrors ()
 getQuery ()
 Get the main Query module.
 keyPartToTitle ($keyPart)
 An alternative to keyToTitle() that doesn't trim trailing spaces.
 keyToTitle ($key)
 The inverse of titleToKey()
 prepareUrlQuerySearchString ($query=null, $protocol=null)
 requestExtraData ($pageSet)
 Override this method to request extra fields from the pageSet using $pageSet->requestField('fieldName')
 selectNamedDB ($name, $db, $groups)
 Selects the query database connection with the given name.
 showHiddenUsersAddBlockInfo ($showBlockInfo)
 Filters hidden users (where the user doesn't have the right to view them) Also adds relevant block information.
 titlePartToKey ($titlePart, $defaultNamespace=NS_MAIN)
 An alternative to titleToKey() that doesn't trim trailing spaces, and does not mangle the input if starts with something that looks like a namespace.
 titleToKey ($title)
 Convert a title to a DB key.
 userCanSeeRevDel ()
 Check whether the current user has permission to view revision-deleted fields.
 validateSha1Base36Hash ($hash)
 validateSha1Hash ($hash)

Static Public Member Functions

static addTitleInfo (&$arr, $title, $prefix= '')
 Add information (title and namespace) about a Title object to a result array.

Public Attributes

 $fields
 $join_conds
 $mDb
 $options
 $tables
 $where

Protected Member Functions

 addFields ($value)
 Add a set of fields to select to the internal array.
 addFieldsIf ($value, $condition)
 Same as addFields(), but add the fields only if a condition is met.
 addJoinConds ($join_conds)
 Add a set of JOIN conditions to the internal array.
 addOption ($name, $value=null)
 Add an option such as LIMIT or USE INDEX.
 addPageSubItem ($pageId, $item, $elemname=null)
 Same as addPageSubItems(), but one element of $data at a time.
 addPageSubItems ($pageId, $data)
 Add a sub-element under the page element with the given page ID.
 addTables ($tables, $alias=null)
 Add a set of tables to the internal array.
 addTimestampWhereRange ($field, $dir, $start, $end, $sort=true)
 Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end to database timestamps.
 addWhere ($value)
 Add a set of WHERE clauses to the internal array.
 addWhereFld ($field, $value)
 Equivalent to addWhere(array($field => $value))
 addWhereIf ($value, $condition)
 Same as addWhere(), but add the WHERE clauses only if a condition is met.
 addWhereRange ($field, $dir, $start, $end, $sort=true)
 Add a WHERE clause corresponding to a range, and an ORDER BY clause to sort in the right direction.
 checkRowCount ()
 Estimate the row count for the SELECT query that would be run if we called select() right now, and check if it's acceptable.
 getDB ()
 Get the Query database connection (read-only)
 getPageSet ()
 Get the PageSet object to work on.
 resetQueryParams ()
 Blank the internal arrays with query parameters.
 select ($method, $extraQuery=array())
 Execute a SELECT query based on the values in the internal arrays.
 setContinueEnumParameter ($paramName, $paramValue)
 Set a query-continue value.

Private Attributes

 $mQueryModule

Detailed Description

This is a base class for all Query modules.

It provides some common functionality such as constructing various SQL queries.

Definition at line 34 of file ApiQueryBase.php.


Constructor & Destructor Documentation

ApiQueryBase::__construct ( ApiBase query,
moduleName,
paramPrefix = '' 
)
Parameters:
$queryApiBase
$moduleNamestring
$paramPrefixstring

Definition at line 43 of file ApiQueryBase.php.

References $query, ApiBase\getMain(), and resetQueryParams().


Member Function Documentation

ApiQueryBase::addJoinConds ( join_conds) [protected]

Add a set of JOIN conditions to the internal array.

JOIN conditions are formatted as array( tablename => array(jointype, conditions) e.g. array('page' => array('LEFT JOIN', 'page_id=rev_page')) . conditions may be a string or an addWhere()-style array

Parameters:
$join_condsarray JOIN conditions

Definition at line 106 of file ApiQueryBase.php.

References $join_conds, and ApiBase\dieDebug().

Referenced by ApiQueryDeletedrevs\execute(), ApiQueryCategoryInfo\execute(), ApiQueryLogEvents\execute(), ApiQueryContributors\execute(), ApiQueryAllUsers\execute(), ApiQueryUsers\execute(), ApiQueryRevisions\execute(), ApiQueryContributions\prepareQuery(), ApiQueryProtectedTitles\run(), ApiQueryCategories\run(), ApiQueryAllCategories\run(), ApiQueryWatchlist\run(), ApiQueryAllPages\run(), ApiQueryAllImages\run(), ApiQueryRecentChanges\run(), and showHiddenUsersAddBlockInfo().

ApiQueryBase::addPageSubItem ( pageId,
item,
elemname = null 
) [protected]

Same as addPageSubItems(), but one element of $data at a time.

Parameters:
int$pageIdPage ID
array$itemData array à la ApiResult
string$elemnameXML element name. If null, getModuleName() is used
Returns:
bool Whether the element fit in the result

Definition at line 383 of file ApiQueryBase.php.

References $result, array(), ApiBase\getModuleName(), ApiBase\getModulePrefix(), and ApiBase\getResult().

Referenced by ApiQueryExternalLinks\execute(), ApiQueryLangLinks\execute(), ApiQueryIWLinks\execute(), ApiQueryImageInfo\execute(), ApiQueryContributors\execute(), ApiQueryRevisions\execute(), ApiQueryImages\run(), ApiQueryRedirects\run(), ApiQueryCategories\run(), ApiQueryDuplicateFiles\run(), and ApiQueryLinks\run().

ApiQueryBase::addPageSubItems ( pageId,
data 
) [protected]

Add a sub-element under the page element with the given page ID.

Parameters:
int$pageIdPage ID
array$dataData array à la ApiResult
Returns:
bool Whether the element fit in the result

Definition at line 366 of file ApiQueryBase.php.

References $result, array(), ApiBase\getModuleName(), ApiBase\getModulePrefix(), and ApiBase\getResult().

Referenced by ApiQueryCategoryInfo\execute().

ApiQueryBase::addTables ( tables,
alias = null 
) [protected]
ApiQueryBase::addTimestampWhereRange ( field,
dir,
start,
end,
sort = true 
) [protected]

Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end to database timestamps.

See also:
addWhereRange
Parameters:
$field
$dir
$start
$end
$sortbool

Definition at line 240 of file ApiQueryBase.php.

References $dir, $sort, and addWhereRange().

Referenced by ApiQueryDeletedrevs\execute(), ApiQueryBlocks\execute(), ApiQueryLogEvents\execute(), ApiQueryRevisions\execute(), ApiQueryContributions\prepareQuery(), ApiQueryProtectedTitles\run(), ApiQueryCategoryMembers\run(), ApiQueryWatchlist\run(), ApiQueryAllImages\run(), and ApiQueryRecentChanges\run().

ApiQueryBase::addWhere ( value) [protected]

Add a set of WHERE clauses to the internal array.

Clauses can be formatted as 'foo=bar' or array('foo' => 'bar'), the latter only works if the value is a constant (i.e. not another field)

If $value is an empty array, this function does nothing.

For example, array('foo=bar', 'baz' => 3, 'bla' => 'foo') translates to "foo=bar AND baz='3' AND bla='foo'"

Parameters:
$valuemixed String or array

Definition at line 152 of file ApiQueryBase.php.

References $value.

Referenced by addWhereIf(), addWhereRange(), ApiQueryLangLinks\execute(), ApiQueryDeletedrevs\execute(), ApiQueryExternalLinks\execute(), ApiQueryCategoryInfo\execute(), ApiQueryIWLinks\execute(), ApiQueryFilearchive\execute(), ApiQueryPageProps\execute(), ApiQueryBlocks\execute(), ApiQueryLogEvents\execute(), ApiQueryContributors\execute(), ApiQueryAllUsers\execute(), ApiQueryRevisions\execute(), ApiQueryInfo\getProtectionInfo(), ApiQueryInfo\getTSIDs(), ApiQueryInfo\getWatchedInfo(), ApiQueryInfo\getWatcherInfo(), ApiQueryContributions\prepareQuery(), ApiQueryImages\run(), ApiQueryIWBacklinks\run(), ApiQueryLangBacklinks\run(), ApiQueryRedirects\run(), ApiQueryProtectedTitles\run(), ApiQueryWatchlistRaw\run(), ApiQueryExtLinksUsage\run(), ApiQueryCategories\run(), ApiQueryAllCategories\run(), ApiQueryCategoryMembers\run(), ApiQueryPagesWithProp\run(), ApiQueryWatchlist\run(), ApiQueryAllPages\run(), ApiQueryAllImages\run(), ApiQueryLinks\run(), ApiQueryAllLinks\run(), ApiQueryRecentChanges\run(), and showHiddenUsersAddBlockInfo().

ApiQueryBase::addWhereIf ( value,
condition 
) [protected]

Same as addWhere(), but add the WHERE clauses only if a condition is met.

Parameters:
$valuemixed See addWhere()
bool$conditionIf false, do nothing
Returns:
bool $condition

Definition at line 170 of file ApiQueryBase.php.

References $value, and addWhere().

Referenced by ApiQueryBlocks\execute(), ApiQueryContributors\execute(), ApiQueryContributions\prepareQuery(), ApiQueryRedirects\run(), ApiQueryWatchlistRaw\run(), ApiQueryWatchlist\run(), and ApiQueryRecentChanges\run().

ApiQueryBase::addWhereRange ( field,
dir,
start,
end,
sort = true 
) [protected]

Add a WHERE clause corresponding to a range, and an ORDER BY clause to sort in the right direction.

Parameters:
string$fieldField name
string$dirIf 'newer', sort in ascending order, otherwise sort in descending order
string$startValue to start the list at. If $dir == 'newer' this is the lower boundary, otherwise it's the upper boundary
string$endValue to end the list at. If $dir == 'newer' this is the upper boundary, otherwise it's the lower boundary
bool$sortIf false, don't add an ORDER BY clause

Definition at line 205 of file ApiQueryBase.php.

References $dir, $sort, addOption(), addWhere(), array(), getDB(), and options().

Referenced by addTimestampWhereRange(), ApiQueryDeletedrevs\execute(), ApiQueryFilearchive\execute(), ApiQueryBlocks\execute(), ApiQueryLogEvents\execute(), ApiQueryPagePropNames\execute(), ApiQueryTags\execute(), ApiQueryAllUsers\execute(), ApiQueryRevisions\execute(), ApiQueryRandom\prepareQuery(), ApiQueryContributions\prepareQuery(), ApiQueryProtectedTitles\run(), ApiQueryCategoryMembers\run(), ApiQueryAllCategories\run(), ApiQueryPagesWithProp\run(), ApiQueryWatchlist\run(), ApiQueryAllPages\run(), ApiQueryAllImages\run(), and ApiQueryAllLinks\run().

ApiQueryBase::checkRowCount ( ) [protected]

Estimate the row count for the SELECT query that would be run if we called select() right now, and check if it's acceptable.

Returns:
bool true if acceptable, false otherwise

Definition at line 312 of file ApiQueryBase.php.

References getDB(), global, options(), ApiBase\profileDBIn(), ApiBase\profileDBOut(), and tables.

ApiQueryBase::getDirectionDescription ( p = '',
extraDirText = '' 
)

Gets the personalised direction parameter description.

Parameters:
string$pModulePrefix
string$extraDirTextAny extra text to be appended on the description
Returns:
array

Definition at line 524 of file ApiQueryBase.php.

References array().

Referenced by ApiQueryProtectedTitles\getParamDescription(), ApiQueryBlocks\getParamDescription(), ApiQueryDeletedrevs\getParamDescription(), ApiQueryContributions\getParamDescription(), ApiQueryLogEvents\getParamDescription(), ApiQueryWatchlist\getParamDescription(), ApiQueryRecentChanges\getParamDescription(), and ApiQueryRevisions\getParamDescription().

Get the main Query module.

Returns:
ApiQuery

Definition at line 356 of file ApiQueryBase.php.

Referenced by getDB(), getPageSet(), selectNamedDB(), and ApiQueryGeneratorBase\setContinueEnumParameter().

An alternative to keyToTitle() that doesn't trim trailing spaces.

Parameters:
string$keyPartKey part with spaces
Returns:
string Key part with underscores

Definition at line 513 of file ApiQueryBase.php.

References keyToTitle().

The inverse of titleToKey()

Parameters:
string$keyPage title with underscores
Returns:
string Page title with spaces

Definition at line 468 of file ApiQueryBase.php.

References $key, $t, array(), ApiBase\dieUsageMsg(), and Title\newFromDBkey().

Referenced by keyPartToTitle().

ApiQueryBase::prepareUrlQuerySearchString ( query = null,
protocol = null 
)
Parameters:
$queryString
$protocolString
Returns:
null|string

Definition at line 537 of file ApiQueryBase.php.

References $query, ApiBase\dieUsage(), LinkFilter\keepOneWildcard(), and LinkFilter\makeLikeArray().

Referenced by ApiQueryExternalLinks\execute(), and ApiQueryExtLinksUsage\run().

Override this method to request extra fields from the pageSet using $pageSet->requestField('fieldName')

Parameters:
$pageSetApiPageSet

Reimplemented in ApiQueryInfo.

Definition at line 349 of file ApiQueryBase.php.

ApiQueryBase::select ( method,
extraQuery = array() 
) [protected]

Execute a SELECT query based on the values in the internal arrays.

Parameters:
string$methodFunction the query should be attributed to. You should usually use __METHOD__ here
array$extraQueryQuery data to add but not store in the object Format is array( 'tables' => ..., 'fields' => ..., 'where' => ..., 'options' => ..., 'join_conds' => ... )
Returns:
ResultWrapper

Definition at line 274 of file ApiQueryBase.php.

References $fields, $join_conds, $options, $res, $tables, $where, array(), getDB(), options(), ApiBase\profileDBIn(), ApiBase\profileDBOut(), and tables.

Referenced by ApiQueryDeletedrevs\execute(), ApiQueryExternalLinks\execute(), ApiQueryLangLinks\execute(), ApiQueryCategoryInfo\execute(), ApiQueryIWLinks\execute(), ApiQueryFilearchive\execute(), ApiQueryPageProps\execute(), ApiQueryBlocks\execute(), ApiQueryContributions\execute(), ApiQueryLogEvents\execute(), ApiQueryPagePropNames\execute(), ApiQueryTags\execute(), ApiQueryContributors\execute(), ApiQueryAllUsers\execute(), ApiQueryUsers\execute(), ApiQueryRevisions\execute(), ApiQueryInfo\getDisplayTitle(), ApiQueryInfo\getProtectionInfo(), ApiQueryInfo\getTSIDs(), ApiQueryInfo\getWatchedInfo(), ApiQueryInfo\getWatcherInfo(), ApiQueryRedirects\run(), ApiQueryIWBacklinks\run(), ApiQueryLangBacklinks\run(), ApiQueryProtectedTitles\run(), ApiQueryImages\run(), ApiQueryWatchlistRaw\run(), ApiQueryExtLinksUsage\run(), ApiQueryCategories\run(), ApiQueryCategoryMembers\run(), ApiQueryAllCategories\run(), ApiQueryPagesWithProp\run(), ApiQueryWatchlist\run(), ApiQueryAllPages\run(), ApiQueryAllImages\run(), ApiQueryLinks\run(), ApiQueryAllLinks\run(), ApiQueryRecentChanges\run(), and ApiQueryRandom\runQuery().

ApiQueryBase::selectNamedDB ( name,
db,
groups 
)

Selects the query database connection with the given name.

See ApiQuery::getNamedDB() for more information

Parameters:
string$nameName to assign to the database connection
int$dbOne of the DB_* constants
array$groupsQuery groups
Returns:
DatabaseBase

Definition at line 433 of file ApiQueryBase.php.

References $name, and getQuery().

Referenced by ApiQueryContributions\execute(), ApiQueryWatchlistRaw\run(), and ApiQueryWatchlist\run().

Filters hidden users (where the user doesn't have the right to view them) Also adds relevant block information.

Parameters:
bool$showBlockInfo
Returns:
void

Definition at line 566 of file ApiQueryBase.php.

References addFields(), addJoinConds(), addTables(), addWhere(), array(), and ContextSource\getUser().

Referenced by ApiQueryAllUsers\execute(), and ApiQueryUsers\execute().

ApiQueryBase::titlePartToKey ( titlePart,
defaultNamespace = NS_MAIN 
)

An alternative to titleToKey() that doesn't trim trailing spaces, and does not mangle the input if starts with something that looks like a namespace.

It is advisable to pass the namespace parameter in order to handle per-namespace capitalization settings.

Parameters:
string$titlePartTitle part with spaces
$defaultNamespaceint Namespace to assume
Returns:
string Title part with underscores

Definition at line 491 of file ApiQueryBase.php.

References $t, array(), ApiBase\dieUsageMsg(), and Title\makeTitleSafe().

Referenced by ApiQueryDeletedrevs\execute(), ApiQueryFilearchive\execute(), ApiQueryAllCategories\run(), ApiQueryAllPages\run(), ApiQueryAllImages\run(), and ApiQueryAllLinks\run().

Convert a title to a DB key.

Parameters:
string$titlePage title with spaces
Returns:
string Page title with underscores

Definition at line 450 of file ApiQueryBase.php.

References $t, $title, array(), ApiBase\dieUsageMsg(), and Title\newFromText().

Check whether the current user has permission to view revision-deleted fields.

Returns:
bool

Definition at line 618 of file ApiQueryBase.php.

References ContextSource\getUser().

Referenced by ApiQueryLogEvents\getCacheMode(), ApiQueryImageInfo\getCacheMode(), ApiQueryRecentChanges\getCacheMode(), and ApiQueryRevisions\getCacheMode().

Parameters:
$hashstring
Returns:
bool

Definition at line 596 of file ApiQueryBase.php.

References $hash.

Referenced by ApiQueryFilearchive\execute(), and ApiQueryAllImages\run().

Parameters:
$hashstring
Returns:
bool

Definition at line 588 of file ApiQueryBase.php.

References $hash.

Referenced by ApiQueryFilearchive\execute(), and ApiQueryAllImages\run().


Member Data Documentation

ApiQueryBase::$fields

Definition at line 36 of file ApiQueryBase.php.

Referenced by ApiQueryORM\getConditions(), and select().

ApiQueryBase::$join_conds

Definition at line 36 of file ApiQueryBase.php.

Referenced by addJoinConds(), and select().

ApiQueryBase::$mDb

Definition at line 36 of file ApiQueryBase.php.

ApiQueryBase::$mQueryModule [private]

Definition at line 36 of file ApiQueryBase.php.

ApiQueryBase::$options

Definition at line 36 of file ApiQueryBase.php.

Referenced by select().

ApiQueryBase::$tables

Definition at line 36 of file ApiQueryBase.php.

Referenced by addTables(), ApiQueryContributions\prepareQuery(), and select().

ApiQueryBase::$where

Definition at line 36 of file ApiQueryBase.php.

Referenced by ApiQueryDeletedrevs\execute(), and select().


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