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