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