54 parent::__construct( $queryModule->
getMain(), $moduleName, $paramPrefix );
55 $this->mQueryModule = $queryModule;
106 return $this->mQueryModule;
120 if ( $this->mDb ===
null ) {
121 $this->mDb = $this->
getQuery()->getDB();
136 $this->mDb = $this->
getQuery()->getNamedDB( $name, $db, $groups );
146 return $this->
getQuery()->getPageSet();
160 $this->queryBuilder =
null;
172 if ( $this->queryBuilder ===
null ) {
173 $this->queryBuilder = $this->
getDB()->newSelectQueryBuilder();
175 return $this->queryBuilder;
185 protected function addTables( $tables, $alias =
null ) {
186 if ( is_array( $tables ) ) {
187 if ( $alias !==
null ) {
205 if ( !is_array( $join_conds ) ) {
249 if ( is_array( $value ) ) {
252 if ( count( $value ) ) {
286 if ( $value !==
null && !( is_array( $value ) && !$value ) ) {
315 if ( count( $ids ) ) {
316 $ids = $this->
filterIDs( [ [ $table, $field ] ], $ids );
325 return count( $ids );
340 protected function addWhereRange( $field, $dir, $start, $end, $sort =
true ) {
341 $isDirNewer = ( $dir ===
'newer' );
342 $after = ( $isDirNewer ?
'>=' :
'<=' );
343 $before = ( $isDirNewer ?
'<=' :
'>=' );
344 $db = $this->
getDB();
346 if ( $start !==
null ) {
347 $this->
addWhere( $field . $after . $db->addQuotes( $start ) );
350 if ( $end !==
null ) {
351 $this->
addWhere( $field . $before . $db->addQuotes( $end ) );
355 $this->
getQueryBuilder()->orderBy( $field, $isDirNewer ?
null :
'DESC' );
370 $db = $this->
getDB();
372 $db->timestampOrNull( $start ), $db->timestampOrNull( $end ), $sort );
402 protected function select( $method, $extraQuery = [], array &$hookData =
null ) {
404 if ( isset( $extraQuery[
'tables'] ) ) {
407 if ( isset( $extraQuery[
'fields'] ) ) {
410 if ( isset( $extraQuery[
'where'] ) ) {
413 if ( isset( $extraQuery[
'options'] ) ) {
416 if ( isset( $extraQuery[
'join_conds'] ) ) {
420 if ( $hookData !==
null && Hooks::isRegistered(
'ApiQueryBaseBeforeQuery' ) ) {
423 $this, $info[
'tables'], $info[
'fields'], $info[
'conds'],
424 $info[
'options'], $info[
'join_conds'], $hookData
432 if ( $hookData !==
null ) {
452 protected function processRow( $row, array &$data, array &$hookData ) {
453 return $this->
getHookRunner()->onApiQueryBaseProcessRow( $this, $row, $data, $hookData );
471 $arr[$prefix .
'ns'] = (int)
$title->getNamespace();
472 $arr[$prefix .
'title'] =
$title->getPrefixedText();
485 return $result->addValue( [
'query',
'pages', (
int)$pageId ],
499 if ( $elemname ===
null ) {
503 $fit = $result->addValue( [
'query',
'pages', $pageId,
508 $result->addIndexedTagName( [
'query',
'pages', $pageId,
534 $t = Title::makeTitleSafe( $namespace, $titlePart .
'x' );
535 if ( !
$t ||
$t->hasFragment() ) {
539 if ( $namespace !=
$t->getNamespace() ||
$t->isExternal() ) {
548 return substr(
$t->getDBkey(), 0, -1 );
561 $titleParser = MediaWikiServices::getInstance()->getTitleParser();
562 $t = $titleParser->parseTitle( $titlePart .
'X', $defaultNamespace );
567 if ( !
$t ||
$t->hasFragment() ||
$t->isExternal() ||
$t->getDBkey() ===
'X' ) {
572 return new TitleValue(
$t->getNamespace(), substr(
$t->getDBkey(), 0, -1 ) );
587 return [
$t->getNamespace(),
$t->getDBkey() ];
595 return (
bool)preg_match(
'/^[a-f0-9]{40}$/', $hash );
603 return (
bool)preg_match(
'/^[a-z0-9]{31}$/', $hash );
633 if ( !
$res->numRows() ) {
637 $services = MediaWikiServices::getInstance();
638 if ( !$services->getContentLanguage()->needsGenderDistinction() ) {
642 $nsInfo = $services->getNamespaceInfo();
643 $namespaceField = $fieldPrefix .
'_namespace';
644 $titleField = $fieldPrefix .
'_title';
647 foreach (
$res as $row ) {
648 if ( $nsInfo->hasGenderDistinction( $row->$namespaceField ) ) {
649 $usernames[] = $row->$titleField;
653 if ( $usernames === [] ) {
657 $genderCache = $services->getGenderCache();
658 $genderCache->doQuery( $usernames, $fname );
addBlockInfoToQuery( $showBlockInfo)
Filters hidden users (where the user doesn't have the right to view them) Also adds relevant block in...
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
This abstract class implements many basic API functions, and is the base of all API classes.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
filterIDs( $fields, array $ids)
Filter out-of-range values from a list of positive integer IDs.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
getMain()
Get the main module.
getResult()
Get the result object.
getModuleName()
Get the name of the module being executed by this instance.
getHookRunner()
Get an ApiHookRunner for running core API hooks.
getContinuationManager()
Get the continuation manager.
This is a base class for all Query modules.
selectNamedDB( $name, $db, $groups)
Selects the query database connection with the given name.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
parsePrefixedTitlePart( $titlePart, $defaultNamespace=NS_MAIN)
Convert an input title or title prefix into a TitleValue.
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
validateSha1Base36Hash( $hash)
resetQueryParams()
Blank the internal arrays with query parameters.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
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.
getQueryBuilder()
Get the SelectQueryBuilder.
addPageSubItems( $pageId, $data)
Add a sub-element under the page element with the given page ID.
addFields( $value)
Add a set of fields to select to the internal array.
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
getParent()
Get the parent of this module Stable to override.1.25 ApiBase|null
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
SelectQueryBuilder $queryBuilder
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
getDB()
Get the Query database connection (read-only) Stable to override.
executeGenderCacheFromResultWrapper(IResultWrapper $res, $fname=__METHOD__, $fieldPrefix='page')
Preprocess the result set to fill the GenderCache with the necessary information before using self::a...
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addWhereIDsFld( $table, $field, $ids)
Like addWhereFld for an integer list of IDs.
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.
getQuery()
Get the main Query module.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
getPageSet()
Get the PageSet object to work on Stable to override.
titlePartToKey( $titlePart, $namespace=NS_MAIN)
Convert an input title or title prefix into a dbkey.
addWhere( $value)
Add a set of WHERE clauses to the internal array.
__construct(ApiQuery $queryModule, $moduleName, $paramPrefix='')
Stable to call.
prefixedTitlePartToKey( $titlePart, $defaultNamespace=NS_MAIN)
Convert an input title or title prefix into a namespace constant and dbkey.
showHiddenUsersAddBlockInfo( $showBlockInfo)
Filters hidden users (where the user doesn't have the right to view them) Also adds relevant block in...
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
This is the main query class.
Represents a page (or page fragment) title within MediaWiki.
trait ApiQueryBlockInfoTrait