3 * Contains classes for formatting log entries
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.
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.
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
21 * @author Niklas Laxström
22 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
27 * Implements the default log formatting.
28 * Can be overridden by subclassing and setting
29 * $wgLogActionsHandlers['type/subtype'] = 'class'; or
30 * $wgLogActionsHandlers['type/*'] = 'class';
34 // Audience options for viewing usernames, comments, and actions
36 const FOR_THIS_USER
= 2;
41 * Constructs a new formatter suitable for given entry.
42 * @param $entry LogEntry
43 * @return LogFormatter
45 public static function newFromEntry( LogEntry
$entry ) {
46 global $wgLogActionsHandlers;
47 $fulltype = $entry->getFullType();
48 $wildcard = $entry->getType() . '/*';
51 if ( isset( $wgLogActionsHandlers[$fulltype] ) ) {
52 $handler = $wgLogActionsHandlers[$fulltype];
53 } elseif ( isset( $wgLogActionsHandlers[$wildcard] ) ) {
54 $handler = $wgLogActionsHandlers[$wildcard];
57 if ( $handler !== '' && is_string( $handler ) && class_exists( $handler ) ) {
58 return new $handler( $entry );
61 return new LegacyLogFormatter( $entry );
65 * Handy shortcut for constructing a formatter directly from
68 * @see DatabaseLogEntry::getSelectQueryData
69 * @return LogFormatter
71 public static function newFromRow( $row ) {
72 return self
::newFromEntry( DatabaseLogEntry
::newFromRow( $row ) );
80 /// Integer constant for handling log_deleted
81 protected $audience = self
::FOR_PUBLIC
;
83 /// Whether to output user tool links
84 protected $linkFlood = false;
87 * Set to true if we are constructing a message text that is going to
88 * be included in page history or send to IRC feed. Links are replaced
89 * with plaintext or with [[pagename]] kind of syntax, that is parsed
90 * by page histories and IRC feeds.
93 protected $plaintext = false;
95 protected $irctext = false;
97 protected function __construct( LogEntry
$entry ) {
98 $this->entry
= $entry;
99 $this->context
= RequestContext
::getMain();
103 * Replace the default context
104 * @param $context IContextSource
106 public function setContext( IContextSource
$context ) {
107 $this->context
= $context;
111 * Set the visibility restrictions for displaying content.
112 * If set to public, and an item is deleted, then it will be replaced
113 * with a placeholder even if the context user is allowed to view it.
114 * @param $audience integer self::FOR_THIS_USER or self::FOR_PUBLIC
116 public function setAudience( $audience ) {
117 $this->audience
= ( $audience == self
::FOR_THIS_USER
)
118 ? self
::FOR_THIS_USER
123 * Check if a log item can be displayed
124 * @param $field integer LogPage::DELETED_* constant
127 protected function canView( $field ) {
128 if ( $this->audience
== self
::FOR_THIS_USER
) {
129 return LogEventsList
::userCanBitfield(
130 $this->entry
->getDeleted(), $field, $this->context
->getUser() );
132 return !$this->entry
->isDeleted( $field );
137 * If set to true, will produce user tool links after
138 * the user name. This should be replaced with generic
140 * @param $value boolean
142 public function setShowUserToolLinks( $value ) {
143 $this->linkFlood
= $value;
147 * Ugly hack to produce plaintext version of the message.
148 * Usually you also want to set extraneous request context
149 * to avoid formatting for any particular user.
150 * @see getActionText()
151 * @return string text
153 public function getPlainActionText() {
154 $this->plaintext
= true;
155 $text = $this->getActionText();
156 $this->plaintext
= false;
161 * Even uglier hack to maintain backwards compatibilty with IRC bots
163 * @see getActionText()
164 * @return string text
166 public function getIRCActionComment() {
167 $actionComment = $this->getIRCActionText();
168 $comment = $this->entry
->getComment();
170 if ( $comment != '' ) {
171 if ( $actionComment == '' ) {
172 $actionComment = $comment;
174 $actionComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $comment;
178 return $actionComment;
182 * Even uglier hack to maintain backwards compatibilty with IRC bots
184 * @see getActionText()
185 * @return string text
187 public function getIRCActionText() {
188 $this->plaintext
= true;
189 $this->irctext
= true;
191 $entry = $this->entry
;
192 $parameters = $entry->getParameters();
193 // @see LogPage::actionText()
194 // Text of title the action is aimed at.
195 $target = $entry->getTarget()->getPrefixedText() ;
197 switch( $entry->getType() ) {
199 switch( $entry->getSubtype() ) {
201 $movesource = $parameters['4::target'];
202 $text = wfMessage( '1movedto2' )
203 ->rawParams( $target, $movesource )->inContentLanguage()->escaped();
206 $movesource = $parameters['4::target'];
207 $text = wfMessage( '1movedto2_redir' )
208 ->rawParams( $target, $movesource )->inContentLanguage()->escaped();
210 case 'move-noredirect':
212 case 'move_redir-noredirect':
218 switch( $entry->getSubtype() ) {
220 $text = wfMessage( 'deletedarticle' )
221 ->rawParams( $target )->inContentLanguage()->escaped();
224 $text = wfMessage( 'undeletedarticle' )
225 ->rawParams( $target )->inContentLanguage()->escaped();
227 //case 'revision': // Revision deletion
228 //case 'event': // Log deletion
229 // see https://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/LogPage.php?&pathrev=97044&r1=97043&r2=97044
235 // https://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/PatrolLog.php?&pathrev=97495&r1=97494&r2=97495
236 // Create a diff link to the patrolled revision
237 if ( $entry->getSubtype() === 'patrol' ) {
238 $diffLink = htmlspecialchars(
239 wfMessage( 'patrol-log-diff', $parameters['4::curid'] )
240 ->inContentLanguage()->text() );
241 $text = wfMessage( 'patrol-log-line', $diffLink, "[[$target]]", "" )
242 ->inContentLanguage()->text();
249 switch( $entry->getSubtype() ) {
251 $text = wfMessage( 'protectedarticle' )
252 ->rawParams( $target . ' ' . $parameters[0] )->inContentLanguage()->escaped();
255 $text = wfMessage( 'unprotectedarticle' )
256 ->rawParams( $target )->inContentLanguage()->escaped();
259 $text = wfMessage( 'modifiedarticleprotection' )
260 ->rawParams( $target . ' ' . $parameters[0] )->inContentLanguage()->escaped();
266 switch( $entry->getSubtype() ) {
269 $text = wfMessage( 'newuserlog-create-entry' )
270 ->inContentLanguage()->escaped();
273 $text = wfMessage( 'newuserlog-create2-entry' )
274 ->rawParams( $target )->inContentLanguage()->escaped();
277 $text = wfMessage( 'newuserlog-autocreate-entry' )
278 ->inContentLanguage()->escaped();
284 switch( $entry->getSubtype() ) {
286 $text = wfMessage( 'uploadedimage' )
287 ->rawParams( $target )->inContentLanguage()->escaped();
290 $text = wfMessage( 'overwroteimage' )
291 ->rawParams( $target )->inContentLanguage()->escaped();
297 if ( count( $parameters['4::oldgroups'] ) ) {
298 $oldgroups = implode( ', ', $parameters['4::oldgroups'] );
300 $oldgroups = wfMessage( 'rightsnone' )->inContentLanguage()->escaped();
302 if ( count( $parameters['5::newgroups'] ) ) {
303 $newgroups = implode( ', ', $parameters['5::newgroups'] );
305 $newgroups = wfMessage( 'rightsnone' )->inContentLanguage()->escaped();
307 switch( $entry->getSubtype() ) {
309 $text = wfMessage( 'rightslogentry' )
310 ->rawParams( $target, $oldgroups, $newgroups )->inContentLanguage()->escaped();
313 $text = wfMessage( 'rightslogentry-autopromote' )
314 ->rawParams( $target, $oldgroups, $newgroups )->inContentLanguage()->escaped();
319 // case 'suppress' --private log -- aaron (sign your messages so we know who to blame in a few years :-D)
322 if( is_null( $text ) ) {
323 $text = $this->getPlainActionText();
326 $this->plaintext
= false;
327 $this->irctext
= false;
332 * Gets the log action, including username.
333 * @return string HTML
335 public function getActionText() {
336 if ( $this->canView( LogPage
::DELETED_ACTION
) ) {
337 $element = $this->getActionMessage();
338 if ( $element instanceof Message
) {
339 $element = $this->plaintext ?
$element->text() : $element->escaped();
341 if ( $this->entry
->isDeleted( LogPage
::DELETED_ACTION
) ) {
342 $element = $this->styleRestricedElement( $element );
345 $performer = $this->getPerformerElement() . $this->msg( 'word-separator' )->text();
346 $element = $performer . $this->getRestrictedElement( 'rev-deleted-event' );
353 * Returns a sentence describing the log action. Usually
354 * a Message object is returned, but old style log types
355 * and entries might return pre-escaped html string.
356 * @return Message|string pre-escaped html
358 protected function getActionMessage() {
359 $message = $this->msg( $this->getMessageKey() );
360 $message->params( $this->getMessageParameters() );
365 * Returns a key to be used for formatting the action sentence.
366 * Default is logentry-TYPE-SUBTYPE for modern logs. Legacy log
367 * types will use custom keys, and subclasses can also alter the
368 * key depending on the entry itself.
369 * @return string message key
371 protected function getMessageKey() {
372 $type = $this->entry
->getType();
373 $subtype = $this->entry
->getSubtype();
375 return "logentry-$type-$subtype";
379 * Returns extra links that comes after the action text, like "revert", etc.
383 public function getActionLinks() {
388 * Extracts the optional extra parameters for use in action messages.
389 * The array indexes start from number 3.
392 protected function extractParameters() {
393 $entry = $this->entry
;
396 if ( $entry->isLegacy() ) {
397 foreach ( $entry->getParameters() as $index => $value ) {
398 $params[$index +
3] = $value;
402 // Filter out parameters which are not in format #:foo
403 foreach ( $entry->getParameters() as $key => $value ) {
404 if ( strpos( $key, ':' ) === false ) continue;
405 list( $index, $type, $name ) = explode( ':', $key, 3 );
406 $params[$index - 1] = $value;
409 /* Message class doesn't like non consecutive numbering.
410 * Fill in missing indexes with empty strings to avoid
411 * incorrect renumbering.
413 if ( count( $params ) ) {
414 $max = max( array_keys( $params ) );
415 for ( $i = 4; $i < $max; $i++
) {
416 if ( !isset( $params[$i] ) ) {
425 * Formats parameters intented for action message from
426 * array of all parameters. There are three hardcoded
427 * parameters (array is zero-indexed, this list not):
428 * - 1: user name with premade link
429 * - 2: usable for gender magic function
430 * - 3: target page with premade link
433 protected function getMessageParameters() {
434 if ( isset( $this->parsedParameters
) ) {
435 return $this->parsedParameters
;
438 $entry = $this->entry
;
439 $params = $this->extractParameters();
440 $params[0] = Message
::rawParam( $this->getPerformerElement() );
441 $params[1] = $entry->getPerformer()->getName();
442 $params[2] = Message
::rawParam( $this->makePageLink( $entry->getTarget() ) );
444 // Bad things happens if the numbers are not in correct order
446 return $this->parsedParameters
= $params;
450 * Helper to make a link to the page, taking the plaintext
451 * value in consideration.
452 * @param $title Title the page
453 * @param $parameters array query parameters
454 * @throws MWException
457 protected function makePageLink( Title
$title = null, $parameters = array() ) {
458 if ( !$this->plaintext
) {
459 $link = Linker
::link( $title, null, array(), $parameters );
461 if ( !$title instanceof Title
) {
462 throw new MWException( "Expected title, got null" );
464 $link = '[[' . $title->getPrefixedText() . ']]';
470 * Provides the name of the user who performed the log action.
471 * Used as part of log action message or standalone, depending
472 * which parts of the log entry has been hidden.
475 public function getPerformerElement() {
476 if ( $this->canView( LogPage
::DELETED_USER
) ) {
477 $performer = $this->entry
->getPerformer();
478 $element = $this->makeUserLink( $performer );
479 if ( $this->entry
->isDeleted( LogPage
::DELETED_USER
) ) {
480 $element = $this->styleRestricedElement( $element );
483 $element = $this->getRestrictedElement( 'rev-deleted-user' );
490 * Gets the luser provided comment
491 * @return string HTML
493 public function getComment() {
494 if ( $this->canView( LogPage
::DELETED_COMMENT
) ) {
495 $comment = Linker
::commentBlock( $this->entry
->getComment() );
496 // No hard coded spaces thanx
497 $element = ltrim( $comment );
498 if ( $this->entry
->isDeleted( LogPage
::DELETED_COMMENT
) ) {
499 $element = $this->styleRestricedElement( $element );
502 $element = $this->getRestrictedElement( 'rev-deleted-comment' );
509 * Helper method for displaying restricted element.
510 * @param $message string
511 * @return string HTML or wikitext
513 protected function getRestrictedElement( $message ) {
514 if ( $this->plaintext
) {
515 return $this->msg( $message )->text();
518 $content = $this->msg( $message )->escaped();
519 $attribs = array( 'class' => 'history-deleted' );
520 return Html
::rawElement( 'span', $attribs, $content );
524 * Helper method for styling restricted element.
525 * @param $content string
526 * @return string HTML or wikitext
528 protected function styleRestricedElement( $content ) {
529 if ( $this->plaintext
) {
532 $attribs = array( 'class' => 'history-deleted' );
533 return Html
::rawElement( 'span', $attribs, $content );
537 * Shortcut for wfMessage which honors local context.
538 * @todo Would it be better to require replacing the global context instead?
542 protected function msg( $key ) {
543 return $this->context
->msg( $key );
546 protected function makeUserLink( User
$user ) {
547 if ( $this->plaintext
) {
548 $element = $user->getName();
550 $element = Linker
::userLink(
555 if ( $this->linkFlood
) {
556 $element .= Linker
::userToolLinksRedContribs(
559 $user->getEditCount()
567 * @return Array of titles that should be preloaded with LinkBatch.
569 public function getPreloadTitles() {
576 * This class formats all log entries for log types
577 * which have not been converted to the new system.
578 * This is not about old log entries which store
579 * parameters in a different format - the new
580 * LogFormatter classes have code to support formatting
584 class LegacyLogFormatter
extends LogFormatter
{
587 * Backward compatibility for extension changing the comment from
588 * the LogLine hook. This will be set by the first call on getComment(),
589 * then it might be modified by the hook when calling getActionLinks(),
590 * so that the modified value will be returned when calling getComment()
595 private $comment = null;
598 * Cache for the result of getActionLinks() so that it does not need to
599 * run multiple times depending on the order that getComment() and
600 * getActionLinks() are called.
604 private $revert = null;
606 public function getComment() {
607 if ( $this->comment
=== null ) {
608 $this->comment
= parent
::getComment();
611 // Make sure we execute the LogLine hook so that we immediately return
612 // the correct value.
613 if ( $this->revert
=== null ) {
614 $this->getActionLinks();
617 return $this->comment
;
620 protected function getActionMessage() {
621 $entry = $this->entry
;
622 $action = LogPage
::actionText(
624 $entry->getSubtype(),
626 $this->plaintext ?
null : $this->context
->getSkin(),
627 (array)$entry->getParameters(),
628 !$this->plaintext
// whether to filter [[]] links
631 $performer = $this->getPerformerElement();
632 if ( !$this->irctext
) {
633 $action = $performer . $this->msg( 'word-separator' )->text() . $action;
639 public function getActionLinks() {
640 if ( $this->revert
!== null ) {
641 return $this->revert
;
644 if ( $this->entry
->isDeleted( LogPage
::DELETED_ACTION
) ) {
645 return $this->revert
= '';
648 $title = $this->entry
->getTarget();
649 $type = $this->entry
->getType();
650 $subtype = $this->entry
->getSubtype();
652 // Show unblock/change block link
653 if ( ( $type == 'block' ||
$type == 'suppress' ) && ( $subtype == 'block' ||
$subtype == 'reblock' ) ) {
654 if ( !$this->context
->getUser()->isAllowed( 'block' ) ) {
660 SpecialPage
::getTitleFor( 'Unblock', $title->getDBkey() ),
661 $this->msg( 'unblocklink' )->escaped()
664 SpecialPage
::getTitleFor( 'Block', $title->getDBkey() ),
665 $this->msg( 'change-blocklink' )->escaped()
668 return $this->msg( 'parentheses' )->rawParams(
669 $this->context
->getLanguage()->pipeList( $links ) )->escaped();
670 // Show change protection link
671 } elseif ( $type == 'protect' && ( $subtype == 'protect' ||
$subtype == 'modify' ||
$subtype == 'unprotect' ) ) {
673 Linker
::link( $title,
674 $this->msg( 'hist' )->escaped(),
677 'action' => 'history',
678 'offset' => $this->entry
->getTimestamp()
682 if ( $this->context
->getUser()->isAllowed( 'protect' ) ) {
683 $links[] = Linker
::linkKnown(
685 $this->msg( 'protect_change' )->escaped(),
687 array( 'action' => 'protect' )
690 return $this->msg( 'parentheses' )->rawParams(
691 $this->context
->getLanguage()->pipeList( $links ) )->escaped();
693 } elseif( $type == 'merge' && $subtype == 'merge' ) {
694 if ( !$this->context
->getUser()->isAllowed( 'mergehistory' ) ) {
698 $params = $this->extractParameters();
699 $revert = Linker
::linkKnown(
700 SpecialPage
::getTitleFor( 'MergeHistory' ),
701 $this->msg( 'revertmerge' )->escaped(),
704 'target' => $params[3],
705 'dest' => $title->getPrefixedDBkey(),
706 'mergepoint' => $params[4]
709 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
712 // Do nothing. The implementation is handled by the hook modifiying the
713 // passed-by-ref parameters. This also changes the default value so that
714 // getComment() and getActionLinks() do not call them indefinitely.
717 // This is to populate the $comment member of this instance so that it
718 // can be modified when calling the hook just below.
719 if ( $this->comment
=== null ) {
723 $params = $this->entry
->getParameters();
725 wfRunHooks( 'LogLine', array( $type, $subtype, $title, $params,
726 &$this->comment
, &$this->revert
, $this->entry
->getTimestamp() ) );
728 return $this->revert
;
733 * This class formats move log entries.
736 class MoveLogFormatter
extends LogFormatter
{
737 public function getPreloadTitles() {
738 $params = $this->extractParameters();
739 return array( Title
::newFromText( $params[3] ) );
742 protected function getMessageKey() {
743 $key = parent
::getMessageKey();
744 $params = $this->getMessageParameters();
745 if ( isset( $params[4] ) && $params[4] === '1' ) {
746 $key .= '-noredirect';
751 protected function getMessageParameters() {
752 $params = parent
::getMessageParameters();
753 $oldname = $this->makePageLink( $this->entry
->getTarget(), array( 'redirect' => 'no' ) );
754 $newname = $this->makePageLink( Title
::newFromText( $params[3] ) );
755 $params[2] = Message
::rawParam( $oldname );
756 $params[3] = Message
::rawParam( $newname );
760 public function getActionLinks() {
761 if ( $this->entry
->isDeleted( LogPage
::DELETED_ACTION
) // Action is hidden
762 ||
$this->entry
->getSubtype() !== 'move'
763 ||
!$this->context
->getUser()->isAllowed( 'move' ) )
768 $params = $this->extractParameters();
769 $destTitle = Title
::newFromText( $params[3] );
774 $revert = Linker
::linkKnown(
775 SpecialPage
::getTitleFor( 'Movepage' ),
776 $this->msg( 'revertmove' )->escaped(),
779 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
780 'wpNewTitle' => $this->entry
->getTarget()->getPrefixedDBkey(),
781 'wpReason' => $this->msg( 'revertmove' )->inContentLanguage()->text(),
785 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
790 * This class formats delete log entries.
793 class DeleteLogFormatter
extends LogFormatter
{
794 protected function getMessageKey() {
795 $key = parent
::getMessageKey();
796 if ( in_array( $this->entry
->getSubtype(), array( 'event', 'revision' ) ) ) {
797 if ( count( $this->getMessageParameters() ) < 5 ) {
798 return "$key-legacy";
804 protected function getMessageParameters() {
805 if ( isset( $this->parsedParametersDeleteLog
) ) {
806 return $this->parsedParametersDeleteLog
;
809 $params = parent
::getMessageParameters();
810 $subtype = $this->entry
->getSubtype();
811 if ( in_array( $subtype, array( 'event', 'revision' ) ) ) {
813 ($subtype === 'event' && count( $params ) === 6 ) ||
814 ($subtype === 'revision' && isset( $params[3] ) && $params[3] === 'revision' )
816 $paramStart = $subtype === 'revision' ?
4 : 3;
818 $old = $this->parseBitField( $params[$paramStart+
1] );
819 $new = $this->parseBitField( $params[$paramStart+
2] );
820 list( $hid, $unhid, $extra ) = RevisionDeleter
::getChanges( $new, $old );
822 foreach ( $hid as $v ) {
823 $changes[] = $this->msg( "$v-hid" )->plain();
825 foreach ( $unhid as $v ) {
826 $changes[] = $this->msg( "$v-unhid" )->plain();
828 foreach ( $extra as $v ) {
829 $changes[] = $this->msg( $v )->plain();
831 $changeText = $this->context
->getLanguage()->listToText( $changes );
834 $newParams = array_slice( $params, 0, 3 );
835 $newParams[3] = $changeText;
836 $count = count( explode( ',', $params[$paramStart] ) );
837 $newParams[4] = $this->context
->getLanguage()->formatNum( $count );
838 return $this->parsedParametersDeleteLog
= $newParams;
840 return $this->parsedParametersDeleteLog
= array_slice( $params, 0, 3 );
844 return $this->parsedParametersDeleteLog
= $params;
847 protected function parseBitField( $string ) {
848 // Input is like ofield=2134 or just the number
849 if ( strpos( $string, 'field=' ) === 1 ) {
850 list( , $field ) = explode( '=', $string );
853 return (int) $string;
857 public function getActionLinks() {
858 $user = $this->context
->getUser();
859 if ( !$user->isAllowed( 'deletedhistory' ) ||
$this->entry
->isDeleted( LogPage
::DELETED_ACTION
) ) {
863 switch ( $this->entry
->getSubtype() ) {
864 case 'delete': // Show undelete link
865 if( $user->isAllowed( 'undelete' ) ) {
866 $message = 'undeletelink';
868 $message = 'undeleteviewlink';
870 $revert = Linker
::linkKnown(
871 SpecialPage
::getTitleFor( 'Undelete' ),
872 $this->msg( $message )->escaped(),
874 array( 'target' => $this->entry
->getTarget()->getPrefixedDBkey() )
876 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
878 case 'revision': // If an edit was hidden from a page give a review link to the history
879 $params = $this->extractParameters();
880 if ( !isset( $params[3] ) ||
!isset( $params[4] ) ) {
884 // Different revision types use different URL params...
886 // This is a CSV of the IDs
887 $ids = explode( ',', $params[4] );
891 // If there's only one item, we can show a diff link
892 if ( count( $ids ) == 1 ) {
893 // Live revision diffs...
894 if ( $key == 'oldid' ||
$key == 'revision' ) {
895 $links[] = Linker
::linkKnown(
896 $this->entry
->getTarget(),
897 $this->msg( 'diff' )->escaped(),
900 'diff' => intval( $ids[0] ),
904 // Deleted revision diffs...
905 } elseif ( $key == 'artimestamp' ||
$key == 'archive' ) {
906 $links[] = Linker
::linkKnown(
907 SpecialPage
::getTitleFor( 'Undelete' ),
908 $this->msg( 'diff' )->escaped(),
911 'target' => $this->entry
->getTarget()->getPrefixedDBKey(),
913 'timestamp' => $ids[0]
919 // View/modify link...
920 $links[] = Linker
::linkKnown(
921 SpecialPage
::getTitleFor( 'Revisiondelete' ),
922 $this->msg( 'revdel-restore' )->escaped(),
925 'target' => $this->entry
->getTarget()->getPrefixedText(),
927 'ids' => implode( ',', $ids ),
931 return $this->msg( 'parentheses' )->rawParams(
932 $this->context
->getLanguage()->pipeList( $links ) )->escaped();
934 case 'event': // Hidden log items, give review link
935 $params = $this->extractParameters();
936 if ( !isset( $params[3] ) ) {
939 // This is a CSV of the IDs
941 // Link to each hidden object ID, $params[1] is the url param
942 $revert = Linker
::linkKnown(
943 SpecialPage
::getTitleFor( 'Revisiondelete' ),
944 $this->msg( 'revdel-restore' )->escaped(),
947 'target' => $this->entry
->getTarget()->getPrefixedText(),
952 return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
960 * This class formats patrol log entries.
963 class PatrolLogFormatter
extends LogFormatter
{
964 protected function getMessageKey() {
965 $key = parent
::getMessageKey();
966 $params = $this->getMessageParameters();
967 if ( isset( $params[5] ) && $params[5] ) {
973 protected function getMessageParameters() {
974 $params = parent
::getMessageParameters();
976 $target = $this->entry
->getTarget();
978 $revision = $this->context
->getLanguage()->formatNum( $oldid, true );
980 if ( $this->plaintext
) {
981 $revlink = $revision;
982 } elseif ( $target->exists() ) {
987 $revlink = Linker
::link( $target, htmlspecialchars( $revision ), array(), $query );
989 $revlink = htmlspecialchars( $revision );
992 $params[3] = Message
::rawParam( $revlink );
998 * This class formats new user log entries.
1001 class NewUsersLogFormatter
extends LogFormatter
{
1002 protected function getMessageParameters() {
1003 $params = parent
::getMessageParameters();
1004 if ( $this->entry
->getSubtype() === 'create2' ) {
1005 if ( isset( $params[3] ) ) {
1006 $target = User
::newFromId( $params[3] );
1008 $target = User
::newFromName( $this->entry
->getTarget()->getText(), false );
1010 $params[2] = Message
::rawParam( $this->makeUserLink( $target ) );
1011 $params[3] = $target->getName();
1016 public function getComment() {
1017 $timestamp = wfTimestamp( TS_MW
, $this->entry
->getTimestamp() );
1018 if ( $timestamp < '20080129000000' ) {
1019 # Suppress $comment from old entries (before 2008-01-29),
1020 # not needed and can contain incorrect links
1023 return parent
::getComment();
1026 public function getPreloadTitles() {
1027 if ( $this->entry
->getSubtype() === 'create2' ) {
1028 //add the user talk to LinkBatch for the userLink
1029 return array( Title
::makeTitle( NS_USER_TALK
, $this->entry
->getTarget()->getText() ) );
1036 * This class formats rights log entries.
1039 class RightsLogFormatter
extends LogFormatter
{
1040 protected function makePageLink( Title
$title = null, $parameters = array() ) {
1041 global $wgContLang, $wgUserrightsInterwikiDelimiter;
1043 if ( !$this->plaintext
) {
1044 $text = $wgContLang->ucfirst( $title->getText() );
1045 $parts = explode( $wgUserrightsInterwikiDelimiter, $text, 2 );
1047 if ( count( $parts ) === 2 ) {
1048 $titleLink = WikiMap
::foreignUserLink( $parts[1], $parts[0],
1049 htmlspecialchars( $title->getPrefixedText() ) );
1051 if ( $titleLink !== false ) {
1057 return parent
::makePageLink( $title, $parameters );
1060 protected function getMessageKey() {
1061 $key = parent
::getMessageKey();
1062 $params = $this->getMessageParameters();
1063 if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
1069 protected function getMessageParameters() {
1070 $params = parent
::getMessageParameters();
1072 // Really old entries
1073 if ( !isset( $params[3] ) && !isset( $params[4] ) ) {
1077 $oldGroups = $params[3];
1078 $newGroups = $params[4];
1081 if ( $oldGroups === '' ) {
1082 $oldGroups = array();
1083 } elseif ( is_string( $oldGroups ) ) {
1084 $oldGroups = array_map( 'trim', explode( ',', $oldGroups ) );
1086 if ( $newGroups === '' ) {
1087 $newGroups = array();
1088 } elseif ( is_string( $newGroups ) ) {
1089 $newGroups = array_map( 'trim', explode( ',', $newGroups ) );
1092 $userName = $this->entry
->getTarget()->getText();
1093 if ( !$this->plaintext
&& count( $oldGroups ) ) {
1094 foreach ( $oldGroups as &$group ) {
1095 $group = User
::getGroupMember( $group, $userName );
1098 if ( !$this->plaintext
&& count( $newGroups ) ) {
1099 foreach ( $newGroups as &$group ) {
1100 $group = User
::getGroupMember( $group, $userName );
1104 $lang = $this->context
->getLanguage();
1105 if ( count( $oldGroups ) ) {
1106 $params[3] = $lang->listToText( $oldGroups );
1108 $params[3] = $this->msg( 'rightsnone' )->text();
1110 if ( count( $newGroups ) ) {
1111 $params[4] = $lang->listToText( $newGroups );
1113 $params[4] = $this->msg( 'rightsnone' )->text();