MediaWiki REL1_28
ChangesListSpecialPage.php
Go to the documentation of this file.
1<?php
30abstract class ChangesListSpecialPage extends SpecialPage {
32 protected $rcSubpage;
33
35 protected $rcOptions;
36
38 protected $customFilters;
39
45 public function execute( $subpage ) {
46 $this->rcSubpage = $subpage;
47
48 $this->setHeaders();
49 $this->outputHeader();
50 $this->addModules();
51
52 $rows = $this->getRows();
53 $opts = $this->getOptions();
54 if ( $rows === false ) {
55 if ( !$this->including() ) {
56 $this->doHeader( $opts, 0 );
57 $this->getOutput()->setStatusCode( 404 );
58 }
59
60 return;
61 }
62
63 $batch = new LinkBatch;
64 foreach ( $rows as $row ) {
65 $batch->add( NS_USER, $row->rc_user_text );
66 $batch->add( NS_USER_TALK, $row->rc_user_text );
67 $batch->add( $row->rc_namespace, $row->rc_title );
68 if ( $row->rc_source === RecentChange::SRC_LOG ) {
69 $formatter = LogFormatter::newFromRow( $row );
70 foreach ( $formatter->getPreloadTitles() as $title ) {
71 $batch->addObj( $title );
72 }
73 }
74 }
75 $batch->execute();
76
77 $this->webOutput( $rows, $opts );
78
79 $rows->free();
80 }
81
87 public function getRows() {
88 $opts = $this->getOptions();
89 $conds = $this->buildMainQueryConds( $opts );
90
91 return $this->doMainQuery( $conds, $opts );
92 }
93
99 public function getOptions() {
100 if ( $this->rcOptions === null ) {
101 $this->rcOptions = $this->setup( $this->rcSubpage );
102 }
103
104 return $this->rcOptions;
105 }
106
114 public function setup( $parameters ) {
115 $opts = $this->getDefaultOptions();
116 foreach ( $this->getCustomFilters() as $key => $params ) {
117 $opts->add( $key, $params['default'] );
118 }
119
120 $opts = $this->fetchOptionsFromRequest( $opts );
121
122 // Give precedence to subpage syntax
123 if ( $parameters !== null ) {
124 $this->parseParameters( $parameters, $opts );
125 }
126
127 $this->validateOptions( $opts );
128
129 return $opts;
130 }
131
138 public function getDefaultOptions() {
139 $config = $this->getConfig();
140 $opts = new FormOptions();
141
142 $opts->add( 'hideminor', false );
143 $opts->add( 'hidebots', false );
144 $opts->add( 'hideanons', false );
145 $opts->add( 'hideliu', false );
146 $opts->add( 'hidepatrolled', false );
147 $opts->add( 'hidemyself', false );
148
149 if ( $config->get( 'RCWatchCategoryMembership' ) ) {
150 $opts->add( 'hidecategorization', false );
151 }
152
153 $opts->add( 'namespace', '', FormOptions::INTNULL );
154 $opts->add( 'invert', false );
155 $opts->add( 'associated', false );
156
157 return $opts;
158 }
159
165 protected function getCustomFilters() {
166 if ( $this->customFilters === null ) {
167 $this->customFilters = [];
168 Hooks::run( 'ChangesListSpecialPageFilters', [ $this, &$this->customFilters ] );
169 }
170
172 }
173
182 protected function fetchOptionsFromRequest( $opts ) {
183 $opts->fetchValuesFromRequest( $this->getRequest() );
184
185 return $opts;
186 }
187
194 public function parseParameters( $par, FormOptions $opts ) {
195 // nothing by default
196 }
197
203 public function validateOptions( FormOptions $opts ) {
204 // nothing by default
205 }
206
213 public function buildMainQueryConds( FormOptions $opts ) {
214 $dbr = $this->getDB();
215 $user = $this->getUser();
216 $conds = [];
217
218 // It makes no sense to hide both anons and logged-in users. When this occurs, try a guess on
219 // what the user meant and either show only bots or force anons to be shown.
220 $botsonly = false;
221 $hideanons = $opts['hideanons'];
222 if ( $opts['hideanons'] && $opts['hideliu'] ) {
223 if ( $opts['hidebots'] ) {
224 $hideanons = false;
225 } else {
226 $botsonly = true;
227 }
228 }
229
230 // Toggles
231 if ( $opts['hideminor'] ) {
232 $conds['rc_minor'] = 0;
233 }
234 if ( $opts['hidebots'] ) {
235 $conds['rc_bot'] = 0;
236 }
237 if ( $user->useRCPatrol() && $opts['hidepatrolled'] ) {
238 $conds['rc_patrolled'] = 0;
239 }
240 if ( $botsonly ) {
241 $conds['rc_bot'] = 1;
242 } else {
243 if ( $opts['hideliu'] ) {
244 $conds[] = 'rc_user = 0';
245 }
246 if ( $hideanons ) {
247 $conds[] = 'rc_user != 0';
248 }
249 }
250 if ( $opts['hidemyself'] ) {
251 if ( $user->getId() ) {
252 $conds[] = 'rc_user != ' . $dbr->addQuotes( $user->getId() );
253 } else {
254 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $user->getName() );
255 }
256 }
257 if ( $this->getConfig()->get( 'RCWatchCategoryMembership' )
258 && $opts['hidecategorization'] === true
259 ) {
260 $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE );
261 }
262
263 // Namespace filtering
264 if ( $opts['namespace'] !== '' ) {
265 $selectedNS = $dbr->addQuotes( $opts['namespace'] );
266 $operator = $opts['invert'] ? '!=' : '=';
267 $boolean = $opts['invert'] ? 'AND' : 'OR';
268
269 // Namespace association (bug 2429)
270 if ( !$opts['associated'] ) {
271 $condition = "rc_namespace $operator $selectedNS";
272 } else {
273 // Also add the associated namespace
274 $associatedNS = $dbr->addQuotes(
275 MWNamespace::getAssociated( $opts['namespace'] )
276 );
277 $condition = "(rc_namespace $operator $selectedNS "
278 . $boolean
279 . " rc_namespace $operator $associatedNS)";
280 }
281
282 $conds[] = $condition;
283 }
284
285 return $conds;
286 }
287
295 public function doMainQuery( $conds, $opts ) {
296 $tables = [ 'recentchanges' ];
297 $fields = RecentChange::selectFields();
298 $query_options = [];
299 $join_conds = [];
300
302 $tables,
303 $fields,
304 $conds,
305 $join_conds,
306 $query_options,
307 ''
308 );
309
310 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
311 $opts )
312 ) {
313 return false;
314 }
315
316 $dbr = $this->getDB();
317
318 return $dbr->select(
319 $tables,
320 $fields,
321 $conds,
322 __METHOD__,
323 $query_options,
324 $join_conds
325 );
326 }
327
328 protected function runMainQueryHook( &$tables, &$fields, &$conds,
329 &$query_options, &$join_conds, $opts
330 ) {
331 return Hooks::run(
332 'ChangesListSpecialPageQuery',
333 [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
334 );
335 }
336
342 protected function getDB() {
343 return wfGetDB( DB_REPLICA );
344 }
345
352 public function webOutput( $rows, $opts ) {
353 if ( !$this->including() ) {
354 $this->outputFeedLinks();
355 $this->doHeader( $opts, $rows->numRows() );
356 }
357
358 $this->outputChangesList( $rows, $opts );
359 }
360
364 public function outputFeedLinks() {
365 // nothing by default
366 }
367
374 abstract public function outputChangesList( $rows, $opts );
375
382 public function doHeader( $opts, $numRows ) {
383 $this->setTopText( $opts );
384
385 // @todo Lots of stuff should be done here.
386
387 $this->setBottomText( $opts );
388 }
389
396 public function setTopText( FormOptions $opts ) {
397 // nothing by default
398 }
399
406 public function setBottomText( FormOptions $opts ) {
407 // nothing by default
408 }
409
418 public function getExtraOptions( $opts ) {
419 return [];
420 }
421
427 public function makeLegend() {
428 $context = $this->getContext();
429 $user = $context->getUser();
430 # The legend showing what the letters and stuff mean
431 $legend = Html::openElement( 'dl' ) . "\n";
432 # Iterates through them and gets the messages for both letter and tooltip
433 $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
434 if ( !( $user->useRCPatrol() || $user->useNPPatrol() ) ) {
435 unset( $legendItems['unpatrolled'] );
436 }
437 foreach ( $legendItems as $key => $item ) { # generate items of the legend
438 $label = isset( $item['legend'] ) ? $item['legend'] : $item['title'];
439 $letter = $item['letter'];
440 $cssClass = isset( $item['class'] ) ? $item['class'] : $key;
441
442 $legend .= Html::element( 'dt',
443 [ 'class' => $cssClass ], $context->msg( $letter )->text()
444 ) . "\n" .
445 Html::rawElement( 'dd',
446 [ 'class' => Sanitizer::escapeClass( 'mw-changeslist-legend-' . $key ) ],
447 $context->msg( $label )->parse()
448 ) . "\n";
449 }
450 # (+-123)
451 $legend .= Html::rawElement( 'dt',
452 [ 'class' => 'mw-plusminus-pos' ],
453 $context->msg( 'recentchanges-legend-plusminus' )->parse()
454 ) . "\n";
455 $legend .= Html::element(
456 'dd',
457 [ 'class' => 'mw-changeslist-legend-plusminus' ],
458 $context->msg( 'recentchanges-label-plusminus' )->text()
459 ) . "\n";
460 $legend .= Html::closeElement( 'dl' ) . "\n";
461
462 # Collapsibility
463 $legend =
464 '<div class="mw-changeslist-legend">' .
465 $context->msg( 'recentchanges-legend-heading' )->parse() .
466 '<div class="mw-collapsible-content">' . $legend . '</div>' .
467 '</div>';
468
469 return $legend;
470 }
471
475 protected function addModules() {
476 $out = $this->getOutput();
477 // Styles and behavior for the legend box (see makeLegend())
478 $out->addModuleStyles( [
479 'mediawiki.special.changeslist.legend',
480 'mediawiki.special.changeslist',
481 ] );
482 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
483 }
484
485 protected function getGroupName() {
486 return 'changes';
487 }
488}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag=false)
Applies all tags-related changes to a query.
Special page which uses a ChangesList to show query results.
buildMainQueryConds(FormOptions $opts)
Return an array of conditions depending of options set in $opts.
validateOptions(FormOptions $opts)
Validate a FormOptions object generated by getDefaultOptions() with values already populated.
getDefaultOptions()
Get a FormOptions object containing the default options.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
setTopText(FormOptions $opts)
Send the text to be displayed before the options.
runMainQueryHook(&$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts)
parseParameters( $par, FormOptions $opts)
Process $par and put options found in $opts.
getExtraOptions( $opts)
Get options to be displayed in a form.
setup( $parameters)
Create a FormOptions object with options as specified by the user.
getCustomFilters()
Get custom show/hide filters.
addModules()
Add page-specific modules.
outputFeedLinks()
Output feed links.
doHeader( $opts, $numRows)
Set the text to be displayed above the changes.
fetchOptionsFromRequest( $opts)
Fetch values for a FormOptions object from the WebRequest associated with this instance.
getOptions()
Get the current FormOptions for this request.
execute( $subpage)
Main execution point.
setBottomText(FormOptions $opts)
Send the text to be displayed after the options.
makeLegend()
Return the legend displayed within the fieldset.
webOutput( $rows, $opts)
Send output to the OutputPage object, only called if not used feeds.
getDB()
Return a IDatabase object for reading.
doMainQuery( $conds, $opts)
Process the query.
outputChangesList( $rows, $opts)
Build and output the actual changes list.
getRows()
Get the database result for this special page instance.
Helper class to keep track of options when mixing links and form elements.
const INTNULL
Integer type or null, maps to WebRequest::getIntOrNull() This is useful for the namespace selector.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition LinkBatch.php:32
add( $ns, $dbkey)
Definition LinkBatch.php:79
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
static selectFields()
Return the list of recentchanges fields that should be selected to create a new recentchanges object.
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
getName()
Get the name of this Special Page.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
getContext()
Gets the context this SpecialPage is executed in.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
including( $x=null)
Whether the special page is being evaluated via transclusion.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
database rows
Definition globals.txt:10
const NS_USER
Definition Defines.php:58
const NS_USER_TALK
Definition Defines.php:59
const RC_CATEGORIZE
Definition Defines.php:140
the array() calling protocol came about after MediaWiki 1.4rc1.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:249
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition hooks.txt:1028
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:986
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition hooks.txt:886
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
$batch
Definition linkcache.txt:23
$context
Definition load.php:50
const DB_REPLICA
Definition defines.php:22
$params