Create ChangesListSpecialPage as a base class for Watchlist and RC
[lhc/web/wiklou.git] / includes / specials / SpecialRecentchanges.php
1 <?php
2 /**
3 * Implements Special:Recentchanges
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * A special page that lists last changes made to the wiki
26 *
27 * @ingroup SpecialPage
28 */
29 class SpecialRecentChanges extends ChangesListSpecialPage {
30 /**
31 * The feed format to output as (either 'rss' or 'atom'), or null if no
32 * feed output was requested
33 *
34 * @var string $feedFormat
35 */
36 protected $feedFormat;
37
38 public function __construct( $name = 'Recentchanges', $restriction = '' ) {
39 parent::__construct( $name, $restriction );
40 }
41
42 public function isIncludable() {
43 return true;
44 }
45
46 /**
47 * Get a FormOptions object containing the default options
48 *
49 * @return FormOptions
50 */
51 public function getDefaultOptions() {
52 $opts = parent::getDefaultOptions();
53 $user = $this->getUser();
54
55 $opts->add( 'days', $user->getIntOption( 'rcdays' ) );
56 $opts->add( 'limit', $user->getIntOption( 'rclimit' ) );
57 $opts->add( 'from', '' );
58
59 $opts->add( 'hideminor', $user->getBoolOption( 'hideminor' ) );
60 $opts->add( 'hidebots', true );
61 $opts->add( 'hideanons', false );
62 $opts->add( 'hideliu', false );
63 $opts->add( 'hidepatrolled', $user->getBoolOption( 'hidepatrolled' ) );
64 $opts->add( 'hidemyself', false );
65
66 $opts->add( 'categories', '' );
67 $opts->add( 'categories_any', false );
68 $opts->add( 'tagfilter', '' );
69
70 return $opts;
71 }
72
73 public function validateOptions( FormOptions $opts ) {
74 global $wgFeedLimit;
75 $opts->validateIntBounds( 'limit', 0, $this->feedFormat ? $wgFeedLimit : 5000 );
76 }
77
78 /**
79 * Get custom show/hide filters
80 *
81 * @return array Map of filter URL param names to properties (msg/default)
82 */
83 protected function getCustomFilters() {
84 if ( $this->customFilters === null ) {
85 $this->customFilters = array();
86 wfRunHooks( 'SpecialRecentChangesFilters', array( $this, &$this->customFilters ) );
87 }
88
89 return $this->customFilters;
90 }
91
92 /**
93 * Main execution point
94 *
95 * @param string $subpage
96 */
97 public function execute( $subpage ) {
98 $this->rcSubpage = $subpage;
99 $this->feedFormat = $this->including() ? null : $this->getRequest()->getVal( 'feed' );
100
101 # 10 seconds server-side caching max
102 $this->getOutput()->setSquidMaxage( 10 );
103 # Check if the client has a cached version
104 $lastmod = $this->checkLastModified( $this->feedFormat );
105 if ( $lastmod === false ) {
106 return;
107 }
108
109 $opts = $this->getOptions();
110 $this->setHeaders();
111 $this->outputHeader();
112 $this->addModules();
113
114 // Fetch results, prepare a batch link existence check query
115 $conds = $this->buildMainQueryConds( $opts );
116 $rows = $this->doMainQuery( $conds, $opts );
117 if ( $rows === false ) {
118 if ( !$this->including() ) {
119 $this->doHeader( $opts );
120 }
121
122 return;
123 }
124
125 if ( !$this->feedFormat ) {
126 $batch = new LinkBatch;
127 foreach ( $rows as $row ) {
128 $batch->add( NS_USER, $row->rc_user_text );
129 $batch->add( NS_USER_TALK, $row->rc_user_text );
130 $batch->add( $row->rc_namespace, $row->rc_title );
131 }
132 $batch->execute();
133 }
134 if ( $this->feedFormat ) {
135 list( $changesFeed, $formatter ) = $this->getFeedObject( $this->feedFormat );
136 /** @var ChangesFeed $changesFeed */
137 $changesFeed->execute( $formatter, $rows, $lastmod, $opts );
138 } else {
139 $this->webOutput( $rows, $opts );
140 }
141
142 $rows->free();
143 }
144
145 /**
146 * Return an array with a ChangesFeed object and ChannelFeed object
147 *
148 * @param string $feedFormat Feed's format (either 'rss' or 'atom')
149 * @return array
150 */
151 public function getFeedObject( $feedFormat ) {
152 $changesFeed = new ChangesFeed( $feedFormat, 'rcfeed' );
153 $formatter = $changesFeed->getFeedObject(
154 $this->msg( 'recentchanges' )->inContentLanguage()->text(),
155 $this->msg( 'recentchanges-feed-description' )->inContentLanguage()->text(),
156 $this->getPageTitle()->getFullURL()
157 );
158
159 return array( $changesFeed, $formatter );
160 }
161
162 /**
163 * Process $par and put options found in $opts. Used when including the page.
164 *
165 * @param string $par
166 * @param FormOptions $opts
167 */
168 public function parseParameters( $par, FormOptions $opts ) {
169 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
170 foreach ( $bits as $bit ) {
171 if ( 'hidebots' === $bit ) {
172 $opts['hidebots'] = true;
173 }
174 if ( 'bots' === $bit ) {
175 $opts['hidebots'] = false;
176 }
177 if ( 'hideminor' === $bit ) {
178 $opts['hideminor'] = true;
179 }
180 if ( 'minor' === $bit ) {
181 $opts['hideminor'] = false;
182 }
183 if ( 'hideliu' === $bit ) {
184 $opts['hideliu'] = true;
185 }
186 if ( 'hidepatrolled' === $bit ) {
187 $opts['hidepatrolled'] = true;
188 }
189 if ( 'hideanons' === $bit ) {
190 $opts['hideanons'] = true;
191 }
192 if ( 'hidemyself' === $bit ) {
193 $opts['hidemyself'] = true;
194 }
195
196 if ( is_numeric( $bit ) ) {
197 $opts['limit'] = $bit;
198 }
199
200 $m = array();
201 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
202 $opts['limit'] = $m[1];
203 }
204 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
205 $opts['days'] = $m[1];
206 }
207 if ( preg_match( '/^namespace=(\d+)$/', $bit, $m ) ) {
208 $opts['namespace'] = $m[1];
209 }
210 }
211 }
212
213 /**
214 * Get last modified date, for client caching
215 * Don't use this if we are using the patrol feature, patrol changes don't
216 * update the timestamp
217 *
218 * @param string $feedFormat
219 * @return string|bool
220 */
221 public function checkLastModified( $feedFormat ) {
222 $dbr = wfGetDB( DB_SLAVE );
223 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
224 if ( $feedFormat || !$this->getUser()->useRCPatrol() ) {
225 if ( $lastmod && $this->getOutput()->checkLastModified( $lastmod ) ) {
226 # Client cache fresh and headers sent, nothing more to do.
227 return false;
228 }
229 }
230
231 return $lastmod;
232 }
233
234 /**
235 * Return an array of conditions depending of options set in $opts
236 *
237 * @param FormOptions $opts
238 * @return array
239 */
240 public function buildMainQueryConds( FormOptions $opts ) {
241 $dbr = wfGetDB( DB_SLAVE );
242 $conds = array();
243
244 # It makes no sense to hide both anons and logged-in users
245 # Where this occurs, force anons to be shown
246 $forcebot = false;
247 if ( $opts['hideanons'] && $opts['hideliu'] ) {
248 # Check if the user wants to show bots only
249 if ( $opts['hidebots'] ) {
250 $opts['hideanons'] = false;
251 } else {
252 $forcebot = true;
253 $opts['hidebots'] = false;
254 }
255 }
256
257 // Calculate cutoff
258 $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
259 $cutoff_unixtime = $cutoff_unixtime - ( $cutoff_unixtime % 86400 );
260 $cutoff = $dbr->timestamp( $cutoff_unixtime );
261
262 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
263 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW, $cutoff ) ) {
264 $cutoff = $dbr->timestamp( $opts['from'] );
265 } else {
266 $opts->reset( 'from' );
267 }
268
269 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
270
271 $hidePatrol = $this->getUser()->useRCPatrol() && $opts['hidepatrolled'];
272 $hideLoggedInUsers = $opts['hideliu'] && !$forcebot;
273 $hideAnonymousUsers = $opts['hideanons'] && !$forcebot;
274
275 if ( $opts['hideminor'] ) {
276 $conds['rc_minor'] = 0;
277 }
278 if ( $opts['hidebots'] ) {
279 $conds['rc_bot'] = 0;
280 }
281 if ( $hidePatrol ) {
282 $conds['rc_patrolled'] = 0;
283 }
284 if ( $forcebot ) {
285 $conds['rc_bot'] = 1;
286 }
287 if ( $hideLoggedInUsers ) {
288 $conds[] = 'rc_user = 0';
289 }
290 if ( $hideAnonymousUsers ) {
291 $conds[] = 'rc_user != 0';
292 }
293
294 if ( $opts['hidemyself'] ) {
295 if ( $this->getUser()->getId() ) {
296 $conds[] = 'rc_user != ' . $dbr->addQuotes( $this->getUser()->getId() );
297 } else {
298 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $this->getUser()->getName() );
299 }
300 }
301
302 # Namespace filtering
303 if ( $opts['namespace'] !== '' ) {
304 $selectedNS = $dbr->addQuotes( $opts['namespace'] );
305 $operator = $opts['invert'] ? '!=' : '=';
306 $boolean = $opts['invert'] ? 'AND' : 'OR';
307
308 # namespace association (bug 2429)
309 if ( !$opts['associated'] ) {
310 $condition = "rc_namespace $operator $selectedNS";
311 } else {
312 # Also add the associated namespace
313 $associatedNS = $dbr->addQuotes(
314 MWNamespace::getAssociated( $opts['namespace'] )
315 );
316 $condition = "(rc_namespace $operator $selectedNS "
317 . $boolean
318 . " rc_namespace $operator $associatedNS)";
319 }
320
321 $conds[] = $condition;
322 }
323
324 return $conds;
325 }
326
327 /**
328 * Process the query
329 *
330 * @param array $conds
331 * @param FormOptions $opts
332 * @return bool|ResultWrapper Result or false (for Recentchangeslinked only)
333 */
334 public function doMainQuery( $conds, $opts ) {
335 $tables = array( 'recentchanges' );
336 $join_conds = array();
337 $query_options = array();
338
339 $uid = $this->getUser()->getId();
340 $dbr = wfGetDB( DB_SLAVE );
341 $limit = $opts['limit'];
342 $namespace = $opts['namespace'];
343 $invert = $opts['invert'];
344 $associated = $opts['associated'];
345
346 $fields = RecentChange::selectFields();
347 // JOIN on watchlist for users
348 if ( $uid && $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
349 $tables[] = 'watchlist';
350 $fields[] = 'wl_user';
351 $fields[] = 'wl_notificationtimestamp';
352 $join_conds['watchlist'] = array( 'LEFT JOIN', array(
353 'wl_user' => $uid,
354 'wl_title=rc_title',
355 'wl_namespace=rc_namespace'
356 ) );
357 }
358 if ( $this->getUser()->isAllowed( 'rollback' ) ) {
359 $tables[] = 'page';
360 $fields[] = 'page_latest';
361 $join_conds['page'] = array( 'LEFT JOIN', 'rc_cur_id=page_id' );
362 }
363 // Tag stuff.
364 ChangeTags::modifyDisplayQuery(
365 $tables,
366 $fields,
367 $conds,
368 $join_conds,
369 $query_options,
370 $opts['tagfilter']
371 );
372
373 if ( !wfRunHooks( 'SpecialRecentChangesQuery',
374 array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ) )
375 ) {
376 return false;
377 }
378
379 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
380 // knowledge to use an index merge if it wants (it may use some other index though).
381 return $dbr->select(
382 $tables,
383 $fields,
384 $conds + array( 'rc_new' => array( 0, 1 ) ),
385 __METHOD__,
386 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) + $query_options,
387 $join_conds
388 );
389 }
390
391 /**
392 * Send output to the OutputPage object, only called if not used feeds
393 *
394 * @param array $rows Database rows
395 * @param FormOptions $opts
396 */
397 public function webOutput( $rows, $opts ) {
398 global $wgRCShowWatchingUsers, $wgShowUpdatedMarker, $wgAllowCategorizedRecentChanges;
399
400 // Build the final data
401
402 if ( $wgAllowCategorizedRecentChanges ) {
403 $this->filterByCategories( $rows, $opts );
404 }
405
406 $limit = $opts['limit'];
407
408 $showWatcherCount = $wgRCShowWatchingUsers && $this->getUser()->getOption( 'shownumberswatching' );
409 $watcherCache = array();
410
411 $dbr = wfGetDB( DB_SLAVE );
412
413 $counter = 1;
414 $list = ChangesList::newFromContext( $this->getContext() );
415
416 $rclistOutput = $list->beginRecentChangesList();
417 foreach ( $rows as $obj ) {
418 if ( $limit == 0 ) {
419 break;
420 }
421 $rc = RecentChange::newFromRow( $obj );
422 $rc->counter = $counter++;
423 # Check if the page has been updated since the last visit
424 if ( $wgShowUpdatedMarker && !empty( $obj->wl_notificationtimestamp ) ) {
425 $rc->notificationtimestamp = ( $obj->rc_timestamp >= $obj->wl_notificationtimestamp );
426 } else {
427 $rc->notificationtimestamp = false; // Default
428 }
429 # Check the number of users watching the page
430 $rc->numberofWatchingusers = 0; // Default
431 if ( $showWatcherCount && $obj->rc_namespace >= 0 ) {
432 if ( !isset( $watcherCache[$obj->rc_namespace][$obj->rc_title] ) ) {
433 $watcherCache[$obj->rc_namespace][$obj->rc_title] =
434 $dbr->selectField(
435 'watchlist',
436 'COUNT(*)',
437 array(
438 'wl_namespace' => $obj->rc_namespace,
439 'wl_title' => $obj->rc_title,
440 ),
441 __METHOD__ . '-watchers'
442 );
443 }
444 $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
445 }
446
447 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
448 if ( $changeLine !== false ) {
449 $rclistOutput .= $changeLine;
450 --$limit;
451 }
452 }
453 $rclistOutput .= $list->endRecentChangesList();
454
455 // Print things out
456
457 if ( !$this->including() ) {
458 // Output options box
459 $this->doHeader( $opts );
460 }
461
462 // And now for the content
463 $feedQuery = $this->getFeedQuery();
464 if ( $feedQuery !== '' ) {
465 $this->getOutput()->setFeedAppendQuery( $feedQuery );
466 } else {
467 $this->getOutput()->setFeedAppendQuery( false );
468 }
469
470 if ( $rows->numRows() === 0 ) {
471 $this->getOutput()->addHtml(
472 '<div class="mw-changeslist-empty">' . $this->msg( 'recentchanges-noresult' )->parse() . '</div>'
473 );
474 } else {
475 $this->getOutput()->addHTML( $rclistOutput );
476 }
477 }
478
479 /**
480 * Get the query string to append to feed link URLs.
481 *
482 * @return string
483 */
484 public function getFeedQuery() {
485 global $wgFeedLimit;
486
487 $this->getOptions()->validateIntBounds( 'limit', 0, $wgFeedLimit );
488 $options = $this->getOptions()->getChangedValues();
489
490 // wfArrayToCgi() omits options set to null or false
491 foreach ( $options as &$value ) {
492 if ( $value === false ) {
493 $value = '0';
494 }
495 }
496 unset( $value );
497
498 return wfArrayToCgi( $options );
499 }
500
501 /**
502 * Return the text to be displayed above the changes
503 *
504 * @param FormOptions $opts
505 * @return string XHTML
506 */
507 public function doHeader( $opts ) {
508 global $wgScript;
509
510 $this->setTopText( $opts );
511
512 $defaults = $opts->getAllValues();
513 $nondefaults = $opts->getChangedValues();
514
515 $panel = array();
516 $panel[] = self::makeLegend( $this->getContext() );
517 $panel[] = $this->optionsPanel( $defaults, $nondefaults );
518 $panel[] = '<hr />';
519
520 $extraOpts = $this->getExtraOptions( $opts );
521 $extraOptsCount = count( $extraOpts );
522 $count = 0;
523 $submit = ' ' . Xml::submitbutton( $this->msg( 'allpagessubmit' )->text() );
524
525 $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) );
526 foreach ( $extraOpts as $name => $optionRow ) {
527 # Add submit button to the last row only
528 ++$count;
529 $addSubmit = ( $count === $extraOptsCount ) ? $submit : '';
530
531 $out .= Xml::openElement( 'tr' );
532 if ( is_array( $optionRow ) ) {
533 $out .= Xml::tags(
534 'td',
535 array( 'class' => 'mw-label mw-' . $name . '-label' ),
536 $optionRow[0]
537 );
538 $out .= Xml::tags(
539 'td',
540 array( 'class' => 'mw-input' ),
541 $optionRow[1] . $addSubmit
542 );
543 } else {
544 $out .= Xml::tags(
545 'td',
546 array( 'class' => 'mw-input', 'colspan' => 2 ),
547 $optionRow . $addSubmit
548 );
549 }
550 $out .= Xml::closeElement( 'tr' );
551 }
552 $out .= Xml::closeElement( 'table' );
553
554 $unconsumed = $opts->getUnconsumedValues();
555 foreach ( $unconsumed as $key => $value ) {
556 $out .= Html::hidden( $key, $value );
557 }
558
559 $t = $this->getPageTitle();
560 $out .= Html::hidden( 'title', $t->getPrefixedText() );
561 $form = Xml::tags( 'form', array( 'action' => $wgScript ), $out );
562 $panel[] = $form;
563 $panelString = implode( "\n", $panel );
564
565 $this->getOutput()->addHTML(
566 Xml::fieldset(
567 $this->msg( 'recentchanges-legend' )->text(),
568 $panelString,
569 array( 'class' => 'rcoptions' )
570 )
571 );
572
573 $this->setBottomText( $opts );
574 }
575
576 /**
577 * Get options to be displayed in a form
578 *
579 * @param FormOptions $opts
580 * @return array
581 */
582 function getExtraOptions( $opts ) {
583 $opts->consumeValues( array(
584 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
585 ) );
586
587 $extraOpts = array();
588 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
589
590 global $wgAllowCategorizedRecentChanges;
591 if ( $wgAllowCategorizedRecentChanges ) {
592 $extraOpts['category'] = $this->categoryFilterForm( $opts );
593 }
594
595 $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
596 if ( count( $tagFilter ) ) {
597 $extraOpts['tagfilter'] = $tagFilter;
598 }
599
600 // Don't fire the hook for subclasses. (Or should we?)
601 if ( $this->getName() === 'Recentchanges' ) {
602 wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) );
603 }
604
605 return $extraOpts;
606 }
607
608 /**
609 * Send the text to be displayed above the options
610 *
611 * @param FormOptions $opts Unused
612 */
613 function setTopText( FormOptions $opts ) {
614 global $wgContLang;
615
616 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
617 if ( !$message->isDisabled() ) {
618 $this->getOutput()->addWikiText(
619 Html::rawElement( 'p',
620 array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ),
621 "\n" . $message->plain() . "\n"
622 ),
623 /* $lineStart */ false,
624 /* $interface */ false
625 );
626 }
627 }
628
629 /**
630 * Creates the choose namespace selection
631 *
632 * @param FormOptions $opts
633 * @return string
634 */
635 protected function namespaceFilterForm( FormOptions $opts ) {
636 $nsSelect = Html::namespaceSelector(
637 array( 'selected' => $opts['namespace'], 'all' => '' ),
638 array( 'name' => 'namespace', 'id' => 'namespace' )
639 );
640 $nsLabel = Xml::label( $this->msg( 'namespace' )->text(), 'namespace' );
641 $invert = Xml::checkLabel(
642 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
643 $opts['invert'],
644 array( 'title' => $this->msg( 'tooltip-invert' )->text() )
645 );
646 $associated = Xml::checkLabel(
647 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
648 $opts['associated'],
649 array( 'title' => $this->msg( 'tooltip-namespace_association' )->text() )
650 );
651
652 return array( $nsLabel, "$nsSelect $invert $associated" );
653 }
654
655 /**
656 * Create a input to filter changes by categories
657 *
658 * @param FormOptions $opts
659 * @return array
660 */
661 protected function categoryFilterForm( FormOptions $opts ) {
662 list( $label, $input ) = Xml::inputLabelSep( $this->msg( 'rc_categories' )->text(),
663 'categories', 'mw-categories', false, $opts['categories'] );
664
665 $input .= ' ' . Xml::checkLabel( $this->msg( 'rc_categories_any' )->text(),
666 'categories_any', 'mw-categories_any', $opts['categories_any'] );
667
668 return array( $label, $input );
669 }
670
671 /**
672 * Filter $rows by categories set in $opts
673 *
674 * @param array $rows Database rows
675 * @param FormOptions $opts
676 */
677 function filterByCategories( &$rows, FormOptions $opts ) {
678 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
679
680 if ( !count( $categories ) ) {
681 return;
682 }
683
684 # Filter categories
685 $cats = array();
686 foreach ( $categories as $cat ) {
687 $cat = trim( $cat );
688 if ( $cat == '' ) {
689 continue;
690 }
691 $cats[] = $cat;
692 }
693
694 # Filter articles
695 $articles = array();
696 $a2r = array();
697 $rowsarr = array();
698 foreach ( $rows as $k => $r ) {
699 $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
700 $id = $nt->getArticleID();
701 if ( $id == 0 ) {
702 continue; # Page might have been deleted...
703 }
704 if ( !in_array( $id, $articles ) ) {
705 $articles[] = $id;
706 }
707 if ( !isset( $a2r[$id] ) ) {
708 $a2r[$id] = array();
709 }
710 $a2r[$id][] = $k;
711 $rowsarr[$k] = $r;
712 }
713
714 # Shortcut?
715 if ( !count( $articles ) || !count( $cats ) ) {
716 return;
717 }
718
719 # Look up
720 $c = new Categoryfinder;
721 $c->seed( $articles, $cats, $opts['categories_any'] ? 'OR' : 'AND' );
722 $match = $c->run();
723
724 # Filter
725 $newrows = array();
726 foreach ( $match as $id ) {
727 foreach ( $a2r[$id] as $rev ) {
728 $k = $rev;
729 $newrows[$k] = $rowsarr[$k];
730 }
731 }
732 $rows = $newrows;
733 }
734
735 /**
736 * Makes change an option link which carries all the other options
737 *
738 * @param string $title Title
739 * @param array $override Options to override
740 * @param array $options Current options
741 * @param bool $active Whether to show the link in bold
742 * @return string
743 */
744 function makeOptionsLink( $title, $override, $options, $active = false ) {
745 $params = $override + $options;
746
747 // Bug 36524: false values have be converted to "0" otherwise
748 // wfArrayToCgi() will omit it them.
749 foreach ( $params as &$value ) {
750 if ( $value === false ) {
751 $value = '0';
752 }
753 }
754 unset( $value );
755
756 $text = htmlspecialchars( $title );
757 if ( $active ) {
758 $text = '<strong>' . $text . '</strong>';
759 }
760
761 return Linker::linkKnown( $this->getPageTitle(), $text, array(), $params );
762 }
763
764 /**
765 * Creates the options panel.
766 *
767 * @param array $defaults
768 * @param array $nondefaults
769 * @return string
770 */
771 function optionsPanel( $defaults, $nondefaults ) {
772 global $wgRCLinkLimits, $wgRCLinkDays;
773
774 $options = $nondefaults + $defaults;
775
776 $note = '';
777 $msg = $this->msg( 'rclegend' );
778 if ( !$msg->isDisabled() ) {
779 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
780 }
781
782 $lang = $this->getLanguage();
783 $user = $this->getUser();
784 if ( $options['from'] ) {
785 $note .= $this->msg( 'rcnotefrom' )->numParams( $options['limit'] )->params(
786 $lang->userTimeAndDate( $options['from'], $user ),
787 $lang->userDate( $options['from'], $user ),
788 $lang->userTime( $options['from'], $user ) )->parse() . '<br />';
789 }
790
791 # Sort data for display and make sure it's unique after we've added user data.
792 $linkLimits = $wgRCLinkLimits;
793 $linkLimits[] = $options['limit'];
794 sort( $linkLimits );
795 $linkLimits = array_unique( $linkLimits );
796
797 $linkDays = $wgRCLinkDays;
798 $linkDays[] = $options['days'];
799 sort( $linkDays );
800 $linkDays = array_unique( $linkDays );
801
802 // limit links
803 $cl = array();
804 foreach ( $linkLimits as $value ) {
805 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
806 array( 'limit' => $value ), $nondefaults, $value == $options['limit'] );
807 }
808 $cl = $lang->pipeList( $cl );
809
810 // day links, reset 'from' to none
811 $dl = array();
812 foreach ( $linkDays as $value ) {
813 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
814 array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] );
815 }
816 $dl = $lang->pipeList( $dl );
817
818 // show/hide links
819 $showhide = array( $this->msg( 'show' )->text(), $this->msg( 'hide' )->text() );
820 $filters = array(
821 'hideminor' => 'rcshowhideminor',
822 'hidebots' => 'rcshowhidebots',
823 'hideanons' => 'rcshowhideanons',
824 'hideliu' => 'rcshowhideliu',
825 'hidepatrolled' => 'rcshowhidepatr',
826 'hidemyself' => 'rcshowhidemine'
827 );
828 foreach ( $this->getCustomFilters() as $key => $params ) {
829 $filters[$key] = $params['msg'];
830 }
831 // Disable some if needed
832 if ( !$user->useRCPatrol() ) {
833 unset( $filters['hidepatrolled'] );
834 }
835
836 $links = array();
837 foreach ( $filters as $key => $msg ) {
838 $link = $this->makeOptionsLink( $showhide[1 - $options[$key]],
839 array( $key => 1 - $options[$key] ), $nondefaults );
840 $links[] = $this->msg( $msg )->rawParams( $link )->escaped();
841 }
842
843 // show from this onward link
844 $timestamp = wfTimestampNow();
845 $now = $lang->userTimeAndDate( $timestamp, $user );
846 $tl = $this->makeOptionsLink(
847 $now, array( 'from' => $timestamp ), $nondefaults
848 );
849
850 $rclinks = $this->msg( 'rclinks' )->rawParams( $cl, $dl, $lang->pipeList( $links ) )
851 ->parse();
852 $rclistfrom = $this->msg( 'rclistfrom' )->rawParams( $tl )->parse();
853
854 return "{$note}$rclinks<br />$rclistfrom";
855 }
856
857 /**
858 * Add page-specific modules.
859 */
860 protected function addModules() {
861 parent::addModules();
862 $out = $this->getOutput();
863 $out->addModules( 'mediawiki.special.recentchanges' );
864 }
865 }