Merge "Add ss_active_users in SiteStats::isSane"
[mediawiki.git] / includes / specials / SpecialRecentchanges.php
blob0d6378cb86404ff5281efc9fbec51ee1f57dc804
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();
45 $opts->add( 'days', $this->getUser()->getIntOption( 'rcdays' ) );
46 $opts->add( 'limit', $this->getUser()->getIntOption( 'rclimit' ) );
47 $opts->add( 'from', '' );
49 $opts->add( 'hideminor', $this->getUser()->getBoolOption( 'hideminor' ) );
50 $opts->add( 'hidebots', true );
51 $opts->add( 'hideanons', false );
52 $opts->add( 'hideliu', false );
53 $opts->add( 'hidepatrolled', $this->getUser()->getBoolOption( 'hidepatrolled' ) );
54 $opts->add( 'hidemyself', false );
56 $opts->add( 'namespace', '', FormOptions::INTNULL );
57 $opts->add( 'invert', false );
58 $opts->add( 'associated', false );
60 $opts->add( 'categories', '' );
61 $opts->add( 'categories_any', false );
62 $opts->add( 'tagfilter', '' );
64 return $opts;
67 /**
68 * Create a FormOptions object with options as specified by the user
70 * @param array $parameters
72 * @return FormOptions
74 public function setup( $parameters ) {
75 $opts = $this->getDefaultOptions();
77 foreach ( $this->getCustomFilters() as $key => $params ) {
78 $opts->add( $key, $params['default'] );
81 $opts->fetchValuesFromRequest( $this->getRequest() );
83 // Give precedence to subpage syntax
84 if ( $parameters !== null ) {
85 $this->parseParameters( $parameters, $opts );
88 $opts->validateIntBounds( 'limit', 0, 5000 );
90 return $opts;
93 /**
94 * Get custom show/hide filters
96 * @return array Map of filter URL param names to properties (msg/default)
98 protected function getCustomFilters() {
99 if ( $this->customFilters === null ) {
100 $this->customFilters = array();
101 wfRunHooks( 'SpecialRecentChangesFilters', array( $this, &$this->customFilters ) );
104 return $this->customFilters;
108 * Create a FormOptions object specific for feed requests and return it
110 * @return FormOptions
112 public function feedSetup() {
113 global $wgFeedLimit;
114 $opts = $this->getDefaultOptions();
115 $opts->fetchValuesFromRequest( $this->getRequest() );
116 $opts->validateIntBounds( 'limit', 0, $wgFeedLimit );
118 return $opts;
122 * Get the current FormOptions for this request
124 public function getOptions() {
125 if ( $this->rcOptions === null ) {
126 if ( $this->including() ) {
127 $isFeed = false;
128 } else {
129 $isFeed = (bool)$this->getRequest()->getVal( 'feed' );
131 $this->rcOptions = $isFeed ? $this->feedSetup() : $this->setup( $this->rcSubpage );
134 return $this->rcOptions;
138 * Main execution point
140 * @param string $subpage
142 public function execute( $subpage ) {
143 $this->rcSubpage = $subpage;
144 $feedFormat = $this->including() ? null : $this->getRequest()->getVal( 'feed' );
146 # 10 seconds server-side caching max
147 $this->getOutput()->setSquidMaxage( 10 );
148 # Check if the client has a cached version
149 $lastmod = $this->checkLastModified( $feedFormat );
150 if ( $lastmod === false ) {
151 return;
154 $opts = $this->getOptions();
155 $this->setHeaders();
156 $this->outputHeader();
157 $this->addRecentChangesJS();
159 // Fetch results, prepare a batch link existence check query
160 $conds = $this->buildMainQueryConds( $opts );
161 $rows = $this->doMainQuery( $conds, $opts );
162 if ( $rows === false ) {
163 if ( !$this->including() ) {
164 $this->doHeader( $opts );
167 return;
170 if ( !$feedFormat ) {
171 $batch = new LinkBatch;
172 foreach ( $rows as $row ) {
173 $batch->add( NS_USER, $row->rc_user_text );
174 $batch->add( NS_USER_TALK, $row->rc_user_text );
175 $batch->add( $row->rc_namespace, $row->rc_title );
177 $batch->execute();
179 if ( $feedFormat ) {
180 list( $changesFeed, $formatter ) = $this->getFeedObject( $feedFormat );
181 /** @var ChangesFeed $changesFeed */
182 $changesFeed->execute( $formatter, $rows, $lastmod, $opts );
183 } else {
184 $this->webOutput( $rows, $opts );
187 $rows->free();
191 * Return an array with a ChangesFeed object and ChannelFeed object
193 * @param string $feedFormat Feed's format (either 'rss' or 'atom')
194 * @return array
196 public function getFeedObject( $feedFormat ) {
197 $changesFeed = new ChangesFeed( $feedFormat, 'rcfeed' );
198 $formatter = $changesFeed->getFeedObject(
199 $this->msg( 'recentchanges' )->inContentLanguage()->text(),
200 $this->msg( 'recentchanges-feed-description' )->inContentLanguage()->text(),
201 $this->getTitle()->getFullURL()
204 return array( $changesFeed, $formatter );
208 * Process $par and put options found if $opts
209 * Mainly used when including the page
211 * @param string $par
212 * @param FormOptions $opts
214 public function parseParameters( $par, FormOptions $opts ) {
215 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
216 foreach ( $bits as $bit ) {
217 if ( 'hidebots' === $bit ) {
218 $opts['hidebots'] = true;
220 if ( 'bots' === $bit ) {
221 $opts['hidebots'] = false;
223 if ( 'hideminor' === $bit ) {
224 $opts['hideminor'] = true;
226 if ( 'minor' === $bit ) {
227 $opts['hideminor'] = false;
229 if ( 'hideliu' === $bit ) {
230 $opts['hideliu'] = true;
232 if ( 'hidepatrolled' === $bit ) {
233 $opts['hidepatrolled'] = true;
235 if ( 'hideanons' === $bit ) {
236 $opts['hideanons'] = true;
238 if ( 'hidemyself' === $bit ) {
239 $opts['hidemyself'] = true;
242 if ( is_numeric( $bit ) ) {
243 $opts['limit'] = $bit;
246 $m = array();
247 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
248 $opts['limit'] = $m[1];
250 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
251 $opts['days'] = $m[1];
253 if ( preg_match( '/^namespace=(\d+)$/', $bit, $m ) ) {
254 $opts['namespace'] = $m[1];
260 * Get last modified date, for client caching
261 * Don't use this if we are using the patrol feature, patrol changes don't
262 * update the timestamp
264 * @param string $feedFormat
265 * @return string|bool
267 public function checkLastModified( $feedFormat ) {
268 $dbr = wfGetDB( DB_SLAVE );
269 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
270 if ( $feedFormat || !$this->getUser()->useRCPatrol() ) {
271 if ( $lastmod && $this->getOutput()->checkLastModified( $lastmod ) ) {
272 # Client cache fresh and headers sent, nothing more to do.
273 return false;
277 return $lastmod;
281 * Return an array of conditions depending of options set in $opts
283 * @param FormOptions $opts
284 * @return array
286 public function buildMainQueryConds( FormOptions $opts ) {
287 $dbr = wfGetDB( DB_SLAVE );
288 $conds = array();
290 # It makes no sense to hide both anons and logged-in users
291 # Where this occurs, force anons to be shown
292 $forcebot = false;
293 if ( $opts['hideanons'] && $opts['hideliu'] ) {
294 # Check if the user wants to show bots only
295 if ( $opts['hidebots'] ) {
296 $opts['hideanons'] = false;
297 } else {
298 $forcebot = true;
299 $opts['hidebots'] = false;
303 // Calculate cutoff
304 $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
305 $cutoff_unixtime = $cutoff_unixtime - ( $cutoff_unixtime % 86400 );
306 $cutoff = $dbr->timestamp( $cutoff_unixtime );
308 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
309 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW, $cutoff ) ) {
310 $cutoff = $dbr->timestamp( $opts['from'] );
311 } else {
312 $opts->reset( 'from' );
315 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
317 $hidePatrol = $this->getUser()->useRCPatrol() && $opts['hidepatrolled'];
318 $hideLoggedInUsers = $opts['hideliu'] && !$forcebot;
319 $hideAnonymousUsers = $opts['hideanons'] && !$forcebot;
321 if ( $opts['hideminor'] ) {
322 $conds['rc_minor'] = 0;
324 if ( $opts['hidebots'] ) {
325 $conds['rc_bot'] = 0;
327 if ( $hidePatrol ) {
328 $conds['rc_patrolled'] = 0;
330 if ( $forcebot ) {
331 $conds['rc_bot'] = 1;
333 if ( $hideLoggedInUsers ) {
334 $conds[] = 'rc_user = 0';
336 if ( $hideAnonymousUsers ) {
337 $conds[] = 'rc_user != 0';
340 if ( $opts['hidemyself'] ) {
341 if ( $this->getUser()->getId() ) {
342 $conds[] = 'rc_user != ' . $dbr->addQuotes( $this->getUser()->getId() );
343 } else {
344 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $this->getUser()->getName() );
348 # Namespace filtering
349 if ( $opts['namespace'] !== '' ) {
350 $selectedNS = $dbr->addQuotes( $opts['namespace'] );
351 $operator = $opts['invert'] ? '!=' : '=';
352 $boolean = $opts['invert'] ? 'AND' : 'OR';
354 # namespace association (bug 2429)
355 if ( !$opts['associated'] ) {
356 $condition = "rc_namespace $operator $selectedNS";
357 } else {
358 # Also add the associated namespace
359 $associatedNS = $dbr->addQuotes(
360 MWNamespace::getAssociated( $opts['namespace'] )
362 $condition = "(rc_namespace $operator $selectedNS "
363 . $boolean
364 . " rc_namespace $operator $associatedNS)";
367 $conds[] = $condition;
370 return $conds;
374 * Process the query
376 * @param array $conds
377 * @param FormOptions $opts
378 * @return bool|ResultWrapper Result or false (for Recentchangeslinked only)
380 public function doMainQuery( $conds, $opts ) {
381 $tables = array( 'recentchanges' );
382 $join_conds = array();
383 $query_options = array(
384 'USE INDEX' => array( 'recentchanges' => 'rc_timestamp' )
387 $uid = $this->getUser()->getId();
388 $dbr = wfGetDB( DB_SLAVE );
389 $limit = $opts['limit'];
390 $namespace = $opts['namespace'];
391 $invert = $opts['invert'];
392 $associated = $opts['associated'];
394 $fields = RecentChange::selectFields();
395 // JOIN on watchlist for users
396 if ( $uid ) {
397 $tables[] = 'watchlist';
398 $fields[] = 'wl_user';
399 $fields[] = 'wl_notificationtimestamp';
400 $join_conds['watchlist'] = array( 'LEFT JOIN', array(
401 'wl_user' => $uid,
402 'wl_title=rc_title',
403 'wl_namespace=rc_namespace'
404 ) );
406 if ( $this->getUser()->isAllowed( 'rollback' ) ) {
407 $tables[] = 'page';
408 $fields[] = 'page_latest';
409 $join_conds['page'] = array( 'LEFT JOIN', 'rc_cur_id=page_id' );
411 // Tag stuff.
412 ChangeTags::modifyDisplayQuery(
413 $tables,
414 $fields,
415 $conds,
416 $join_conds,
417 $query_options,
418 $opts['tagfilter']
421 if ( !wfRunHooks( 'SpecialRecentChangesQuery',
422 array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ) )
424 return false;
427 // Don't use the new_namespace_time timestamp index if:
428 // (a) "All namespaces" selected
429 // (b) We want pages in more than one namespace (inverted/associated)
430 // (c) There is a tag to filter on (use tag index instead)
431 // (d) UNION + sort/limit is not an option for the DBMS
432 if ( $namespace === ''
433 || ( $invert || $associated )
434 || $opts['tagfilter'] != ''
435 || !$dbr->unionSupportsOrderAndLimit()
437 $res = $dbr->select( $tables, $fields, $conds, __METHOD__,
438 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) +
439 $query_options,
440 $join_conds );
441 } else {
442 // We have a new_namespace_time index! UNION over new=(0,1) and sort result set!
444 // New pages
445 $sqlNew = $dbr->selectSQLText(
446 $tables,
447 $fields,
448 array( 'rc_new' => 1 ) + $conds,
449 __METHOD__,
450 array(
451 'ORDER BY' => 'rc_timestamp DESC',
452 'LIMIT' => $limit,
453 'USE INDEX' => array( 'recentchanges' => 'new_name_timestamp' )
455 $join_conds
458 // Old pages
459 $sqlOld = $dbr->selectSQLText(
460 $tables,
461 $fields,
462 array( 'rc_new' => 0 ) + $conds,
463 __METHOD__,
464 array(
465 'ORDER BY' => 'rc_timestamp DESC',
466 'LIMIT' => $limit,
467 'USE INDEX' => array( 'recentchanges' => 'new_name_timestamp' )
469 $join_conds
472 # Join the two fast queries, and sort the result set
473 $sql = $dbr->unionQueries( array( $sqlNew, $sqlOld ), false ) .
474 ' ORDER BY rc_timestamp DESC';
475 $sql = $dbr->limitResult( $sql, $limit, false );
476 $res = $dbr->query( $sql, __METHOD__ );
479 return $res;
483 * Send output to the OutputPage object, only called if not used feeds
485 * @param array $rows Database rows
486 * @param FormOptions $opts
488 public function webOutput( $rows, $opts ) {
489 global $wgRCShowWatchingUsers, $wgShowUpdatedMarker, $wgAllowCategorizedRecentChanges;
491 $limit = $opts['limit'];
493 if ( !$this->including() ) {
494 // Output options box
495 $this->doHeader( $opts );
498 // And now for the content
499 $feedQuery = $this->getFeedQuery();
500 if ( $feedQuery !== '' ) {
501 $this->getOutput()->setFeedAppendQuery( $feedQuery );
502 } else {
503 $this->getOutput()->setFeedAppendQuery( false );
506 if ( $wgAllowCategorizedRecentChanges ) {
507 $this->filterByCategories( $rows, $opts );
510 $showNumsWachting = $this->getUser()->getOption( 'shownumberswatching' );
511 $showWatcherCount = $wgRCShowWatchingUsers && $showNumsWachting;
512 $watcherCache = array();
514 $dbr = wfGetDB( DB_SLAVE );
516 $counter = 1;
517 $list = ChangesList::newFromContext( $this->getContext() );
519 $s = $list->beginRecentChangesList();
520 foreach ( $rows as $obj ) {
521 if ( $limit == 0 ) {
522 break;
524 $rc = RecentChange::newFromRow( $obj );
525 $rc->counter = $counter++;
526 # Check if the page has been updated since the last visit
527 if ( $wgShowUpdatedMarker && !empty( $obj->wl_notificationtimestamp ) ) {
528 $rc->notificationtimestamp = ( $obj->rc_timestamp >= $obj->wl_notificationtimestamp );
529 } else {
530 $rc->notificationtimestamp = false; // Default
532 # Check the number of users watching the page
533 $rc->numberofWatchingusers = 0; // Default
534 if ( $showWatcherCount && $obj->rc_namespace >= 0 ) {
535 if ( !isset( $watcherCache[$obj->rc_namespace][$obj->rc_title] ) ) {
536 $watcherCache[$obj->rc_namespace][$obj->rc_title] =
537 $dbr->selectField(
538 'watchlist',
539 'COUNT(*)',
540 array(
541 'wl_namespace' => $obj->rc_namespace,
542 'wl_title' => $obj->rc_title,
544 __METHOD__ . '-watchers'
547 $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
550 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
551 if ( $changeLine !== false ) {
552 $s .= $changeLine;
553 --$limit;
556 $s .= $list->endRecentChangesList();
557 $this->getOutput()->addHTML( $s );
561 * Get the query string to append to feed link URLs.
563 * @return string
565 public function getFeedQuery() {
566 global $wgFeedLimit;
568 $this->getOptions()->validateIntBounds( 'limit', 0, $wgFeedLimit );
569 $options = $this->getOptions()->getChangedValues();
571 // wfArrayToCgi() omits options set to null or false
572 foreach ( $options as &$value ) {
573 if ( $value === false ) {
574 $value = '0';
577 unset( $value );
579 return wfArrayToCgi( $options );
583 * Return the text to be displayed above the changes
585 * @param FormOptions $opts
586 * @return string XHTML
588 public function doHeader( $opts ) {
589 global $wgScript;
591 $this->setTopText( $opts );
593 $defaults = $opts->getAllValues();
594 $nondefaults = $opts->getChangedValues();
595 $opts->consumeValues( array(
596 'namespace', 'invert', 'associated', 'tagfilter',
597 'categories', 'categories_any'
598 ) );
600 $panel = array();
601 $panel[] = $this->optionsPanel( $defaults, $nondefaults );
602 $panel[] = '<hr />';
604 $extraOpts = $this->getExtraOptions( $opts );
605 $extraOptsCount = count( $extraOpts );
606 $count = 0;
607 $submit = ' ' . Xml::submitbutton( $this->msg( 'allpagessubmit' )->text() );
609 $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) );
610 foreach ( $extraOpts as $name => $optionRow ) {
611 # Add submit button to the last row only
612 ++$count;
613 $addSubmit = ( $count === $extraOptsCount ) ? $submit : '';
615 $out .= Xml::openElement( 'tr' );
616 if ( is_array( $optionRow ) ) {
617 $out .= Xml::tags(
618 'td',
619 array( 'class' => 'mw-label mw-' . $name . '-label' ),
620 $optionRow[0]
622 $out .= Xml::tags(
623 'td',
624 array( 'class' => 'mw-input' ),
625 $optionRow[1] . $addSubmit
627 } else {
628 $out .= Xml::tags(
629 'td',
630 array( 'class' => 'mw-input', 'colspan' => 2 ),
631 $optionRow . $addSubmit
634 $out .= Xml::closeElement( 'tr' );
636 $out .= Xml::closeElement( 'table' );
638 $unconsumed = $opts->getUnconsumedValues();
639 foreach ( $unconsumed as $key => $value ) {
640 $out .= Html::hidden( $key, $value );
643 $t = $this->getTitle();
644 $out .= Html::hidden( 'title', $t->getPrefixedText() );
645 $form = Xml::tags( 'form', array( 'action' => $wgScript ), $out );
646 $panel[] = $form;
647 $panelString = implode( "\n", $panel );
649 $this->getOutput()->addHTML(
650 Xml::fieldset(
651 $this->msg( 'recentchanges-legend' )->text(),
652 $panelString,
653 array( 'class' => 'rcoptions' )
657 $this->setBottomText( $opts );
661 * Get options to be displayed in a form
663 * @param FormOptions $opts
664 * @return array
666 function getExtraOptions( $opts ) {
667 $extraOpts = array();
668 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
670 global $wgAllowCategorizedRecentChanges;
671 if ( $wgAllowCategorizedRecentChanges ) {
672 $extraOpts['category'] = $this->categoryFilterForm( $opts );
675 $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
676 if ( count( $tagFilter ) ) {
677 $extraOpts['tagfilter'] = $tagFilter;
680 wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) );
682 return $extraOpts;
686 * Send the text to be displayed above the options
688 * @param FormOptions $opts Unused
690 function setTopText( FormOptions $opts ) {
691 global $wgContLang;
693 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
694 if ( !$message->isDisabled() ) {
695 $this->getOutput()->addWikiText(
696 Html::rawElement( 'p',
697 array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ),
698 "\n" . $message->plain() . "\n"
700 /* $lineStart */ false,
701 /* $interface */ false
707 * Send the text to be displayed after the options, for use in
708 * Recentchangeslinked
710 * @param FormOptions $opts
712 function setBottomText( FormOptions $opts ) {
716 * Creates the choose namespace selection
718 * @todo Uses radio buttons (HASHAR)
719 * @param FormOptions $opts
720 * @return string
722 protected function namespaceFilterForm( FormOptions $opts ) {
723 $nsSelect = Html::namespaceSelector(
724 array( 'selected' => $opts['namespace'], 'all' => '' ),
725 array( 'name' => 'namespace', 'id' => 'namespace' )
727 $nsLabel = Xml::label( $this->msg( 'namespace' )->text(), 'namespace' );
728 $invert = Xml::checkLabel(
729 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
730 $opts['invert'],
731 array( 'title' => $this->msg( 'tooltip-invert' )->text() )
733 $associated = Xml::checkLabel(
734 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
735 $opts['associated'],
736 array( 'title' => $this->msg( 'tooltip-namespace_association' )->text() )
739 return array( $nsLabel, "$nsSelect $invert $associated" );
743 * Create a input to filter changes by categories
745 * @param FormOptions $opts
746 * @return array
748 protected function categoryFilterForm( FormOptions $opts ) {
749 list( $label, $input ) = Xml::inputLabelSep( $this->msg( 'rc_categories' )->text(),
750 'categories', 'mw-categories', false, $opts['categories'] );
752 $input .= ' ' . Xml::checkLabel( $this->msg( 'rc_categories_any' )->text(),
753 'categories_any', 'mw-categories_any', $opts['categories_any'] );
755 return array( $label, $input );
759 * Filter $rows by categories set in $opts
761 * @param array $rows Database rows
762 * @param FormOptions $opts
764 function filterByCategories( &$rows, FormOptions $opts ) {
765 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
767 if ( !count( $categories ) ) {
768 return;
771 # Filter categories
772 $cats = array();
773 foreach ( $categories as $cat ) {
774 $cat = trim( $cat );
775 if ( $cat == '' ) {
776 continue;
778 $cats[] = $cat;
781 # Filter articles
782 $articles = array();
783 $a2r = array();
784 $rowsarr = array();
785 foreach ( $rows as $k => $r ) {
786 $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
787 $id = $nt->getArticleID();
788 if ( $id == 0 ) {
789 continue; # Page might have been deleted...
791 if ( !in_array( $id, $articles ) ) {
792 $articles[] = $id;
794 if ( !isset( $a2r[$id] ) ) {
795 $a2r[$id] = array();
797 $a2r[$id][] = $k;
798 $rowsarr[$k] = $r;
801 # Shortcut?
802 if ( !count( $articles ) || !count( $cats ) ) {
803 return;
806 # Look up
807 $c = new Categoryfinder;
808 $c->seed( $articles, $cats, $opts['categories_any'] ? 'OR' : 'AND' );
809 $match = $c->run();
811 # Filter
812 $newrows = array();
813 foreach ( $match as $id ) {
814 foreach ( $a2r[$id] as $rev ) {
815 $k = $rev;
816 $newrows[$k] = $rowsarr[$k];
819 $rows = $newrows;
823 * Makes change an option link which carries all the other options
825 * @param string $title Title
826 * @param array $override Options to override
827 * @param array $options Current options
828 * @param bool $active Whether to show the link in bold
829 * @return string
831 function makeOptionsLink( $title, $override, $options, $active = false ) {
832 $params = $override + $options;
834 // Bug 36524: false values have be converted to "0" otherwise
835 // wfArrayToCgi() will omit it them.
836 foreach ( $params as &$value ) {
837 if ( $value === false ) {
838 $value = '0';
841 unset( $value );
843 $text = htmlspecialchars( $title );
844 if ( $active ) {
845 $text = '<strong>' . $text . '</strong>';
848 return Linker::linkKnown( $this->getTitle(), $text, array(), $params );
852 * Creates the options panel.
854 * @param array $defaults
855 * @param array $nondefaults
856 * @return string
858 function optionsPanel( $defaults, $nondefaults ) {
859 global $wgRCLinkLimits, $wgRCLinkDays;
861 $options = $nondefaults + $defaults;
863 $note = '';
864 $msg = $this->msg( 'rclegend' );
865 if ( !$msg->isDisabled() ) {
866 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
869 $lang = $this->getLanguage();
870 $user = $this->getUser();
871 if ( $options['from'] ) {
872 $note .= $this->msg( 'rcnotefrom' )->numParams( $options['limit'] )->params(
873 $lang->userTimeAndDate( $options['from'], $user ),
874 $lang->userDate( $options['from'], $user ),
875 $lang->userTime( $options['from'], $user ) )->parse() . '<br />';
878 # Sort data for display and make sure it's unique after we've added user data.
879 $wgRCLinkLimits[] = $options['limit'];
880 $wgRCLinkDays[] = $options['days'];
881 sort( $wgRCLinkLimits );
882 sort( $wgRCLinkDays );
883 $wgRCLinkLimits = array_unique( $wgRCLinkLimits );
884 $wgRCLinkDays = array_unique( $wgRCLinkDays );
886 // limit links
887 $cl = array();
888 foreach ( $wgRCLinkLimits as $value ) {
889 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
890 array( 'limit' => $value ), $nondefaults, $value == $options['limit'] );
892 $cl = $lang->pipeList( $cl );
894 // day links, reset 'from' to none
895 $dl = array();
896 foreach ( $wgRCLinkDays as $value ) {
897 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
898 array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] );
900 $dl = $lang->pipeList( $dl );
902 // show/hide links
903 $showhide = array( $this->msg( 'show' )->text(), $this->msg( 'hide' )->text() );
904 $filters = array(
905 'hideminor' => 'rcshowhideminor',
906 'hidebots' => 'rcshowhidebots',
907 'hideanons' => 'rcshowhideanons',
908 'hideliu' => 'rcshowhideliu',
909 'hidepatrolled' => 'rcshowhidepatr',
910 'hidemyself' => 'rcshowhidemine'
912 foreach ( $this->getCustomFilters() as $key => $params ) {
913 $filters[$key] = $params['msg'];
915 // Disable some if needed
916 if ( !$user->useRCPatrol() ) {
917 unset( $filters['hidepatrolled'] );
920 $links = array();
921 foreach ( $filters as $key => $msg ) {
922 $link = $this->makeOptionsLink( $showhide[1 - $options[$key]],
923 array( $key => 1 - $options[$key] ), $nondefaults );
924 $links[] = $this->msg( $msg )->rawParams( $link )->escaped();
927 // show from this onward link
928 $timestamp = wfTimestampNow();
929 $now = $lang->userTimeAndDate( $timestamp, $user );
930 $tl = $this->makeOptionsLink(
931 $now, array( 'from' => $timestamp ), $nondefaults
934 $rclinks = $this->msg( 'rclinks' )->rawParams( $cl, $dl, $lang->pipeList( $links ) )
935 ->parse();
936 $rclistfrom = $this->msg( 'rclistfrom' )->rawParams( $tl )->parse();
938 return "{$note}$rclinks<br />$rclistfrom";
942 * Add JavaScript to the page
944 function addRecentChangesJS() {
945 $this->getOutput()->addModules( array(
946 'mediawiki.special.recentchanges',
947 ) );
950 protected function getGroupName() {
951 return 'changes';