Restore new_name_timestamp index usage in UNION. Since r51907, there was no reason...
[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 global $wgRequest;
115 $feedFormat = $wgRequest->getVal( 'feed' );
116 $this->rcOptions = $feedFormat ? $this->feedSetup() : $this->setup( $this->rcSubpage );
117 }
118 return $this->rcOptions;
119 }
120
121
122 /**
123 * Main execution point
124 *
125 * @param $subpage String
126 */
127 public function execute( $subpage ) {
128 global $wgRequest, $wgOut;
129 $this->rcSubpage = $subpage;
130 $feedFormat = $wgRequest->getVal( 'feed' );
131
132 # 10 seconds server-side caching max
133 $wgOut->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
144 // Fetch results, prepare a batch link existence check query
145 $conds = $this->buildMainQueryConds( $opts );
146 $rows = $this->doMainQuery( $conds, $opts );
147 if( $rows === false ){
148 if( !$this->including() ) {
149 $this->doHeader( $opts );
150 }
151 return;
152 }
153
154 if( !$feedFormat ) {
155 $batch = new LinkBatch;
156 foreach( $rows as $row ) {
157 $batch->add( NS_USER, $row->rc_user_text );
158 $batch->add( NS_USER_TALK, $row->rc_user_text );
159 $batch->add( $row->rc_namespace, $row->rc_title );
160 }
161 $batch->execute();
162 }
163 if( $feedFormat ) {
164 list( $changesFeed, $formatter ) = $this->getFeedObject( $feedFormat );
165 $changesFeed->execute( $formatter, $rows, $lastmod, $opts );
166 } else {
167 $this->webOutput( $rows, $opts );
168 }
169
170 $rows->free();
171 }
172
173 /**
174 * Return an array with a ChangesFeed object and ChannelFeed object
175 *
176 * @return Array
177 */
178 public function getFeedObject( $feedFormat ){
179 $changesFeed = new ChangesFeed( $feedFormat, 'rcfeed' );
180 $formatter = $changesFeed->getFeedObject(
181 wfMsgForContent( 'recentchanges' ),
182 wfMsgForContent( 'recentchanges-feed-description' ),
183 $this->getTitle()->getFullURL()
184 );
185 return array( $changesFeed, $formatter );
186 }
187
188 /**
189 * Process $par and put options found if $opts
190 * Mainly used when including the page
191 *
192 * @param $par String
193 * @param $opts FormOptions
194 */
195 public function parseParameters( $par, FormOptions $opts ) {
196 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
197 foreach( $bits as $bit ) {
198 if( 'hidebots' === $bit ) {
199 $opts['hidebots'] = true;
200 }
201 if( 'bots' === $bit ) {
202 $opts['hidebots'] = false;
203 }
204 if( 'hideminor' === $bit ) {
205 $opts['hideminor'] = true;
206 }
207 if( 'minor' === $bit ) {
208 $opts['hideminor'] = false;
209 }
210 if( 'hideliu' === $bit ) {
211 $opts['hideliu'] = true;
212 }
213 if( 'hidepatrolled' === $bit ) {
214 $opts['hidepatrolled'] = true;
215 }
216 if( 'hideanons' === $bit ) {
217 $opts['hideanons'] = true;
218 }
219 if( 'hidemyself' === $bit ) {
220 $opts['hidemyself'] = true;
221 }
222
223 if( is_numeric( $bit ) ) {
224 $opts['limit'] = $bit;
225 }
226
227 $m = array();
228 if( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
229 $opts['limit'] = $m[1];
230 }
231 if( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
232 $opts['days'] = $m[1];
233 }
234 }
235 }
236
237 /**
238 * Get last modified date, for client caching
239 * Don't use this if we are using the patrol feature, patrol changes don't
240 * update the timestamp
241 *
242 * @param $feedFormat String
243 * @return String or false
244 */
245 public function checkLastModified( $feedFormat ) {
246 $dbr = wfGetDB( DB_SLAVE );
247 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
248 if( $feedFormat || !$this->getUser()->useRCPatrol() ) {
249 if( $lastmod && $this->getOutput()->checkLastModified( $lastmod ) ) {
250 # Client cache fresh and headers sent, nothing more to do.
251 return false;
252 }
253 }
254 return $lastmod;
255 }
256
257 /**
258 * Return an array of conditions depending of options set in $opts
259 *
260 * @param $opts FormOptions
261 * @return array
262 */
263 public function buildMainQueryConds( FormOptions $opts ) {
264 $dbr = wfGetDB( DB_SLAVE );
265 $conds = array();
266
267 # It makes no sense to hide both anons and logged-in users
268 # Where this occurs, force anons to be shown
269 $forcebot = false;
270 if( $opts['hideanons'] && $opts['hideliu'] ){
271 # Check if the user wants to show bots only
272 if( $opts['hidebots'] ){
273 $opts['hideanons'] = false;
274 } else {
275 $forcebot = true;
276 $opts['hidebots'] = false;
277 }
278 }
279
280 // Calculate cutoff
281 $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
282 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
283 $cutoff = $dbr->timestamp( $cutoff_unixtime );
284
285 $fromValid = preg_match('/^[0-9]{14}$/', $opts['from']);
286 if( $fromValid && $opts['from'] > wfTimestamp(TS_MW,$cutoff) ) {
287 $cutoff = $dbr->timestamp($opts['from']);
288 } else {
289 $opts->reset( 'from' );
290 }
291
292 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
293
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 $wgOut, 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 $wgOut, $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
459 global $wgAllowCategorizedRecentChanges;
460
461 $limit = $opts['limit'];
462
463 if( !$this->including() ) {
464 // Output options box
465 $this->doHeader( $opts );
466 }
467
468 // And now for the content
469 $wgOut->setFeedAppendQuery( $this->getFeedQuery() );
470
471 if( $wgAllowCategorizedRecentChanges ) {
472 $this->filterByCategories( $rows, $opts );
473 }
474
475 $showWatcherCount = $wgRCShowWatchingUsers && $this->getUser()->getOption( 'shownumberswatching' );
476 $watcherCache = array();
477
478 $dbr = wfGetDB( DB_SLAVE );
479
480 $counter = 1;
481 $list = ChangesList::newFromUser( $this->getUser() );
482
483 $s = $list->beginRecentChangesList();
484 foreach( $rows as $obj ) {
485 if( $limit == 0 ) {
486 break;
487 }
488 $rc = RecentChange::newFromRow( $obj );
489 $rc->counter = $counter++;
490 # Check if the page has been updated since the last visit
491 if( $wgShowUpdatedMarker && !empty( $obj->wl_notificationtimestamp ) ) {
492 $rc->notificationtimestamp = ( $obj->rc_timestamp >= $obj->wl_notificationtimestamp );
493 } else {
494 $rc->notificationtimestamp = false; // Default
495 }
496 # Check the number of users watching the page
497 $rc->numberofWatchingusers = 0; // Default
498 if( $showWatcherCount && $obj->rc_namespace >= 0 ) {
499 if( !isset( $watcherCache[$obj->rc_namespace][$obj->rc_title] ) ) {
500 $watcherCache[$obj->rc_namespace][$obj->rc_title] =
501 $dbr->selectField(
502 'watchlist',
503 'COUNT(*)',
504 array(
505 'wl_namespace' => $obj->rc_namespace,
506 'wl_title' => $obj->rc_title,
507 ),
508 __METHOD__ . '-watchers'
509 );
510 }
511 $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
512 }
513 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
514 --$limit;
515 }
516 $s .= $list->endRecentChangesList();
517 $wgOut->addHTML( $s );
518 }
519
520 /**
521 * Get the query string to append to feed link URLs.
522 * This is overridden by RCL to add the target parameter
523 */
524 public function getFeedQuery() {
525 return false;
526 }
527
528 /**
529 * Return the text to be displayed above the changes
530 *
531 * @param $opts FormOptions
532 * @return String: XHTML
533 */
534 public function doHeader( $opts ) {
535 global $wgScript, $wgOut;
536
537 $this->setTopText( $wgOut, $opts );
538
539 $defaults = $opts->getAllValues();
540 $nondefaults = $opts->getChangedValues();
541 $opts->consumeValues( array(
542 'namespace', 'invert', 'associated', 'tagfilter',
543 'categories', 'categories_any'
544 ) );
545
546 $panel = array();
547 $panel[] = $this->optionsPanel( $defaults, $nondefaults );
548 $panel[] = '<hr />';
549
550 $extraOpts = $this->getExtraOptions( $opts );
551 $extraOptsCount = count( $extraOpts );
552 $count = 0;
553 $submit = ' ' . Xml::submitbutton( wfMsg( 'allpagessubmit' ) );
554
555 $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) );
556 foreach( $extraOpts as $optionRow ) {
557 # Add submit button to the last row only
558 ++$count;
559 $addSubmit = $count === $extraOptsCount ? $submit : '';
560
561 $out .= Xml::openElement( 'tr' );
562 if( is_array( $optionRow ) ) {
563 $out .= Xml::tags( 'td', array( 'class' => 'mw-label' ), $optionRow[0] );
564 $out .= Xml::tags( 'td', array( 'class' => 'mw-input' ), $optionRow[1] . $addSubmit );
565 } else {
566 $out .= Xml::tags( 'td', array( 'class' => 'mw-input', 'colspan' => 2 ), $optionRow . $addSubmit );
567 }
568 $out .= Xml::closeElement( 'tr' );
569 }
570 $out .= Xml::closeElement( 'table' );
571
572 $unconsumed = $opts->getUnconsumedValues();
573 foreach( $unconsumed as $key => $value ) {
574 $out .= Html::hidden( $key, $value );
575 }
576
577 $t = $this->getTitle();
578 $out .= Html::hidden( 'title', $t->getPrefixedText() );
579 $form = Xml::tags( 'form', array( 'action' => $wgScript ), $out );
580 $panel[] = $form;
581 $panelString = implode( "\n", $panel );
582
583 $wgOut->addHTML(
584 Xml::fieldset( wfMsg( 'recentchanges-legend' ), $panelString, array( 'class' => 'rcoptions' ) )
585 );
586
587 $this->setBottomText( $wgOut, $opts );
588 }
589
590 /**
591 * Get options to be displayed in a form
592 *
593 * @param $opts FormOptions
594 * @return Array
595 */
596 function getExtraOptions( $opts ) {
597 $extraOpts = array();
598 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
599
600 global $wgAllowCategorizedRecentChanges;
601 if( $wgAllowCategorizedRecentChanges ) {
602 $extraOpts['category'] = $this->categoryFilterForm( $opts );
603 }
604
605 $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
606 if ( count( $tagFilter ) ) {
607 $extraOpts['tagfilter'] = $tagFilter;
608 }
609
610 wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) );
611 return $extraOpts;
612 }
613
614 /**
615 * Send the text to be displayed above the options
616 *
617 * @param $out OutputPage
618 * @param $opts FormOptions
619 */
620 function setTopText( OutputPage $out, FormOptions $opts ) {
621 $out->addWikiText( wfMsgForContentNoTrans( 'recentchangestext' ) );
622 }
623
624 /**
625 * Send the text to be displayed after the options, for use in
626 * Recentchangeslinked
627 *
628 * @param $out OutputPage
629 * @param $opts FormOptions
630 */
631 function setBottomText( OutputPage $out, FormOptions $opts ) {}
632
633 /**
634 * Creates the choose namespace selection
635 *
636 * @todo Uses radio buttons (HASHAR)
637 * @param $opts FormOptions
638 * @return String
639 */
640 protected function namespaceFilterForm( FormOptions $opts ) {
641 $nsSelect = Xml::namespaceSelector( $opts['namespace'], '' );
642 $nsLabel = Xml::label( wfMsg( 'namespace' ), 'namespace' );
643 $invert = Xml::checkLabel(
644 wfMsg( 'invert' ), 'invert', 'nsinvert',
645 $opts['invert'],
646 array( 'title' => wfMsg( 'tooltip-invert' ) )
647 );
648 $associated = Xml::checkLabel(
649 wfMsg( 'namespace_association' ), 'associated', 'nsassociated',
650 $opts['associated'],
651 array( 'title' => wfMsg( 'tooltip-namespace_association' ) )
652 );
653 return array( $nsLabel, "$nsSelect $invert $associated" );
654 }
655
656 /**
657 * Create a input to filter changes by categories
658 *
659 * @param $opts FormOptions
660 * @return Array
661 */
662 protected function categoryFilterForm( FormOptions $opts ) {
663 list( $label, $input ) = Xml::inputLabelSep( wfMsg( 'rc_categories' ),
664 'categories', 'mw-categories', false, $opts['categories'] );
665
666 $input .= ' ' . Xml::checkLabel( wfMsg( 'rc_categories_any' ),
667 'categories_any', 'mw-categories_any', $opts['categories_any'] );
668
669 return array( $label, $input );
670 }
671
672 /**
673 * Filter $rows by categories set in $opts
674 *
675 * @param $rows Array of database rows
676 * @param $opts FormOptions
677 */
678 function filterByCategories( &$rows, FormOptions $opts ) {
679 $categories = array_map( 'trim', explode( '|' , $opts['categories'] ) );
680
681 if( !count( $categories ) ) {
682 return;
683 }
684
685 # Filter categories
686 $cats = array();
687 foreach( $categories as $cat ) {
688 $cat = trim( $cat );
689 if( $cat == '' ) {
690 continue;
691 }
692 $cats[] = $cat;
693 }
694
695 # Filter articles
696 $articles = array();
697 $a2r = array();
698 $rowsarr = array();
699 foreach( $rows as $k => $r ) {
700 $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
701 $id = $nt->getArticleID();
702 if( $id == 0 ) {
703 continue; # Page might have been deleted...
704 }
705 if( !in_array( $id, $articles ) ) {
706 $articles[] = $id;
707 }
708 if( !isset( $a2r[$id] ) ) {
709 $a2r[$id] = array();
710 }
711 $a2r[$id][] = $k;
712 $rowsarr[$k] = $r;
713 }
714
715 # Shortcut?
716 if( !count( $articles ) || !count( $cats ) ) {
717 return;
718 }
719
720 # Look up
721 $c = new Categoryfinder;
722 $c->seed( $articles, $cats, $opts['categories_any'] ? 'OR' : 'AND' );
723 $match = $c->run();
724
725 # Filter
726 $newrows = array();
727 foreach( $match as $id ) {
728 foreach( $a2r[$id] as $rev ) {
729 $k = $rev;
730 $newrows[$k] = $rowsarr[$k];
731 }
732 }
733 $rows = $newrows;
734 }
735
736 /**
737 * Makes change an option link which carries all the other options
738 *
739 * @param $title Title
740 * @param $override Array: options to override
741 * @param $options Array: current options
742 * @param $active Boolean: whether to show the link in bold
743 */
744 function makeOptionsLink( $title, $override, $options, $active = false ) {
745 $params = $override + $options;
746 if ( $active ) {
747 return $this->getSkin()->link(
748 $this->getTitle(),
749 '<strong>' . htmlspecialchars( $title ) . '</strong>',
750 array(), $params, array( 'known' ) );
751 } else {
752 return $this->getSkin()->link(
753 $this->getTitle(), htmlspecialchars( $title ), array(),
754 $params, array( 'known' ) );
755 }
756 }
757
758 /**
759 * Creates the options panel.
760 *
761 * @param $defaults Array
762 * @param $nondefaults Array
763 */
764 function optionsPanel( $defaults, $nondefaults ) {
765 global $wgLang, $wgRCLinkLimits, $wgRCLinkDays;
766
767 $options = $nondefaults + $defaults;
768
769 $note = '';
770 if( !wfEmptyMsg( 'rclegend' ) ) {
771 $note .= '<div class="mw-rclegend">' .
772 wfMsgExt( 'rclegend', array( 'parseinline' ) ) . "</div>\n";
773 }
774 if( $options['from'] ) {
775 $note .= wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
776 $wgLang->formatNum( $options['limit'] ),
777 $wgLang->timeanddate( $options['from'], true ),
778 $wgLang->date( $options['from'], true ),
779 $wgLang->time( $options['from'], true ) ) . '<br />';
780 }
781
782 # Sort data for display and make sure it's unique after we've added user data.
783 $wgRCLinkLimits[] = $options['limit'];
784 $wgRCLinkDays[] = $options['days'];
785 sort( $wgRCLinkLimits );
786 sort( $wgRCLinkDays );
787 $wgRCLinkLimits = array_unique( $wgRCLinkLimits );
788 $wgRCLinkDays = array_unique( $wgRCLinkDays );
789
790 // limit links
791 foreach( $wgRCLinkLimits as $value ) {
792 $cl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
793 array( 'limit' => $value ), $nondefaults, $value == $options['limit'] );
794 }
795 $cl = $wgLang->pipeList( $cl );
796
797 // day links, reset 'from' to none
798 foreach( $wgRCLinkDays as $value ) {
799 $dl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
800 array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] );
801 }
802 $dl = $wgLang->pipeList( $dl );
803
804
805 // show/hide links
806 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ) );
807 $filters = array(
808 'hideminor' => 'rcshowhideminor',
809 'hidebots' => 'rcshowhidebots',
810 'hideanons' => 'rcshowhideanons',
811 'hideliu' => 'rcshowhideliu',
812 'hidepatrolled' => 'rcshowhidepatr',
813 'hidemyself' => 'rcshowhidemine'
814 );
815 foreach ( $this->customFilters as $key => $params ) {
816 $filters[$key] = $params['msg'];
817 }
818 // Disable some if needed
819 if ( !$this->getUser()->useRCPatrol() ) {
820 unset( $filters['hidepatrolled'] );
821 }
822
823 $links = array();
824 foreach ( $filters as $key => $msg ) {
825 $link = $this->makeOptionsLink( $showhide[1 - $options[$key]],
826 array( $key => 1-$options[$key] ), $nondefaults );
827 $links[] = wfMsgHtml( $msg, $link );
828 }
829
830 // show from this onward link
831 $timestamp = wfTimestampNow();
832 $now = $wgLang->timeanddate( $timestamp, true );
833 $tl = $this->makeOptionsLink(
834 $now, array( 'from' => $timestamp ), $nondefaults
835 );
836
837 $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter' ),
838 $cl, $dl, $wgLang->pipeList( $links ) );
839 $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter' ), $tl );
840 return "{$note}$rclinks<br />$rclistfrom";
841 }
842 }