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