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