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