Merge "Set visibility on class properties of UnregisteredLocalFile"
[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 // @codingStandardsIgnoreStart Long line
229 //case 'revision': // Revision deletion
230 //case 'event': // Log deletion
231 // see https://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/LogPage.php?&pathrev=97044&r1=97043&r2=97044
232 //default:
233 // @codingStandardsIgnoreEnd
234 }
235 break;
236
237 case 'patrol':
238 // @codingStandardsIgnoreStart Long line
239 // https://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/PatrolLog.php?&pathrev=97495&r1=97494&r2=97495
240 // @codingStandardsIgnoreEnd
241 // Create a diff link to the patrolled revision
242 if ( $entry->getSubtype() === 'patrol' ) {
243 $diffLink = htmlspecialchars(
244 wfMessage( 'patrol-log-diff', $parameters['4::curid'] )
245 ->inContentLanguage()->text() );
246 $text = wfMessage( 'patrol-log-line', $diffLink, "[[$target]]", "" )
247 ->inContentLanguage()->text();
248 } else {
249 // broken??
250 }
251 break;
252
253 case 'protect':
254 switch ( $entry->getSubtype() ) {
255 case 'protect':
256 $text = wfMessage( 'protectedarticle' )
257 ->rawParams( $target . ' ' . $parameters[0] )->inContentLanguage()->escaped();
258 break;
259 case 'unprotect':
260 $text = wfMessage( 'unprotectedarticle' )
261 ->rawParams( $target )->inContentLanguage()->escaped();
262 break;
263 case 'modify':
264 $text = wfMessage( 'modifiedarticleprotection' )
265 ->rawParams( $target . ' ' . $parameters[0] )->inContentLanguage()->escaped();
266 break;
267 }
268 break;
269
270 case 'newusers':
271 switch ( $entry->getSubtype() ) {
272 case 'newusers':
273 case 'create':
274 $text = wfMessage( 'newuserlog-create-entry' )
275 ->inContentLanguage()->escaped();
276 break;
277 case 'create2':
278 case 'byemail':
279 $text = wfMessage( 'newuserlog-create2-entry' )
280 ->rawParams( $target )->inContentLanguage()->escaped();
281 break;
282 case 'autocreate':
283 $text = wfMessage( 'newuserlog-autocreate-entry' )
284 ->inContentLanguage()->escaped();
285 break;
286 }
287 break;
288
289 case 'upload':
290 switch ( $entry->getSubtype() ) {
291 case 'upload':
292 $text = wfMessage( 'uploadedimage' )
293 ->rawParams( $target )->inContentLanguage()->escaped();
294 break;
295 case 'overwrite':
296 $text = wfMessage( 'overwroteimage' )
297 ->rawParams( $target )->inContentLanguage()->escaped();
298 break;
299 }
300 break;
301
302 case 'rights':
303 if ( count( $parameters['4::oldgroups'] ) ) {
304 $oldgroups = implode( ', ', $parameters['4::oldgroups'] );
305 } else {
306 $oldgroups = wfMessage( 'rightsnone' )->inContentLanguage()->escaped();
307 }
308 if ( count( $parameters['5::newgroups'] ) ) {
309 $newgroups = implode( ', ', $parameters['5::newgroups'] );
310 } else {
311 $newgroups = wfMessage( 'rightsnone' )->inContentLanguage()->escaped();
312 }
313 switch ( $entry->getSubtype() ) {
314 case 'rights':
315 $text = wfMessage( 'rightslogentry' )
316 ->rawParams( $target, $oldgroups, $newgroups )->inContentLanguage()->escaped();
317 break;
318 case 'autopromote':
319 $text = wfMessage( 'rightslogentry-autopromote' )
320 ->rawParams( $target, $oldgroups, $newgroups )->inContentLanguage()->escaped();
321 break;
322 }
323 break;
324 // case 'suppress' --private log -- aaron (so we know who to blame in a few years :-D)
325 // default:
326 }
327 if ( is_null( $text ) ) {
328 $text = $this->getPlainActionText();
329 }
330
331 $this->plaintext = false;
332 $this->irctext = false;
333
334 return $text;
335 }
336
337 /**
338 * Gets the log action, including username.
339 * @return string HTML
340 */
341 public function getActionText() {
342 if ( $this->canView( LogPage::DELETED_ACTION ) ) {
343 $element = $this->getActionMessage();
344 if ( $element instanceof Message ) {
345 $element = $this->plaintext ? $element->text() : $element->escaped();
346 }
347 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) {
348 $element = $this->styleRestricedElement( $element );
349 }
350 } else {
351 $performer = $this->getPerformerElement() . $this->msg( 'word-separator' )->text();
352 $element = $performer . $this->getRestrictedElement( 'rev-deleted-event' );
353 }
354
355 return $element;
356 }
357
358 /**
359 * Returns a sentence describing the log action. Usually
360 * a Message object is returned, but old style log types
361 * and entries might return pre-escaped html string.
362 * @return Message|string pre-escaped html
363 */
364 protected function getActionMessage() {
365 $message = $this->msg( $this->getMessageKey() );
366 $message->params( $this->getMessageParameters() );
367
368 return $message;
369 }
370
371 /**
372 * Returns a key to be used for formatting the action sentence.
373 * Default is logentry-TYPE-SUBTYPE for modern logs. Legacy log
374 * types will use custom keys, and subclasses can also alter the
375 * key depending on the entry itself.
376 * @return string message key
377 */
378 protected function getMessageKey() {
379 $type = $this->entry->getType();
380 $subtype = $this->entry->getSubtype();
381
382 return "logentry-$type-$subtype";
383 }
384
385 /**
386 * Returns extra links that comes after the action text, like "revert", etc.
387 *
388 * @return string
389 */
390 public function getActionLinks() {
391 return '';
392 }
393
394 /**
395 * Extracts the optional extra parameters for use in action messages.
396 * The array indexes start from number 3.
397 * @return array
398 */
399 protected function extractParameters() {
400 $entry = $this->entry;
401 $params = array();
402
403 if ( $entry->isLegacy() ) {
404 foreach ( $entry->getParameters() as $index => $value ) {
405 $params[$index + 3] = $value;
406 }
407 }
408
409 // Filter out parameters which are not in format #:foo
410 foreach ( $entry->getParameters() as $key => $value ) {
411 if ( strpos( $key, ':' ) === false ) {
412 continue;
413 }
414 list( $index, $type, ) = explode( ':', $key, 3 );
415 $params[$index - 1] = $this->formatParameterValue( $type, $value );
416 }
417
418 /* Message class doesn't like non consecutive numbering.
419 * Fill in missing indexes with empty strings to avoid
420 * incorrect renumbering.
421 */
422 if ( count( $params ) ) {
423 $max = max( array_keys( $params ) );
424 for ( $i = 4; $i < $max; $i++ ) {
425 if ( !isset( $params[$i] ) ) {
426 $params[$i] = '';
427 }
428 }
429 }
430
431 return $params;
432 }
433
434 /**
435 * Formats parameters intented for action message from
436 * array of all parameters. There are three hardcoded
437 * parameters (array is zero-indexed, this list not):
438 * - 1: user name with premade link
439 * - 2: usable for gender magic function
440 * - 3: target page with premade link
441 * @return array
442 */
443 protected function getMessageParameters() {
444 if ( isset( $this->parsedParameters ) ) {
445 return $this->parsedParameters;
446 }
447
448 $entry = $this->entry;
449 $params = $this->extractParameters();
450 $params[0] = Message::rawParam( $this->getPerformerElement() );
451 $params[1] = $this->canView( LogPage::DELETED_USER ) ? $entry->getPerformer()->getName() : '';
452 $params[2] = Message::rawParam( $this->makePageLink( $entry->getTarget() ) );
453
454 // Bad things happens if the numbers are not in correct order
455 ksort( $params );
456
457 return $this->parsedParameters = $params;
458 }
459
460 /**
461 * Formats parameters values dependent to their type
462 * @param string $type The type of the value.
463 * Valid are currently:
464 * * - (empty) or plain: The value is returned as-is
465 * * raw: The value will be added to the log message
466 * as raw parameter (e.g. no escaping)
467 * Use this only if there is no other working
468 * type like user-link or title-link
469 * * msg: The value is a message-key, the output is
470 * the message in user language
471 * * msg-content: The value is a message-key, the output
472 * is the message in content language
473 * * user: The value is a user name, e.g. for GENDER
474 * * user-link: The value is a user name, returns a
475 * link for the user
476 * * title: The value is a page title,
477 * returns name of page
478 * * title-link: The value is a page title,
479 * returns link to this page
480 * * number: Format value as number
481 * @param string $value The parameter value that should
482 * be formated
483 * @return string or Message::numParam or Message::rawParam
484 * Formated value
485 * @since 1.21
486 */
487 protected function formatParameterValue( $type, $value ) {
488 $saveLinkFlood = $this->linkFlood;
489
490 switch ( strtolower( trim( $type ) ) ) {
491 case 'raw':
492 $value = Message::rawParam( $value );
493 break;
494 case 'msg':
495 $value = $this->msg( $value )->text();
496 break;
497 case 'msg-content':
498 $value = $this->msg( $value )->inContentLanguage()->text();
499 break;
500 case 'number':
501 $value = Message::numParam( $value );
502 break;
503 case 'user':
504 $user = User::newFromName( $value );
505 $value = $user->getName();
506 break;
507 case 'user-link':
508 $this->setShowUserToolLinks( false );
509
510 $user = User::newFromName( $value );
511 $value = Message::rawParam( $this->makeUserLink( $user ) );
512
513 $this->setShowUserToolLinks( $saveLinkFlood );
514 break;
515 case 'title':
516 $title = Title::newFromText( $value );
517 $value = $title->getPrefixedText();
518 break;
519 case 'title-link':
520 $title = Title::newFromText( $value );
521 $value = Message::rawParam( $this->makePageLink( $title ) );
522 break;
523 case 'plain':
524 // Plain text, nothing to do
525 default:
526 // Catch other types and use the old behavior (return as-is)
527 }
528
529 return $value;
530 }
531
532 /**
533 * Helper to make a link to the page, taking the plaintext
534 * value in consideration.
535 * @param $title Title the page
536 * @param array $parameters query parameters
537 * @throws MWException
538 * @return String
539 */
540 protected function makePageLink( Title $title = null, $parameters = array() ) {
541 if ( !$this->plaintext ) {
542 $link = Linker::link( $title, null, array(), $parameters );
543 } else {
544 if ( !$title instanceof Title ) {
545 throw new MWException( "Expected title, got null" );
546 }
547 $link = '[[' . $title->getPrefixedText() . ']]';
548 }
549
550 return $link;
551 }
552
553 /**
554 * Provides the name of the user who performed the log action.
555 * Used as part of log action message or standalone, depending
556 * which parts of the log entry has been hidden.
557 * @return String
558 */
559 public function getPerformerElement() {
560 if ( $this->canView( LogPage::DELETED_USER ) ) {
561 $performer = $this->entry->getPerformer();
562 $element = $this->makeUserLink( $performer );
563 if ( $this->entry->isDeleted( LogPage::DELETED_USER ) ) {
564 $element = $this->styleRestricedElement( $element );
565 }
566 } else {
567 $element = $this->getRestrictedElement( 'rev-deleted-user' );
568 }
569
570 return $element;
571 }
572
573 /**
574 * Gets the luser provided comment
575 * @return string HTML
576 */
577 public function getComment() {
578 if ( $this->canView( LogPage::DELETED_COMMENT ) ) {
579 $comment = Linker::commentBlock( $this->entry->getComment() );
580 // No hard coded spaces thanx
581 $element = ltrim( $comment );
582 if ( $this->entry->isDeleted( LogPage::DELETED_COMMENT ) ) {
583 $element = $this->styleRestricedElement( $element );
584 }
585 } else {
586 $element = $this->getRestrictedElement( 'rev-deleted-comment' );
587 }
588
589 return $element;
590 }
591
592 /**
593 * Helper method for displaying restricted element.
594 * @param $message string
595 * @return string HTML or wikitext
596 */
597 protected function getRestrictedElement( $message ) {
598 if ( $this->plaintext ) {
599 return $this->msg( $message )->text();
600 }
601
602 $content = $this->msg( $message )->escaped();
603 $attribs = array( 'class' => 'history-deleted' );
604
605 return Html::rawElement( 'span', $attribs, $content );
606 }
607
608 /**
609 * Helper method for styling restricted element.
610 * @param $content string
611 * @return string HTML or wikitext
612 */
613 protected function styleRestricedElement( $content ) {
614 if ( $this->plaintext ) {
615 return $content;
616 }
617 $attribs = array( 'class' => 'history-deleted' );
618
619 return Html::rawElement( 'span', $attribs, $content );
620 }
621
622 /**
623 * Shortcut for wfMessage which honors local context.
624 * @todo Would it be better to require replacing the global context instead?
625 * @param $key string
626 * @return Message
627 */
628 protected function msg( $key ) {
629 return $this->context->msg( $key );
630 }
631
632 protected function makeUserLink( User $user ) {
633 if ( $this->plaintext ) {
634 $element = $user->getName();
635 } else {
636 $element = Linker::userLink(
637 $user->getId(),
638 $user->getName()
639 );
640
641 if ( $this->linkFlood ) {
642 $element .= Linker::userToolLinksRedContribs(
643 $user->getId(),
644 $user->getName(),
645 $user->getEditCount()
646 );
647 }
648 }
649
650 return $element;
651 }
652
653 /**
654 * @return Array of titles that should be preloaded with LinkBatch.
655 */
656 public function getPreloadTitles() {
657 return array();
658 }
659
660 /**
661 * @return Output of getMessageParameters() for testing
662 */
663 public function getMessageParametersForTesting() {
664 // This function was added because getMessageParameters() is
665 // protected and a change from protected to public caused
666 // problems with extensions
667 return $this->getMessageParameters();
668 }
669 }
670
671 /**
672 * This class formats all log entries for log types
673 * which have not been converted to the new system.
674 * This is not about old log entries which store
675 * parameters in a different format - the new
676 * LogFormatter classes have code to support formatting
677 * those too.
678 * @since 1.19
679 */
680 class LegacyLogFormatter extends LogFormatter {
681
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 return $this->revert = '';
742 }
743
744 $title = $this->entry->getTarget();
745 $type = $this->entry->getType();
746 $subtype = $this->entry->getSubtype();
747
748 // Show unblock/change block link
749 if ( ( $type == 'block' || $type == 'suppress' )
750 && ( $subtype == 'block' || $subtype == 'reblock' )
751 ) {
752 if ( !$this->context->getUser()->isAllowed( 'block' ) ) {
753 return '';
754 }
755
756 $links = array(
757 Linker::linkKnown(
758 SpecialPage::getTitleFor( 'Unblock', $title->getDBkey() ),
759 $this->msg( 'unblocklink' )->escaped()
760 ),
761 Linker::linkKnown(
762 SpecialPage::getTitleFor( 'Block', $title->getDBkey() ),
763 $this->msg( 'change-blocklink' )->escaped()
764 )
765 );
766
767 return $this->msg( 'parentheses' )->rawParams(
768 $this->context->getLanguage()->pipeList( $links ) )->escaped();
769 // Show change protection link
770 } elseif ( $type == 'protect'
771 && ( $subtype == 'protect' || $subtype == 'modify' || $subtype == 'unprotect' )
772 ) {
773 $links = array(
774 Linker::link( $title,
775 $this->msg( 'hist' )->escaped(),
776 array(),
777 array(
778 'action' => 'history',
779 'offset' => $this->entry->getTimestamp()
780 )
781 )
782 );
783 if ( $this->context->getUser()->isAllowed( 'protect' ) ) {
784 $links[] = Linker::linkKnown(
785 $title,
786 $this->msg( 'protect_change' )->escaped(),
787 array(),
788 array( 'action' => 'protect' )
789 );
790 }
791
792 return $this->msg( 'parentheses' )->rawParams(
793 $this->context->getLanguage()->pipeList( $links ) )->escaped();
794 // Show unmerge link
795 } elseif ( $type == 'merge' && $subtype == 'merge' ) {
796 if ( !$this->context->getUser()->isAllowed( 'mergehistory' ) ) {
797 return '';
798 }
799
800 $params = $this->extractParameters();
801 $revert = Linker::linkKnown(
802 SpecialPage::getTitleFor( 'MergeHistory' ),
803 $this->msg( 'revertmerge' )->escaped(),
804 array(),
805 array(
806 'target' => $params[3],
807 'dest' => $title->getPrefixedDBkey(),
808 'mergepoint' => $params[4]
809 )
810 );
811
812 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
813 }
814
815 // Do nothing. The implementation is handled by the hook modifiying the
816 // passed-by-ref parameters. This also changes the default value so that
817 // getComment() and getActionLinks() do not call them indefinitely.
818 $this->revert = '';
819
820 // This is to populate the $comment member of this instance so that it
821 // can be modified when calling the hook just below.
822 if ( $this->comment === null ) {
823 $this->getComment();
824 }
825
826 $params = $this->entry->getParameters();
827
828 wfRunHooks( 'LogLine', array( $type, $subtype, $title, $params,
829 &$this->comment, &$this->revert, $this->entry->getTimestamp() ) );
830
831 return $this->revert;
832 }
833 }