36 private array $virtualDBs;
37 private string|
false $currentDomain;
42 private $queryBuilder;
51 private readonly
ApiQuery $mQueryModule,
55 parent::__construct( $mQueryModule->getMain(), $moduleName, $paramPrefix );
57 $this->virtualDBs = [];
58 $this->currentDomain =
false;
106 return $this->mQueryModule;
122 if ( $this->currentDomain ) {
123 if ( !isset( $this->virtualDBs[$this->currentDomain] ) ) {
125 ->getConnectionProvider()
126 ->getReplicaDatabase( $this->currentDomain );
127 $this->virtualDBs[$this->currentDomain] = $db;
129 return $this->virtualDBs[$this->currentDomain];
132 $this->mDb ??= $this->
getQuery()->getDB();
144 $this->currentDomain = $virtualDomain;
145 $this->updateQueryBuilderConnection();
154 $this->currentDomain =
false;
155 $this->updateQueryBuilderConnection();
158 private function updateQueryBuilderConnection() {
159 if ( $this->queryBuilder ) {
160 $this->queryBuilder->connection( $this->
getDB() );
170 return $this->
getQuery()->getPageSet();
183 $this->queryBuilder =
null;
195 $this->queryBuilder ??= $this->
getDB()->newSelectQueryBuilder();
196 return $this->queryBuilder;
206 protected function addTables( $tables, $alias =
null ) {
207 if ( is_array( $tables ) ) {
208 if ( $alias !==
null ) {
226 if ( !is_array( $join_conds ) ) {
270 if ( is_array( $value ) ) {
273 if ( count( $value ) ) {
307 if ( $value !==
null && !( is_array( $value ) && !$value ) ) {
336 if ( count( $ids ) ) {
337 $ids = $this->
filterIDs( [ [ $table, $field ] ], $ids );
346 return count( $ids );
361 protected function addWhereRange( $field, $dir, $start, $end, $sort =
true ) {
362 $isDirNewer = ( $dir ===
'newer' );
363 $after = ( $isDirNewer ?
'>=' :
'<=' );
364 $before = ( $isDirNewer ?
'<=' :
'>=' );
365 $db = $this->
getDB();
367 if ( $start !==
null ) {
368 $this->
addWhere( $db->expr( $field, $after, $start ) );
371 if ( $end !==
null ) {
372 $this->
addWhere( $db->expr( $field, $before, $end ) );
376 $this->
getQueryBuilder()->orderBy( $field, $isDirNewer ?
null :
'DESC' );
391 $db = $this->
getDB();
393 $db->timestampOrNull( $start ), $db->timestampOrNull( $end ), $sort );
423 protected function select( $method, $extraQuery = [], ?array &$hookData =
null ) {
425 if ( isset( $extraQuery[
'tables'] ) ) {
426 $queryBuilder->
rawTables( (array)$extraQuery[
'tables'] );
428 if ( isset( $extraQuery[
'fields'] ) ) {
429 $queryBuilder->
fields( (array)$extraQuery[
'fields'] );
431 if ( isset( $extraQuery[
'where'] ) ) {
432 $queryBuilder->
where( (array)$extraQuery[
'where'] );
434 if ( isset( $extraQuery[
'options'] ) ) {
435 $queryBuilder->
options( (array)$extraQuery[
'options'] );
437 if ( isset( $extraQuery[
'join_conds'] ) ) {
438 $queryBuilder->
joinConds( (array)$extraQuery[
'join_conds'] );
441 if ( $hookData !==
null && $this->
getHookContainer()->isRegistered(
'ApiQueryBaseBeforeQuery' ) ) {
444 $this, $info[
'tables'], $info[
'fields'], $info[
'conds'],
445 $info[
'options'], $info[
'join_conds'], $hookData
447 $queryBuilder = $this->
getDB()->newSelectQueryBuilder()->
queryInfo( $info );
450 $queryBuilder->
caller( $method );
453 if ( $hookData !==
null ) {
454 $this->
getHookRunner()->onApiQueryBaseAfterQuery( $this, $res, $hookData );
473 protected function processRow( $row, array &$data, array &$hookData ) {
474 return $this->
getHookRunner()->onApiQueryBaseProcessRow( $this, $row, $data, $hookData );
491 $arr[$prefix .
'ns'] = $title->getNamespace();
492 $arr[$prefix .
'title'] = $title->getPrefixedText();
505 return $result->addValue( [
'query',
'pages', (
int)$pageId ],
520 $fit = $result->addValue( [
'query',
'pages', $pageId,
525 $result->addIndexedTagName(
553 $t = Title::makeTitleSafe( $namespace, $titlePart .
'x' );
554 if ( !$t || $t->hasFragment() ) {
558 if ( $namespace != $t->getNamespace() || $t->isExternal() ) {
567 return substr( $t->getDBkey(), 0, -1 );
581 $t = $titleParser->parseTitle( $titlePart .
'X', $defaultNamespace );
586 if ( !$t || $t->hasFragment() || $t->isExternal() || $t->getDBkey() ===
'X' ) {
591 return new TitleValue( $t->getNamespace(), substr( $t->getDBkey(), 0, -1 ) );
599 return (
bool)preg_match(
'/^[a-f0-9]{40}$/', $hash );
607 return (
bool)preg_match(
'/^[a-z0-9]{31}$/', $hash );
642 if ( !$services->getContentLanguage()->needsGenderDistinction() ) {
646 $nsInfo = $services->getNamespaceInfo();
647 $namespaceField = $fieldPrefix .
'_namespace';
648 $titleField = $fieldPrefix .
'_title';
651 foreach ( $res as $row ) {
652 if ( $nsInfo->hasGenderDistinction( $row->$namespaceField ) ) {
653 $usernames[] = $row->$titleField;
657 if ( $usernames === [] ) {
661 $genderCache = $services->getGenderCache();
662 $genderCache->doQuery( $usernames, $fname );
669class_alias( ApiQueryBase::class,
'ApiQueryBase' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
trait ApiQueryBlockInfoTrait