96 protected function doMainQuery( $tables, $select, $conds, $query_options,
99 $target = $opts[
'target'];
100 $showlinkedto = $opts[
'showlinkedto'];
101 $limit = $opts[
'limit'];
103 if ( $target ===
'' ) {
107 $title = Title::newFromText( $target );
108 if ( !$title || $title->isExternal() ) {
109 $outputPage->addHTML(
110 Html::errorBox( $this->
msg(
'allpagesbadtitle' )->parse(),
'',
'mw-recentchangeslinked-errorbox' )
115 $outputPage->setPageTitleMsg(
116 $this->
msg(
'recentchangeslinked-title' )->plaintextParams( $title->getPrefixedText() )
127 $dbr = $this->
getDB();
128 $id = $title->getArticleID();
129 $ns = $title->getNamespace();
130 $dbkey = $title->getDBkey();
132 $rcQuery = RecentChange::getQueryInfo();
133 $tables = array_unique( array_merge( $rcQuery[
'tables'], $tables ) );
134 $select = array_unique( array_merge( $rcQuery[
'fields'], $select ) );
135 $join_conds = array_merge( $rcQuery[
'joins'], $join_conds );
142 $join_conds[
'page'] = [
'LEFT JOIN',
'rc_cur_id=page_id' ];
143 $select[] =
'page_latest';
145 $tagFilter = $opts[
'tagfilter'] !==
'' ? explode(
'|', $opts[
'tagfilter'] ) : [];
146 $this->changeTagsStore->modifyDisplayQuery(
156 if ( $dbr->unionSupportsOrderAndLimit() ) {
157 if ( in_array(
'DISTINCT', $query_options ) ) {
162 'GROUP BY' => [
'rc_timestamp',
'rc_id' ],
163 'ORDER BY' => [
'rc_timestamp DESC',
'rc_id DESC' ]
166 $order = [
'ORDER BY' =>
'rc_timestamp DESC' ];
172 if ( !$this->
runMainQueryHook( $tables, $select, $conds, $query_options, $join_conds,
181 $link_tables = [
'categorylinks' ];
182 $showlinkedto =
true;
185 $link_tables = [
'pagelinks',
'templatelinks' ];
187 if ( $ns ===
NS_FILE || !$showlinkedto ) {
188 $link_tables[] =
'imagelinks';
192 if ( $id == 0 && !$showlinkedto ) {
199 'templatelinks' =>
'tl',
200 'categorylinks' =>
'cl',
206 foreach ( $link_tables as $link_table ) {
207 $queryBuilder = $dbr->newSelectQueryBuilder();
208 $linksMigration = \MediaWiki\MediaWikiServices::getInstance()->getLinksMigration();
209 $queryBuilder = $queryBuilder
213 ->caller( __METHOD__ )
214 ->options( $order + $query_options )
215 ->joinConds( $join_conds );
216 $pfx = $prefix[$link_table];
220 if ( $link_table ==
'imagelinks' ) {
222 } elseif ( $link_table ==
'categorylinks' ) {
228 if ( $showlinkedto ) {
231 if ( $ns != $link_ns ) {
234 $queryBuilder->where( [
"{$pfx}_to" => $dbkey ] );
236 if ( isset( $linksMigration::$mapping[$link_table] ) ) {
237 $queryBuilder->where( $linksMigration->getLinksConditions( $link_table, $title ) );
239 $queryBuilder->where( [
"{$pfx}_namespace" => $ns,
"{$pfx}_title" => $dbkey ] );
242 $queryBuilder->join( $link_table,
null,
"rc_cur_id = {$pfx}_from" );
245 $queryBuilder->where( [
"{$pfx}_from" => $id ] );
246 if ( $link_table ==
'imagelinks' || $link_table ==
'categorylinks' ) {
247 $queryBuilder->where( [
"rc_namespace" => $link_ns ] );
248 $queryBuilder->join( $link_table,
null,
"rc_title = {$pfx}_to" );
251 if ( isset( $linksMigration::$mapping[$link_table] ) ) {
252 $queryInfo = $linksMigration->getQueryInfo( $link_table, $link_table );
253 [ $nsField, $titleField ] = $linksMigration->getTitleFields( $link_table );
254 if ( in_array(
'linktarget', $queryInfo[
'tables'] ) ) {
255 $joinTable =
'linktarget';
257 $joinTable = $link_table;
262 [
"rc_namespace = {$nsField}",
"rc_title = {$titleField}" ]
264 if ( in_array(
'linktarget', $queryInfo[
'tables'] ) ) {
265 $queryBuilder->joinConds( $queryInfo[
'joins'] );
266 $queryBuilder->table( $link_table );
272 [
"rc_namespace = {$pfx}_namespace",
"rc_title = {$pfx}_title" ]
278 if ( $dbr->unionSupportsOrderAndLimit() ) {
279 $queryBuilder->limit( $limit );
282 $subsql[] = $queryBuilder;
285 if ( count( $subsql ) == 0 ) {
288 if ( count( $subsql ) == 1 && $dbr->unionSupportsOrderAndLimit() ) {
291 ->caller( __METHOD__ )->fetchResultSet();
293 $unionQueryBuilder = $dbr->newUnionQueryBuilder()->caller( __METHOD__ );
294 foreach ( $subsql as $selectQueryBuilder ) {
295 $unionQueryBuilder->add( $selectQueryBuilder );
297 return $dbr->newSelectQueryBuilder()
300 new Subquery( $unionQueryBuilder->getSQL() ),
303 ->orderBy(
'rc_timestamp', SelectQueryBuilder::SORT_DESC )
306 ->caller( __METHOD__ )->fetchResultSet();