Go to the documentation of this file.
54 parent::__construct( $queryModule->
getMain(), $moduleName, $paramPrefix );
55 $this->mQueryModule = $queryModule;
118 if ( $this->mDb ===
null ) {
119 $this->mDb = $this->
getQuery()->getDB();
134 $this->mDb = $this->
getQuery()->getNamedDB( $name, $db, $groups );
144 return $this->
getQuery()->getPageSet();
157 $this->queryBuilder =
null;
169 if ( $this->queryBuilder ===
null ) {
170 $this->queryBuilder = $this->
getDB()->newSelectQueryBuilder();
182 protected function addTables( $tables, $alias =
null ) {
183 if ( is_array( $tables ) ) {
184 if ( $alias !==
null ) {
202 if ( !is_array( $join_conds ) ) {
246 if ( is_array( $value ) ) {
249 if ( count( $value ) ) {
283 if ( $value !==
null && !( is_array( $value ) && !$value ) ) {
312 if ( count( $ids ) ) {
313 $ids = $this->
filterIDs( [ [ $table, $field ] ], $ids );
322 return count( $ids );
337 protected function addWhereRange( $field, $dir, $start, $end, $sort =
true ) {
338 $isDirNewer = ( $dir ===
'newer' );
339 $after = ( $isDirNewer ?
'>=' :
'<=' );
340 $before = ( $isDirNewer ?
'<=' :
'>=' );
341 $db = $this->
getDB();
343 if ( $start !==
null ) {
344 $this->
addWhere( $field . $after . $db->addQuotes( $start ) );
347 if ( $end !==
null ) {
348 $this->
addWhere( $field . $before . $db->addQuotes( $end ) );
352 $this->
getQueryBuilder()->orderBy( $field, $isDirNewer ?
null :
'DESC' );
367 $db = $this->
getDB();
369 $db->timestampOrNull( $start ), $db->timestampOrNull( $end ), $sort );
399 protected function select( $method, $extraQuery = [], array &$hookData =
null ) {
401 if ( isset( $extraQuery[
'tables'] ) ) {
404 if ( isset( $extraQuery[
'fields'] ) ) {
407 if ( isset( $extraQuery[
'where'] ) ) {
410 if ( isset( $extraQuery[
'options'] ) ) {
413 if ( isset( $extraQuery[
'join_conds'] ) ) {
420 $this, $info[
'tables'], $info[
'fields'], $info[
'conds'],
421 $info[
'options'], $info[
'join_conds'], $hookData
429 if ( $hookData !==
null ) {
449 protected function processRow( $row, array &$data, array &$hookData ) {
450 return $this->
getHookRunner()->onApiQueryBaseProcessRow( $this, $row, $data, $hookData );
467 $arr[$prefix .
'ns'] =
$title->getNamespace();
468 $arr[$prefix .
'title'] =
$title->getPrefixedText();
481 return $result->addValue( [
'query',
'pages', (
int)$pageId ],
495 if ( $elemname ===
null ) {
499 $fit = $result->addValue( [
'query',
'pages', $pageId,
504 $result->addIndexedTagName( [
'query',
'pages', $pageId,
531 if ( !
$t ||
$t->hasFragment() ) {
535 if ( $namespace !=
$t->getNamespace() ||
$t->isExternal() ) {
544 return substr(
$t->getDBkey(), 0, -1 );
557 $titleParser = MediaWikiServices::getInstance()->getTitleParser();
558 $t = $titleParser->parseTitle( $titlePart .
'X', $defaultNamespace );
563 if ( !
$t ||
$t->hasFragment() ||
$t->isExternal() ||
$t->getDBkey() ===
'X' ) {
568 return new TitleValue(
$t->getNamespace(), substr(
$t->getDBkey(), 0, -1 ) );
583 return [
$t->getNamespace(),
$t->getDBkey() ];
591 return (
bool)preg_match(
'/^[a-f0-9]{40}$/', $hash );
599 return (
bool)preg_match(
'/^[a-z0-9]{31}$/', $hash );
629 if ( !
$res->numRows() ) {
633 $services = MediaWikiServices::getInstance();
634 if ( !$services->getContentLanguage()->needsGenderDistinction() ) {
638 $nsInfo = $services->getNamespaceInfo();
639 $namespaceField = $fieldPrefix .
'_namespace';
640 $titleField = $fieldPrefix .
'_title';
643 foreach (
$res as $row ) {
644 if ( $nsInfo->hasGenderDistinction( $row->$namespaceField ) ) {
645 $usernames[] = $row->$titleField;
649 if ( $usernames === [] ) {
653 $genderCache = $services->getGenderCache();
654 $genderCache->doQuery( $usernames, $fname );
validateSha1Base36Hash( $hash)
addWhereIDsFld( $table, $field, $ids)
Like addWhereFld for an integer list of IDs.
showHiddenUsersAddBlockInfo( $showBlockInfo)
Filters hidden users (where the user doesn't have the right to view them) Also adds relevant block in...
addPageSubItems( $pageId, $data)
Add a sub-element under the page element with the given page ID.
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
addFields( $value)
Add a set of fields to select to the internal array.
This is the main query class.
resetQueryParams()
Blank the internal arrays with query parameters.
getParent()
Get the parent of this module Stable to override.1.25 ApiBase|null
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
getResult()
Get the result object.
getQuery()
Get the main Query module.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
getUser()
Stable to override.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
This abstract class implements many basic API functions, and is the base of all API classes.
trait ApiQueryBlockInfoTrait
executeGenderCacheFromResultWrapper(IResultWrapper $res, $fname=__METHOD__, $fieldPrefix='page')
Preprocess the result set to fill the GenderCache with the necessary information before using self::a...
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
This is a base class for all Query modules.
getDB()
Get the Query database connection (read-only) Stable to override.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
SelectQueryBuilder $queryBuilder
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
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.
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
getQueryBuilder()
Get the SelectQueryBuilder.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
requestExtraData( $pageSet)
Override this method to request extra fields from the pageSet using $pageSet->requestField('fieldName...
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
getCacheMode( $params)
Get the cache mode for the data generated by this module.
prefixedTitlePartToKey( $titlePart, $defaultNamespace=NS_MAIN)
Convert an input title or title prefix into a namespace constant and dbkey.
getPageSet()
Get the PageSet object to work on Stable to override.
static isRegistered( $name)
Returns true if a hook has a function registered to it.
filterIDs( $fields, array $ids)
Filter out-of-range values from a list of positive integer IDs.
selectNamedDB( $name, $db, $groups)
Selects the query database connection with the given name.
__construct(ApiQuery $queryModule, $moduleName, $paramPrefix='')
Stable to call.
parsePrefixedTitlePart( $titlePart, $defaultNamespace=NS_MAIN)
Convert an input title or title prefix into a TitleValue.
getModuleName()
Get the name of the module being executed by this instance.
getMain()
Get the main module.
addWhere( $value)
Add a set of WHERE clauses to the internal array.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
titlePartToKey( $titlePart, $namespace=NS_MAIN)
Convert an input title or title prefix into a dbkey.
getHookRunner()
Get an ApiHookRunner for running core API hooks.
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
addBlockInfoToQuery( $showBlockInfo)
Filters hidden users (where the user doesn't have the right to view them) Also adds relevant block in...
Represents a page (or page fragment) title within MediaWiki.