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