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