45 parent::__construct( $queryModule->
getMain(), $moduleName, $paramPrefix );
46 $this->mQueryModule = $queryModule;
95 return $this->mQueryModule;
108 if ( is_null( $this->mDb ) ) {
109 $this->mDb = $this->
getQuery()->getDB();
124 $this->mDb = $this->
getQuery()->getNamedDB( $name, $db, $groups );
133 return $this->
getQuery()->getPageSet();
151 $this->join_conds = [];
161 protected function addTables( $tables, $alias =
null ) {
162 if ( is_array( $tables ) ) {
163 if ( $alias !==
null ) {
166 $this->tables = array_merge( $this->tables, $tables );
167 } elseif ( $alias !==
null ) {
168 $this->tables[$alias] = $tables;
170 $this->tables[] = $tables;
183 if ( !is_array( $join_conds ) ) {
186 $this->join_conds = array_merge( $this->join_conds, $join_conds );
194 if ( is_array( $value ) ) {
195 $this->fields = array_merge( $this->fields, $value );
197 $this->fields[] = $value;
229 if ( is_array( $value ) ) {
232 if ( count( $value ) ) {
233 $this->where = array_merge( $this->where, $value );
236 $this->where[] = $value;
262 if ( $value !==
null && !( is_array( $value ) && !$value ) ) {
263 $this->where[$field] = $value;
278 if ( count( $ids ) ) {
279 $ids = $this->
filterIDs( [ [ $table, $field ] ], $ids );
283 $this->where[] =
'0 = 1';
285 $this->where[$field] = $ids;
288 return count( $ids );
304 $isDirNewer = ( $dir ===
'newer' );
305 $after = ( $isDirNewer ?
'>=' :
'<=' );
306 $before = ( $isDirNewer ?
'<=' :
'>=' );
307 $db = $this->
getDB();
309 if ( !is_null( $start ) ) {
310 $this->
addWhere( $field . $after . $db->addQuotes( $start ) );
313 if ( !is_null( $end ) ) {
314 $this->
addWhere( $field . $before . $db->addQuotes( $end ) );
318 $order = $field . ( $isDirNewer ?
'' :
' DESC' );
320 $optionOrderBy = isset( $this->options[
'ORDER BY'] )
321 ? (array)$this->options[
'ORDER BY']
323 $optionOrderBy[] = $order;
324 $this->
addOption(
'ORDER BY', $optionOrderBy );
339 $db = $this->
getDB();
341 $db->timestampOrNull( $start ), $db->timestampOrNull( $end ),
$sort );
351 if ( is_null( $value ) ) {
352 $this->options[] = $name;
354 $this->options[$name] = $value;
375 protected function select( $method, $extraQuery = [], array &$hookData =
null ) {
376 $tables = array_merge(
378 isset( $extraQuery[
'tables'] ) ? (array)$extraQuery[
'tables'] : []
380 $fields = array_merge(
382 isset( $extraQuery[
'fields'] ) ? (array)$extraQuery[
'fields'] : []
384 $where = array_merge(
386 isset( $extraQuery[
'where'] ) ? (array)$extraQuery[
'where'] : []
388 $options = array_merge(
390 isset( $extraQuery[
'options'] ) ? (array)$extraQuery[
'options'] : []
392 $join_conds = array_merge(
394 isset( $extraQuery[
'join_conds'] ) ? (array)$extraQuery[
'join_conds'] : []
397 if ( $hookData !==
null ) {
398 Hooks::run(
'ApiQueryBaseBeforeQuery',
399 [ $this, &$tables, &$fields, &$where, &$options, &$join_conds, &$hookData ]
403 $res = $this->
getDB()->select( $tables, $fields, $where, $method, $options, $join_conds );
405 if ( $hookData !==
null ) {
406 Hooks::run(
'ApiQueryBaseAfterQuery', [ $this,
$res, &$hookData ] );
425 protected function processRow( $row, array &$data, array &$hookData ) {
426 return Hooks::run(
'ApiQueryBaseProcessRow', [ $this, $row, &$data, &$hookData ] );
444 $arr[$prefix .
'ns'] = (int)
$title->getNamespace();
445 $arr[$prefix .
'title'] =
$title->getPrefixedText();
458 return $result->addValue( [
'query',
'pages', (
int)$pageId ],
472 if ( is_null( $elemname ) ) {
476 $fit = $result->addValue( [
'query',
'pages', $pageId,
481 $result->addIndexedTagName( [
'query',
'pages', $pageId,
507 $t = Title::makeTitleSafe( $namespace, $titlePart .
'x' );
508 if ( !
$t ||
$t->hasFragment() ) {
512 if ( $namespace !=
$t->getNamespace() ||
$t->isExternal() ) {
521 return substr(
$t->getDBkey(), 0, -1 );
533 $t = Title::newFromText( $titlePart .
'x', $defaultNamespace );
534 if ( !
$t ||
$t->hasFragment() ||
$t->isExternal() ) {
539 return [
$t->getNamespace(), substr(
$t->getDBkey(), 0, -1 ) ];
547 return (
bool)preg_match(
'/^[a-f0-9]{40}$/', $hash );
555 return (
bool)preg_match(
'/^[a-z0-9]{31}$/', $hash );
585 if ( !
$res->numRows() ) {
589 $services = MediaWikiServices::getInstance();
590 $nsInfo = $services->getNamespaceInfo();
591 $namespaceField = $fieldPrefix .
'_namespace';
592 $titleField = $fieldPrefix .
'_title';
595 foreach (
$res as $row ) {
596 if ( $nsInfo->hasGenderDistinction( $row->$namespaceField ) ) {
597 $usernames[] = $row->$titleField;
601 if ( $usernames === [] ) {
605 $genderCache = $services->getGenderCache();
606 $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)
Throws a warning that $function is deprecated.
This abstract class implements many basic API functions, and is the base of all API classes.
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.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
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.
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.
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.
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.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='')
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.
trait ApiQueryBlockInfoTrait