45 private $mQueryModule, $mDb;
50 private $queryBuilder;
59 parent::__construct( $queryModule->
getMain(), $moduleName, $paramPrefix );
60 $this->mQueryModule = $queryModule;
109 return $this->mQueryModule;
123 $this->mDb ??= $this->
getQuery()->getDB();
134 return $this->
getQuery()->getPageSet();
147 $this->queryBuilder =
null;
159 $this->queryBuilder ??= $this->
getDB()->newSelectQueryBuilder();
160 return $this->queryBuilder;
170 protected function addTables( $tables, $alias =
null ) {
171 if ( is_array( $tables ) ) {
172 if ( $alias !==
null ) {
190 if ( !is_array( $join_conds ) ) {
234 if ( is_array( $value ) ) {
237 if ( count( $value ) ) {
271 if ( $value !==
null && !( is_array( $value ) && !$value ) ) {
300 if ( count( $ids ) ) {
301 $ids = $this->
filterIDs( [ [ $table, $field ] ], $ids );
310 return count( $ids );
325 protected function addWhereRange( $field, $dir, $start, $end, $sort =
true ) {
326 $isDirNewer = ( $dir ===
'newer' );
327 $after = ( $isDirNewer ?
'>=' :
'<=' );
328 $before = ( $isDirNewer ?
'<=' :
'>=' );
329 $db = $this->
getDB();
331 if ( $start !==
null ) {
332 $this->
addWhere( $db->expr( $field, $after, $start ) );
335 if ( $end !==
null ) {
336 $this->
addWhere( $db->expr( $field, $before, $end ) );
340 $this->
getQueryBuilder()->orderBy( $field, $isDirNewer ?
null :
'DESC' );
355 $db = $this->
getDB();
357 $db->timestampOrNull( $start ), $db->timestampOrNull( $end ), $sort );
387 protected function select( $method, $extraQuery = [], array &$hookData =
null ) {
389 if ( isset( $extraQuery[
'tables'] ) ) {
390 $queryBuilder->
rawTables( (array)$extraQuery[
'tables'] );
392 if ( isset( $extraQuery[
'fields'] ) ) {
393 $queryBuilder->
fields( (array)$extraQuery[
'fields'] );
395 if ( isset( $extraQuery[
'where'] ) ) {
396 $queryBuilder->
where( (array)$extraQuery[
'where'] );
398 if ( isset( $extraQuery[
'options'] ) ) {
399 $queryBuilder->
options( (array)$extraQuery[
'options'] );
401 if ( isset( $extraQuery[
'join_conds'] ) ) {
402 $queryBuilder->
joinConds( (array)$extraQuery[
'join_conds'] );
405 if ( $hookData !==
null && $this->
getHookContainer()->isRegistered(
'ApiQueryBaseBeforeQuery' ) ) {
408 $this, $info[
'tables'], $info[
'fields'], $info[
'conds'],
409 $info[
'options'], $info[
'join_conds'], $hookData
411 $queryBuilder = $this->
getDB()->newSelectQueryBuilder()->
queryInfo( $info );
414 $queryBuilder->
caller( $method );
417 if ( $hookData !==
null ) {
418 $this->
getHookRunner()->onApiQueryBaseAfterQuery( $this, $res, $hookData );
437 protected function processRow( $row, array &$data, array &$hookData ) {
438 return $this->
getHookRunner()->onApiQueryBaseProcessRow( $this, $row, $data, $hookData );
455 $arr[$prefix .
'ns'] = $title->getNamespace();
456 $arr[$prefix .
'title'] = $title->getPrefixedText();
469 return $result->addValue( [
'query',
'pages', (
int)$pageId ],
484 $fit = $result->addValue( [
'query',
'pages', $pageId,
489 $result->addIndexedTagName(
517 $t = Title::makeTitleSafe( $namespace, $titlePart .
'x' );
518 if ( !$t || $t->hasFragment() ) {
522 if ( $namespace != $t->getNamespace() || $t->isExternal() ) {
531 return substr( $t->getDBkey(), 0, -1 );
544 $titleParser = MediaWikiServices::getInstance()->getTitleParser();
545 $t = $titleParser->parseTitle( $titlePart .
'X', $defaultNamespace );
550 if ( !$t || $t->hasFragment() || $t->isExternal() || $t->getDBkey() ===
'X' ) {
555 return new TitleValue( $t->getNamespace(), substr( $t->getDBkey(), 0, -1 ) );
563 return (
bool)preg_match(
'/^[a-f0-9]{40}$/', $hash );
571 return (
bool)preg_match(
'/^[a-z0-9]{31}$/', $hash );
605 $services = MediaWikiServices::getInstance();
606 if ( !$services->getContentLanguage()->needsGenderDistinction() ) {
610 $nsInfo = $services->getNamespaceInfo();
611 $namespaceField = $fieldPrefix .
'_namespace';
612 $titleField = $fieldPrefix .
'_title';
615 foreach ( $res as $row ) {
616 if ( $nsInfo->hasGenderDistinction( $row->$namespaceField ) ) {
617 $usernames[] = $row->$titleField;
621 if ( $usernames === [] ) {
625 $genderCache = $services->getGenderCache();
626 $genderCache->doQuery( $usernames, $fname );
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
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.
getHookContainer()
Get a HookContainer, for running extension hooks or for hook metadata.
This is a base class for all Query modules.
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.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.
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)
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.
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='')
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
This is the main query class.
trait ApiQueryBlockInfoTrait