Update formatting for log related classes
[lhc/web/wiklou.git] / includes / logging / LogFormatter.php
1 <?php
2 /**
3 * Contains classes for formatting log entries
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 * @author Niklas Laxström
22 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
23 * @since 1.19
24 */
25
26 /**
27 * Implements the default log formatting.
28 * Can be overridden by subclassing and setting
29 * $wgLogActionsHandlers['type/subtype'] = 'class'; or
30 * $wgLogActionsHandlers['type/*'] = 'class';
31 * @since 1.19
32 */
33 class LogFormatter {
34 // Audience options for viewing usernames, comments, and actions
35 const FOR_PUBLIC = 1;
36 const FOR_THIS_USER = 2;
37
38 // Static->
39
40 /**
41 * Constructs a new formatter suitable for given entry.
42 * @param $entry LogEntry
43 * @return LogFormatter
44 */
45 public static function newFromEntry( LogEntry $entry ) {
46 global $wgLogActionsHandlers;
47 $fulltype = $entry->getFullType();
48 $wildcard = $entry->getType() . '/*';
49 $handler = '';
50
51 if ( isset( $wgLogActionsHandlers[$fulltype] ) ) {
52 $handler = $wgLogActionsHandlers[$fulltype];
53 } elseif ( isset( $wgLogActionsHandlers[$wildcard] ) ) {
54 $handler = $wgLogActionsHandlers[$wildcard];
55 }
56
57 if ( $handler !== '' && is_string( $handler ) && class_exists( $handler ) ) {
58 return new $handler( $entry );
59 }
60
61 return new LegacyLogFormatter( $entry );
62 }
63
64 /**
65 * Handy shortcut for constructing a formatter directly from
66 * database row.
67 * @param $row
68 * @see DatabaseLogEntry::getSelectQueryData
69 * @return LogFormatter
70 */
71 public static function newFromRow( $row ) {
72 return self::newFromEntry( DatabaseLogEntry::newFromRow( $row ) );
73 }
74
75 // Nonstatic->
76
77 /// @var LogEntry
78 protected $entry;
79
80 /// Integer constant for handling log_deleted
81 protected $audience = self::FOR_PUBLIC;
82
83 /// Whether to output user tool links
84 protected $linkFlood = false;
85
86 /**
87 * Set to true if we are constructing a message text that is going to
88 * be included in page history or send to IRC feed. Links are replaced
89 * with plaintext or with [[pagename]] kind of syntax, that is parsed
90 * by page histories and IRC feeds.
91 * @var boolean
92 */
93 protected $plaintext = false;
94
95 protected $irctext = false;
96
97 protected function __construct( LogEntry $entry ) {
98 $this->entry = $entry;
99 $this->context = RequestContext::getMain();
100 }
101
102 /**
103 * Replace the default context
104 * @param $context IContextSource
105 */
106 public function setContext( IContextSource $context ) {
107 $this->context = $context;
108 }
109
110 /**
111 * Set the visibility restrictions for displaying content.
112 * If set to public, and an item is deleted, then it will be replaced
113 * with a placeholder even if the context user is allowed to view it.
114 * @param $audience integer self::FOR_THIS_USER or self::FOR_PUBLIC
115 */
116 public function setAudience( $audience ) {
117 $this->audience = ( $audience == self::FOR_THIS_USER )
118 ? self::FOR_THIS_USER
119 : self::FOR_PUBLIC;
120 }
121
122 /**
123 * Check if a log item can be displayed
124 * @param $field integer LogPage::DELETED_* constant
125 * @return bool
126 */
127 protected function canView( $field ) {
128 if ( $this->audience == self::FOR_THIS_USER ) {
129 return LogEventsList::userCanBitfield(
130 $this->entry->getDeleted(), $field, $this->context->getUser() );
131 } else {
132 return !$this->entry->isDeleted( $field );
133 }
134 }
135
136 /**
137 * If set to true, will produce user tool links after
138 * the user name. This should be replaced with generic
139 * CSS/JS solution.
140 * @param $value boolean
141 */
142 public function setShowUserToolLinks( $value ) {
143 $this->linkFlood = $value;
144 }
145
146 /**
147 * Ugly hack to produce plaintext version of the message.
148 * Usually you also want to set extraneous request context
149 * to avoid formatting for any particular user.
150 * @see getActionText()
151 * @return string text
152 */
153 public function getPlainActionText() {
154 $this->plaintext = true;
155 $text = $this->getActionText();
156 $this->plaintext = false;
157
158 return $text;
159 }
160
161 /**
162 * Even uglier hack to maintain backwards compatibilty with IRC bots
163 * (bug 34508).
164 * @see getActionText()
165 * @return string text
166 */
167 public function getIRCActionComment() {
168 $actionComment = $this->getIRCActionText();
169 $comment = $this->entry->getComment();
170
171 if ( $comment != '' ) {
172 if ( $actionComment == '' ) {
173 $actionComment = $comment;
174 } else {
175 $actionComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $comment;
176 }
177 }
178
179 return $actionComment;
180 }
181
182 /**
183 * Even uglier hack to maintain backwards compatibilty with IRC bots
184 * (bug 34508).
185 * @see getActionText()
186 * @return string text
187 */
188 public function getIRCActionText() {
189 $this->plaintext = true;
190 $this->irctext = true;
191
192 $entry = $this->entry;
193 $parameters = $entry->getParameters();
194 // @see LogPage::actionText()
195 // Text of title the action is aimed at.
196 $target = $entry->getTarget()->getPrefixedText();
197 $text = null;
198 switch ( $entry->getType() ) {
199 case 'move':
200 switch ( $entry->getSubtype() ) {
201 case 'move':
202 $movesource = $parameters['4::target'];
203 $text = wfMessage( '1movedto2' )
204 ->rawParams( $target, $movesource )->inContentLanguage()->escaped();
205 break;
206 case 'move_redir':
207 $movesource = $parameters['4::target'];
208 $text = wfMessage( '1movedto2_redir' )
209 ->rawParams( $target, $movesource )->inContentLanguage()->escaped();
210 break;
211 case 'move-noredirect':
212 break;
213 case 'move_redir-noredirect':
214 break;
215 }
216 break;
217
218 case 'delete':
219 switch ( $entry->getSubtype() ) {
220 case 'delete':
221 $text = wfMessage( 'deletedarticle' )
222 ->rawParams( $target )->inContentLanguage()->escaped();
223 break;
224 case 'restore':
225 $text = wfMessage( 'undeletedarticle' )
226 ->rawParams( $target )->inContentLanguage()->escaped();
227 break;
228 //case 'revision': // Revision deletion
229 //case 'event': // Log deletion
230 // see https://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/LogPage.php?&pathrev=97044&r1=97043&r2=97044
231 //default:
232 }
233 break;
234
235 case 'patrol':
236 // https://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/PatrolLog.php?&pathrev=97495&r1=97494&r2=97495
237 // Create a diff link to the patrolled revision
238 if ( $entry->getSubtype() === 'patrol' ) {
239 $diffLink = htmlspecialchars(
240 wfMessage( 'patrol-log-diff', $parameters['4::curid'] )
241 ->inContentLanguage()->text() );
242 $text = wfMessage( 'patrol-log-line', $diffLink, "[[$target]]", "" )
243 ->inContentLanguage()->text();
244 } else {
245 // broken??
246 }
247 break;
248
249 case 'protect':
250 switch ( $entry->getSubtype() ) {
251 case 'protect':
252 $text = wfMessage( 'protectedarticle' )
253 ->rawParams( $target . ' ' . $parameters[0] )->inContentLanguage()->escaped();
254 break;
255 case 'unprotect':
256 $text = wfMessage( 'unprotectedarticle' )
257 ->rawParams( $target )->inContentLanguage()->escaped();
258 break;
259 case 'modify':
260 $text = wfMessage( 'modifiedarticleprotection' )
261 ->rawParams( $target . ' ' . $parameters[0] )->inContentLanguage()->escaped();
262 break;
263 }
264 break;
265
266 case 'newusers':
267 switch ( $entry->getSubtype() ) {
268 case 'newusers':
269 case 'create':
270 $text = wfMessage( 'newuserlog-create-entry' )
271 ->inContentLanguage()->escaped();
272 break;
273 case 'create2':
274 case 'byemail':
275 $text = wfMessage( 'newuserlog-create2-entry' )
276 ->rawParams( $target )->inContentLanguage()->escaped();
277 break;
278 case 'autocreate':
279 $text = wfMessage( 'newuserlog-autocreate-entry' )
280 ->inContentLanguage()->escaped();
281 break;
282 }
283 break;
284
285 case 'upload':
286 switch ( $entry->getSubtype() ) {
287 case 'upload':
288 $text = wfMessage( 'uploadedimage' )
289 ->rawParams( $target )->inContentLanguage()->escaped();
290 break;
291 case 'overwrite':
292 $text = wfMessage( 'overwroteimage' )
293 ->rawParams( $target )->inContentLanguage()->escaped();
294 break;
295 }
296 break;
297
298 case 'rights':
299 if ( count( $parameters['4::oldgroups'] ) ) {
300 $oldgroups = implode( ', ', $parameters['4::oldgroups'] );
301 } else {
302 $oldgroups = wfMessage( 'rightsnone' )->inContentLanguage()->escaped();
303 }
304 if ( count( $parameters['5::newgroups'] ) ) {
305 $newgroups = implode( ', ', $parameters['5::newgroups'] );
306 } else {
307 $newgroups = wfMessage( 'rightsnone' )->inContentLanguage()->escaped();
308 }
309 switch ( $entry->getSubtype() ) {
310 case 'rights':
311 $text = wfMessage( 'rightslogentry' )
312 ->rawParams( $target, $oldgroups, $newgroups )->inContentLanguage()->escaped();
313 break;
314 case 'autopromote':
315 $text = wfMessage( 'rightslogentry-autopromote' )
316 ->rawParams( $target, $oldgroups, $newgroups )->inContentLanguage()->escaped();
317 break;
318 }
319 break;
320 // case 'suppress' --private log -- aaron (sign your messages so we know who to blame in a few years :-D)
321 // default:
322 }
323 if ( is_null( $text ) ) {
324 $text = $this->getPlainActionText();
325 }
326
327 $this->plaintext = false;
328 $this->irctext = false;
329
330 return $text;
331 }
332
333 /**
334 * Gets the log action, including username.
335 * @return string HTML
336 */
337 public function getActionText() {
338 if ( $this->canView( LogPage::DELETED_ACTION ) ) {
339 $element = $this->getActionMessage();
340 if ( $element instanceof Message ) {
341 $element = $this->plaintext ? $element->text() : $element->escaped();
342 }
343 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) {
344 $element = $this->styleRestricedElement( $element );
345 }
346 } else {
347 $performer = $this->getPerformerElement() . $this->msg( 'word-separator' )->text();
348 $element = $performer . $this->getRestrictedElement( 'rev-deleted-event' );
349 }
350
351 return $element;
352 }
353
354 /**
355 * Returns a sentence describing the log action. Usually
356 * a Message object is returned, but old style log types
357 * and entries might return pre-escaped html string.
358 * @return Message|string pre-escaped html
359 */
360 protected function getActionMessage() {
361 $message = $this->msg( $this->getMessageKey() );
362 $message->params( $this->getMessageParameters() );
363
364 return $message;
365 }
366
367 /**
368 * Returns a key to be used for formatting the action sentence.
369 * Default is logentry-TYPE-SUBTYPE for modern logs. Legacy log
370 * types will use custom keys, and subclasses can also alter the
371 * key depending on the entry itself.
372 * @return string message key
373 */
374 protected function getMessageKey() {
375 $type = $this->entry->getType();
376 $subtype = $this->entry->getSubtype();
377
378 return "logentry-$type-$subtype";
379 }
380
381 /**
382 * Returns extra links that comes after the action text, like "revert", etc.
383 *
384 * @return string
385 */
386 public function getActionLinks() {
387 return '';
388 }
389
390 /**
391 * Extracts the optional extra parameters for use in action messages.
392 * The array indexes start from number 3.
393 * @return array
394 */
395 protected function extractParameters() {
396 $entry = $this->entry;
397 $params = array();
398
399 if ( $entry->isLegacy() ) {
400 foreach ( $entry->getParameters() as $index => $value ) {
401 $params[$index + 3] = $value;
402 }
403 }
404
405 // Filter out parameters which are not in format #:foo
406 foreach ( $entry->getParameters() as $key => $value ) {
407 if ( strpos( $key, ':' ) === false ) {
408 continue;
409 }
410 list( $index, $type, ) = explode( ':', $key, 3 );
411 $params[$index - 1] = $this->formatParameterValue( $type, $value );
412 }
413
414 /* Message class doesn't like non consecutive numbering.
415 * Fill in missing indexes with empty strings to avoid
416 * incorrect renumbering.
417 */
418 if ( count( $params ) ) {
419 $max = max( array_keys( $params ) );
420 for ( $i = 4; $i < $max; $i++ ) {
421 if ( !isset( $params[$i] ) ) {
422 $params[$i] = '';
423 }
424 }
425 }
426
427 return $params;
428 }
429
430 /**
431 * Formats parameters intented for action message from
432 * array of all parameters. There are three hardcoded
433 * parameters (array is zero-indexed, this list not):
434 * - 1: user name with premade link
435 * - 2: usable for gender magic function
436 * - 3: target page with premade link
437 * @return array
438 */
439 protected function getMessageParameters() {
440 if ( isset( $this->parsedParameters ) ) {
441 return $this->parsedParameters;
442 }
443
444 $entry = $this->entry;
445 $params = $this->extractParameters();
446 $params[0] = Message::rawParam( $this->getPerformerElement() );
447 $params[1] = $this->canView( LogPage::DELETED_USER ) ? $entry->getPerformer()->getName() : '';
448 $params[2] = Message::rawParam( $this->makePageLink( $entry->getTarget() ) );
449
450 // Bad things happens if the numbers are not in correct order
451 ksort( $params );
452
453 return $this->parsedParameters = $params;
454 }
455
456 /**
457 * Formats parameters values dependent to their type
458 * @param string $type The type of the value.
459 * Valid are currently:
460 * * - (empty) or plain: The value is returned as-is
461 * * raw: The value will be added to the log message
462 * as raw parameter (e.g. no escaping)
463 * Use this only if there is no other working
464 * type like user-link or title-link
465 * * msg: The value is a message-key, the output is
466 * the message in user language
467 * * msg-content: The value is a message-key, the output
468 * is the message in content language
469 * * user: The value is a user name, e.g. for GENDER
470 * * user-link: The value is a user name, returns a
471 * link for the user
472 * * title: The value is a page title,
473 * returns name of page
474 * * title-link: The value is a page title,
475 * returns link to this page
476 * * number: Format value as number
477 * @param string $value The parameter value that should
478 * be formated
479 * @return string or Message::numParam or Message::rawParam
480 * Formated value
481 * @since 1.21
482 */
483 protected function formatParameterValue( $type, $value ) {
484 $saveLinkFlood = $this->linkFlood;
485
486 switch ( strtolower( trim( $type ) ) ) {
487 case 'raw':
488 $value = Message::rawParam( $value );
489 break;
490 case 'msg':
491 $value = $this->msg( $value )->text();
492 break;
493 case 'msg-content':
494 $value = $this->msg( $value )->inContentLanguage()->text();
495 break;
496 case 'number':
497 $value = Message::numParam( $value );
498 break;
499 case 'user':
500 $user = User::newFromName( $value );
501 $value = $user->getName();
502 break;
503 case 'user-link':
504 $this->setShowUserToolLinks( false );
505
506 $user = User::newFromName( $value );
507 $value = Message::rawParam( $this->makeUserLink( $user ) );
508
509 $this->setShowUserToolLinks( $saveLinkFlood );
510 break;
511 case 'title':
512 $title = Title::newFromText( $value );
513 $value = $title->getPrefixedText();
514 break;
515 case 'title-link':
516 $title = Title::newFromText( $value );
517 $value = Message::rawParam( $this->makePageLink( $title ) );
518 break;
519 case 'plain':
520 // Plain text, nothing to do
521 default:
522 // Catch other types and use the old behavior (return as-is)
523 }
524
525 return $value;
526 }
527
528 /**
529 * Helper to make a link to the page, taking the plaintext
530 * value in consideration.
531 * @param $title Title the page
532 * @param array $parameters query parameters
533 * @throws MWException
534 * @return String
535 */
536 protected function makePageLink( Title $title = null, $parameters = array() ) {
537 if ( !$this->plaintext ) {
538 $link = Linker::link( $title, null, array(), $parameters );
539 } else {
540 if ( !$title instanceof Title ) {
541 throw new MWException( "Expected title, got null" );
542 }
543 $link = '[[' . $title->getPrefixedText() . ']]';
544 }
545
546 return $link;
547 }
548
549 /**
550 * Provides the name of the user who performed the log action.
551 * Used as part of log action message or standalone, depending
552 * which parts of the log entry has been hidden.
553 * @return String
554 */
555 public function getPerformerElement() {
556 if ( $this->canView( LogPage::DELETED_USER ) ) {
557 $performer = $this->entry->getPerformer();
558 $element = $this->makeUserLink( $performer );
559 if ( $this->entry->isDeleted( LogPage::DELETED_USER ) ) {
560 $element = $this->styleRestricedElement( $element );
561 }
562 } else {
563 $element = $this->getRestrictedElement( 'rev-deleted-user' );
564 }
565
566 return $element;
567 }
568
569 /**
570 * Gets the luser provided comment
571 * @return string HTML
572 */
573 public function getComment() {
574 if ( $this->canView( LogPage::DELETED_COMMENT ) ) {
575 $comment = Linker::commentBlock( $this->entry->getComment() );
576 // No hard coded spaces thanx
577 $element = ltrim( $comment );
578 if ( $this->entry->isDeleted( LogPage::DELETED_COMMENT ) ) {
579 $element = $this->styleRestricedElement( $element );
580 }
581 } else {
582 $element = $this->getRestrictedElement( 'rev-deleted-comment' );
583 }
584
585 return $element;
586 }
587
588 /**
589 * Helper method for displaying restricted element.
590 * @param $message string
591 * @return string HTML or wikitext
592 */
593 protected function getRestrictedElement( $message ) {
594 if ( $this->plaintext ) {
595 return $this->msg( $message )->text();
596 }
597
598 $content = $this->msg( $message )->escaped();
599 $attribs = array( 'class' => 'history-deleted' );
600
601 return Html::rawElement( 'span', $attribs, $content );
602 }
603
604 /**
605 * Helper method for styling restricted element.
606 * @param $content string
607 * @return string HTML or wikitext
608 */
609 protected function styleRestricedElement( $content ) {
610 if ( $this->plaintext ) {
611 return $content;
612 }
613 $attribs = array( 'class' => 'history-deleted' );
614
615 return Html::rawElement( 'span', $attribs, $content );
616 }
617
618 /**
619 * Shortcut for wfMessage which honors local context.
620 * @todo Would it be better to require replacing the global context instead?
621 * @param $key string
622 * @return Message
623 */
624 protected function msg( $key ) {
625 return $this->context->msg( $key );
626 }
627
628 protected function makeUserLink( User $user ) {
629 if ( $this->plaintext ) {
630 $element = $user->getName();
631 } else {
632 $element = Linker::userLink(
633 $user->getId(),
634 $user->getName()
635 );
636
637 if ( $this->linkFlood ) {
638 $element .= Linker::userToolLinksRedContribs(
639 $user->getId(),
640 $user->getName(),
641 $user->getEditCount()
642 );
643 }
644 }
645
646 return $element;
647 }
648
649 /**
650 * @return Array of titles that should be preloaded with LinkBatch.
651 */
652 public function getPreloadTitles() {
653 return array();
654 }
655
656 /**
657 * @return Output of getMessageParameters() for testing
658 */
659 public function getMessageParametersForTesting() {
660 // This function was added because getMessageParameters() is
661 // protected and a change from protected to public caused
662 // problems with extensions
663 return $this->getMessageParameters();
664 }
665 }
666
667 /**
668 * This class formats all log entries for log types
669 * which have not been converted to the new system.
670 * This is not about old log entries which store
671 * parameters in a different format - the new
672 * LogFormatter classes have code to support formatting
673 * those too.
674 * @since 1.19
675 */
676 class LegacyLogFormatter extends LogFormatter {
677
678 /**
679 * Backward compatibility for extension changing the comment from
680 * the LogLine hook. This will be set by the first call on getComment(),
681 * then it might be modified by the hook when calling getActionLinks(),
682 * so that the modified value will be returned when calling getComment()
683 * a second time.
684 *
685 * @var string|null
686 */
687 private $comment = null;
688
689 /**
690 * Cache for the result of getActionLinks() so that it does not need to
691 * run multiple times depending on the order that getComment() and
692 * getActionLinks() are called.
693 *
694 * @var string|null
695 */
696 private $revert = null;
697
698 public function getComment() {
699 if ( $this->comment === null ) {
700 $this->comment = parent::getComment();
701 }
702
703 // Make sure we execute the LogLine hook so that we immediately return
704 // the correct value.
705 if ( $this->revert === null ) {
706 $this->getActionLinks();
707 }
708
709 return $this->comment;
710 }
711
712 protected function getActionMessage() {
713 $entry = $this->entry;
714 $action = LogPage::actionText(
715 $entry->getType(),
716 $entry->getSubtype(),
717 $entry->getTarget(),
718 $this->plaintext ? null : $this->context->getSkin(),
719 (array)$entry->getParameters(),
720 !$this->plaintext // whether to filter [[]] links
721 );
722
723 $performer = $this->getPerformerElement();
724 if ( !$this->irctext ) {
725 $action = $performer . $this->msg( 'word-separator' )->text() . $action;
726 }
727
728 return $action;
729 }
730
731 public function getActionLinks() {
732 if ( $this->revert !== null ) {
733 return $this->revert;
734 }
735
736 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) {
737 return $this->revert = '';
738 }
739
740 $title = $this->entry->getTarget();
741 $type = $this->entry->getType();
742 $subtype = $this->entry->getSubtype();
743
744 // Show unblock/change block link
745 if ( ( $type == 'block' || $type == 'suppress' ) && ( $subtype == 'block' || $subtype == 'reblock' ) ) {
746 if ( !$this->context->getUser()->isAllowed( 'block' ) ) {
747 return '';
748 }
749
750 $links = array(
751 Linker::linkKnown(
752 SpecialPage::getTitleFor( 'Unblock', $title->getDBkey() ),
753 $this->msg( 'unblocklink' )->escaped()
754 ),
755 Linker::linkKnown(
756 SpecialPage::getTitleFor( 'Block', $title->getDBkey() ),
757 $this->msg( 'change-blocklink' )->escaped()
758 )
759 );
760
761 return $this->msg( 'parentheses' )->rawParams(
762 $this->context->getLanguage()->pipeList( $links ) )->escaped();
763 // Show change protection link
764 } elseif ( $type == 'protect' && ( $subtype == 'protect' || $subtype == 'modify' || $subtype == 'unprotect' ) ) {
765 $links = array(
766 Linker::link( $title,
767 $this->msg( 'hist' )->escaped(),
768 array(),
769 array(
770 'action' => 'history',
771 'offset' => $this->entry->getTimestamp()
772 )
773 )
774 );
775 if ( $this->context->getUser()->isAllowed( 'protect' ) ) {
776 $links[] = Linker::linkKnown(
777 $title,
778 $this->msg( 'protect_change' )->escaped(),
779 array(),
780 array( 'action' => 'protect' )
781 );
782 }
783
784 return $this->msg( 'parentheses' )->rawParams(
785 $this->context->getLanguage()->pipeList( $links ) )->escaped();
786 // Show unmerge link
787 } elseif ( $type == 'merge' && $subtype == 'merge' ) {
788 if ( !$this->context->getUser()->isAllowed( 'mergehistory' ) ) {
789 return '';
790 }
791
792 $params = $this->extractParameters();
793 $revert = Linker::linkKnown(
794 SpecialPage::getTitleFor( 'MergeHistory' ),
795 $this->msg( 'revertmerge' )->escaped(),
796 array(),
797 array(
798 'target' => $params[3],
799 'dest' => $title->getPrefixedDBkey(),
800 'mergepoint' => $params[4]
801 )
802 );
803
804 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
805 }
806
807 // Do nothing. The implementation is handled by the hook modifiying the
808 // passed-by-ref parameters. This also changes the default value so that
809 // getComment() and getActionLinks() do not call them indefinitely.
810 $this->revert = '';
811
812 // This is to populate the $comment member of this instance so that it
813 // can be modified when calling the hook just below.
814 if ( $this->comment === null ) {
815 $this->getComment();
816 }
817
818 $params = $this->entry->getParameters();
819
820 wfRunHooks( 'LogLine', array( $type, $subtype, $title, $params,
821 &$this->comment, &$this->revert, $this->entry->getTimestamp() ) );
822
823 return $this->revert;
824 }
825 }