Go to the documentation of this file.
45 parent::__construct( $queryModule->
getMain(), $moduleName, $paramPrefix );
46 $this->mQueryModule = $queryModule;
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 = [];
163 if ( $alias !==
null ) {
166 $this->tables = array_merge( $this->tables,
$tables );
167 } elseif ( $alias !==
null ) {
168 $this->tables[$alias] =
$tables;
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 ) {
378 isset( $extraQuery[
'tables'] ) ? (array)$extraQuery[
'tables'] : []
382 isset( $extraQuery[
'fields'] ) ? (array)$extraQuery[
'fields'] : []
386 isset( $extraQuery[
'where'] ) ? (array)$extraQuery[
'where'] : []
390 isset( $extraQuery[
'options'] ) ? (array)$extraQuery[
'options'] : []
394 isset( $extraQuery[
'join_conds'] ) ? (array)$extraQuery[
'join_conds'] : []
397 if ( $hookData !==
null ) {
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,
508 if ( !
$t ||
$t->hasFragment() ) {
512 if ( $namespace !=
$t->getNamespace() ||
$t->isExternal() ) {
521 return substr(
$t->getDBkey(), 0, -1 );
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 );
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.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
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.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.
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)
Throws a warning that $function is deprecated.
This is a base class for all Query modules.
getDB()
Get the Query database connection (read-only)
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.
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.
getContinuationManager()
Get the continuation manager.
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.
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.
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='')
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.
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
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...