97 protected function doMainQuery( $tables, $select, $conds, $query_options,
100 $target = $opts[
'target'];
101 $showlinkedto = $opts[
'showlinkedto'];
102 $limit = $opts[
'limit'];
104 if ( $target ===
'' ) {
108 $title = Title::newFromText( $target );
109 if ( !$title || $title->isExternal() ) {
110 $outputPage->addHTML(
111 Html::errorBox( $this->
msg(
'allpagesbadtitle' )->parse(),
'',
'mw-recentchangeslinked-errorbox' )
116 $outputPage->setPageTitleMsg(
117 $this->
msg(
'recentchangeslinked-title' )->plaintextParams( $title->getPrefixedText() )
128 $dbr = $this->
getDB();
129 $id = $title->getArticleID();
130 $ns = $title->getNamespace();
131 $dbkey = $title->getDBkey();
133 $rcQuery = RecentChange::getQueryInfo();
134 $tables = array_unique( array_merge( $rcQuery[
'tables'], $tables ) );
135 $select = array_unique( array_merge( $rcQuery[
'fields'], $select ) );
136 $join_conds = array_merge( $rcQuery[
'joins'], $join_conds );
143 $join_conds[
'page'] = [
'LEFT JOIN',
'rc_cur_id=page_id' ];
144 $select[] =
'page_latest';
146 $tagFilter = $opts[
'tagfilter'] !==
'' ? explode(
'|', $opts[
'tagfilter'] ) : [];
147 $this->changeTagsStore->modifyDisplayQuery(
157 if ( $dbr->unionSupportsOrderAndLimit() ) {
158 if ( in_array(
'DISTINCT', $query_options ) ) {
163 'GROUP BY' => [
'rc_timestamp',
'rc_id' ],
164 'ORDER BY' => [
'rc_timestamp DESC',
'rc_id DESC' ]
167 $order = [
'ORDER BY' =>
'rc_timestamp DESC' ];
173 if ( !$this->
runMainQueryHook( $tables, $select, $conds, $query_options, $join_conds,
182 $link_tables = [
'categorylinks' ];
183 $showlinkedto =
true;
186 $link_tables = [
'pagelinks',
'templatelinks' ];
188 if ( $ns ===
NS_FILE || !$showlinkedto ) {
189 $link_tables[] =
'imagelinks';
193 if ( $id == 0 && !$showlinkedto ) {
200 'templatelinks' =>
'tl',
201 'categorylinks' =>
'cl',
207 foreach ( $link_tables as $link_table ) {
208 $queryBuilder = $dbr->newSelectQueryBuilder();
209 $linksMigration = \MediaWiki\MediaWikiServices::getInstance()->getLinksMigration();
210 $queryBuilder = $queryBuilder
214 ->caller( __METHOD__ )
215 ->options( $order + $query_options )
216 ->joinConds( $join_conds );
217 $pfx = $prefix[$link_table];
221 if ( $link_table ==
'imagelinks' ) {
223 } elseif ( $link_table ==
'categorylinks' ) {
229 if ( $showlinkedto ) {
232 if ( $ns != $link_ns ) {
235 $queryBuilder->where( [
"{$pfx}_to" => $dbkey ] );
237 if ( isset( $linksMigration::$mapping[$link_table] ) ) {
238 $queryBuilder->where( $linksMigration->getLinksConditions( $link_table, $title ) );
240 $queryBuilder->where( [
"{$pfx}_namespace" => $ns,
"{$pfx}_title" => $dbkey ] );
243 $queryBuilder->join( $link_table,
null,
"rc_cur_id = {$pfx}_from" );
246 $queryBuilder->where( [
"{$pfx}_from" => $id ] );
247 if ( $link_table ==
'imagelinks' || $link_table ==
'categorylinks' ) {
248 $queryBuilder->where( [
"rc_namespace" => $link_ns ] );
249 $queryBuilder->join( $link_table,
null,
"rc_title = {$pfx}_to" );
252 if ( isset( $linksMigration::$mapping[$link_table] ) ) {
253 $queryInfo = $linksMigration->getQueryInfo( $link_table, $link_table );
254 [ $nsField, $titleField ] = $linksMigration->getTitleFields( $link_table );
255 if ( in_array(
'linktarget', $queryInfo[
'tables'] ) ) {
256 $joinTable =
'linktarget';
258 $joinTable = $link_table;
263 [
"rc_namespace = {$nsField}",
"rc_title = {$titleField}" ]
265 if ( in_array(
'linktarget', $queryInfo[
'tables'] ) ) {
266 $queryBuilder->joinConds( $queryInfo[
'joins'] );
267 $queryBuilder->table( $link_table );
273 [
"rc_namespace = {$pfx}_namespace",
"rc_title = {$pfx}_title" ]
279 if ( $dbr->unionSupportsOrderAndLimit() ) {
280 $queryBuilder->limit( $limit );
283 $subsql[] = $queryBuilder;
286 if ( count( $subsql ) == 0 ) {
289 if ( count( $subsql ) == 1 && $dbr->unionSupportsOrderAndLimit() ) {
292 ->caller( __METHOD__ )->fetchResultSet();
294 $unionQueryBuilder = $dbr->newUnionQueryBuilder()->caller( __METHOD__ );
295 foreach ( $subsql as $selectQueryBuilder ) {
296 $unionQueryBuilder->add( $selectQueryBuilder );
298 return $dbr->newSelectQueryBuilder()
301 new Subquery( $unionQueryBuilder->getSQL() ),
304 ->orderBy(
'rc_timestamp', SelectQueryBuilder::SORT_DESC )
307 ->caller( __METHOD__ )->fetchResultSet();