Migrate block log to new log system
[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 object $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 /** @var int Constant for handling log_deleted */
81 protected $audience = self::FOR_PUBLIC;
82
83 /** @var bool 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 Const 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
326 case 'merge':
327 $text = wfMessage( 'pagemerge-logentry' )
328 ->rawParams( $target, $parameters['4::dest'], $parameters['5::mergepoint'] )
329 ->inContentLanguage()->escaped();
330 break;
331
332 case 'block':
333 switch ( $entry->getSubtype() ) {
334 case 'block':
335 global $wgContLang;
336 $duration = $wgContLang->translateBlockExpiry( $parameters['5::duration'] );
337 $flags = BlockLogFormatter::formatBlockFlags( $parameters['6::flags'], $wgContLang );
338 $text = wfMessage( 'blocklogentry' )
339 ->rawParams( $target, $duration, $flags )->inContentLanguage()->escaped();
340 break;
341 case 'unblock':
342 $text = wfMessage( 'unblocklogentry' )
343 ->rawParams( $target )->inContentLanguage()->escaped();
344 break;
345 case 'reblock':
346 global $wgContLang;
347 $duration = $wgContLang->translateBlockExpiry( $parameters['5::duration'] );
348 $flags = BlockLogFormatter::formatBlockFlags( $parameters['6::flags'], $wgContLang );
349 $text = wfMessage( 'reblock-logentry' )
350 ->rawParams( $target, $duration, $flags )->inContentLanguage()->escaped();
351 break;
352 }
353 break;
354 // case 'suppress' --private log -- aaron (so we know who to blame in a few years :-D)
355 // default:
356 }
357 if ( is_null( $text ) ) {
358 $text = $this->getPlainActionText();
359 }
360
361 $this->plaintext = false;
362 $this->irctext = false;
363
364 return $text;
365 }
366
367 /**
368 * Gets the log action, including username.
369 * @return string HTML
370 */
371 public function getActionText() {
372 if ( $this->canView( LogPage::DELETED_ACTION ) ) {
373 $element = $this->getActionMessage();
374 if ( $element instanceof Message ) {
375 $element = $this->plaintext ? $element->text() : $element->escaped();
376 }
377 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) {
378 $element = $this->styleRestricedElement( $element );
379 }
380 } else {
381 $sep = $this->msg( 'word-separator' );
382 $sep = $this->plaintext ? $sep->text() : $sep->escaped();
383 $performer = $this->getPerformerElement();
384 $element = $performer . $sep . $this->getRestrictedElement( 'rev-deleted-event' );
385 }
386
387 return $element;
388 }
389
390 /**
391 * Returns a sentence describing the log action. Usually
392 * a Message object is returned, but old style log types
393 * and entries might return pre-escaped HTML string.
394 * @return Message|string Pre-escaped HTML
395 */
396 protected function getActionMessage() {
397 $message = $this->msg( $this->getMessageKey() );
398 $message->params( $this->getMessageParameters() );
399
400 return $message;
401 }
402
403 /**
404 * Returns a key to be used for formatting the action sentence.
405 * Default is logentry-TYPE-SUBTYPE for modern logs. Legacy log
406 * types will use custom keys, and subclasses can also alter the
407 * key depending on the entry itself.
408 * @return string Message key
409 */
410 protected function getMessageKey() {
411 $type = $this->entry->getType();
412 $subtype = $this->entry->getSubtype();
413
414 return "logentry-$type-$subtype";
415 }
416
417 /**
418 * Returns extra links that comes after the action text, like "revert", etc.
419 *
420 * @return string
421 */
422 public function getActionLinks() {
423 return '';
424 }
425
426 /**
427 * Extracts the optional extra parameters for use in action messages.
428 * The array indexes start from number 3.
429 * @return array
430 */
431 protected function extractParameters() {
432 $entry = $this->entry;
433 $params = array();
434
435 if ( $entry->isLegacy() ) {
436 foreach ( $entry->getParameters() as $index => $value ) {
437 $params[$index + 3] = $value;
438 }
439 }
440
441 // Filter out parameters which are not in format #:foo
442 foreach ( $entry->getParameters() as $key => $value ) {
443 if ( strpos( $key, ':' ) === false ) {
444 continue;
445 }
446 list( $index, $type, ) = explode( ':', $key, 3 );
447 $params[$index - 1] = $this->formatParameterValue( $type, $value );
448 }
449
450 /* Message class doesn't like non consecutive numbering.
451 * Fill in missing indexes with empty strings to avoid
452 * incorrect renumbering.
453 */
454 if ( count( $params ) ) {
455 $max = max( array_keys( $params ) );
456 for ( $i = 4; $i < $max; $i++ ) {
457 if ( !isset( $params[$i] ) ) {
458 $params[$i] = '';
459 }
460 }
461 }
462
463 return $params;
464 }
465
466 /**
467 * Formats parameters intented for action message from
468 * array of all parameters. There are three hardcoded
469 * parameters (array is zero-indexed, this list not):
470 * - 1: user name with premade link
471 * - 2: usable for gender magic function
472 * - 3: target page with premade link
473 * @return array
474 */
475 protected function getMessageParameters() {
476 if ( isset( $this->parsedParameters ) ) {
477 return $this->parsedParameters;
478 }
479
480 $entry = $this->entry;
481 $params = $this->extractParameters();
482 $params[0] = Message::rawParam( $this->getPerformerElement() );
483 $params[1] = $this->canView( LogPage::DELETED_USER ) ? $entry->getPerformer()->getName() : '';
484 $params[2] = Message::rawParam( $this->makePageLink( $entry->getTarget() ) );
485
486 // Bad things happens if the numbers are not in correct order
487 ksort( $params );
488
489 $this->parsedParameters = $params;
490 return $this->parsedParameters;
491 }
492
493 /**
494 * Formats parameters values dependent to their type
495 * @param string $type The type of the value.
496 * Valid are currently:
497 * * - (empty) or plain: The value is returned as-is
498 * * raw: The value will be added to the log message
499 * as raw parameter (e.g. no escaping)
500 * Use this only if there is no other working
501 * type like user-link or title-link
502 * * msg: The value is a message-key, the output is
503 * the message in user language
504 * * msg-content: The value is a message-key, the output
505 * is the message in content language
506 * * user: The value is a user name, e.g. for GENDER
507 * * user-link: The value is a user name, returns a
508 * link for the user
509 * * title: The value is a page title,
510 * returns name of page
511 * * title-link: The value is a page title,
512 * returns link to this page
513 * * number: Format value as number
514 * @param string $value The parameter value that should
515 * be formated
516 * @return string|array Formated value
517 * @since 1.21
518 */
519 protected function formatParameterValue( $type, $value ) {
520 $saveLinkFlood = $this->linkFlood;
521
522 switch ( strtolower( trim( $type ) ) ) {
523 case 'raw':
524 $value = Message::rawParam( $value );
525 break;
526 case 'msg':
527 $value = $this->msg( $value )->text();
528 break;
529 case 'msg-content':
530 $value = $this->msg( $value )->inContentLanguage()->text();
531 break;
532 case 'number':
533 $value = Message::numParam( $value );
534 break;
535 case 'user':
536 $user = User::newFromName( $value );
537 $value = $user->getName();
538 break;
539 case 'user-link':
540 $this->setShowUserToolLinks( false );
541
542 $user = User::newFromName( $value );
543 $value = Message::rawParam( $this->makeUserLink( $user ) );
544
545 $this->setShowUserToolLinks( $saveLinkFlood );
546 break;
547 case 'title':
548 $title = Title::newFromText( $value );
549 $value = $title->getPrefixedText();
550 break;
551 case 'title-link':
552 $title = Title::newFromText( $value );
553 $value = Message::rawParam( $this->makePageLink( $title ) );
554 break;
555 case 'plain':
556 // Plain text, nothing to do
557 default:
558 // Catch other types and use the old behavior (return as-is)
559 }
560
561 return $value;
562 }
563
564 /**
565 * Helper to make a link to the page, taking the plaintext
566 * value in consideration.
567 * @param Title $title The page
568 * @param array $parameters Query parameters
569 * @throws MWException
570 * @return string
571 */
572 protected function makePageLink( Title $title = null, $parameters = array() ) {
573 if ( !$this->plaintext ) {
574 $link = Linker::link( $title, null, array(), $parameters );
575 } else {
576 if ( !$title instanceof Title ) {
577 throw new MWException( "Expected title, got null" );
578 }
579 $link = '[[' . $title->getPrefixedText() . ']]';
580 }
581
582 return $link;
583 }
584
585 /**
586 * Provides the name of the user who performed the log action.
587 * Used as part of log action message or standalone, depending
588 * which parts of the log entry has been hidden.
589 * @return string
590 */
591 public function getPerformerElement() {
592 if ( $this->canView( LogPage::DELETED_USER ) ) {
593 $performer = $this->entry->getPerformer();
594 $element = $this->makeUserLink( $performer );
595 if ( $this->entry->isDeleted( LogPage::DELETED_USER ) ) {
596 $element = $this->styleRestricedElement( $element );
597 }
598 } else {
599 $element = $this->getRestrictedElement( 'rev-deleted-user' );
600 }
601
602 return $element;
603 }
604
605 /**
606 * Gets the user provided comment
607 * @return string HTML
608 */
609 public function getComment() {
610 if ( $this->canView( LogPage::DELETED_COMMENT ) ) {
611 $comment = Linker::commentBlock( $this->entry->getComment() );
612 // No hard coded spaces thanx
613 $element = ltrim( $comment );
614 if ( $this->entry->isDeleted( LogPage::DELETED_COMMENT ) ) {
615 $element = $this->styleRestricedElement( $element );
616 }
617 } else {
618 $element = $this->getRestrictedElement( 'rev-deleted-comment' );
619 }
620
621 return $element;
622 }
623
624 /**
625 * Helper method for displaying restricted element.
626 * @param string $message
627 * @return string HTML or wiki text
628 */
629 protected function getRestrictedElement( $message ) {
630 if ( $this->plaintext ) {
631 return $this->msg( $message )->text();
632 }
633
634 $content = $this->msg( $message )->escaped();
635 $attribs = array( 'class' => 'history-deleted' );
636
637 return Html::rawElement( 'span', $attribs, $content );
638 }
639
640 /**
641 * Helper method for styling restricted element.
642 * @param string $content
643 * @return string HTML or wiki text
644 */
645 protected function styleRestricedElement( $content ) {
646 if ( $this->plaintext ) {
647 return $content;
648 }
649 $attribs = array( 'class' => 'history-deleted' );
650
651 return Html::rawElement( 'span', $attribs, $content );
652 }
653
654 /**
655 * Shortcut for wfMessage which honors local context.
656 * @param string $key
657 * @return Message
658 */
659 protected function msg( $key ) {
660 return $this->context->msg( $key );
661 }
662
663 protected function makeUserLink( User $user, $toolFlags = 0 ) {
664 if ( $this->plaintext ) {
665 $element = $user->getName();
666 } else {
667 $element = Linker::userLink(
668 $user->getId(),
669 $user->getName()
670 );
671
672 if ( $this->linkFlood ) {
673 $element .= Linker::userToolLinks(
674 $user->getId(),
675 $user->getName(),
676 true, // redContribsWhenNoEdits
677 $toolFlags,
678 $user->getEditCount()
679 );
680 }
681 }
682
683 return $element;
684 }
685
686 /**
687 * @return array Array of titles that should be preloaded with LinkBatch
688 */
689 public function getPreloadTitles() {
690 return array();
691 }
692
693 /**
694 * @return array Output of getMessageParameters() for testing
695 */
696 public function getMessageParametersForTesting() {
697 // This function was added because getMessageParameters() is
698 // protected and a change from protected to public caused
699 // problems with extensions
700 return $this->getMessageParameters();
701 }
702 }
703
704 /**
705 * This class formats all log entries for log types
706 * which have not been converted to the new system.
707 * This is not about old log entries which store
708 * parameters in a different format - the new
709 * LogFormatter classes have code to support formatting
710 * those too.
711 * @since 1.19
712 */
713 class LegacyLogFormatter extends LogFormatter {
714 /**
715 * Backward compatibility for extension changing the comment from
716 * the LogLine hook. This will be set by the first call on getComment(),
717 * then it might be modified by the hook when calling getActionLinks(),
718 * so that the modified value will be returned when calling getComment()
719 * a second time.
720 *
721 * @var string|null
722 */
723 private $comment = null;
724
725 /**
726 * Cache for the result of getActionLinks() so that it does not need to
727 * run multiple times depending on the order that getComment() and
728 * getActionLinks() are called.
729 *
730 * @var string|null
731 */
732 private $revert = null;
733
734 public function getComment() {
735 if ( $this->comment === null ) {
736 $this->comment = parent::getComment();
737 }
738
739 // Make sure we execute the LogLine hook so that we immediately return
740 // the correct value.
741 if ( $this->revert === null ) {
742 $this->getActionLinks();
743 }
744
745 return $this->comment;
746 }
747
748 protected function getActionMessage() {
749 $entry = $this->entry;
750 $action = LogPage::actionText(
751 $entry->getType(),
752 $entry->getSubtype(),
753 $entry->getTarget(),
754 $this->plaintext ? null : $this->context->getSkin(),
755 (array)$entry->getParameters(),
756 !$this->plaintext // whether to filter [[]] links
757 );
758
759 $performer = $this->getPerformerElement();
760 if ( !$this->irctext ) {
761 $sep = $this->msg( 'word-separator' );
762 $sep = $this->plaintext ? $sep->text() : $sep->escaped();
763 $action = $performer . $sep . $action;
764 }
765
766 return $action;
767 }
768
769 public function getActionLinks() {
770 if ( $this->revert !== null ) {
771 return $this->revert;
772 }
773
774 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) {
775 $this->revert = '';
776 return $this->revert;
777 }
778
779 $title = $this->entry->getTarget();
780 $type = $this->entry->getType();
781 $subtype = $this->entry->getSubtype();
782
783 if ( $type == 'protect'
784 && ( $subtype == 'protect' || $subtype == 'modify' || $subtype == 'unprotect' )
785 ) {
786 $links = array(
787 Linker::link( $title,
788 $this->msg( 'hist' )->escaped(),
789 array(),
790 array(
791 'action' => 'history',
792 'offset' => $this->entry->getTimestamp()
793 )
794 )
795 );
796 if ( $this->context->getUser()->isAllowed( 'protect' ) ) {
797 $links[] = Linker::linkKnown(
798 $title,
799 $this->msg( 'protect_change' )->escaped(),
800 array(),
801 array( 'action' => 'protect' )
802 );
803 }
804
805 return $this->msg( 'parentheses' )->rawParams(
806 $this->context->getLanguage()->pipeList( $links ) )->escaped();
807 }
808
809 // Do nothing. The implementation is handled by the hook modifiying the
810 // passed-by-ref parameters. This also changes the default value so that
811 // getComment() and getActionLinks() do not call them indefinitely.
812 $this->revert = '';
813
814 // This is to populate the $comment member of this instance so that it
815 // can be modified when calling the hook just below.
816 if ( $this->comment === null ) {
817 $this->getComment();
818 }
819
820 $params = $this->entry->getParameters();
821
822 Hooks::run( 'LogLine', array( $type, $subtype, $title, $params,
823 &$this->comment, &$this->revert, $this->entry->getTimestamp() ) );
824
825 return $this->revert;
826 }
827 }