MediaWiki master
SpecialRecentChangesLinked.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
21
30 protected $rclTargetTitle;
31
32 public function __construct(
33 WatchedItemStoreInterface $watchedItemStore,
34 MessageParser $messageParser,
35 UserOptionsLookup $userOptionsLookup,
36 private readonly SearchEngineFactory $searchEngineFactory,
37 UserIdentityUtils $userIdentityUtils,
38 TempUserConfig $tempUserConfig,
39 RecentChangeFactory $recentChangeFactory,
40 ChangesListQueryFactory $changesListQueryFactory,
41 ) {
42 parent::__construct(
43 $watchedItemStore,
44 $messageParser,
45 $userOptionsLookup,
46 $userIdentityUtils,
47 $tempUserConfig,
48 $recentChangeFactory,
49 $changesListQueryFactory,
50 );
51 $this->mName = 'Recentchangeslinked';
52 }
53
55 public function getDefaultOptions() {
56 $opts = parent::getDefaultOptions();
57 $opts->add( 'target', '' );
58 $opts->add( 'showlinkedto', false );
59
60 return $opts;
61 }
62
64 public function parseParameters( $par, FormOptions $opts ) {
65 $opts['target'] = $par;
66 }
67
71 protected function modifyQuery( ChangesListQuery $query, FormOptions $opts ) {
72 $target = $opts['target'];
73 $showlinkedto = $opts['showlinkedto'];
74
75 if ( $target === '' ) {
76 $query->forceEmptySet();
77 return;
78 }
79 $outputPage = $this->getOutput();
80 $title = Title::newFromText( $target );
81 if ( !$title || $title->isExternal() ) {
82 $outputPage->addModuleStyles( 'mediawiki.codex.messagebox.styles' );
83 $outputPage->addHTML(
84 Html::errorBox( $this->msg( 'allpagesbadtitle' )->parse(), '', 'mw-recentchangeslinked-errorbox' )
85 );
86 $query->forceEmptySet();
87 return;
88 }
89
90 $outputPage->setPageTitleMsg(
91 $this->msg( 'recentchangeslinked-title' )->plaintextParams( $title->getPrefixedText() )
92 );
93
94 $ns = $title->getNamespace();
95 if ( $ns === NS_CATEGORY && !$showlinkedto ) {
96 // special handling for categories
97 // XXX: should try to make this less kludgy
98 $link_tables = [ 'categorylinks' ];
99 $showlinkedto = true;
100 } else {
101 // for now, always join on these tables; really should be configurable as in whatlinkshere
102 $link_tables = [ 'pagelinks', 'templatelinks' ];
103 // imagelinks only contains links to pages in NS_FILE
104 if ( $ns === NS_FILE || !$showlinkedto ) {
105 $link_tables[] = 'imagelinks';
106 }
107 }
108
109 $query->requireLink(
110 $showlinkedto ? ChangesListQuery::LINKS_TO : ChangesListQuery::LINKS_FROM,
111 $link_tables,
112 $title
113 );
114 }
115
116 public function setTopText( FormOptions $opts ) {
117 $target = $this->getTargetTitle();
118 if ( $target ) {
119 $this->getOutput()->addBacklinkSubtitle( $target );
120 $this->getSkin()->setRelevantTitle( $target );
121 }
122 }
123
130 public function getExtraOptions( $opts ) {
131 $extraOpts = parent::getExtraOptions( $opts );
132
133 $opts->consumeValues( [ 'showlinkedto', 'target' ] );
134
135 $extraOpts['target'] = [ $this->msg( 'recentchangeslinked-page' )->escaped(),
136 Html::input( 'target', str_replace( '_', ' ', $opts['target'] ), 'text', [ 'size' => 40 ] ) . ' ' .
137 Html::check( 'showlinkedto', $opts['showlinkedto'], [ 'id' => 'showlinkedto' ] ) . ' ' .
138 Html::label( $this->msg( 'recentchangeslinked-to' )->text(), 'showlinkedto' ) ];
139
140 $this->addHelpLink( 'Help:Related changes' );
141 return $extraOpts;
142 }
143
147 private function getTargetTitle() {
148 if ( $this->rclTargetTitle === null ) {
149 $opts = $this->getOptions();
150 if ( isset( $opts['target'] ) && $opts['target'] !== '' ) {
151 $this->rclTargetTitle = Title::newFromText( $opts['target'] );
152 } else {
153 $this->rclTargetTitle = false;
154 }
155 }
156
158 }
159
168 public function prefixSearchSubpages( $search, $limit, $offset ) {
169 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
170 }
171
172 protected function outputNoResults() {
173 $targetTitle = $this->getTargetTitle();
174 if ( $targetTitle === false ) {
175 $this->getOutput()->addHTML(
176 Html::rawElement(
177 'div',
178 [ 'class' => [ 'mw-changeslist-empty', 'mw-changeslist-notargetpage' ] ],
179 $this->msg( 'recentchanges-notargetpage' )->parse()
180 )
181 );
182 } elseif ( !$targetTitle || $targetTitle->isExternal() ) {
183 $this->getOutput()->addHTML(
184 Html::rawElement(
185 'div',
186 [ 'class' => [ 'mw-changeslist-empty', 'mw-changeslist-invalidtargetpage' ] ],
187 $this->msg( 'allpagesbadtitle' )->parse()
188 )
189 );
190 } else {
191 parent::outputNoResults();
192 }
193 }
194}
195
200class_alias( SpecialRecentChangesLinked::class, 'SpecialRecentChangesLinked' );
const NS_FILE
Definition Defines.php:57
const NS_CATEGORY
Definition Defines.php:65
Helper class to keep track of options when mixing links and form elements.
This class is a collection of static functions that serve two purposes:
Definition Html.php:43
Service for transformation of interface message text.
Build and execute a query on the recentchanges table, optionally with joins and conditions.
requireLink(string $direction, array $tables, PageIdentity $page)
Require that the changed page links from or to the specified page, via the specified links tables.
forceEmptySet()
Set a flag forcing the query to return no rows when it is executed.
Factory class for SearchEngine.
getOptions()
Get the current FormOptions for this request.
getSkin()
Shortcut to get the skin being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
prefixSearchString( $search, $limit, $offset, ?SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
This is to display changes made to all articles linked in an article.
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
setTopText(FormOptions $opts)
Send the text to be displayed above the options.
parseParameters( $par, FormOptions $opts)
Process the subpage $par and put options found in $opts.This is a legacy feature predating query para...
__construct(WatchedItemStoreInterface $watchedItemStore, MessageParser $messageParser, UserOptionsLookup $userOptionsLookup, private readonly SearchEngineFactory $searchEngineFactory, UserIdentityUtils $userIdentityUtils, TempUserConfig $tempUserConfig, RecentChangeFactory $recentChangeFactory, ChangesListQueryFactory $changesListQueryFactory,)
outputNoResults()
Add the "no results" message to the output.
getDefaultOptions()
Get a FormOptions object containing the default options.By default, returns some basic options....
getExtraOptions( $opts)
Get options to be displayed in a form.
modifyQuery(ChangesListQuery $query, FormOptions $opts)
Allow subclasses to modify the main query.
List of the last changes made to the wiki.
Represents a title within MediaWiki.
Definition Title.php:69
Provides access to user options.
Convenience functions for interpreting UserIdentity objects using additional services or config.
Interface for temporary user creation config and name matching.