Fix for r86186: correct check
[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 $select = '*';
323 $invert = $opts['invert'];
324
325 // JOIN on watchlist for users
326 if( $uid ) {
327 $tables[] = 'watchlist';
328 $join_conds['watchlist'] = array('LEFT JOIN',
329 "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace");
330 }
331 if ($this->getUser()->isAllowed("rollback")) {
332 $tables[] = 'page';
333 $join_conds['page'] = array('LEFT JOIN', 'rc_cur_id=page_id');
334 }
335 if ( !$this->including() ) {
336 // Tag stuff.
337 // Doesn't work when transcluding. See bug 23293
338 $fields = array();
339 // Fields are * in this case, so let the function modify an empty array to keep it happy.
340 ChangeTags::modifyDisplayQuery(
341 $tables, $fields, $conds, $join_conds, $query_options, $opts['tagfilter']
342 );
343 }
344
345 if ( !wfRunHooks( 'SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$select ) ) )
346 return false;
347
348 // Don't use the new_namespace_time timestamp index if:
349 // (a) "All namespaces" selected
350 // (b) We want all pages NOT in a certain namespaces (inverted)
351 // (c) There is a tag to filter on (use tag index instead)
352 // (d) UNION + sort/limit is not an option for the DBMS
353 if( is_null( $namespace )
354 || ( $invert && !is_null( $namespace ) )
355 || $opts['tagfilter'] != ''
356 || !$dbr->unionSupportsOrderAndLimit() )
357 {
358 $res = $dbr->select( $tables, '*', $conds, __METHOD__,
359 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) +
360 $query_options,
361 $join_conds );
362 // We have a new_namespace_time index! UNION over new=(0,1) and sort result set!
363 } else {
364 // New pages
365 $sqlNew = $dbr->selectSQLText( $tables, $select,
366 array( 'rc_new' => 1 ) + $conds,
367 __METHOD__,
368 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
369 'USE INDEX' => array('recentchanges' => 'rc_timestamp') ),
370 $join_conds );
371 // Old pages
372 $sqlOld = $dbr->selectSQLText( $tables, '*',
373 array( 'rc_new' => 0 ) + $conds,
374 __METHOD__,
375 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit,
376 'USE INDEX' => array('recentchanges' => 'rc_timestamp') ),
377 $join_conds );
378 # Join the two fast queries, and sort the result set
379 $sql = $dbr->unionQueries(array($sqlNew, $sqlOld), false).' ORDER BY rc_timestamp DESC';
380 $sql = $dbr->limitResult($sql, $limit, false);
381 $res = $dbr->query( $sql, __METHOD__ );
382 }
383
384 return $res;
385 }
386
387 /**
388 * Send output to $wgOut, only called if not used feeds
389 *
390 * @param $rows Array of database rows
391 * @param $opts FormOptions
392 */
393 public function webOutput( $rows, $opts ) {
394 global $wgOut, $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
395 global $wgAllowCategorizedRecentChanges;
396
397 $limit = $opts['limit'];
398
399 if( !$this->including() ) {
400 // Output options box
401 $this->doHeader( $opts );
402 }
403
404 // And now for the content
405 $wgOut->setFeedAppendQuery( $this->getFeedQuery() );
406
407 if( $wgAllowCategorizedRecentChanges ) {
408 $this->filterByCategories( $rows, $opts );
409 }
410
411 $showWatcherCount = $wgRCShowWatchingUsers && $this->getUser()->getOption( 'shownumberswatching' );
412 $watcherCache = array();
413
414 $dbr = wfGetDB( DB_SLAVE );
415
416 $counter = 1;
417 $list = ChangesList::newFromUser( $this->getUser() );
418
419 $s = $list->beginRecentChangesList();
420 foreach( $rows as $obj ) {
421 if( $limit == 0 ) break;
422 $rc = RecentChange::newFromRow( $obj );
423 $rc->counter = $counter++;
424 # Check if the page has been updated since the last visit
425 if( $wgShowUpdatedMarker && !empty($obj->wl_notificationtimestamp) ) {
426 $rc->notificationtimestamp = ($obj->rc_timestamp >= $obj->wl_notificationtimestamp);
427 } else {
428 $rc->notificationtimestamp = false; // Default
429 }
430 # Check the number of users watching the page
431 $rc->numberofWatchingusers = 0; // Default
432 if( $showWatcherCount && $obj->rc_namespace >= 0 ) {
433 if( !isset($watcherCache[$obj->rc_namespace][$obj->rc_title]) ) {
434 $watcherCache[$obj->rc_namespace][$obj->rc_title] =
435 $dbr->selectField( 'watchlist',
436 'COUNT(*)',
437 array(
438 'wl_namespace' => $obj->rc_namespace,
439 'wl_title' => $obj->rc_title,
440 ),
441 __METHOD__ . '-watchers' );
442 }
443 $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
444 }
445 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
446 --$limit;
447 }
448 $s .= $list->endRecentChangesList();
449 $wgOut->addHTML( $s );
450 }
451
452 /**
453 * Get the query string to append to feed link URLs.
454 * This is overridden by RCL to add the target parameter
455 */
456 public function getFeedQuery() {
457 return false;
458 }
459
460 /**
461 * Return the text to be displayed above the changes
462 *
463 * @param $opts FormOptions
464 * @return String: XHTML
465 */
466 public function doHeader( $opts ) {
467 global $wgScript, $wgOut;
468
469 $this->setTopText( $wgOut, $opts );
470
471 $defaults = $opts->getAllValues();
472 $nondefaults = $opts->getChangedValues();
473 $opts->consumeValues( array( 'namespace', 'invert', 'associated', 'tagfilter',
474 'categories', 'categories_any' ) );
475
476 $panel = array();
477 $panel[] = $this->optionsPanel( $defaults, $nondefaults );
478 $panel[] = '<hr />';
479
480 $extraOpts = $this->getExtraOptions( $opts );
481 $extraOptsCount = count( $extraOpts );
482 $count = 0;
483 $submit = ' ' . Xml::submitbutton( wfMsg( 'allpagessubmit' ) );
484
485 $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) );
486 foreach( $extraOpts as $optionRow ) {
487 # Add submit button to the last row only
488 ++$count;
489 $addSubmit = $count === $extraOptsCount ? $submit : '';
490
491 $out .= Xml::openElement( 'tr' );
492 if( is_array( $optionRow ) ) {
493 $out .= Xml::tags( 'td', array( 'class' => 'mw-label' ), $optionRow[0] );
494 $out .= Xml::tags( 'td', array( 'class' => 'mw-input' ), $optionRow[1] . $addSubmit );
495 } else {
496 $out .= Xml::tags( 'td', array( 'class' => 'mw-input', 'colspan' => 2 ), $optionRow . $addSubmit );
497 }
498 $out .= Xml::closeElement( 'tr' );
499 }
500 $out .= Xml::closeElement( 'table' );
501
502 $unconsumed = $opts->getUnconsumedValues();
503 foreach( $unconsumed as $key => $value ) {
504 $out .= Html::hidden( $key, $value );
505 }
506
507 $t = $this->getTitle();
508 $out .= Html::hidden( 'title', $t->getPrefixedText() );
509 $form = Xml::tags( 'form', array( 'action' => $wgScript ), $out );
510 $panel[] = $form;
511 $panelString = implode( "\n", $panel );
512
513 $wgOut->addHTML(
514 Xml::fieldset( wfMsg( 'recentchanges-legend' ), $panelString, array( 'class' => 'rcoptions' ) )
515 );
516
517 $this->setBottomText( $wgOut, $opts );
518 }
519
520 /**
521 * Get options to be displayed in a form
522 *
523 * @param $opts FormOptions
524 * @return Array
525 */
526 function getExtraOptions( $opts ){
527 $extraOpts = array();
528 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
529
530 global $wgAllowCategorizedRecentChanges;
531 if( $wgAllowCategorizedRecentChanges ) {
532 $extraOpts['category'] = $this->categoryFilterForm( $opts );
533 }
534
535 $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
536 if ( count($tagFilter) )
537 $extraOpts['tagfilter'] = $tagFilter;
538
539 wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) );
540 return $extraOpts;
541 }
542
543 /**
544 * Send the text to be displayed above the options
545 *
546 * @param $out OutputPage
547 * @param $opts FormOptions
548 */
549 function setTopText( OutputPage $out, FormOptions $opts ){
550 $message = wfMessage( 'recentchangestext' )->inContentLanguage();
551 if ( !$message->isDisabled() ) {
552 $out->addWikiText( $message->plain() );
553 }
554 }
555
556 /**
557 * Send the text to be displayed after the options, for use in
558 * Recentchangeslinked
559 *
560 * @param $out OutputPage
561 * @param $opts FormOptions
562 */
563 function setBottomText( OutputPage $out, FormOptions $opts ){}
564
565 /**
566 * Creates the choose namespace selection
567 *
568 * @todo Uses radio buttons (HASHAR)
569 * @param $opts FormOptions
570 * @return String
571 */
572 protected function namespaceFilterForm( FormOptions $opts ) {
573 $nsSelect = Xml::namespaceSelector( $opts['namespace'], '' );
574 $nsLabel = Xml::label( wfMsg('namespace'), 'namespace' );
575 $invert = Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $opts['invert'] );
576 $associated = Xml::checkLabel( wfMsg('namespace_association'), 'associated', 'nsassociated', $opts['associated'] );
577 return array( $nsLabel, "$nsSelect $invert $associated" );
578 }
579
580 /**
581 * Create a input to filter changes by categories
582 *
583 * @param $opts FormOptions
584 * @return Array
585 */
586 protected function categoryFilterForm( FormOptions $opts ) {
587 list( $label, $input ) = Xml::inputLabelSep( wfMsg('rc_categories'),
588 'categories', 'mw-categories', false, $opts['categories'] );
589
590 $input .= ' ' . Xml::checkLabel( wfMsg('rc_categories_any'),
591 'categories_any', 'mw-categories_any', $opts['categories_any'] );
592
593 return array( $label, $input );
594 }
595
596 /**
597 * Filter $rows by categories set in $opts
598 *
599 * @param $rows Array of database rows
600 * @param $opts FormOptions
601 */
602 function filterByCategories( &$rows, FormOptions $opts ) {
603 $categories = array_map( 'trim', explode( '|' , $opts['categories'] ) );
604
605 if( !count( $categories ) ) {
606 return;
607 }
608
609 # Filter categories
610 $cats = array();
611 foreach( $categories as $cat ) {
612 $cat = trim( $cat );
613 if( $cat == '' ) continue;
614 $cats[] = $cat;
615 }
616
617 # Filter articles
618 $articles = array();
619 $a2r = array();
620 $rowsarr = array();
621 foreach( $rows AS $k => $r ) {
622 $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
623 $id = $nt->getArticleID();
624 if( $id == 0 ) continue; # Page might have been deleted...
625 if( !in_array( $id, $articles ) ) {
626 $articles[] = $id;
627 }
628 if( !isset( $a2r[$id] ) ) {
629 $a2r[$id] = array();
630 }
631 $a2r[$id][] = $k;
632 $rowsarr[$k] = $r;
633 }
634
635 # Shortcut?
636 if( !count( $articles ) || !count( $cats ) )
637 return ;
638
639 # Look up
640 $c = new Categoryfinder;
641 $c->seed( $articles, $cats, $opts['categories_any'] ? "OR" : "AND" ) ;
642 $match = $c->run();
643
644 # Filter
645 $newrows = array();
646 foreach( $match AS $id ) {
647 foreach( $a2r[$id] AS $rev ) {
648 $k = $rev;
649 $newrows[$k] = $rowsarr[$k];
650 }
651 }
652 $rows = $newrows;
653 }
654
655 /**
656 * Makes change an option link which carries all the other options
657 *
658 * @param $title Title
659 * @param $override Array: options to override
660 * @param $options Array: current options
661 * @param $active Boolean: whether to show the link in bold
662 */
663 function makeOptionsLink( $title, $override, $options, $active = false ) {
664 $params = $override + $options;
665 if ( $active ) {
666 return $this->getSkin()->link( $this->getTitle(), '<strong>' . htmlspecialchars( $title ) . '</strong>',
667 array(), $params, array( 'known' ) );
668 } else {
669 return $this->getSkin()->link( $this->getTitle(), htmlspecialchars( $title ), array() , $params, array( 'known' ) );
670 }
671 }
672
673 /**
674 * Creates the options panel.
675 *
676 * @param $defaults Array
677 * @param $nondefaults Array
678 */
679 function optionsPanel( $defaults, $nondefaults ) {
680 global $wgLang, $wgRCLinkLimits, $wgRCLinkDays;
681
682 $options = $nondefaults + $defaults;
683
684 $note = '';
685 if( !wfEmptyMsg( 'rclegend' ) ) {
686 $note .= '<div class="mw-rclegend">' . wfMsgExt( 'rclegend', array('parseinline') ) . "</div>\n";
687 }
688 if( $options['from'] ) {
689 $note .= wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
690 $wgLang->formatNum( $options['limit'] ),
691 $wgLang->timeanddate( $options['from'], true ),
692 $wgLang->date( $options['from'], true ),
693 $wgLang->time( $options['from'], true ) ) . '<br />';
694 }
695
696 # Sort data for display and make sure it's unique after we've added user data.
697 $wgRCLinkLimits[] = $options['limit'];
698 $wgRCLinkDays[] = $options['days'];
699 sort( $wgRCLinkLimits );
700 sort( $wgRCLinkDays );
701 $wgRCLinkLimits = array_unique( $wgRCLinkLimits );
702 $wgRCLinkDays = array_unique( $wgRCLinkDays );
703
704 // limit links
705 foreach( $wgRCLinkLimits as $value ) {
706 $cl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
707 array( 'limit' => $value ), $nondefaults, $value == $options['limit'] ) ;
708 }
709 $cl = $wgLang->pipeList( $cl );
710
711 // day links, reset 'from' to none
712 foreach( $wgRCLinkDays as $value ) {
713 $dl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
714 array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] ) ;
715 }
716 $dl = $wgLang->pipeList( $dl );
717
718
719 // show/hide links
720 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ) );
721 $minorLink = $this->makeOptionsLink( $showhide[1-$options['hideminor']],
722 array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
723 $botLink = $this->makeOptionsLink( $showhide[1-$options['hidebots']],
724 array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
725 $anonsLink = $this->makeOptionsLink( $showhide[ 1 - $options['hideanons'] ],
726 array( 'hideanons' => 1 - $options['hideanons'] ), $nondefaults );
727 $liuLink = $this->makeOptionsLink( $showhide[1-$options['hideliu']],
728 array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
729 $patrLink = $this->makeOptionsLink( $showhide[1-$options['hidepatrolled']],
730 array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
731 $myselfLink = $this->makeOptionsLink( $showhide[1-$options['hidemyself']],
732 array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
733
734 $links[] = wfMsgHtml( 'rcshowhideminor', $minorLink );
735 $links[] = wfMsgHtml( 'rcshowhidebots', $botLink );
736 $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink );
737 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
738 if( $this->getUser()->useRCPatrol() )
739 $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
740 $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
741 $hl = $wgLang->pipeList( $links );
742
743 // show from this onward link
744 $now = $wgLang->timeanddate( wfTimestampNow(), true );
745 $tl = $this->makeOptionsLink( $now, array( 'from' => wfTimestampNow() ), $nondefaults );
746
747 $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter' ),
748 $cl, $dl, $hl );
749 $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter' ), $tl );
750 return "{$note}$rclinks<br />$rclistfrom";
751 }
752 }