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