85 protected function doMainQuery( $tables, $select, $conds, $query_options,
88 $target = $opts[
'target'];
89 $showlinkedto = $opts[
'showlinkedto'];
90 $limit = $opts[
'limit'];
92 if ( $target ===
'' ) {
96 $title = Title::newFromText( $target );
99 Html::errorBox( $this->
msg(
'allpagesbadtitle' )->parse(),
'',
'mw-recentchangeslinked-errorbox' )
104 $outputPage->setPageTitle( $this->
msg(
'recentchangeslinked-title',
$title->getPrefixedText() ) );
115 $dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA,
'recentchangeslinked' );
116 $id =
$title->getArticleID();
117 $ns =
$title->getNamespace();
118 $dbkey =
$title->getDBkey();
120 $rcQuery = RecentChange::getQueryInfo();
121 $tables = array_unique( array_merge( $rcQuery[
'tables'], $tables ) );
122 $select = array_unique( array_merge( $rcQuery[
'fields'], $select ) );
123 $join_conds = array_merge( $rcQuery[
'joins'], $join_conds );
130 $join_conds[
'page'] = [
'LEFT JOIN',
'rc_cur_id=page_id' ];
131 $select[] =
'page_latest';
133 $tagFilter = $opts[
'tagfilter'] !==
'' ? explode(
'|', $opts[
'tagfilter'] ) : [];
143 if (
$dbr->unionSupportsOrderAndLimit() ) {
144 if ( count( $tagFilter ) > 1 ) {
149 'GROUP BY' => [
'rc_timestamp',
'rc_id' ],
150 'ORDER BY' => [
'rc_timestamp DESC',
'rc_id DESC' ]
153 $order = [
'ORDER BY' =>
'rc_timestamp DESC' ];
159 if ( !$this->
runMainQueryHook( $tables, $select, $conds, $query_options, $join_conds,
168 $link_tables = [
'categorylinks' ];
169 $showlinkedto =
true;
172 $link_tables = [
'pagelinks',
'templatelinks' ];
174 if ( $ns ===
NS_FILE || !$showlinkedto ) {
175 $link_tables[] =
'imagelinks';
179 if ( $id == 0 && !$showlinkedto ) {
186 'templatelinks' =>
'tl',
187 'categorylinks' =>
'cl',
193 foreach ( $link_tables as $link_table ) {
194 $queryBuilder =
$dbr->newSelectQueryBuilder();
195 $linksMigration = \MediaWiki\MediaWikiServices::getInstance()->getLinksMigration();
196 $queryBuilder = $queryBuilder
200 ->caller( __METHOD__ )
201 ->options( $order + $query_options )
202 ->joinConds( $join_conds );
203 $pfx = $prefix[$link_table];
207 if ( $link_table ==
'imagelinks' ) {
209 } elseif ( $link_table ==
'categorylinks' ) {
215 if ( $showlinkedto ) {
218 if ( $ns != $link_ns ) {
221 $queryBuilder->where( [
"{$pfx}_to" => $dbkey ] );
223 if ( isset( $linksMigration::$mapping[$link_table] ) ) {
224 $queryBuilder->where( $linksMigration->getLinksConditions( $link_table,
$title ) );
226 $queryBuilder->where( [
"{$pfx}_namespace" => $ns,
"{$pfx}_title" => $dbkey ] );
229 $queryBuilder->join( $link_table,
null,
"rc_cur_id = {$pfx}_from" );
232 $queryBuilder->where( [
"{$pfx}_from" => $id ] );
233 if ( $link_table ==
'imagelinks' || $link_table ==
'categorylinks' ) {
234 $queryBuilder->where( [
"rc_namespace" => $link_ns ] );
235 $queryBuilder->join( $link_table,
null,
"rc_title = {$pfx}_to" );
238 if ( isset( $linksMigration::$mapping[$link_table] ) ) {
239 $queryInfo = $linksMigration->getQueryInfo( $link_table, $link_table );
240 list( $nsField, $titleField ) = $linksMigration->getTitleFields( $link_table );
241 if ( in_array(
'linktarget', $queryInfo[
'tables'] ) ) {
242 $joinTable =
'linktarget';
244 $joinTable = $link_table;
249 [
"rc_namespace = {$nsField}",
"rc_title = {$titleField}" ]
251 if ( in_array(
'linktarget', $queryInfo[
'tables'] ) ) {
252 $queryBuilder->joinConds( $queryInfo[
'joins'] );
253 $queryBuilder->table( $link_table );
259 [
"rc_namespace = {$pfx}_namespace",
"rc_title = {$pfx}_title" ]
265 if (
$dbr->unionSupportsOrderAndLimit() ) {
266 $queryBuilder->limit( $limit );
269 $subsql[] = $queryBuilder;
272 if ( count( $subsql ) == 0 ) {
275 if ( count( $subsql ) == 1 &&
$dbr->unionSupportsOrderAndLimit() ) {
277 ->setMaxExecutionTime( $this->
getConfig()->
get( MainConfigNames::MaxExecutionTimeForExpensiveQueries ) )
280 $sqls = array_map(
static function ( $queryBuilder ) {
281 return $queryBuilder->getSQL();
283 $queryBuilder =
$dbr->newSelectQueryBuilder()
286 (
string)(
new Subquery(
$dbr->unionQueries( $sqls, $dbr::UNION_DISTINCT ) ) ),
289 ->orderBy(
'rc_timestamp', SelectQueryBuilder::SORT_DESC )
290 ->setMaxExecutionTime( $this->
getConfig()->
get( MainConfigNames::MaxExecutionTimeForExpensiveQueries ) )
292 $sql = $queryBuilder->getSQL();
294 return $dbr->query( $sql, __METHOD__ );