99 protected function doMainQuery( $tables, $select, $conds, $query_options,
102 $target = $opts[
'target'];
103 $showlinkedto = $opts[
'showlinkedto'];
104 $limit = $opts[
'limit'];
106 if ( $target ===
'' ) {
110 $title = Title::newFromText( $target );
111 if ( !$title || $title->isExternal() ) {
112 $outputPage->addHTML(
113 Html::errorBox( $this->
msg(
'allpagesbadtitle' )->parse(),
'',
'mw-recentchangeslinked-errorbox' )
118 $outputPage->setPageTitleMsg(
119 $this->
msg(
'recentchangeslinked-title' )->plaintextParams( $title->getPrefixedText() )
130 $dbr = $this->
getDB();
131 $id = $title->getArticleID();
132 $ns = $title->getNamespace();
133 $dbkey = $title->getDBkey();
135 $rcQuery = RecentChange::getQueryInfo();
136 $tables = array_unique( array_merge( $rcQuery[
'tables'], $tables ) );
137 $select = array_unique( array_merge( $rcQuery[
'fields'], $select ) );
138 $join_conds = array_merge( $rcQuery[
'joins'], $join_conds );
145 $join_conds[
'page'] = [
'LEFT JOIN',
'rc_cur_id=page_id' ];
146 $select[] =
'page_latest';
148 $tagFilter = $opts[
'tagfilter'] !==
'' ? explode(
'|', $opts[
'tagfilter'] ) : [];
149 $this->changeTagsStore->modifyDisplayQuery(
159 if ( $dbr->unionSupportsOrderAndLimit() ) {
160 if ( in_array(
'DISTINCT', $query_options ) ) {
165 'GROUP BY' => [
'rc_timestamp',
'rc_id' ],
166 'ORDER BY' => [
'rc_timestamp DESC',
'rc_id DESC' ]
169 $order = [
'ORDER BY' =>
'rc_timestamp DESC' ];
175 if ( !$this->
runMainQueryHook( $tables, $select, $conds, $query_options, $join_conds,
184 $link_tables = [
'categorylinks' ];
185 $showlinkedto =
true;
188 $link_tables = [
'pagelinks',
'templatelinks' ];
190 if ( $ns ===
NS_FILE || !$showlinkedto ) {
191 $link_tables[] =
'imagelinks';
195 if ( $id == 0 && !$showlinkedto ) {
202 'templatelinks' =>
'tl',
203 'categorylinks' =>
'cl',
209 foreach ( $link_tables as $link_table ) {
210 $queryBuilder = $dbr->newSelectQueryBuilder();
211 $linksMigration = \MediaWiki\MediaWikiServices::getInstance()->getLinksMigration();
212 $queryBuilder = $queryBuilder
216 ->caller( __METHOD__ )
217 ->options( $order + $query_options )
218 ->joinConds( $join_conds );
219 $pfx = $prefix[$link_table];
223 if ( $link_table ==
'imagelinks' ) {
225 } elseif ( $link_table ==
'categorylinks' ) {
231 if ( $showlinkedto ) {
234 if ( $ns != $link_ns ) {
237 $queryBuilder->where( [
"{$pfx}_to" => $dbkey ] );
239 if ( isset( $linksMigration::$mapping[$link_table] ) ) {
240 $queryBuilder->where( $linksMigration->getLinksConditions( $link_table, $title ) );
242 $queryBuilder->where( [
"{$pfx}_namespace" => $ns,
"{$pfx}_title" => $dbkey ] );
245 $queryBuilder->join( $link_table,
null,
"rc_cur_id = {$pfx}_from" );
248 $queryBuilder->where( [
"{$pfx}_from" => $id ] );
249 if ( $link_table ==
'imagelinks' || $link_table ==
'categorylinks' ) {
250 $queryBuilder->where( [
"rc_namespace" => $link_ns ] );
251 $queryBuilder->join( $link_table,
null,
"rc_title = {$pfx}_to" );
254 if ( isset( $linksMigration::$mapping[$link_table] ) ) {
255 $queryInfo = $linksMigration->getQueryInfo( $link_table, $link_table );
256 [ $nsField, $titleField ] = $linksMigration->getTitleFields( $link_table );
257 if ( in_array(
'linktarget', $queryInfo[
'tables'] ) ) {
258 $joinTable =
'linktarget';
260 $joinTable = $link_table;
265 [
"rc_namespace = {$nsField}",
"rc_title = {$titleField}" ]
267 if ( in_array(
'linktarget', $queryInfo[
'tables'] ) ) {
268 $queryBuilder->joinConds( $queryInfo[
'joins'] );
269 $queryBuilder->table( $link_table );
275 [
"rc_namespace = {$pfx}_namespace",
"rc_title = {$pfx}_title" ]
281 if ( $dbr->unionSupportsOrderAndLimit() ) {
282 $queryBuilder->limit( $limit );
285 $subsql[] = $queryBuilder;
288 if ( count( $subsql ) == 0 ) {
291 if ( count( $subsql ) == 1 && $dbr->unionSupportsOrderAndLimit() ) {
294 ->caller( __METHOD__ )->fetchResultSet();
296 $sqls = array_map(
static function ( $queryBuilder ) {
297 return $queryBuilder->getSQL();
299 return $dbr->newSelectQueryBuilder()
302 new Subquery( $dbr->unionQueries( $sqls, $dbr::UNION_DISTINCT ) ),
305 ->orderBy(
'rc_timestamp', SelectQueryBuilder::SORT_DESC )
308 ->caller( __METHOD__ )->fetchResultSet();