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