Allow users to add, remove and apply change tags using the API
[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 * * list: Format value as a comma-separated list
544 * @param mixed $value The parameter value that should be formatted
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 'list':
556 $value = $this->context->getLanguage()->commaList( $value );
557 break;
558 case 'msg':
559 $value = $this->msg( $value )->text();
560 break;
561 case 'msg-content':
562 $value = $this->msg( $value )->inContentLanguage()->text();
563 break;
564 case 'number':
565 $value = Message::numParam( $value );
566 break;
567 case 'user':
568 $user = User::newFromName( $value );
569 $value = $user->getName();
570 break;
571 case 'user-link':
572 $this->setShowUserToolLinks( false );
573
574 $user = User::newFromName( $value );
575 $value = Message::rawParam( $this->makeUserLink( $user ) );
576
577 $this->setShowUserToolLinks( $saveLinkFlood );
578 break;
579 case 'title':
580 $title = Title::newFromText( $value );
581 $value = $title->getPrefixedText();
582 break;
583 case 'title-link':
584 $title = Title::newFromText( $value );
585 $value = Message::rawParam( $this->makePageLink( $title ) );
586 break;
587 case 'plain':
588 // Plain text, nothing to do
589 default:
590 // Catch other types and use the old behavior (return as-is)
591 }
592
593 return $value;
594 }
595
596 /**
597 * Helper to make a link to the page, taking the plaintext
598 * value in consideration.
599 * @param Title $title The page
600 * @param array $parameters Query parameters
601 * @throws MWException
602 * @return string
603 */
604 protected function makePageLink( Title $title = null, $parameters = array() ) {
605 if ( !$this->plaintext ) {
606 $link = Linker::link( $title, null, array(), $parameters );
607 } else {
608 if ( !$title instanceof Title ) {
609 throw new MWException( "Expected title, got null" );
610 }
611 $link = '[[' . $title->getPrefixedText() . ']]';
612 }
613
614 return $link;
615 }
616
617 /**
618 * Provides the name of the user who performed the log action.
619 * Used as part of log action message or standalone, depending
620 * which parts of the log entry has been hidden.
621 * @return string
622 */
623 public function getPerformerElement() {
624 if ( $this->canView( LogPage::DELETED_USER ) ) {
625 $performer = $this->entry->getPerformer();
626 $element = $this->makeUserLink( $performer );
627 if ( $this->entry->isDeleted( LogPage::DELETED_USER ) ) {
628 $element = $this->styleRestricedElement( $element );
629 }
630 } else {
631 $element = $this->getRestrictedElement( 'rev-deleted-user' );
632 }
633
634 return $element;
635 }
636
637 /**
638 * Gets the user provided comment
639 * @return string HTML
640 */
641 public function getComment() {
642 if ( $this->canView( LogPage::DELETED_COMMENT ) ) {
643 $comment = Linker::commentBlock( $this->entry->getComment() );
644 // No hard coded spaces thanx
645 $element = ltrim( $comment );
646 if ( $this->entry->isDeleted( LogPage::DELETED_COMMENT ) ) {
647 $element = $this->styleRestricedElement( $element );
648 }
649 } else {
650 $element = $this->getRestrictedElement( 'rev-deleted-comment' );
651 }
652
653 return $element;
654 }
655
656 /**
657 * Helper method for displaying restricted element.
658 * @param string $message
659 * @return string HTML or wiki text
660 */
661 protected function getRestrictedElement( $message ) {
662 if ( $this->plaintext ) {
663 return $this->msg( $message )->text();
664 }
665
666 $content = $this->msg( $message )->escaped();
667 $attribs = array( 'class' => 'history-deleted' );
668
669 return Html::rawElement( 'span', $attribs, $content );
670 }
671
672 /**
673 * Helper method for styling restricted element.
674 * @param string $content
675 * @return string HTML or wiki text
676 */
677 protected function styleRestricedElement( $content ) {
678 if ( $this->plaintext ) {
679 return $content;
680 }
681 $attribs = array( 'class' => 'history-deleted' );
682
683 return Html::rawElement( 'span', $attribs, $content );
684 }
685
686 /**
687 * Shortcut for wfMessage which honors local context.
688 * @param string $key
689 * @return Message
690 */
691 protected function msg( $key ) {
692 return $this->context->msg( $key );
693 }
694
695 protected function makeUserLink( User $user, $toolFlags = 0 ) {
696 if ( $this->plaintext ) {
697 $element = $user->getName();
698 } else {
699 $element = Linker::userLink(
700 $user->getId(),
701 $user->getName()
702 );
703
704 if ( $this->linkFlood ) {
705 $element .= Linker::userToolLinks(
706 $user->getId(),
707 $user->getName(),
708 true, // redContribsWhenNoEdits
709 $toolFlags,
710 $user->getEditCount()
711 );
712 }
713 }
714
715 return $element;
716 }
717
718 /**
719 * @return array Array of titles that should be preloaded with LinkBatch
720 */
721 public function getPreloadTitles() {
722 return array();
723 }
724
725 /**
726 * @return array Output of getMessageParameters() for testing
727 */
728 public function getMessageParametersForTesting() {
729 // This function was added because getMessageParameters() is
730 // protected and a change from protected to public caused
731 // problems with extensions
732 return $this->getMessageParameters();
733 }
734 }
735
736 /**
737 * This class formats all log entries for log types
738 * which have not been converted to the new system.
739 * This is not about old log entries which store
740 * parameters in a different format - the new
741 * LogFormatter classes have code to support formatting
742 * those too.
743 * @since 1.19
744 */
745 class LegacyLogFormatter extends LogFormatter {
746 /**
747 * Backward compatibility for extension changing the comment from
748 * the LogLine hook. This will be set by the first call on getComment(),
749 * then it might be modified by the hook when calling getActionLinks(),
750 * so that the modified value will be returned when calling getComment()
751 * a second time.
752 *
753 * @var string|null
754 */
755 private $comment = null;
756
757 /**
758 * Cache for the result of getActionLinks() so that it does not need to
759 * run multiple times depending on the order that getComment() and
760 * getActionLinks() are called.
761 *
762 * @var string|null
763 */
764 private $revert = null;
765
766 public function getComment() {
767 if ( $this->comment === null ) {
768 $this->comment = parent::getComment();
769 }
770
771 // Make sure we execute the LogLine hook so that we immediately return
772 // the correct value.
773 if ( $this->revert === null ) {
774 $this->getActionLinks();
775 }
776
777 return $this->comment;
778 }
779
780 protected function getActionMessage() {
781 $entry = $this->entry;
782 $action = LogPage::actionText(
783 $entry->getType(),
784 $entry->getSubtype(),
785 $entry->getTarget(),
786 $this->plaintext ? null : $this->context->getSkin(),
787 (array)$entry->getParameters(),
788 !$this->plaintext // whether to filter [[]] links
789 );
790
791 $performer = $this->getPerformerElement();
792 if ( !$this->irctext ) {
793 $sep = $this->msg( 'word-separator' );
794 $sep = $this->plaintext ? $sep->text() : $sep->escaped();
795 $action = $performer . $sep . $action;
796 }
797
798 return $action;
799 }
800
801 public function getActionLinks() {
802 if ( $this->revert !== null ) {
803 return $this->revert;
804 }
805
806 if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) {
807 $this->revert = '';
808 return $this->revert;
809 }
810
811 $title = $this->entry->getTarget();
812 $type = $this->entry->getType();
813 $subtype = $this->entry->getSubtype();
814
815 if ( $type == 'protect'
816 && ( $subtype == 'protect' || $subtype == 'modify' || $subtype == 'unprotect' )
817 ) {
818 $links = array(
819 Linker::link( $title,
820 $this->msg( 'hist' )->escaped(),
821 array(),
822 array(
823 'action' => 'history',
824 'offset' => $this->entry->getTimestamp()
825 )
826 )
827 );
828 if ( $this->context->getUser()->isAllowed( 'protect' ) ) {
829 $links[] = Linker::linkKnown(
830 $title,
831 $this->msg( 'protect_change' )->escaped(),
832 array(),
833 array( 'action' => 'protect' )
834 );
835 }
836
837 return $this->msg( 'parentheses' )->rawParams(
838 $this->context->getLanguage()->pipeList( $links ) )->escaped();
839 }
840
841 // Do nothing. The implementation is handled by the hook modifiying the
842 // passed-by-ref parameters. This also changes the default value so that
843 // getComment() and getActionLinks() do not call them indefinitely.
844 $this->revert = '';
845
846 // This is to populate the $comment member of this instance so that it
847 // can be modified when calling the hook just below.
848 if ( $this->comment === null ) {
849 $this->getComment();
850 }
851
852 $params = $this->entry->getParameters();
853
854 Hooks::run( 'LogLine', array( $type, $subtype, $title, $params,
855 &$this->comment, &$this->revert, $this->entry->getTimestamp() ) );
856
857 return $this->revert;
858 }
859 }