DifferenceEngine cleanup
[mediawiki.git] / includes / specials / SpecialRecentchanges.php
blob51e7450600cef44c04c7e3b44a39c79044746fc6
1 <?php
2 /**
3 * Implements Special:Recentchanges
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * A special page that lists last changes made to the wiki
27 * @ingroup SpecialPage
29 class SpecialRecentChanges extends IncludableSpecialPage {
30 var $rcOptions, $rcSubpage;
31 protected $customFilters;
33 public function __construct( $name = 'Recentchanges' ) {
34 parent::__construct( $name );
37 /**
38 * Get a FormOptions object containing the default options
40 * @return FormOptions
42 public function getDefaultOptions() {
43 $opts = new FormOptions();
44 $user = $this->getUser();
46 $opts->add( 'days', $user->getIntOption( 'rcdays' ) );
47 $opts->add( 'limit', $user->getIntOption( 'rclimit' ) );
48 $opts->add( 'from', '' );
50 $opts->add( 'hideminor', $user->getBoolOption( 'hideminor' ) );
51 $opts->add( 'hidebots', true );
52 $opts->add( 'hideanons', false );
53 $opts->add( 'hideliu', false );
54 $opts->add( 'hidepatrolled', $user->getBoolOption( 'hidepatrolled' ) );
55 $opts->add( 'hidemyself', false );
57 $opts->add( 'namespace', '', FormOptions::INTNULL );
58 $opts->add( 'invert', false );
59 $opts->add( 'associated', false );
61 $opts->add( 'categories', '' );
62 $opts->add( 'categories_any', false );
63 $opts->add( 'tagfilter', '' );
65 return $opts;
68 /**
69 * Create a FormOptions object with options as specified by the user
71 * @param array $parameters
73 * @return FormOptions
75 public function setup( $parameters ) {
76 $opts = $this->getDefaultOptions();
78 foreach ( $this->getCustomFilters() as $key => $params ) {
79 $opts->add( $key, $params['default'] );
82 $opts->fetchValuesFromRequest( $this->getRequest() );
84 // Give precedence to subpage syntax
85 if ( $parameters !== null ) {
86 $this->parseParameters( $parameters, $opts );
89 $opts->validateIntBounds( 'limit', 0, 5000 );
91 return $opts;
94 /**
95 * Get custom show/hide filters
97 * @return array Map of filter URL param names to properties (msg/default)
99 protected function getCustomFilters() {
100 if ( $this->customFilters === null ) {
101 $this->customFilters = array();
102 wfRunHooks( 'SpecialRecentChangesFilters', array( $this, &$this->customFilters ) );
105 return $this->customFilters;
109 * Create a FormOptions object specific for feed requests and return it
111 * @return FormOptions
113 public function feedSetup() {
114 global $wgFeedLimit;
115 $opts = $this->getDefaultOptions();
116 $opts->fetchValuesFromRequest( $this->getRequest() );
117 $opts->validateIntBounds( 'limit', 0, $wgFeedLimit );
119 return $opts;
123 * Get the current FormOptions for this request
125 public function getOptions() {
126 if ( $this->rcOptions === null ) {
127 if ( $this->including() ) {
128 $isFeed = false;
129 } else {
130 $isFeed = (bool)$this->getRequest()->getVal( 'feed' );
132 $this->rcOptions = $isFeed ? $this->feedSetup() : $this->setup( $this->rcSubpage );
135 return $this->rcOptions;
139 * Main execution point
141 * @param string $subpage
143 public function execute( $subpage ) {
144 $this->rcSubpage = $subpage;
145 $feedFormat = $this->including() ? null : $this->getRequest()->getVal( 'feed' );
147 # 10 seconds server-side caching max
148 $this->getOutput()->setSquidMaxage( 10 );
149 # Check if the client has a cached version
150 $lastmod = $this->checkLastModified( $feedFormat );
151 if ( $lastmod === false ) {
152 return;
155 $opts = $this->getOptions();
156 $this->setHeaders();
157 $this->outputHeader();
158 $this->addModules();
160 // Fetch results, prepare a batch link existence check query
161 $conds = $this->buildMainQueryConds( $opts );
162 $rows = $this->doMainQuery( $conds, $opts );
163 if ( $rows === false ) {
164 if ( !$this->including() ) {
165 $this->doHeader( $opts );
168 return;
171 if ( !$feedFormat ) {
172 $batch = new LinkBatch;
173 foreach ( $rows as $row ) {
174 $batch->add( NS_USER, $row->rc_user_text );
175 $batch->add( NS_USER_TALK, $row->rc_user_text );
176 $batch->add( $row->rc_namespace, $row->rc_title );
178 $batch->execute();
180 if ( $feedFormat ) {
181 list( $changesFeed, $formatter ) = $this->getFeedObject( $feedFormat );
182 /** @var ChangesFeed $changesFeed */
183 $changesFeed->execute( $formatter, $rows, $lastmod, $opts );
184 } else {
185 $this->webOutput( $rows, $opts );
188 $rows->free();
192 * Return an array with a ChangesFeed object and ChannelFeed object
194 * @param string $feedFormat Feed's format (either 'rss' or 'atom')
195 * @return array
197 public function getFeedObject( $feedFormat ) {
198 $changesFeed = new ChangesFeed( $feedFormat, 'rcfeed' );
199 $formatter = $changesFeed->getFeedObject(
200 $this->msg( 'recentchanges' )->inContentLanguage()->text(),
201 $this->msg( 'recentchanges-feed-description' )->inContentLanguage()->text(),
202 $this->getTitle()->getFullURL()
205 return array( $changesFeed, $formatter );
209 * Process $par and put options found if $opts
210 * Mainly used when including the page
212 * @param string $par
213 * @param FormOptions $opts
215 public function parseParameters( $par, FormOptions $opts ) {
216 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
217 foreach ( $bits as $bit ) {
218 if ( 'hidebots' === $bit ) {
219 $opts['hidebots'] = true;
221 if ( 'bots' === $bit ) {
222 $opts['hidebots'] = false;
224 if ( 'hideminor' === $bit ) {
225 $opts['hideminor'] = true;
227 if ( 'minor' === $bit ) {
228 $opts['hideminor'] = false;
230 if ( 'hideliu' === $bit ) {
231 $opts['hideliu'] = true;
233 if ( 'hidepatrolled' === $bit ) {
234 $opts['hidepatrolled'] = true;
236 if ( 'hideanons' === $bit ) {
237 $opts['hideanons'] = true;
239 if ( 'hidemyself' === $bit ) {
240 $opts['hidemyself'] = true;
243 if ( is_numeric( $bit ) ) {
244 $opts['limit'] = $bit;
247 $m = array();
248 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
249 $opts['limit'] = $m[1];
251 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
252 $opts['days'] = $m[1];
254 if ( preg_match( '/^namespace=(\d+)$/', $bit, $m ) ) {
255 $opts['namespace'] = $m[1];
261 * Get last modified date, for client caching
262 * Don't use this if we are using the patrol feature, patrol changes don't
263 * update the timestamp
265 * @param string $feedFormat
266 * @return string|bool
268 public function checkLastModified( $feedFormat ) {
269 $dbr = wfGetDB( DB_SLAVE );
270 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
271 if ( $feedFormat || !$this->getUser()->useRCPatrol() ) {
272 if ( $lastmod && $this->getOutput()->checkLastModified( $lastmod ) ) {
273 # Client cache fresh and headers sent, nothing more to do.
274 return false;
278 return $lastmod;
282 * Return an array of conditions depending of options set in $opts
284 * @param FormOptions $opts
285 * @return array
287 public function buildMainQueryConds( FormOptions $opts ) {
288 $dbr = wfGetDB( DB_SLAVE );
289 $conds = array();
291 # It makes no sense to hide both anons and logged-in users
292 # Where this occurs, force anons to be shown
293 $forcebot = false;
294 if ( $opts['hideanons'] && $opts['hideliu'] ) {
295 # Check if the user wants to show bots only
296 if ( $opts['hidebots'] ) {
297 $opts['hideanons'] = false;
298 } else {
299 $forcebot = true;
300 $opts['hidebots'] = false;
304 // Calculate cutoff
305 $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
306 $cutoff_unixtime = $cutoff_unixtime - ( $cutoff_unixtime % 86400 );
307 $cutoff = $dbr->timestamp( $cutoff_unixtime );
309 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
310 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW, $cutoff ) ) {
311 $cutoff = $dbr->timestamp( $opts['from'] );
312 } else {
313 $opts->reset( 'from' );
316 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
318 $hidePatrol = $this->getUser()->useRCPatrol() && $opts['hidepatrolled'];
319 $hideLoggedInUsers = $opts['hideliu'] && !$forcebot;
320 $hideAnonymousUsers = $opts['hideanons'] && !$forcebot;
322 if ( $opts['hideminor'] ) {
323 $conds['rc_minor'] = 0;
325 if ( $opts['hidebots'] ) {
326 $conds['rc_bot'] = 0;
328 if ( $hidePatrol ) {
329 $conds['rc_patrolled'] = 0;
331 if ( $forcebot ) {
332 $conds['rc_bot'] = 1;
334 if ( $hideLoggedInUsers ) {
335 $conds[] = 'rc_user = 0';
337 if ( $hideAnonymousUsers ) {
338 $conds[] = 'rc_user != 0';
341 if ( $opts['hidemyself'] ) {
342 if ( $this->getUser()->getId() ) {
343 $conds[] = 'rc_user != ' . $dbr->addQuotes( $this->getUser()->getId() );
344 } else {
345 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $this->getUser()->getName() );
349 # Namespace filtering
350 if ( $opts['namespace'] !== '' ) {
351 $selectedNS = $dbr->addQuotes( $opts['namespace'] );
352 $operator = $opts['invert'] ? '!=' : '=';
353 $boolean = $opts['invert'] ? 'AND' : 'OR';
355 # namespace association (bug 2429)
356 if ( !$opts['associated'] ) {
357 $condition = "rc_namespace $operator $selectedNS";
358 } else {
359 # Also add the associated namespace
360 $associatedNS = $dbr->addQuotes(
361 MWNamespace::getAssociated( $opts['namespace'] )
363 $condition = "(rc_namespace $operator $selectedNS "
364 . $boolean
365 . " rc_namespace $operator $associatedNS)";
368 $conds[] = $condition;
371 return $conds;
375 * Process the query
377 * @param array $conds
378 * @param FormOptions $opts
379 * @return bool|ResultWrapper Result or false (for Recentchangeslinked only)
381 public function doMainQuery( $conds, $opts ) {
382 $tables = array( 'recentchanges' );
383 $join_conds = array();
384 $query_options = array(
385 'USE INDEX' => array( 'recentchanges' => 'rc_timestamp' )
388 $uid = $this->getUser()->getId();
389 $dbr = wfGetDB( DB_SLAVE );
390 $limit = $opts['limit'];
391 $namespace = $opts['namespace'];
392 $invert = $opts['invert'];
393 $associated = $opts['associated'];
395 $fields = RecentChange::selectFields();
396 // JOIN on watchlist for users
397 if ( $uid && $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
398 $tables[] = 'watchlist';
399 $fields[] = 'wl_user';
400 $fields[] = 'wl_notificationtimestamp';
401 $join_conds['watchlist'] = array( 'LEFT JOIN', array(
402 'wl_user' => $uid,
403 'wl_title=rc_title',
404 'wl_namespace=rc_namespace'
405 ) );
407 if ( $this->getUser()->isAllowed( 'rollback' ) ) {
408 $tables[] = 'page';
409 $fields[] = 'page_latest';
410 $join_conds['page'] = array( 'LEFT JOIN', 'rc_cur_id=page_id' );
412 // Tag stuff.
413 ChangeTags::modifyDisplayQuery(
414 $tables,
415 $fields,
416 $conds,
417 $join_conds,
418 $query_options,
419 $opts['tagfilter']
422 if ( !wfRunHooks( 'SpecialRecentChangesQuery',
423 array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ) )
425 return false;
428 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
429 // knowledge to use an index merge if it wants (it may use some other index though).
430 return $dbr->select(
431 $tables,
432 $fields,
433 $conds + array( 'rc_new' => array( 0, 1 ) ),
434 __METHOD__,
435 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) + $query_options,
436 $join_conds
441 * Send output to the OutputPage object, only called if not used feeds
443 * @param array $rows Database rows
444 * @param FormOptions $opts
446 public function webOutput( $rows, $opts ) {
447 global $wgRCShowWatchingUsers, $wgShowUpdatedMarker, $wgAllowCategorizedRecentChanges;
449 // Build the final data
451 if ( $wgAllowCategorizedRecentChanges ) {
452 $this->filterByCategories( $rows, $opts );
455 $limit = $opts['limit'];
457 $showWatcherCount = $wgRCShowWatchingUsers && $this->getUser()->getOption( 'shownumberswatching' );
458 $watcherCache = array();
460 $dbr = wfGetDB( DB_SLAVE );
462 $counter = 1;
463 $list = ChangesList::newFromContext( $this->getContext() );
465 $rclistOutput = $list->beginRecentChangesList();
466 foreach ( $rows as $obj ) {
467 if ( $limit == 0 ) {
468 break;
470 $rc = RecentChange::newFromRow( $obj );
471 $rc->counter = $counter++;
472 # Check if the page has been updated since the last visit
473 if ( $wgShowUpdatedMarker && !empty( $obj->wl_notificationtimestamp ) ) {
474 $rc->notificationtimestamp = ( $obj->rc_timestamp >= $obj->wl_notificationtimestamp );
475 } else {
476 $rc->notificationtimestamp = false; // Default
478 # Check the number of users watching the page
479 $rc->numberofWatchingusers = 0; // Default
480 if ( $showWatcherCount && $obj->rc_namespace >= 0 ) {
481 if ( !isset( $watcherCache[$obj->rc_namespace][$obj->rc_title] ) ) {
482 $watcherCache[$obj->rc_namespace][$obj->rc_title] =
483 $dbr->selectField(
484 'watchlist',
485 'COUNT(*)',
486 array(
487 'wl_namespace' => $obj->rc_namespace,
488 'wl_title' => $obj->rc_title,
490 __METHOD__ . '-watchers'
493 $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
496 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
497 if ( $changeLine !== false ) {
498 $rclistOutput .= $changeLine;
499 --$limit;
502 $rclistOutput .= $list->endRecentChangesList();
504 // Print things out
506 if ( !$this->including() ) {
507 // Output options box
508 $this->doHeader( $opts );
511 // And now for the content
512 $feedQuery = $this->getFeedQuery();
513 if ( $feedQuery !== '' ) {
514 $this->getOutput()->setFeedAppendQuery( $feedQuery );
515 } else {
516 $this->getOutput()->setFeedAppendQuery( false );
519 if ( $rows->numRows() === 0 ) {
520 $this->getOutput()->addHtml(
521 '<div class="mw-changeslist-empty">' . $this->msg( 'recentchanges-noresult' )->parse() . '</div>'
523 } else {
524 $this->getOutput()->addHTML( $rclistOutput );
529 * Get the query string to append to feed link URLs.
531 * @return string
533 public function getFeedQuery() {
534 global $wgFeedLimit;
536 $this->getOptions()->validateIntBounds( 'limit', 0, $wgFeedLimit );
537 $options = $this->getOptions()->getChangedValues();
539 // wfArrayToCgi() omits options set to null or false
540 foreach ( $options as &$value ) {
541 if ( $value === false ) {
542 $value = '0';
545 unset( $value );
547 return wfArrayToCgi( $options );
551 * Return the text to be displayed above the changes
553 * @param FormOptions $opts
554 * @return string XHTML
556 public function doHeader( $opts ) {
557 global $wgScript;
559 $this->setTopText( $opts );
561 $defaults = $opts->getAllValues();
562 $nondefaults = $opts->getChangedValues();
564 $panel = array();
565 $panel[] = $this->optionsPanel( $defaults, $nondefaults );
566 $panel[] = '<hr />';
568 $extraOpts = $this->getExtraOptions( $opts );
569 $extraOptsCount = count( $extraOpts );
570 $count = 0;
571 $submit = ' ' . Xml::submitbutton( $this->msg( 'allpagessubmit' )->text() );
573 $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) );
574 foreach ( $extraOpts as $name => $optionRow ) {
575 # Add submit button to the last row only
576 ++$count;
577 $addSubmit = ( $count === $extraOptsCount ) ? $submit : '';
579 $out .= Xml::openElement( 'tr' );
580 if ( is_array( $optionRow ) ) {
581 $out .= Xml::tags(
582 'td',
583 array( 'class' => 'mw-label mw-' . $name . '-label' ),
584 $optionRow[0]
586 $out .= Xml::tags(
587 'td',
588 array( 'class' => 'mw-input' ),
589 $optionRow[1] . $addSubmit
591 } else {
592 $out .= Xml::tags(
593 'td',
594 array( 'class' => 'mw-input', 'colspan' => 2 ),
595 $optionRow . $addSubmit
598 $out .= Xml::closeElement( 'tr' );
600 $out .= Xml::closeElement( 'table' );
602 $unconsumed = $opts->getUnconsumedValues();
603 foreach ( $unconsumed as $key => $value ) {
604 $out .= Html::hidden( $key, $value );
607 $t = $this->getTitle();
608 $out .= Html::hidden( 'title', $t->getPrefixedText() );
609 $form = Xml::tags( 'form', array( 'action' => $wgScript ), $out );
610 $panel[] = $form;
611 $panelString = implode( "\n", $panel );
613 $this->getOutput()->addHTML(
614 Xml::fieldset(
615 $this->msg( 'recentchanges-legend' )->text(),
616 $panelString,
617 array( 'class' => 'rcoptions' )
621 $this->setBottomText( $opts );
625 * Get options to be displayed in a form
627 * @param FormOptions $opts
628 * @return array
630 function getExtraOptions( $opts ) {
631 $opts->consumeValues( array(
632 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
633 ) );
635 $extraOpts = array();
636 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
638 global $wgAllowCategorizedRecentChanges;
639 if ( $wgAllowCategorizedRecentChanges ) {
640 $extraOpts['category'] = $this->categoryFilterForm( $opts );
643 $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
644 if ( count( $tagFilter ) ) {
645 $extraOpts['tagfilter'] = $tagFilter;
648 // Don't fire the hook for subclasses. (Or should we?)
649 if ( $this->getName() === 'Recentchanges' ) {
650 wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) );
653 return $extraOpts;
657 * Send the text to be displayed above the options
659 * @param FormOptions $opts Unused
661 function setTopText( FormOptions $opts ) {
662 global $wgContLang;
664 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
665 if ( !$message->isDisabled() ) {
666 $this->getOutput()->addWikiText(
667 Html::rawElement( 'p',
668 array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ),
669 "\n" . $message->plain() . "\n"
671 /* $lineStart */ false,
672 /* $interface */ false
678 * Send the text to be displayed after the options, for use in subclasses.
680 * @param FormOptions $opts
682 function setBottomText( FormOptions $opts ) {
686 * Creates the choose namespace selection
688 * @todo Uses radio buttons (HASHAR)
689 * @param FormOptions $opts
690 * @return string
692 protected function namespaceFilterForm( FormOptions $opts ) {
693 $nsSelect = Html::namespaceSelector(
694 array( 'selected' => $opts['namespace'], 'all' => '' ),
695 array( 'name' => 'namespace', 'id' => 'namespace' )
697 $nsLabel = Xml::label( $this->msg( 'namespace' )->text(), 'namespace' );
698 $invert = Xml::checkLabel(
699 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
700 $opts['invert'],
701 array( 'title' => $this->msg( 'tooltip-invert' )->text() )
703 $associated = Xml::checkLabel(
704 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
705 $opts['associated'],
706 array( 'title' => $this->msg( 'tooltip-namespace_association' )->text() )
709 return array( $nsLabel, "$nsSelect $invert $associated" );
713 * Create a input to filter changes by categories
715 * @param FormOptions $opts
716 * @return array
718 protected function categoryFilterForm( FormOptions $opts ) {
719 list( $label, $input ) = Xml::inputLabelSep( $this->msg( 'rc_categories' )->text(),
720 'categories', 'mw-categories', false, $opts['categories'] );
722 $input .= ' ' . Xml::checkLabel( $this->msg( 'rc_categories_any' )->text(),
723 'categories_any', 'mw-categories_any', $opts['categories_any'] );
725 return array( $label, $input );
729 * Filter $rows by categories set in $opts
731 * @param array $rows Database rows
732 * @param FormOptions $opts
734 function filterByCategories( &$rows, FormOptions $opts ) {
735 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
737 if ( !count( $categories ) ) {
738 return;
741 # Filter categories
742 $cats = array();
743 foreach ( $categories as $cat ) {
744 $cat = trim( $cat );
745 if ( $cat == '' ) {
746 continue;
748 $cats[] = $cat;
751 # Filter articles
752 $articles = array();
753 $a2r = array();
754 $rowsarr = array();
755 foreach ( $rows as $k => $r ) {
756 $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
757 $id = $nt->getArticleID();
758 if ( $id == 0 ) {
759 continue; # Page might have been deleted...
761 if ( !in_array( $id, $articles ) ) {
762 $articles[] = $id;
764 if ( !isset( $a2r[$id] ) ) {
765 $a2r[$id] = array();
767 $a2r[$id][] = $k;
768 $rowsarr[$k] = $r;
771 # Shortcut?
772 if ( !count( $articles ) || !count( $cats ) ) {
773 return;
776 # Look up
777 $c = new Categoryfinder;
778 $c->seed( $articles, $cats, $opts['categories_any'] ? 'OR' : 'AND' );
779 $match = $c->run();
781 # Filter
782 $newrows = array();
783 foreach ( $match as $id ) {
784 foreach ( $a2r[$id] as $rev ) {
785 $k = $rev;
786 $newrows[$k] = $rowsarr[$k];
789 $rows = $newrows;
793 * Makes change an option link which carries all the other options
795 * @param string $title Title
796 * @param array $override Options to override
797 * @param array $options Current options
798 * @param bool $active Whether to show the link in bold
799 * @return string
801 function makeOptionsLink( $title, $override, $options, $active = false ) {
802 $params = $override + $options;
804 // Bug 36524: false values have be converted to "0" otherwise
805 // wfArrayToCgi() will omit it them.
806 foreach ( $params as &$value ) {
807 if ( $value === false ) {
808 $value = '0';
811 unset( $value );
813 $text = htmlspecialchars( $title );
814 if ( $active ) {
815 $text = '<strong>' . $text . '</strong>';
818 return Linker::linkKnown( $this->getTitle(), $text, array(), $params );
822 * Creates the options panel.
824 * @param array $defaults
825 * @param array $nondefaults
826 * @return string
828 function optionsPanel( $defaults, $nondefaults ) {
829 global $wgRCLinkLimits, $wgRCLinkDays;
831 $options = $nondefaults + $defaults;
833 $note = '';
834 $msg = $this->msg( 'rclegend' );
835 if ( !$msg->isDisabled() ) {
836 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
839 $lang = $this->getLanguage();
840 $user = $this->getUser();
841 if ( $options['from'] ) {
842 $note .= $this->msg( 'rcnotefrom' )->numParams( $options['limit'] )->params(
843 $lang->userTimeAndDate( $options['from'], $user ),
844 $lang->userDate( $options['from'], $user ),
845 $lang->userTime( $options['from'], $user ) )->parse() . '<br />';
848 # Sort data for display and make sure it's unique after we've added user data.
849 $linkLimits = $wgRCLinkLimits;
850 $linkLimits[] = $options['limit'];
851 sort( $linkLimits );
852 $linkLimits = array_unique( $linkLimits );
854 $linkDays = $wgRCLinkDays;
855 $linkDays[] = $options['days'];
856 sort( $linkDays );
857 $linkDays = array_unique( $linkDays );
859 // limit links
860 $cl = array();
861 foreach ( $linkLimits as $value ) {
862 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
863 array( 'limit' => $value ), $nondefaults, $value == $options['limit'] );
865 $cl = $lang->pipeList( $cl );
867 // day links, reset 'from' to none
868 $dl = array();
869 foreach ( $linkDays as $value ) {
870 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
871 array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] );
873 $dl = $lang->pipeList( $dl );
875 // show/hide links
876 $showhide = array( $this->msg( 'show' )->text(), $this->msg( 'hide' )->text() );
877 $filters = array(
878 'hideminor' => 'rcshowhideminor',
879 'hidebots' => 'rcshowhidebots',
880 'hideanons' => 'rcshowhideanons',
881 'hideliu' => 'rcshowhideliu',
882 'hidepatrolled' => 'rcshowhidepatr',
883 'hidemyself' => 'rcshowhidemine'
885 foreach ( $this->getCustomFilters() as $key => $params ) {
886 $filters[$key] = $params['msg'];
888 // Disable some if needed
889 if ( !$user->useRCPatrol() ) {
890 unset( $filters['hidepatrolled'] );
893 $links = array();
894 foreach ( $filters as $key => $msg ) {
895 $link = $this->makeOptionsLink( $showhide[1 - $options[$key]],
896 array( $key => 1 - $options[$key] ), $nondefaults );
897 $links[] = $this->msg( $msg )->rawParams( $link )->escaped();
900 // show from this onward link
901 $timestamp = wfTimestampNow();
902 $now = $lang->userTimeAndDate( $timestamp, $user );
903 $tl = $this->makeOptionsLink(
904 $now, array( 'from' => $timestamp ), $nondefaults
907 $rclinks = $this->msg( 'rclinks' )->rawParams( $cl, $dl, $lang->pipeList( $links ) )
908 ->parse();
909 $rclistfrom = $this->msg( 'rclistfrom' )->rawParams( $tl )->parse();
911 return "{$note}$rclinks<br />$rclistfrom";
915 * Add page-specific modules.
917 protected function addModules() {
918 $this->getOutput()->addModules( array(
919 'mediawiki.special.recentchanges',
920 ) );
923 protected function getGroupName() {
924 return 'changes';