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