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