37 private array $virtualDBs;
38 private string|
false $currentDomain;
43 private $queryBuilder;
52 parent::__construct( $queryModule->
getMain(), $moduleName, $paramPrefix );
53 $this->mQueryModule = $queryModule;
55 $this->virtualDBs = [];
56 $this->currentDomain =
false;
104 return $this->mQueryModule;
120 if ( $this->currentDomain ) {
121 if ( !isset( $this->virtualDBs[$this->currentDomain] ) ) {
123 ->getConnectionProvider()
124 ->getReplicaDatabase( $this->currentDomain );
125 $this->virtualDBs[$this->currentDomain] = $db;
127 return $this->virtualDBs[$this->currentDomain];
130 $this->mDb ??= $this->
getQuery()->getDB();
142 $this->currentDomain = $virtualDomain;
143 $this->updateQueryBuilderConnection();
152 $this->currentDomain =
false;
153 $this->updateQueryBuilderConnection();
156 private function updateQueryBuilderConnection() {
157 if ( $this->queryBuilder ) {
158 $this->queryBuilder->connection( $this->
getDB() );
168 return $this->
getQuery()->getPageSet();
181 $this->queryBuilder =
null;
193 $this->queryBuilder ??= $this->
getDB()->newSelectQueryBuilder();
194 return $this->queryBuilder;
204 protected function addTables( $tables, $alias =
null ) {
205 if ( is_array( $tables ) ) {
206 if ( $alias !==
null ) {
224 if ( !is_array( $join_conds ) ) {
268 if ( is_array( $value ) ) {
271 if ( count( $value ) ) {
305 if ( $value !==
null && !( is_array( $value ) && !$value ) ) {
334 if ( count( $ids ) ) {
335 $ids = $this->
filterIDs( [ [ $table, $field ] ], $ids );
344 return count( $ids );
359 protected function addWhereRange( $field, $dir, $start, $end, $sort =
true ) {
360 $isDirNewer = ( $dir ===
'newer' );
361 $after = ( $isDirNewer ?
'>=' :
'<=' );
362 $before = ( $isDirNewer ?
'<=' :
'>=' );
363 $db = $this->
getDB();
365 if ( $start !==
null ) {
366 $this->
addWhere( $db->expr( $field, $after, $start ) );
369 if ( $end !==
null ) {
370 $this->
addWhere( $db->expr( $field, $before, $end ) );
374 $this->
getQueryBuilder()->orderBy( $field, $isDirNewer ?
null :
'DESC' );
389 $db = $this->
getDB();
391 $db->timestampOrNull( $start ), $db->timestampOrNull( $end ), $sort );
421 protected function select( $method, $extraQuery = [], ?array &$hookData =
null ) {
423 if ( isset( $extraQuery[
'tables'] ) ) {
424 $queryBuilder->
rawTables( (array)$extraQuery[
'tables'] );
426 if ( isset( $extraQuery[
'fields'] ) ) {
427 $queryBuilder->
fields( (array)$extraQuery[
'fields'] );
429 if ( isset( $extraQuery[
'where'] ) ) {
430 $queryBuilder->
where( (array)$extraQuery[
'where'] );
432 if ( isset( $extraQuery[
'options'] ) ) {
433 $queryBuilder->
options( (array)$extraQuery[
'options'] );
435 if ( isset( $extraQuery[
'join_conds'] ) ) {
436 $queryBuilder->
joinConds( (array)$extraQuery[
'join_conds'] );
439 if ( $hookData !==
null && $this->
getHookContainer()->isRegistered(
'ApiQueryBaseBeforeQuery' ) ) {
442 $this, $info[
'tables'], $info[
'fields'], $info[
'conds'],
443 $info[
'options'], $info[
'join_conds'], $hookData
445 $queryBuilder = $this->
getDB()->newSelectQueryBuilder()->
queryInfo( $info );
448 $queryBuilder->
caller( $method );
451 if ( $hookData !==
null ) {
452 $this->
getHookRunner()->onApiQueryBaseAfterQuery( $this, $res, $hookData );
471 protected function processRow( $row, array &$data, array &$hookData ) {
472 return $this->
getHookRunner()->onApiQueryBaseProcessRow( $this, $row, $data, $hookData );
489 $arr[$prefix .
'ns'] = $title->getNamespace();
490 $arr[$prefix .
'title'] = $title->getPrefixedText();
503 return $result->addValue( [
'query',
'pages', (
int)$pageId ],
518 $fit = $result->addValue( [
'query',
'pages', $pageId,
523 $result->addIndexedTagName(
551 $t = Title::makeTitleSafe( $namespace, $titlePart .
'x' );
552 if ( !$t || $t->hasFragment() ) {
556 if ( $namespace != $t->getNamespace() || $t->isExternal() ) {
565 return substr( $t->getDBkey(), 0, -1 );
579 $t = $titleParser->parseTitle( $titlePart .
'X', $defaultNamespace );
584 if ( !$t || $t->hasFragment() || $t->isExternal() || $t->getDBkey() ===
'X' ) {
589 return new TitleValue( $t->getNamespace(), substr( $t->getDBkey(), 0, -1 ) );
597 return (
bool)preg_match(
'/^[a-f0-9]{40}$/', $hash );
605 return (
bool)preg_match(
'/^[a-z0-9]{31}$/', $hash );
640 if ( !$services->getContentLanguage()->needsGenderDistinction() ) {
644 $nsInfo = $services->getNamespaceInfo();
645 $namespaceField = $fieldPrefix .
'_namespace';
646 $titleField = $fieldPrefix .
'_title';
649 foreach ( $res as $row ) {
650 if ( $nsInfo->hasGenderDistinction( $row->$namespaceField ) ) {
651 $usernames[] = $row->$titleField;
655 if ( $usernames === [] ) {
659 $genderCache = $services->getGenderCache();
660 $genderCache->doQuery( $usernames, $fname );
667class_alias( ApiQueryBase::class,
'ApiQueryBase' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
trait ApiQueryBlockInfoTrait