ApiQueryBase Class Reference
[API]

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

Inherits ApiBase.

Inherited by ApiPageSet, ApiQueryAllmessages, ApiQueryAllUsers, ApiQueryBlocks, ApiQueryCategoryInfo, ApiQueryContributions, ApiQueryDeletedrevs, ApiQueryDisabled, ApiQueryExternalLinks, ApiQueryGeneratorBase, ApiQueryImageInfo, ApiQueryInfo, ApiQueryLangLinks, ApiQueryLogEvents, ApiQueryRecentChanges, ApiQueryRevisions, ApiQuerySiteinfo, ApiQueryUserInfo, and ApiQueryUsers.

List of all members.

Public Member Functions

 __construct ($query, $moduleName, $paramPrefix= '')
 Constructor.
 requestExtraData ($pageSet)
 Override this method to request extra fields from the pageSet using $pageSet->requestField('fieldName').
 getQuery ()
 Get the main Query module.
 selectNamedDB ($name, $db, $groups)
 Selects the query database connection with the given name.
 titleToKey ($title)
 Convert a title to a DB key.
 keyToTitle ($key)
 The inverse of titleToKey().
 titlePartToKey ($titlePart)
 An alternative to titleToKey() that doesn't trim trailing spaces.
 keyPartToTitle ($keyPart)
 An alternative to keyToTitle() that doesn't trim trailing spaces.

Static Public Member Functions

static addTitleInfo (&$arr, $title, $prefix='')
 Add information (title and namespace) about a Title object to a result array.
static getBaseVersion ()
 Get version string for use in the API help output.

Protected Member Functions

 resetQueryParams ()
 Blank the internal arrays with query parameters.
 addTables ($tables, $alias=null)
 Add a set of tables to the internal array.
 getAliasedName ($table, $alias)
 Get the SQL for a table name with alias.
 addJoinConds ($join_conds)
 Add a set of JOIN conditions to the internal array.
 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.
 addWhere ($value)
 Add a set of WHERE clauses to the internal array.
 addWhereIf ($value, $condition)
 Same as addWhere(), but add the WHERE clauses only if a condition is met.
 addWhereFld ($field, $value)
 Equivalent to addWhere(array($field => $value)).
 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.
 addOption ($name, $value=null)
 Add an option such as LIMIT or USE INDEX.
 select ($method)
 Execute a SELECT query based on the values in the internal arrays.
 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.
 addPageSubItems ($pageId, $data)
 Add a sub-element under the page element with the given page ID.
 addPageSubItem ($pageId, $item, $elemname=null)
 Same as addPageSubItems(), but one element of $data at a time.
 setContinueEnumParameter ($paramName, $paramValue)
 Set a query-continue value.
 getDB ()
 Get the Query database connection (read-only).
 getPageSet ()
 Get the PageSet object to work on.

Private Attributes

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


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 38 of file ApiQueryBase.php.


Constructor & Destructor Documentation

ApiQueryBase::__construct ( mainModule,
moduleName,
modulePrefix = '' 
)

Constructor.

Parameters:
$mainModule ApiMain object
$moduleName string Name of this module
$modulePrefix string Prefix to use for parameter names

Reimplemented from ApiBase.

Reimplemented in ApiQueryGeneratorBase.

Definition at line 42 of file ApiQueryBase.php.

References resetQueryParams().


Member Function Documentation

ApiQueryBase::addFields ( value  )  [protected]

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

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_conds array JOIN conditions

Definition at line 97 of file ApiQueryBase.php.

References $join_conds, and ApiBase::dieDebug().

Referenced by ApiQueryUsers::execute(), ApiQueryRecentChanges::execute(), ApiQueryLogEvents::execute(), ApiQueryCategoryInfo::execute(), ApiQueryAllUsers::execute(), ApiQueryContributions::prepareQuery(), ApiQueryProtectedTitles::run(), ApiQueryCategories::run(), ApiQueryAllpages::run(), and ApiQueryAllCategories::run().

ApiQueryBase::addOption ( name,
value = null 
) [protected]

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

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

Parameters:
$pageId int Page ID
$data array Data array à la ApiResult
$elemname string XML element name. If null, getModuleName() is used
Returns:
bool Whether the element fit in the result

Definition at line 307 of file ApiQueryBase.php.

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

Referenced by ApiQueryRevisions::execute(), ApiQueryLangLinks::execute(), ApiQueryImageInfo::execute(), ApiQueryExternalLinks::execute(), ApiQueryLinks::run(), ApiQueryImages::run(), ApiQueryDuplicateFiles::run(), and ApiQueryCategories::run().

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

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

Parameters:
$pageId int Page ID
$data array Data array à la ApiResult
Returns:
bool Whether the element fit in the result

Definition at line 291 of file ApiQueryBase.php.

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

Referenced by ApiQueryCategoryInfo::execute().

ApiQueryBase::addTables ( tables,
alias = null 
) [protected]

static ApiQueryBase::addTitleInfo ( &$  arr,
title,
prefix = '' 
) [static]

ApiQueryBase::addWhere ( value  )  [protected]

ApiQueryBase::addWhereFld ( field,
value 
) [protected]

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

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

Parameters:
$value mixed See addWhere()
$condition boolIf false, do nothing
Returns:
bool $condition

Definition at line 156 of file ApiQueryBase.php.

References addWhere().

