Disable feed mode when including the page. I know that there is already r87705 to...
[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
300 $hidePatrol = $this->getUser()->useRCPatrol() && $opts['hidepatrolled'];
301 $hideLoggedInUsers = $opts['hideliu'] && !$forcebot;
302 $hideAnonymousUsers = $opts['hideanons'] && !$forcebot;
303
304 if( $opts['hideminor'] ) {
305 $conds['rc_minor'] = 0;
306 }
307 if( $opts['hidebots'] ) {
308 $conds['rc_bot'] = 0;
309 }
310 if( $hidePatrol ) {
311 $conds['rc_patrolled'] = 0;
312 }
313 if( $forcebot ) {
314 $conds['rc_bot'] = 1;
315 }
316 if( $hideLoggedInUsers ) {
317 $conds[] = 'rc_user = 0';
318 }
319 if( $hideAnonymousUsers ) {
320 $conds[] = 'rc_user != 0';
321 }
322
323 if( $opts['hidemyself'] ) {
324 if( $this->getUser()->getId() ) {
325 $conds[] = 'rc_user != ' . $dbr->addQuotes( $this->getUser()->getId() );
326 } else {
327 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $this->getUser()->getName() );
328 }
329 }
330
331 # Namespace filtering
332 if( $opts['namespace'] !== '' ) {
333 $namespaces[] = $opts['namespace'];
334
335 $inversionSuffix = $opts['invert'] ? '!' : '';
336
337 if( $opts['associated'] ) {
338 # namespace association (bug 2429)
339 $namespaces[] = MWNamespace::getAssociated( $opts['namespace'] );
340 }
341
342 $condition = $dbr->makeList(
343 array( 'rc_namespace' . $inversionSuffix
344 => $namespaces ),
345 LIST_AND
346 );
347
348 $conds[] = $condition;
349 }
350
351 return $conds;
352 }
353
354 /**
355 * Process the query
356 *
357 * @param $conds Array
358 * @param $opts FormOptions
359 * @return database result or false (for Recentchangeslinked only)
360 */
361 public function doMainQuery( $conds, $opts ) {
362 $tables = array( 'recentchanges' );
363 $join_conds = array();
364 $query_options = array(
365 'USE INDEX' => array( 'recentchanges' => 'rc_timestamp' )
366 );
367
368 $uid = $this->getUser()->getId();
369 $dbr = wfGetDB( DB_SLAVE );
370 $limit = $opts['limit'];
371 $namespace = $opts['namespace'];
372 $invert = $opts['invert'];
373 $associated = $opts['associated'];
374
375 $fields = array( $dbr->tableName( 'recentchanges' ) . '.*' ); // all rc columns
376 // JOIN on watchlist for users
377 if ( $uid ) {
378 $tables[] = 'watchlist';
379 $fields[] = 'wl_user';
380 $fields[] = 'wl_notificationtimestamp';
381 $join_conds['watchlist'] = array('LEFT JOIN',
382 "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace");
383 }
384 if ( $this->getUser()->isAllowed( 'rollback' ) ) {
385 $tables[] = 'page';
386 $fields[] = 'page_latest';
387 $join_conds['page'] = array('LEFT JOIN', 'rc_cur_id=page_id');
388 }
389 if ( !$this->including() ) {
390 // Tag stuff.
391 // Doesn't work when transcluding. See bug 23293
392 ChangeTags::modifyDisplayQuery(
393 $tables, $fields, $conds, $join_conds, $query_options,
394 $opts['tagfilter']
395 );
396 }
397
398 if ( !wfRunHooks( 'SpecialRecentChangesQuery',
399 array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ) ) )
400 {
401 return false;
402 }
403
404 // Don't use the new_namespace_time timestamp index if:
405 // (a) "All namespaces" selected
406 // (b) We want pages in more than one namespace (inverted/associated)
407 // (c) There is a tag to filter on (use tag index instead)
408 // (d) UNION + sort/limit is not an option for the DBMS
409 if( $namespace === ''
410 || ( $invert || $associated )
411 || $opts['tagfilter'] != ''
412 || !$dbr->unionSupportsOrderAndLimit() )
413 {
414 $res = $dbr->select( $tables, $fields, $conds, __METHOD__,
415 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) +
416 $query_options,
417 $join_conds );
418 // We have a new_namespace_time index! UNION over new=(0,1) and sort result set!
419 } else {
420 // New pages
421 $sqlNew = $dbr->selectSQLText(
422 $tables,
423 $fields,
424 array( 'rc_new' => 1 ) + $conds,
425 __METHOD__,
426 array(
427 'ORDER BY' => 'rc_timestamp DESC',
428 'LIMIT' => $limit,
429 'USE INDEX' => array( 'recentchanges' => 'new_name_timestamp' )
430 ),
431 $join_conds
432 );
433 // Old pages
434 $sqlOld = $dbr->selectSQLText(
435 $tables,
436 $fields,
437 array( 'rc_new' => 0 ) + $conds,
438 __METHOD__,
439 array(
440 'ORDER BY' => 'rc_timestamp DESC',
441 'LIMIT' => $limit,
442 'USE INDEX' => array( 'recentchanges' => 'new_name_timestamp' )
443 ),
444 $join_conds
445 );
446 # Join the two fast queries, and sort the result set
447 $sql = $dbr->unionQueries( array( $sqlNew, $sqlOld ), false ) .
448 ' ORDER BY rc_timestamp DESC';
449 $sql = $dbr->limitResult( $sql, $limit, false );
450 $res = $dbr->query( $sql, __METHOD__ );
451 }
452
453 return $res;
454 }
455
456 /**
457 * Send output to $wgOut, only called if not used feeds
458 *
459 * @param $rows Array of database rows
460 * @param $opts FormOptions
461 */
462 public function webOutput( $rows, $opts ) {
463 global $wgOut, $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
464 global $wgAllowCategorizedRecentChanges;
465
466 $limit = $opts['limit'];
467
468 if( !$this->including() ) {
469 // Output options box
470 $this->doHeader( $opts );
471 }
472
473 // And now for the content
474 $wgOut->setFeedAppendQuery( $this->getFeedQuery() );
475
476 if( $wgAllowCategorizedRecentChanges ) {
477 $this->filterByCategories( $rows, $opts );
478 }
479
480 $showWatcherCount = $wgRCShowWatchingUsers && $this->getUser()->getOption( 'shownumberswatching' );
481 $watcherCache = array();
482
483 $dbr = wfGetDB( DB_SLAVE );
484
485 $counter = 1;
486 $list = ChangesList::newFromUser( $this->getUser() );
487
488 $s = $list->beginRecentChangesList();
489 foreach( $rows as $obj ) {
490 if( $limit == 0 ) {
491 break;
492 }
493 $rc = RecentChange::newFromRow( $obj );
494 $rc->counter = $counter++;
495 # Check if the page has been updated since the last visit
496 if( $wgShowUpdatedMarker && !empty( $obj->wl_notificationtimestamp ) ) {
497 $rc->notificationtimestamp = ( $obj->rc_timestamp >= $obj->wl_notificationtimestamp );
498 } else {
499 $rc->notificationtimestamp = false; // Default
500 }
501 # Check the number of users watching the page
502 $rc->numberofWatchingusers = 0; // Default
503 if( $showWatcherCount && $obj->rc_namespace >= 0 ) {
504 if( !isset( $watcherCache[$obj->rc_namespace][$obj->rc_title] ) ) {
505 $watcherCache[$obj->rc_namespace][$obj->rc_title] =
506 $dbr->selectField(
507 'watchlist',
508 'COUNT(*)',
509 array(
510 'wl_namespace' => $obj->rc_namespace,
511 'wl_title' => $obj->rc_title,
512 ),
513 __METHOD__ . '-watchers'
514 );
515 }
516 $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
517 }
518 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
519 --$limit;
520 }
521 $s .= $list->endRecentChangesList();
522 $wgOut->addHTML( $s );
523 }
524
525 /**
526 * Get the query string to append to feed link URLs.
527 * This is overridden by RCL to add the target parameter
528 */
529 public function getFeedQuery() {
530 return false;
531 }
532
533 /**
534 * Return the text to be displayed above the changes
535 *
536 * @param $opts FormOptions
537 * @return String: XHTML
538 */
539 public function doHeader( $opts ) {
540 global $wgScript, $wgOut;
541
542 $this->setTopText( $wgOut, $opts );
543
544 $defaults = $opts->getAllValues();
545 $nondefaults = $opts->getChangedValues();
546 $opts->consumeValues( array(
547 'namespace', 'invert', 'associated', 'tagfilter',
548 'categories', 'categories_any'
549 ) );
550
551 $panel = array();
552 $panel[] = $this->optionsPanel( $defaults, $nondefaults );
553 $panel[] = '<hr />';
554
555 $extraOpts = $this->getExtraOptions( $opts );
556 $extraOptsCount = count( $extraOpts );
557 $count = 0;
558 $submit = ' ' . Xml::submitbutton( wfMsg( 'allpagessubmit' ) );
559
560 $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) );
561 foreach( $extraOpts as $optionRow ) {
562 # Add submit button to the last row only
563 ++$count;
564 $addSubmit = $count === $extraOptsCount ? $submit : '';
565
566 $out .= Xml::openElement( 'tr' );
567 if( is_array( $optionRow ) ) {
568 $out .= Xml::tags( 'td', array( 'class' => 'mw-label' ), $optionRow[0] );
569 $out .= Xml::tags( 'td', array( 'class' => 'mw-input' ), $optionRow[1] . $addSubmit );
570 } else {
571 $out .= Xml::tags( 'td', array( 'class' => 'mw-input', 'colspan' => 2 ), $optionRow . $addSubmit );
572 }
573 $out .= Xml::closeElement( 'tr' );
574 }
575 $out .= Xml::closeElement( 'table' );
576
577 $unconsumed = $opts->getUnconsumedValues();
578 foreach( $unconsumed as $key => $value ) {
579 $out .= Html::hidden( $key, $value );
580 }
581
582 $t = $this->getTitle();
583 $out .= Html::hidden( 'title', $t->getPrefixedText() );
584 $form = Xml::tags( 'form', array( 'action' => $wgScript ), $out );
585 $panel[] = $form;
586 $panelString = implode( "\n", $panel );
587
588 $wgOut->addHTML(
589 Xml::fieldset( wfMsg( 'recentchanges-legend' ), $panelString, array( 'class' => 'rcoptions' ) )
590 );
591
592 $this->setBottomText( $wgOut, $opts );
593 }
594
595 /**
596 * Get options to be displayed in a form
597 *
598 * @param $opts FormOptions
599 * @return Array
600 */
601 function getExtraOptions( $opts ) {
602 $extraOpts = array();
603 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
604
605 global $wgAllowCategorizedRecentChanges;
606 if( $wgAllowCategorizedRecentChanges ) {
607 $extraOpts['category'] = $this->categoryFilterForm( $opts );
608 }
609
610 $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
611 if ( count( $tagFilter ) ) {
612 $extraOpts['tagfilter'] = $tagFilter;
613 }
614
615 wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) );
616 return $extraOpts;
617 }
618
619 /**
620 * Send the text to be displayed above the options
621 *
622 * @param $out OutputPage
623 * @param $opts FormOptions
624 */
625 function setTopText( OutputPage $out, FormOptions $opts ) {
626 $out->addWikiText( wfMsgForContentNoTrans( 'recentchangestext' ) );
627 }
628
629 /**
630 * Send the text to be displayed after the options, for use in
631 * Recentchangeslinked
632 *
633 * @param $out OutputPage
634 * @param $opts FormOptions
635 */
636 function setBottomText( OutputPage $out, FormOptions $opts ) {}
637
638 /**
639 * Creates the choose namespace selection
640 *
641 * @todo Uses radio buttons (HASHAR)
642 * @param $opts FormOptions
643 * @return String
644 */
645 protected function namespaceFilterForm( FormOptions $opts ) {
646 $nsSelect = Xml::namespaceSelector( $opts['namespace'], '' );
647 $nsLabel = Xml::label( wfMsg( 'namespace' ), 'namespace' );
648 $invert = Xml::checkLabel(
649 wfMsg( 'invert' ), 'invert', 'nsinvert',
650 $opts['invert'],
651 array( 'title' => wfMsg( 'tooltip-invert' ) )
652 );
653 $associated = Xml::checkLabel(
654 wfMsg( 'namespace_association' ), 'associated', 'nsassociated',
655 $opts['associated'],
656 array( 'title' => wfMsg( 'tooltip-namespace_association' ) )
657 );
658 return array( $nsLabel, "$nsSelect $invert $associated" );
659 }
660
661 /**
662 * Create a input to filter changes by categories
663 *
664 * @param $opts FormOptions
665 * @return Array
666 */
667 protected function categoryFilterForm( FormOptions $opts ) {
668 list( $label, $input ) = Xml::inputLabelSep( wfMsg( 'rc_categories' ),
669 'categories', 'mw-categories', false, $opts['categories'] );
670
671 $input .= ' ' . Xml::checkLabel( wfMsg( 'rc_categories_any' ),
672 'categories_any', 'mw-categories_any', $opts['categories_any'] );
673
674 return array( $label, $input );
675 }
676
677 /**
678 * Filter $rows by categories set in $opts
679 *
680 * @param $rows Array of database rows
681 * @param $opts FormOptions
682 */
683 function filterByCategories( &$rows, FormOptions $opts ) {
684 $categories = array_map( 'trim', explode( '|' , $opts['categories'] ) );
685
686 if( !count( $categories ) ) {
687 return;
688 }
689
690 # Filter categories
691 $cats = array();
692 foreach( $categories as $cat ) {
693 $cat = trim( $cat );
694 if( $cat == '' ) {
695 continue;
696 }
697 $cats[] = $cat;
698 }
699
700 # Filter articles
701 $articles = array();
702 $a2r = array();
703 $rowsarr = array();
704 foreach( $rows as $k => $r ) {
705 $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
706 $id = $nt->getArticleID();
707 if( $id == 0 ) {
708 continue; # Page might have been deleted...
709 }
710 if( !in_array( $id, $articles ) ) {
711 $articles[] = $id;
712 }
713 if( !isset( $a2r[$id] ) ) {
714 $a2r[$id] = array();
715 }
716 $a2r[$id][] = $k;
717 $rowsarr[$k] = $r;
718 }
719
720 # Shortcut?
721 if( !count( $articles ) || !count( $cats ) ) {
722 return;
723 }
724
725 # Look up
726 $c = new Categoryfinder;
727 $c->seed( $articles, $cats, $opts['categories_any'] ? 'OR' : 'AND' );
728 $match = $c->run();
729
730 # Filter
731 $newrows = array();
732 foreach( $match as $id ) {
733 foreach( $a2r[$id] as $rev ) {
734 $k = $rev;
735 $newrows[$k] = $rowsarr[$k];
736 }
737 }
738 $rows = $newrows;
739 }
740
741 /**
742 * Makes change an option link which carries all the other options
743 *
744 * @param $title Title
745 * @param $override Array: options to override
746 * @param $options Array: current options
747 * @param $active Boolean: whether to show the link in bold
748 */
749 function makeOptionsLink( $title, $override, $options, $active = false ) {
750 $params = $override + $options;
751 if ( $active ) {
752 return $this->getSkin()->link(
753 $this->getTitle(),
754 '<strong>' . htmlspecialchars( $title ) . '</strong>',
755 array(), $params, array( 'known' ) );
756 } else {
757 return $this->getSkin()->link(
758 $this->getTitle(), htmlspecialchars( $title ), array(),
759 $params, array( 'known' ) );
760 }
761 }
762
763 /**
764 * Creates the options panel.
765 *
766 * @param $defaults Array
767 * @param $nondefaults Array
768 */
769 function optionsPanel( $defaults, $nondefaults ) {
770 global $wgLang, $wgRCLinkLimits, $wgRCLinkDays;
771
772 $options = $nondefaults + $defaults;
773
774 $note = '';
775 if( !wfEmptyMsg( 'rclegend' ) ) {
776 $note .= '<div class="mw-rclegend">' .
777 wfMsgExt( 'rclegend', array( 'parseinline' ) ) . "</div>\n";
778 }
779 if( $options['from'] ) {
780 $note .= wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
781 $wgLang->formatNum( $options['limit'] ),
782 $wgLang->timeanddate( $options['from'], true ),
783 $wgLang->date( $options['from'], true ),
784 $wgLang->time( $options['from'], true ) ) . '<br />';
785 }
786
787 # Sort data for display and make sure it's unique after we've added user data.
788 $wgRCLinkLimits[] = $options['limit'];
789 $wgRCLinkDays[] = $options['days'];
790 sort( $wgRCLinkLimits );
791 sort( $wgRCLinkDays );
792 $wgRCLinkLimits = array_unique( $wgRCLinkLimits );
793 $wgRCLinkDays = array_unique( $wgRCLinkDays );
794
795 // limit links
796 foreach( $wgRCLinkLimits as $value ) {
797 $cl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
798 array( 'limit' => $value ), $nondefaults, $value == $options['limit'] );
799 }
800 $cl = $wgLang->pipeList( $cl );
801
802 // day links, reset 'from' to none
803 foreach( $wgRCLinkDays as $value ) {
804 $dl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
805 array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] );
806 }
807 $dl = $wgLang->pipeList( $dl );
808
809
810 // show/hide links
811 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ) );
812 $filters = array(
813 'hideminor' => 'rcshowhideminor',
814 'hidebots' => 'rcshowhidebots',
815 'hideanons' => 'rcshowhideanons',
816 'hideliu' => 'rcshowhideliu',
817 'hidepatrolled' => 'rcshowhidepatr',
818 'hidemyself' => 'rcshowhidemine'
819 );
820 foreach ( $this->customFilters as $key => $params ) {
821 $filters[$key] = $params['msg'];
822 }
823 // Disable some if needed
824 if ( !$this->getUser()->useRCPatrol() ) {
825 unset( $filters['hidepatrolled'] );
826 }
827
828 $links = array();
829 foreach ( $filters as $key => $msg ) {
830 $link = $this->makeOptionsLink( $showhide[1 - $options[$key]],
831 array( $key => 1-$options[$key] ), $nondefaults );
832 $links[] = wfMsgHtml( $msg, $link );
833 }
834
835 // show from this onward link
836 $timestamp = wfTimestampNow();
837 $now = $wgLang->timeanddate( $timestamp, true );
838 $tl = $this->makeOptionsLink(
839 $now, array( 'from' => $timestamp ), $nondefaults
840 );
841
842 $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter' ),
843 $cl, $dl, $wgLang->pipeList( $links ) );
844 $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter' ), $tl );
845 return "{$note}$rclinks<br />$rclistfrom";
846 }
847
848 /**
849 * add javascript specific to the [[Special:RecentChanges]] page
850 */
851 function addRecentChangesJS() {
852 global $wgOut;
853 $wgOut->addModules( array(
854 'mediawiki.special.recentchanges',
855 ) );
856 }
857 }