dced986b594854665f4885720e03918eeecb39ce
[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 global $wgUser;
43 $opts = new FormOptions();
44
45 $opts->add( 'days', (int)$wgUser->getOption( 'rcdays' ) );
46 $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) );
47 $opts->add( 'from', '' );
48
49 $opts->add( 'hideminor', $wgUser->getBoolOption( 'hideminor' ) );
50 $opts->add( 'hidebots', true );
51 $opts->add( 'hideanons', false );
52 $opts->add( 'hideliu', false );
53 $opts->add( 'hidepatrolled', $wgUser->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;
73
74 $opts = $this->getDefaultOptions();
75 $opts->fetchValuesFromRequest( $wgRequest );
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 ) $opts['hidebots'] = true;
190 if( 'bots' === $bit ) $opts['hidebots'] = false;
191 if( 'hideminor' === $bit ) $opts['hideminor'] = true;
192 if( 'minor' === $bit ) $opts['hideminor'] = false;
193 if( 'hideliu' === $bit ) $opts['hideliu'] = true;
194 if( 'hidepatrolled' === $bit ) $opts['hidepatrolled'] = true;
195 if( 'hideanons' === $bit ) $opts['hideanons'] = true;
196 if( 'hidemyself' === $bit ) $opts['hidemyself'] = true;
197
198 if( is_numeric( $bit ) ) $opts['limit'] = $bit;
199
200 $m = array();
201 if( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) $opts['limit'] = $m[1];
202 if( preg_match( '/^days=(\d+)$/', $bit, $m ) ) $opts['days'] = $m[1];
203 }
204 }
205
206 /**
207 * Get last modified date, for client caching
208 * Don't use this if we are using the patrol feature, patrol changes don't
209 * update the timestamp
210 *
211 * @param $feedFormat String
212 * @return String or false
213 */
214 public function checkLastModified( $feedFormat ) {
215 global $wgOut, $wgUser;
216 $dbr = wfGetDB( DB_SLAVE );
217 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
218 if( $feedFormat || !$wgUser->useRCPatrol() ) {
219 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ) {
220 # Client cache fresh and headers sent, nothing more to do.
221 return false;
222 }
223 }
224 return $lastmod;
225 }
226
227 /**
228 * Return an array of conditions depending of options set in $opts
229 *
230 * @param $opts FormOptions
231 * @return array
232 */
233 public function buildMainQueryConds( FormOptions $opts ) {
234 global $wgUser;
235
236 $dbr = wfGetDB( DB_SLAVE );
237 $conds = array();
238
239 # It makes no sense to hide both anons and logged-in users
240 # Where this occurs, force anons to be shown
241 $forcebot = false;
242 if( $opts['hideanons'] && $opts['hideliu'] ){
243 # Check if the user wants to show bots only
244 if( $opts['hidebots'] ){
245 $opts['hideanons'] = false;
246 } else {
247 $forcebot = true;
248 $opts['hidebots'] = false;
249 }
250 }
251
252 // Calculate cutoff
253 $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
254 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
255 $cutoff = $dbr->timestamp( $cutoff_unixtime );
256
257 $fromValid = preg_match('/^[0-9]{14}$/', $opts['from']);
258 if( $fromValid && $opts['from'] > wfTimestamp(TS_MW,$cutoff) ) {
259 $cutoff = $dbr->timestamp($opts['from']);
260 } else {
261 $opts->reset( 'from' );
262 }
263
264 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
265
266
267 $hidePatrol = $wgUser->useRCPatrol() && $opts['hidepatrolled'];
268 $hideLoggedInUsers = $opts['hideliu'] && !$forcebot;
269 $hideAnonymousUsers = $opts['hideanons'] && !$forcebot;
270
271 if( $opts['hideminor'] ) $conds['rc_minor'] = 0;
272 if( $opts['hidebots'] ) $conds['rc_bot'] = 0;
273 if( $hidePatrol ) $conds['rc_patrolled'] = 0;
274 if( $forcebot ) $conds['rc_bot'] = 1;
275 if( $hideLoggedInUsers ) $conds[] = 'rc_user = 0';
276 if( $hideAnonymousUsers ) $conds[] = 'rc_user != 0';
277
278 if( $opts['hidemyself'] ) {
279 if( $wgUser->getId() ) {
280 $conds[] = 'rc_user != ' . $dbr->addQuotes( $wgUser->getId() );
281 } else {
282 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $wgUser->getName() );
283 }
284 }
285
286 # Namespace filtering
287 if( $opts['namespace'] !== '' ) {
288 $selectedNS = $dbr->addQuotes( $opts['namespace'] );
289 $operator = $opts['invert'] ? '!=' : '=';
290 $boolean = $opts['invert'] ? 'AND' : 'OR';
291
292 # namespace association (bug 2429)
293 if( !$opts['associated'] ) {
294 $condition = "rc_namespace $operator $selectedNS";
295 } else {
296 # Also add the associated namespace
297 $associatedNS = $dbr->addQuotes(
298 MWNamespace::getAssociated( $opts['namespace'] )
299 );
300 $condition = "(rc_namespace $operator $selectedNS "
301 . $boolean
302 . " rc_namespace $operator $associatedNS)";
303 }
304
305 $conds[] = $condition;
306 }
307 return $conds;
308 }
309
310 /**
311 * Process the query
312 *
313 * @param $conds Array
314 * @param $opts FormOptions
315 * @return database result or false (for Recentchangeslinked only)
316 */
317 public function doMainQuery( $conds, $opts ) {
318 global $wgUser;
319
320 $tables = array( 'recentchanges' );
321 $join_conds = array();
322 $query_options = array( 'USE INDEX' => array('recentchanges' => 'rc_timestamp') );
323
324 $uid = $wgUser->getId();
325 $dbr = wfGetDB( DB_SLAVE );
326 $limit = $opts['limit'];
327 $namespace = $opts['namespace'];
328 $select = '*';
329 $invert = $opts['invert'];
330
331 // JOIN on watchlist for users
332 if( $uid ) {
333 $tables[] = 'watchlist';
334 $join_conds['watchlist'] = array('LEFT JOIN',
335 "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace");
336 }
337 if ($wgUser->isAllowed("rollback")) {
338 $tables[] = 'page';
339 $join_conds['page'] = array('LEFT JOIN', 'rc_cur_id=page_id');
340 }
341 if ( !$this->including() ) {
342 // Tag stuff.
343 // Doesn't work when transcluding. See bug 23293
344 $fields = array();
345 // Fields are * in this case, so let the function modify an empty array to keep it happy.
346 ChangeTags::modifyDisplayQuery(
347 $tables, $fields, $conds, $join_conds, $query_options, $opts['tagfilter']
348 );
349 }
350
351 if ( !wfRunHooks( 'SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$select ) ) )
352 return false;
353
354 // Don't use the new_namespace_time timestamp index if:
355 // (a) "All namespaces" selected
356 // (b) We want all pages NOT in a certain namespaces (inverted)
357 // (c) There is a tag to filter on (use tag index instead)
358 // (d) UNION + sort/limit is not an option for the DBMS
359 if( is_null( $namespace )
360 || ( $invert && !is_null( $namespace ) )
361 || $opts['tagfilter'] != ''
362 || !$dbr->unionSupportsOrderAndLimit() )
363 {
364 $res = $dbr->select( $tables, '*', $conds, __METHOD__,
365 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) +
366 $query_options,
367 $join_conds );
368 // We have a new_namespace_time index! UNION over new=(0,1) and sort result set!
369 } else {
370 // New pages
371 $sqlNew = $dbr->selectSQLText( $tables, $select,
372 array( 'rc_new' => 1 ) + $conds,
373 __METHOD__,
374 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
375 'USE INDEX' => array('recentchanges' => 'rc_timestamp') ),
376 $join_conds );
377 // Old pages
378 $sqlOld = $dbr->selectSQLText( $tables, '*',
379 array( 'rc_new' => 0 ) + $conds,
380 __METHOD__,
381 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
382 'USE INDEX' => array('recentchanges' => 'rc_timestamp') ),
383 $join_conds );
384 # Join the two fast queries, and sort the result set
385 $sql = $dbr->unionQueries(array($sqlNew, $sqlOld), false).' ORDER BY rc_timestamp DESC';
386 $sql = $dbr->limitResult($sql, $limit, false);
387 $res = $dbr->query( $sql, __METHOD__ );
388 }
389
390 return $res;
391 }
392
393 /**
394 * Send output to $wgOut, only called if not used feeds
395 *
396 * @param $rows Array of database rows
397 * @param $opts FormOptions
398 */
399 public function webOutput( $rows, $opts ) {
400 global $wgOut, $wgUser, $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
401 global $wgAllowCategorizedRecentChanges;
402
403 $limit = $opts['limit'];
404
405 if( !$this->including() ) {
406 // Output options box
407 $this->doHeader( $opts );
408 }
409
410 // And now for the content
411 $wgOut->setFeedAppendQuery( $this->getFeedQuery() );
412
413 if( $wgAllowCategorizedRecentChanges ) {
414 $this->filterByCategories( $rows, $opts );
415 }
416
417 $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' );
418 $watcherCache = array();
419
420 $dbr = wfGetDB( DB_SLAVE );
421
422 $counter = 1;
423 $list = ChangesList::newFromUser( $wgUser );
424
425 $s = $list->beginRecentChangesList();
426 foreach( $rows as $obj ) {
427 if( $limit == 0 ) break;
428 $rc = RecentChange::newFromRow( $obj );
429 $rc->counter = $counter++;
430 # Check if the page has been updated since the last visit
431 if( $wgShowUpdatedMarker && !empty($obj->wl_notificationtimestamp) ) {
432 $rc->notificationtimestamp = ($obj->rc_timestamp >= $obj->wl_notificationtimestamp);
433 } else {
434 $rc->notificationtimestamp = false; // Default
435 }
436 # Check the number of users watching the page
437 $rc->numberofWatchingusers = 0; // Default
438 if( $showWatcherCount && $obj->rc_namespace >= 0 ) {
439 if( !isset($watcherCache[$obj->rc_namespace][$obj->rc_title]) ) {
440 $watcherCache[$obj->rc_namespace][$obj->rc_title] =
441 $dbr->selectField( 'watchlist',
442 'COUNT(*)',
443 array(
444 'wl_namespace' => $obj->rc_namespace,
445 'wl_title' => $obj->rc_title,
446 ),
447 __METHOD__ . '-watchers' );
448 }
449 $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
450 }
451 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
452 --$limit;
453 }
454 $s .= $list->endRecentChangesList();
455 $wgOut->addHTML( $s );
456 }
457
458 /**
459 * Get the query string to append to feed link URLs.
460 * This is overridden by RCL to add the target parameter
461 */
462 public function getFeedQuery() {
463 return false;
464 }
465
466 /**
467 * Return the text to be displayed above the changes
468 *
469 * @param $opts FormOptions
470 * @return String: XHTML
471 */
472 public function doHeader( $opts ) {
473 global $wgScript, $wgOut;
474
475 $this->setTopText( $wgOut, $opts );
476
477 $defaults = $opts->getAllValues();
478 $nondefaults = $opts->getChangedValues();
479 $opts->consumeValues( array( 'namespace', 'invert', 'associated', 'tagfilter',
480 'categories', 'categories_any' ) );
481
482 $panel = array();
483 $panel[] = $this->optionsPanel( $defaults, $nondefaults );
484 $panel[] = '<hr />';
485
486 $extraOpts = $this->getExtraOptions( $opts );
487 $extraOptsCount = count( $extraOpts );
488 $count = 0;
489 $submit = ' ' . Xml::submitbutton( wfMsg( 'allpagessubmit' ) );
490
491 $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) );
492 foreach( $extraOpts as $optionRow ) {
493 # Add submit button to the last row only
494 ++$count;
495 $addSubmit = $count === $extraOptsCount ? $submit : '';
496
497 $out .= Xml::openElement( 'tr' );
498 if( is_array( $optionRow ) ) {
499 $out .= Xml::tags( 'td', array( 'class' => 'mw-label' ), $optionRow[0] );
500 $out .= Xml::tags( 'td', array( 'class' => 'mw-input' ), $optionRow[1] . $addSubmit );
501 } else {
502 $out .= Xml::tags( 'td', array( 'class' => 'mw-input', 'colspan' => 2 ), $optionRow . $addSubmit );
503 }
504 $out .= Xml::closeElement( 'tr' );
505 }
506 $out .= Xml::closeElement( 'table' );
507
508 $unconsumed = $opts->getUnconsumedValues();
509 foreach( $unconsumed as $key => $value ) {
510 $out .= Html::hidden( $key, $value );
511 }
512
513 $t = $this->getTitle();
514 $out .= Html::hidden( 'title', $t->getPrefixedText() );
515 $form = Xml::tags( 'form', array( 'action' => $wgScript ), $out );
516 $panel[] = $form;
517 $panelString = implode( "\n", $panel );
518
519 $wgOut->addHTML(
520 Xml::fieldset( wfMsg( 'recentchanges-legend' ), $panelString, array( 'class' => 'rcoptions' ) )
521 );
522
523 $this->setBottomText( $wgOut, $opts );
524 }
525
526 /**
527 * Get options to be displayed in a form
528 *
529 * @param $opts FormOptions
530 * @return Array
531 */
532 function getExtraOptions( $opts ){
533 $extraOpts = array();
534 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
535
536 global $wgAllowCategorizedRecentChanges;
537 if( $wgAllowCategorizedRecentChanges ) {
538 $extraOpts['category'] = $this->categoryFilterForm( $opts );
539 }
540
541 $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
542 if ( count($tagFilter) )
543 $extraOpts['tagfilter'] = $tagFilter;
544
545 wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) );
546 return $extraOpts;
547 }
548
549 /**
550 * Send the text to be displayed above the options
551 *
552 * @param $out OutputPage
553 * @param $opts FormOptions
554 */
555 function setTopText( OutputPage $out, FormOptions $opts ){
556 $out->addWikiText( wfMsgForContentNoTrans( 'recentchangestext' ) );
557 }
558
559 /**
560 * Send the text to be displayed after the options, for use in
561 * Recentchangeslinked
562 *
563 * @param $out OutputPage
564 * @param $opts FormOptions
565 */
566 function setBottomText( OutputPage $out, FormOptions $opts ){}
567
568 /**
569 * Creates the choose namespace selection
570 *
571 * @todo Uses radio buttons (HASHAR)
572 * @param $opts FormOptions
573 * @return String
574 */
575 protected function namespaceFilterForm( FormOptions $opts ) {
576 $nsSelect = Xml::namespaceSelector( $opts['namespace'], '' );
577 $nsLabel = Xml::label( wfMsg('namespace'), 'namespace' );
578 $invert = Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $opts['invert'] );
579 $associated = Xml::checkLabel( wfMsg('namespace_association'), 'associated', 'nsassociated', $opts['associated'] );
580 return array( $nsLabel, "$nsSelect $invert $associated" );
581 }
582
583 /**
584 * Create a input to filter changes by categories
585 *
586 * @param $opts FormOptions
587 * @return Array
588 */
589 protected function categoryFilterForm( FormOptions $opts ) {
590 list( $label, $input ) = Xml::inputLabelSep( wfMsg('rc_categories'),
591 'categories', 'mw-categories', false, $opts['categories'] );
592
593 $input .= ' ' . Xml::checkLabel( wfMsg('rc_categories_any'),
594 'categories_any', 'mw-categories_any', $opts['categories_any'] );
595
596 return array( $label, $input );
597 }
598
599 /**
600 * Filter $rows by categories set in $opts
601 *
602 * @param $rows Array of database rows
603 * @param $opts FormOptions
604 */
605 function filterByCategories( &$rows, FormOptions $opts ) {
606 $categories = array_map( 'trim', explode( '|' , $opts['categories'] ) );
607
608 if( !count( $categories ) ) {
609 return;
610 }
611
612 # Filter categories
613 $cats = array();
614 foreach( $categories as $cat ) {
615 $cat = trim( $cat );
616 if( $cat == '' ) continue;
617 $cats[] = $cat;
618 }
619
620 # Filter articles
621 $articles = array();
622 $a2r = array();
623 $rowsarr = array();
624 foreach( $rows AS $k => $r ) {
625 $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
626 $id = $nt->getArticleID();
627 if( $id == 0 ) continue; # Page might have been deleted...
628 if( !in_array( $id, $articles ) ) {
629 $articles[] = $id;
630 }
631 if( !isset( $a2r[$id] ) ) {
632 $a2r[$id] = array();
633 }
634 $a2r[$id][] = $k;
635 $rowsarr[$k] = $r;
636 }
637
638 # Shortcut?
639 if( !count( $articles ) || !count( $cats ) )
640 return ;
641
642 # Look up
643 $c = new Categoryfinder;
644 $c->seed( $articles, $cats, $opts['categories_any'] ? "OR" : "AND" ) ;
645 $match = $c->run();
646
647 # Filter
648 $newrows = array();
649 foreach( $match AS $id ) {
650 foreach( $a2r[$id] AS $rev ) {
651 $k = $rev;
652 $newrows[$k] = $rowsarr[$k];
653 }
654 }
655 $rows = $newrows;
656 }
657
658 /**
659 * Makes change an option link which carries all the other options
660 *
661 * @param $title Title
662 * @param $override Array: options to override
663 * @param $options Array: current options
664 * @param $active Boolean: whether to show the link in bold
665 */
666 function makeOptionsLink( $title, $override, $options, $active = false ) {
667 global $wgUser;
668 $sk = $wgUser->getSkin();
669 $params = $override + $options;
670 if ( $active ) {
671 return $sk->link( $this->getTitle(), '<strong>' . htmlspecialchars( $title ) . '</strong>',
672 array(), $params, array( 'known' ) );
673 } else {
674 return $sk->link( $this->getTitle(), htmlspecialchars( $title ), array() , $params, array( 'known' ) );
675 }
676 }
677
678 /**
679 * Creates the options panel.
680 *
681 * @param $defaults Array
682 * @param $nondefaults Array
683 */
684 function optionsPanel( $defaults, $nondefaults ) {
685 global $wgLang, $wgUser, $wgRCLinkLimits, $wgRCLinkDays;
686
687 $options = $nondefaults + $defaults;
688
689 $note = '';
690 if( !wfEmptyMsg( 'rclegend' ) ) {
691 $note .= '<div class="mw-rclegend">' . wfMsgExt( 'rclegend', array('parseinline') ) . "</div>\n";
692 }
693 if( $options['from'] ) {
694 $note .= wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
695 $wgLang->formatNum( $options['limit'] ),
696 $wgLang->timeanddate( $options['from'], true ),
697 $wgLang->date( $options['from'], true ),
698 $wgLang->time( $options['from'], true ) ) . '<br />';
699 }
700
701 # Sort data for display and make sure it's unique after we've added user data.
702 $wgRCLinkLimits[] = $options['limit'];
703 $wgRCLinkDays[] = $options['days'];
704 sort( $wgRCLinkLimits );
705 sort( $wgRCLinkDays );
706 $wgRCLinkLimits = array_unique( $wgRCLinkLimits );
707 $wgRCLinkDays = array_unique( $wgRCLinkDays );
708
709 // limit links
710 foreach( $wgRCLinkLimits as $value ) {
711 $cl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
712 array( 'limit' => $value ), $nondefaults, $value == $options['limit'] ) ;
713 }
714 $cl = $wgLang->pipeList( $cl );
715
716 // day links, reset 'from' to none
717 foreach( $wgRCLinkDays as $value ) {
718 $dl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
719 array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] ) ;
720 }
721 $dl = $wgLang->pipeList( $dl );
722
723
724 // show/hide links
725 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ) );
726 $minorLink = $this->makeOptionsLink( $showhide[1-$options['hideminor']],
727 array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
728 $botLink = $this->makeOptionsLink( $showhide[1-$options['hidebots']],
729 array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
730 $anonsLink = $this->makeOptionsLink( $showhide[ 1 - $options['hideanons'] ],
731 array( 'hideanons' => 1 - $options['hideanons'] ), $nondefaults );
732 $liuLink = $this->makeOptionsLink( $showhide[1-$options['hideliu']],
733 array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
734 $patrLink = $this->makeOptionsLink( $showhide[1-$options['hidepatrolled']],
735 array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
736 $myselfLink = $this->makeOptionsLink( $showhide[1-$options['hidemyself']],
737 array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
738
739 $links[] = wfMsgHtml( 'rcshowhideminor', $minorLink );
740 $links[] = wfMsgHtml( 'rcshowhidebots', $botLink );
741 $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink );
742 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
743 if( $wgUser->useRCPatrol() )
744 $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
745 $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
746 $hl = $wgLang->pipeList( $links );
747
748 // show from this onward link
749 $now = $wgLang->timeanddate( wfTimestampNow(), true );
750 $tl = $this->makeOptionsLink( $now, array( 'from' => wfTimestampNow() ), $nondefaults );
751
752 $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter' ),
753 $cl, $dl, $hl );
754 $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter' ), $tl );
755 return "{$note}$rclinks<br />$rclistfrom";
756 }
757 }