MediaWiki master
SpecialRecentChangesLinked.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
21
30 protected $rclTargetTitle;
31
32 private SearchEngineFactory $searchEngineFactory;
33
34 public function __construct(
35 WatchedItemStoreInterface $watchedItemStore,
36 MessageParser $messageParser,
37 UserOptionsLookup $userOptionsLookup,
38 SearchEngineFactory $searchEngineFactory,
43 ) {
44 parent::__construct(
45 $watchedItemStore,
46 $messageParser,
47 $userOptionsLookup,
52 );
53 $this->mName = 'Recentchangeslinked';
54 $this->searchEngineFactory = $searchEngineFactory;
55 }
56
58 public function getDefaultOptions() {
59 $opts = parent::getDefaultOptions();
60 $opts->add( 'target', '' );
61 $opts->add( 'showlinkedto', false );
62
63 return $opts;
64 }
65
67 public function parseParameters( $par, FormOptions $opts ) {
68 $opts['target'] = $par;
69 }
70
74 protected function modifyQuery( ChangesListQuery $query, FormOptions $opts ) {
75 $target = $opts['target'];
76 $showlinkedto = $opts['showlinkedto'];
77
78 if ( $target === '' ) {
79 $query->forceEmptySet();
80 return;
81 }
82 $outputPage = $this->getOutput();
83 $title = Title::newFromText( $target );
84 if ( !$title || $title->isExternal() ) {
85 $outputPage->addModuleStyles( 'mediawiki.codex.messagebox.styles' );
86 $outputPage->addHTML(
87 Html::errorBox( $this->msg( 'allpagesbadtitle' )->parse(), '', 'mw-recentchangeslinked-errorbox' )
88 );
89 $query->forceEmptySet();
90 return;
91 }
92
93 $outputPage->setPageTitleMsg(
94 $this->msg( 'recentchangeslinked-title' )->plaintextParams( $title->getPrefixedText() )
95 );
96
97 $ns = $title->getNamespace();
98 if ( $ns === NS_CATEGORY && !$showlinkedto ) {
99 // special handling for categories
100 // XXX: should try to make this less kludgy
101 $link_tables = [ 'categorylinks' ];
102 $showlinkedto = true;
103 } else {
104 // for now, always join on these tables; really should be configurable as in whatlinkshere
105 $link_tables = [ 'pagelinks', 'templatelinks' ];
106 // imagelinks only contains links to pages in NS_FILE
107 if ( $ns === NS_FILE || !$showlinkedto ) {
108 $link_tables[] = 'imagelinks';
109 }
110 }
111
112 $query->requireLink(
113 $showlinkedto ? ChangesListQuery::LINKS_TO : ChangesListQuery::LINKS_FROM,
114 $link_tables,
115 $title
116 );
117 }
118
119 public function setTopText( FormOptions $opts ) {
120 $target = $this->getTargetTitle();
121 if ( $target ) {
122 $this->getOutput()->addBacklinkSubtitle( $target );
123 $this->getSkin()->setRelevantTitle( $target );
124 }
125 }
126
133 public function getExtraOptions( $opts ) {
134 $extraOpts = parent::getExtraOptions( $opts );
135
136 $opts->consumeValues( [ 'showlinkedto', 'target' ] );
137
138 $extraOpts['target'] = [ $this->msg( 'recentchangeslinked-page' )->escaped(),
139 Html::input( 'target', str_replace( '_', ' ', $opts['target'] ), 'text', [ 'size' => 40 ] ) . ' ' .
140 Html::check( 'showlinkedto', $opts['showlinkedto'], [ 'id' => 'showlinkedto' ] ) . ' ' .
141 Html::label( $this->msg( 'recentchangeslinked-to' )->text(), 'showlinkedto' ) ];
142
143 $this->addHelpLink( 'Help:Related changes' );
144 return $extraOpts;
145 }
146
150 private function getTargetTitle() {
151 if ( $this->rclTargetTitle === null ) {
152 $opts = $this->getOptions();
153 if ( isset( $opts['target'] ) && $opts['target'] !== '' ) {
154 $this->rclTargetTitle = Title::newFromText( $opts['target'] );
155 } else {
156 $this->rclTargetTitle = false;
157 }
158 }
159
161 }
162
171 public function prefixSearchSubpages( $search, $limit, $offset ) {
172 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
173 }
174
175 protected function outputNoResults() {
176 $targetTitle = $this->getTargetTitle();
177 if ( $targetTitle === false ) {
178 $this->getOutput()->addHTML(
179 Html::rawElement(
180 'div',
181 [ 'class' => [ 'mw-changeslist-empty', 'mw-changeslist-notargetpage' ] ],
182 $this->msg( 'recentchanges-notargetpage' )->parse()
183 )
184 );
185 } elseif ( !$targetTitle || $targetTitle->isExternal() ) {
186 $this->getOutput()->addHTML(
187 Html::rawElement(
188 'div',
189 [ 'class' => [ 'mw-changeslist-empty', 'mw-changeslist-invalidtargetpage' ] ],
190 $this->msg( 'allpagesbadtitle' )->parse()
191 )
192 );
193 } else {
194 parent::outputNoResults();
195 }
196 }
197}
198
203class_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.
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.
__construct(WatchedItemStoreInterface $watchedItemStore, MessageParser $messageParser, UserOptionsLookup $userOptionsLookup, SearchEngineFactory $searchEngineFactory, UserIdentityUtils $userIdentityUtils, TempUserConfig $tempUserConfig, RecentChangeFactory $recentChangeFactory, ChangesListQueryFactory $changesListQueryFactory,)
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...
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:70
Provides access to user options.
Convenience functions for interpreting UserIdentity objects using additional services or config.
Factory class for SearchEngine.
Interface for temporary user creation config and name matching.