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