Referenced by ApiQueryRecentChanges::execute(), ApiQueryContributions::prepareQuery(), ApiQueryWatchlistRaw::run(), ApiQueryWatchlist::run(), and ApiQueryAllpages::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:
$field string Field name
$dir string If 'newer', sort in ascending order, otherwise sort in descending order
$start string Value to start the list at. If $dir == 'newer' this is the lower boundary, otherwise it's the upper boundary
$end string Value to end the list at. If $dir == 'newer' this is the upper boundary, otherwise it's the lower boundary
$sort bool If false, don't add an ORDER BY clause

Definition at line 188 of file ApiQueryBase.php.

References $db, $end, $sort, $start, addOption(), addWhere(), and getDB().

Referenced by ApiQueryRevisions::execute(), ApiQueryRecentChanges::execute(), ApiQueryLogEvents::execute(), ApiQueryDeletedrevs::execute(), ApiQueryBlocks::execute(), ApiQueryContributions::prepareQuery(), ApiQueryRandom::prepareQuery(), ApiQueryWatchlist::run(), ApiQueryProtectedTitles::run(), ApiQueryCategoryMembers::run(), ApiQueryAllpages::run(), ApiQueryAllimages::run(), and ApiQueryAllCategories::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 245 of file ApiQueryBase.php.

References $db, $wgAPIMaxDBRows, getDB(), ApiBase::profileDBIn(), and ApiBase::profileDBOut().

ApiQueryBase::getAliasedName ( table,
alias 
) [protected]

Get the SQL for a table name with alias.

Parameters:
$table string Table name
$alias string Alias
Returns:
string SQL

Definition at line 84 of file ApiQueryBase.php.

References getDB().

Referenced by addTables(), ApiQueryUsers::execute(), and ApiQueryAllUsers::execute().

static ApiQueryBase::getBaseVersion (  )  [static]

Get version string for use in the API help output.

Returns:
string

Reimplemented from ApiBase.

Definition at line 416 of file ApiQueryBase.php.

ApiQueryBase::getDB (  )  [protected]

ApiQueryBase::getPageSet (  )  [protected]

ApiQueryBase::getQuery (  ) 

Get the main Query module.

Returns:
ApiQuery

Definition at line 281 of file ApiQueryBase.php.

Referenced by getDB(), getPageSet(), and selectNamedDB().

ApiQueryBase::keyPartToTitle ( keyPart  ) 

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

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

Definition at line 408 of file ApiQueryBase.php.

References keyToTitle().

ApiQueryBase::keyToTitle ( key  ) 

The inverse of titleToKey().

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

Definition at line 383 of file ApiQueryBase.php.

References $key, $t, and ApiBase::dieUsageMsg().

Referenced by ApiQueryAllUsers::execute(), keyPartToTitle(), ApiQueryLinks::run(), ApiQueryDuplicateFiles::run(), ApiQueryAllpages::run(), ApiQueryAllLinks::run(), ApiQueryAllimages::run(), and ApiQueryAllCategories::run().

ApiQueryBase::requestExtraData ( pageSet  ) 

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

Parameters:
$pageSet ApiPageSet

Reimplemented in ApiQueryInfo.

Definition at line 274 of file ApiQueryBase.php.

ApiQueryBase::resetQueryParams (  )  [protected]

ApiQueryBase::select ( method  )  [protected]

ApiQueryBase::selectNamedDB ( name,
db,
groups 
)

Selects the query database connection with the given name.

See ApiQuery::getNamedDB() for more information

Parameters:
$name string Name to assign to the database connection
$db int One of the DB_* constants
$groups array Query groups
Returns:
Database

Definition at line 351 of file ApiQueryBase.php.

References $db, $name, and getQuery().

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

ApiQueryBase::setContinueEnumParameter ( paramName,
paramValue 
) [protected]

ApiQueryBase::titlePartToKey ( titlePart  ) 

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

Parameters:
$titlePart string Title part with spaces
Returns:
string Title part with underscores

Definition at line 399 of file ApiQueryBase.php.

References titleToKey().

Referenced by ApiQueryAllpages::run(), ApiQueryAllimages::run(), and ApiQueryAllCategories::run().

ApiQueryBase::titleToKey ( title  ) 

Convert a title to a DB key.

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

Definition at line 368 of file ApiQueryBase.php.

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

Referenced by ApiQueryDeletedrevs::execute(), ApiQueryWatchlistRaw::run(), ApiQueryLinks::run(), ApiQueryImages::run(), ApiQueryDuplicateFiles::run(), ApiQueryCategories::run(), ApiQueryAllLinks::run(), and titlePartToKey().


Member Data Documentation

ApiQueryBase::$fields [private]

Definition at line 40 of file ApiQueryBase.php.

Referenced by ApiPageSet::initFromRevIDs().

ApiQueryBase::$join_conds [private]

Definition at line 40 of file ApiQueryBase.php.

Referenced by addJoinConds().

ApiQueryBase::$mDb [private]

Definition at line 40 of file ApiQueryBase.php.

ApiQueryBase::$mQueryModule [private]

Definition at line 40 of file ApiQueryBase.php.

ApiQueryBase::$options [private]

Definition at line 40 of file ApiQueryBase.php.

ApiQueryBase::$tables [private]

ApiQueryBase::$where [private]

Definition at line 40 of file ApiQueryBase.php.

Referenced by ApiQueryDeletedrevs::execute(), and ApiPageSet::initFromRevIDs().


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

Generated on Sat Sep 5 02:08:31 2009 for MediaWiki by  doxygen 1.5.9