90 protected function doMainQuery( $tables, $select, $conds, $query_options,
93 $target = $opts[
'target'];
94 $showlinkedto = $opts[
'showlinkedto'];
95 $limit = $opts[
'limit'];
97 if ( $target ===
'' ) {
101 $title = Title::newFromText( $target );
102 if ( !$title || $title->isExternal() ) {
103 $outputPage->addModuleStyles(
'mediawiki.codex.messagebox.styles' );
104 $outputPage->addHTML(
105 Html::errorBox( $this->
msg(
'allpagesbadtitle' )->parse(),
'',
'mw-recentchangeslinked-errorbox' )
110 $outputPage->setPageTitleMsg(
111 $this->
msg(
'recentchangeslinked-title' )->plaintextParams( $title->getPrefixedText() )
122 $dbr = $this->
getDB();
123 $id = $title->getArticleID();
124 $ns = $title->getNamespace();
125 $dbkey = $title->getDBkey();
127 $rcQuery = RecentChange::getQueryInfo();
128 $tables = array_unique( array_merge( $rcQuery[
'tables'], $tables ) );
129 $select = array_unique( array_merge( $rcQuery[
'fields'], $select ) );
130 $join_conds = array_merge( $rcQuery[
'joins'], $join_conds );
137 $join_conds[
'page'] = [
'LEFT JOIN',
'rc_cur_id=page_id' ];
138 $select[] =
'page_latest';
140 $tagFilter = $opts[
'tagfilter'] !==
'' ? explode(
'|', $opts[
'tagfilter'] ) : [];
141 $this->changeTagsStore->modifyDisplayQuery(
151 if ( $dbr->unionSupportsOrderAndLimit() ) {
152 if ( in_array(
'DISTINCT', $query_options ) ) {
157 'GROUP BY' => [
'rc_timestamp',
'rc_id' ],
158 'ORDER BY' => [
'rc_timestamp DESC',
'rc_id DESC' ]
161 $order = [
'ORDER BY' =>
'rc_timestamp DESC' ];
167 if ( !$this->
runMainQueryHook( $tables, $select, $conds, $query_options, $join_conds,
176 $link_tables = [
'categorylinks' ];
177 $showlinkedto =
true;
180 $link_tables = [
'pagelinks',
'templatelinks' ];
182 if ( $ns ===
NS_FILE || !$showlinkedto ) {
183 $link_tables[] =
'imagelinks';
187 if ( $id == 0 && !$showlinkedto ) {
194 'templatelinks' =>
'tl',
195 'categorylinks' =>
'cl',
201 foreach ( $link_tables as $link_table ) {
202 $queryBuilder = $dbr->newSelectQueryBuilder();
203 $linksMigration = \MediaWiki\MediaWikiServices::getInstance()->getLinksMigration();
204 $queryBuilder = $queryBuilder
208 ->caller( __METHOD__ )
209 ->options( $order + $query_options )
210 ->joinConds( $join_conds );
211 $pfx = $prefix[$link_table];
215 if ( $link_table ==
'imagelinks' ) {
217 } elseif ( $link_table ==
'categorylinks' ) {
223 if ( $showlinkedto ) {
226 if ( $ns != $link_ns ) {
229 $queryBuilder->where( [
"{$pfx}_to" => $dbkey ] );
231 if ( isset( $linksMigration::$mapping[$link_table] ) ) {
232 $queryBuilder->where( $linksMigration->getLinksConditions( $link_table, $title ) );
234 $queryBuilder->where( [
"{$pfx}_namespace" => $ns,
"{$pfx}_title" => $dbkey ] );
237 $queryBuilder->join( $link_table,
null,
"rc_cur_id = {$pfx}_from" );
240 $queryBuilder->where( [
"{$pfx}_from" => $id ] );
241 if ( $link_table ==
'imagelinks' || $link_table ==
'categorylinks' ) {
242 $queryBuilder->where( [
"rc_namespace" => $link_ns ] );
243 $queryBuilder->join( $link_table,
null,
"rc_title = {$pfx}_to" );
246 if ( isset( $linksMigration::$mapping[$link_table] ) ) {
247 $queryInfo = $linksMigration->getQueryInfo( $link_table, $link_table );
248 [ $nsField, $titleField ] = $linksMigration->getTitleFields( $link_table );
249 if ( in_array(
'linktarget', $queryInfo[
'tables'] ) ) {
250 $joinTable =
'linktarget';
252 $joinTable = $link_table;
257 [
"rc_namespace = {$nsField}",
"rc_title = {$titleField}" ]
259 if ( in_array(
'linktarget', $queryInfo[
'tables'] ) ) {
260 $queryBuilder->joinConds( $queryInfo[
'joins'] );
261 $queryBuilder->table( $link_table );
267 [
"rc_namespace = {$pfx}_namespace",
"rc_title = {$pfx}_title" ]
273 if ( $dbr->unionSupportsOrderAndLimit() ) {
274 $queryBuilder->limit( $limit );
277 $subsql[] = $queryBuilder;
280 if ( count( $subsql ) == 0 ) {
283 if ( count( $subsql ) == 1 && $dbr->unionSupportsOrderAndLimit() ) {
286 ->caller( __METHOD__ )->fetchResultSet();
288 $unionQueryBuilder = $dbr->newUnionQueryBuilder()->caller( __METHOD__ );
289 foreach ( $subsql as $selectQueryBuilder ) {
290 $unionQueryBuilder->add( $selectQueryBuilder );
292 return $dbr->newSelectQueryBuilder()
295 new Subquery( $unionQueryBuilder->getSQL() ),
298 ->orderBy(
'rc_timestamp', SelectQueryBuilder::SORT_DESC )
301 ->caller( __METHOD__ )->fetchResultSet();