54 private $queryBuilder;
63 parent::__construct( $queryModule->
getMain(), $moduleName, $paramPrefix );
64 $this->mQueryModule = $queryModule;
113 return $this->mQueryModule;
127 $this->mDb ??= $this->
getQuery()->getDB();
138 return $this->
getQuery()->getPageSet();
151 $this->queryBuilder =
null;
163 $this->queryBuilder ??= $this->
getDB()->newSelectQueryBuilder();
164 return $this->queryBuilder;
174 protected function addTables( $tables, $alias =
null ) {
175 if ( is_array( $tables ) ) {
176 if ( $alias !==
null ) {
194 if ( !is_array( $join_conds ) ) {
238 if ( is_array( $value ) ) {
241 if ( count( $value ) ) {
275 if ( $value !==
null && !( is_array( $value ) && !$value ) ) {
304 if ( count( $ids ) ) {
305 $ids = $this->
filterIDs( [ [ $table, $field ] ], $ids );
314 return count( $ids );
329 protected function addWhereRange( $field, $dir, $start, $end, $sort =
true ) {
330 $isDirNewer = ( $dir ===
'newer' );
331 $after = ( $isDirNewer ?
'>=' :
'<=' );
332 $before = ( $isDirNewer ?
'<=' :
'>=' );
333 $db = $this->
getDB();
335 if ( $start !==
null ) {
336 $this->
addWhere( $db->expr( $field, $after, $start ) );
339 if ( $end !==
null ) {
340 $this->
addWhere( $db->expr( $field, $before, $end ) );
344 $this->
getQueryBuilder()->orderBy( $field, $isDirNewer ?
null :
'DESC' );
359 $db = $this->
getDB();
361 $db->timestampOrNull( $start ), $db->timestampOrNull( $end ), $sort );
391 protected function select( $method, $extraQuery = [], ?array &$hookData =
null ) {
393 if ( isset( $extraQuery[
'tables'] ) ) {
394 $queryBuilder->
rawTables( (array)$extraQuery[
'tables'] );
396 if ( isset( $extraQuery[
'fields'] ) ) {
397 $queryBuilder->
fields( (array)$extraQuery[
'fields'] );
399 if ( isset( $extraQuery[
'where'] ) ) {
400 $queryBuilder->
where( (array)$extraQuery[
'where'] );
402 if ( isset( $extraQuery[
'options'] ) ) {
403 $queryBuilder->
options( (array)$extraQuery[
'options'] );
405 if ( isset( $extraQuery[
'join_conds'] ) ) {
406 $queryBuilder->
joinConds( (array)$extraQuery[
'join_conds'] );
409 if ( $hookData !==
null && $this->
getHookContainer()->isRegistered(
'ApiQueryBaseBeforeQuery' ) ) {
412 $this, $info[
'tables'], $info[
'fields'], $info[
'conds'],
413 $info[
'options'], $info[
'join_conds'], $hookData
415 $queryBuilder = $this->
getDB()->newSelectQueryBuilder()->
queryInfo( $info );
418 $queryBuilder->
caller( $method );
421 if ( $hookData !==
null ) {
422 $this->
getHookRunner()->onApiQueryBaseAfterQuery( $this, $res, $hookData );
441 protected function processRow( $row, array &$data, array &$hookData ) {
442 return $this->
getHookRunner()->onApiQueryBaseProcessRow( $this, $row, $data, $hookData );
459 $arr[$prefix .
'ns'] = $title->getNamespace();
460 $arr[$prefix .
'title'] = $title->getPrefixedText();
473 return $result->addValue( [
'query',
'pages', (
int)$pageId ],
488 $fit = $result->addValue( [
'query',
'pages', $pageId,
493 $result->addIndexedTagName(
521 $t = Title::makeTitleSafe( $namespace, $titlePart .
'x' );
522 if ( !$t || $t->hasFragment() ) {
526 if ( $namespace != $t->getNamespace() || $t->isExternal() ) {
535 return substr( $t->getDBkey(), 0, -1 );
549 $t = $titleParser->parseTitle( $titlePart .
'X', $defaultNamespace );
554 if ( !$t || $t->hasFragment() || $t->isExternal() || $t->getDBkey() ===
'X' ) {
559 return new TitleValue( $t->getNamespace(), substr( $t->getDBkey(), 0, -1 ) );
567 return (
bool)preg_match(
'/^[a-f0-9]{40}$/', $hash );
575 return (
bool)preg_match(
'/^[a-z0-9]{31}$/', $hash );
610 if ( !$services->getContentLanguage()->needsGenderDistinction() ) {
614 $nsInfo = $services->getNamespaceInfo();
615 $namespaceField = $fieldPrefix .
'_namespace';
616 $titleField = $fieldPrefix .
'_title';
619 foreach ( $res as $row ) {
620 if ( $nsInfo->hasGenderDistinction( $row->$namespaceField ) ) {
621 $usernames[] = $row->$titleField;
625 if ( $usernames === [] ) {
629 $genderCache = $services->getGenderCache();
630 $genderCache->doQuery( $usernames, $fname );
637class_alias( ApiQueryBase::class,
'ApiQueryBase' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
array $params
The job parameters.
trait ApiQueryBlockInfoTrait