MediaWiki 1.42.1
LogFormatter Class Reference

Implements the default log formatting. More...

Inherited by BlockLogFormatter, ContentModelLogFormatter, DeleteLogFormatter, ImportLogFormatter, LegacyLogFormatter, MergeLogFormatter, MoveLogFormatter, NewUsersLogFormatter, PageLangLogFormatter, PatrolLogFormatter, ProtectLogFormatter, RenameuserLogFormatter, RightsLogFormatter, TagLogFormatter, UploadLogFormatter, and WikitextLogFormatter.

Collaboration diagram for LogFormatter:

Public Member Functions

 __construct (LogEntry $entry)
 
 canViewLogType ()
 Check if a log item type can be displayed.
 
 formatParametersForApi ()
 Format parameters for API output.
 
 getActionLinks ()
 Returns extra links that comes after the action text, like "revert", etc.
 
 getActionText ()
 Gets the log action, including username.
 
 getComment ()
 Gets the user provided comment.
 
 getCommentFormatter ()
 
 getContentLanguage ()
 
 getIRCActionComment ()
 Even uglier hack to maintain backwards compatibility with IRC bots (T36508).
 
 getIRCActionText ()
 Even uglier hack to maintain backwards compatibility with IRC bots (T36508).
 
 getLinkRenderer ()
 
 getMessageParametersForTesting ()
 
 getPerformerElement ()
 Provides the name of the user who performed the log action.
 
 getPlainActionText ()
 Ugly hack to produce plaintext version of the message.
 
 getPreloadTitles ()
 
 getUserEditTracker ()
 
 setAudience ( $audience)
 Set the visibility restrictions for displaying content.
 
 setCommentFormatter (CommentFormatter $commentFormatter)
 
 setContentLanguage (Language $contentLanguage)
 
 setContext (IContextSource $context)
 Replace the default context.
 
 setLinkRenderer (LinkRenderer $linkRenderer)
 
 setShowUserToolLinks ( $value)
 If set to true, will produce user tool links after the user name.
 
 setUserEditTracker (UserEditTracker $userEditTracker)
 

Static Public Member Functions

static newFromEntry (LogEntry $entry)
 Constructs a new formatter suitable for given entry.
 
static newFromRow ( $row)
 Handy shortcut for constructing a formatter directly from database row.
 

Public Attributes

IContextSource $context
 Context for logging.
 
const FOR_PUBLIC = 1
 
const FOR_THIS_USER = 2
 

Protected Member Functions

 canView ( $field)
 Check if a log item can be displayed.
 
 extractParameters ()
 Extracts the optional extra parameters for use in action messages.
 
 formatParameterValue ( $type, $value)
 Formats parameters values dependent to their type.
 
 formatParameterValueForApi ( $name, $type, $value)
 Format a single parameter value for API output.
 
 getActionMessage ()
 Returns a sentence describing the log action.
 
 getMessageKey ()
 Returns a key to be used for formatting the action sentence.
 
 getMessageParameters ()
 Formats parameters intended for action message from array of all parameters.
 
 getParametersForApi ()
 Get the array of parameters, converted from legacy format if necessary.
 
 getRestrictedElement ( $message)
 Helper method for displaying restricted element.
 
 makePageLink (Title $title=null, $parameters=[], $html=null)
 Helper to make a link to the page, taking the plaintext value in consideration.
 
 makeUserLink (UserIdentity $user, $toolFlags=0)
 
 msg ( $key,... $params)
 Shortcut for wfMessage which honors local context.
 
 styleRestrictedElement ( $content)
 Helper method for styling restricted element.
 

Protected Attributes

int $audience = self::FOR_PUBLIC
 Constant for handling log_deleted.
 
LogEntryBase $entry
 
bool $irctext = false
 
bool $linkFlood = false
 Whether to output user tool links.
 
array $parsedParameters
 
bool $plaintext = false
 Set to true if we are constructing a message text that is going to be included in page history or send to IRC feed.
 

Detailed Description

Implements the default log formatting.

Can be overridden by subclassing and setting:

$wgLogActionsHandlers['type/subtype'] = 'class'; or
$wgLogActionsHandlers['type/*'] = 'class';
*
$wgLogActionsHandlers
Config variable stub for the LogActionsHandlers setting, for use by phpdoc and IDEs.
Stability: stable
to extend
Since
1.19

Definition at line 53 of file LogFormatter.php.

Constructor & Destructor Documentation

◆ __construct()

LogFormatter::__construct ( LogEntry $entry)
Stability: stable
to call
Parameters
LogEntry$entry

Definition at line 131 of file LogFormatter.php.

Member Function Documentation

◆ canView()

LogFormatter::canView ( $field)
protected

Check if a log item can be displayed.

Parameters
int$fieldLogPage::DELETED_* constant
Returns
bool

Definition at line 258 of file LogFormatter.php.

◆ canViewLogType()

LogFormatter::canViewLogType ( )

Check if a log item type can be displayed.

Returns
bool

Definition at line 244 of file LogFormatter.php.

◆ extractParameters()

◆ formatParametersForApi()

LogFormatter::formatParametersForApi ( )

Format parameters for API output.

The result array should generally map named keys to values. Index and type should be omitted, e.g. "4::foo" should be returned as "foo" in the output. Values should generally be unformatted.

Renames or removals of keys besides from the legacy numeric format to modern named style should be avoided. Any renames should be announced to the mediawiki-api-announce mailing list.

Since
1.25
Stability: stable
to override
Returns
array

Reimplemented in BlockLogFormatter, DeleteLogFormatter, ProtectLogFormatter, and RightsLogFormatter.

Definition at line 936 of file LogFormatter.php.

References wfLogWarning().

◆ formatParameterValue()

LogFormatter::formatParameterValue ( $type,
$value )
protected

Formats parameters values dependent to their type.

Parameters
string$typeThe type of the value. Valid are currently:
  • - (empty) or plain: The value is returned as-is
  • raw: The value will be added to the log message as raw parameter (e.g. no escaping) Use this only if there is no other working type like user-link or title-link
  • msg: The value is a message-key, the output is the message in user language
  • msg-content: The value is a message-key, the output is the message in content language
  • user: The value is a user name, e.g. for GENDER
  • user-link: The value is a user name, returns a link for the user
  • title: The value is a page title, returns name of page
  • title-link: The value is a page title, returns link to this page
  • number: Format value as number
  • list: Format value as a comma-separated list
mixed$valueThe parameter value that should be formatted
Returns
string|array Formatted value
Since
1.21

Definition at line 697 of file LogFormatter.php.

◆ formatParameterValueForApi()

LogFormatter::formatParameterValueForApi ( $name,
$type,
$value )
protected

Format a single parameter value for API output.

Since
1.25
Parameters
string$name
string$type
string$value
Returns
array

Definition at line 966 of file LogFormatter.php.

References wfTimestamp().

Referenced by BlockLogFormatter\formatParametersForApi().

◆ getActionLinks()

LogFormatter::getActionLinks ( )

Returns extra links that comes after the action text, like "revert", etc.

Stability: stable
to override
Returns
string

Reimplemented in BlockLogFormatter, ContentModelLogFormatter, DeleteLogFormatter, LegacyLogFormatter, MergeLogFormatter, MoveLogFormatter, and ProtectLogFormatter.

Definition at line 588 of file LogFormatter.php.

◆ getActionMessage()

LogFormatter::getActionMessage ( )
protected

Returns a sentence describing the log action.

Usually a Message object is returned, but old style log types and entries might return pre-escaped HTML string.

Returns
Message|string Pre-escaped HTML

Reimplemented in LegacyLogFormatter, and WikitextLogFormatter.

Definition at line 560 of file LogFormatter.php.

◆ getActionText()

LogFormatter::getActionText ( )

Gets the log action, including username.

Stability: stable
to override
Returns
string HTML phan-taint-check gets very confused by $this->plaintext, so disable.

Definition at line 535 of file LogFormatter.php.

◆ getComment()

LogFormatter::getComment ( )

Gets the user provided comment.

Stability: stable
to override
Returns
string HTML

Reimplemented in LegacyLogFormatter, and NewUsersLogFormatter.

Definition at line 804 of file LogFormatter.php.

◆ getCommentFormatter()

LogFormatter::getCommentFormatter ( )
final
Since
1.42
Returns
CommentFormatter

Definition at line 199 of file LogFormatter.php.

References wfDeprecated().

◆ getContentLanguage()

LogFormatter::getContentLanguage ( )
final
Since
1.42
Returns
Language

Definition at line 178 of file LogFormatter.php.

References wfDeprecated().

Referenced by ProtectLogFormatter\formatParametersForApi(), and RightsLogFormatter\makePageLink().

◆ getIRCActionComment()

LogFormatter::getIRCActionComment ( )

Even uglier hack to maintain backwards compatibility with IRC bots (T36508).

See also
getActionText()
Returns
string Text

Definition at line 300 of file LogFormatter.php.

References wfMessage().

◆ getIRCActionText()

LogFormatter::getIRCActionText ( )

Even uglier hack to maintain backwards compatibility with IRC bots (T36508).

See also
getActionText()
Returns
string Text

Definition at line 322 of file LogFormatter.php.

References wfMessage(), and wfTimestamp().

◆ getLinkRenderer()

◆ getMessageKey()

LogFormatter::getMessageKey ( )
protected

Returns a key to be used for formatting the action sentence.

Default is logentry-TYPE-SUBTYPE for modern logs. Legacy log types will use custom keys, and subclasses can also alter the key depending on the entry itself.

Stability: stable
to override
Returns
string Message key

Reimplemented in BlockLogFormatter, DeleteLogFormatter, ImportLogFormatter, MoveLogFormatter, PatrolLogFormatter, ProtectLogFormatter, RenameuserLogFormatter, RightsLogFormatter, and TagLogFormatter.

Definition at line 575 of file LogFormatter.php.

◆ getMessageParameters()

LogFormatter::getMessageParameters ( )
protected

Formats parameters intended for action message from array of all parameters.

There are three hardcoded parameters:

  • $1: user name with premade link
  • $2: usable for gender magic function
  • $3: target page with premade link More parameters might be present, depending on what code created the log entry.

The parameters are returned as a non-associative array that can be passed to Message::params(), so $logFormatter->getMessageParameters()[0] is the $1 parameter in the message and so on.

Stability: stable
to override
Returns
array
See also
ManualLogEntry::setParameters() for how parameters are determined.

Reimplemented in BlockLogFormatter, ContentModelLogFormatter, DeleteLogFormatter, MergeLogFormatter, MoveLogFormatter, NewUsersLogFormatter, PageLangLogFormatter, PatrolLogFormatter, ProtectLogFormatter, RenameuserLogFormatter, RightsLogFormatter, and TagLogFormatter.

Definition at line 653 of file LogFormatter.php.

References $params.

◆ getMessageParametersForTesting()

LogFormatter::getMessageParametersForTesting ( )
Returns
array Output of getMessageParameters() for testing

Definition at line 904 of file LogFormatter.php.

◆ getParametersForApi()

LogFormatter::getParametersForApi ( )
protected

Get the array of parameters, converted from legacy format if necessary.

Since
1.25
Stability: stable
to override
Returns
array

Reimplemented in BlockLogFormatter, DeleteLogFormatter, MergeLogFormatter, MoveLogFormatter, PatrolLogFormatter, ProtectLogFormatter, RightsLogFormatter, and UploadLogFormatter.

Definition at line 917 of file LogFormatter.php.

◆ getPerformerElement()

LogFormatter::getPerformerElement ( )

Provides the name of the user who performed the log action.

Used as part of log action message or standalone, depending which parts of the log entry has been hidden.

Returns
string

Definition at line 785 of file LogFormatter.php.

Referenced by LegacyLogFormatter\getActionMessage().

◆ getPlainActionText()

LogFormatter::getPlainActionText ( )

Ugly hack to produce plaintext version of the message.

Usually you also want to set extraneous request context to avoid formatting for any particular user.

See also
getActionText()
Returns
string Plain text

Definition at line 286 of file LogFormatter.php.

◆ getPreloadTitles()

LogFormatter::getPreloadTitles ( )
Stability: stable
to override
Returns
LinkTarget[] Array of titles that should be preloaded with LinkBatch

Reimplemented in BlockLogFormatter, MergeLogFormatter, MoveLogFormatter, NewUsersLogFormatter, ProtectLogFormatter, and RenameuserLogFormatter.

Definition at line 897 of file LogFormatter.php.

◆ getRestrictedElement()

LogFormatter::getRestrictedElement ( $message)
protected

Helper method for displaying restricted element.

Parameters
string$message
Returns
string HTML or wiki text

Definition at line 826 of file LogFormatter.php.

◆ getUserEditTracker()

LogFormatter::getUserEditTracker ( )
final
Since
1.42
Returns
UserEditTracker

Definition at line 220 of file LogFormatter.php.

References wfDeprecated().

◆ makePageLink()

LogFormatter::makePageLink ( Title $title = null,
$parameters = [],
$html = null )
protected

Helper to make a link to the page, taking the plaintext value in consideration.

Stability: stable
to override
Parameters
Title | null$titleThe page
array$parametersQuery parameters
string | null$htmlLinktext of the link as raw html
Returns
string wikitext or html

Reimplemented in RightsLogFormatter.

Definition at line 759 of file LogFormatter.php.

Referenced by BlockLogFormatter\getMessageParameters(), MergeLogFormatter\getMessageParameters(), MoveLogFormatter\getMessageParameters(), and ProtectLogFormatter\getMessageParameters().

◆ makeUserLink()

LogFormatter::makeUserLink ( UserIdentity $user,
$toolFlags = 0 )
protected
Parameters
UserIdentity$user
int$toolFlagsCombination of Linker::TOOL_LINKS_* flags
Returns
string wikitext or html

Definition at line 867 of file LogFormatter.php.

References MediaWiki\User\UserIdentity\getId(), and MediaWiki\User\UserIdentity\getName().

Referenced by BlockLogFormatter\getMessageParameters(), and NewUsersLogFormatter\getMessageParameters().

◆ msg()

◆ newFromEntry()

static LogFormatter::newFromEntry ( LogEntry $entry)
static

Constructs a new formatter suitable for given entry.

Parameters
LogEntry$entry
Returns
LogFormatter
Deprecated
since 1.42, use LogFormatterFactory instead

Definition at line 66 of file LogFormatter.php.

◆ newFromRow()

static LogFormatter::newFromRow ( $row)
static

Handy shortcut for constructing a formatter directly from database row.

Parameters
stdClass | array$row
See also
DatabaseLogEntry::getSelectQueryData
Returns
LogFormatter
Deprecated
since 1.42, use LogFormatterFactory instead

Definition at line 78 of file LogFormatter.php.

Referenced by MediaWiki\Feed\FeedUtils\formatDiff().

◆ setAudience()

LogFormatter::setAudience ( $audience)

Set the visibility restrictions for displaying content.

If set to public, and an item is deleted, then it will be replaced with a placeholder even if the context user is allowed to view it.

Parameters
int$audienceConst self::FOR_THIS_USER or self::FOR_PUBLIC

Definition at line 234 of file LogFormatter.php.

◆ setCommentFormatter()

LogFormatter::setCommentFormatter ( CommentFormatter $commentFormatter)
final
Access: internal
For factory only
Since
1.42
Parameters
CommentFormatter$commentFormatter

Definition at line 191 of file LogFormatter.php.

◆ setContentLanguage()

LogFormatter::setContentLanguage ( Language $contentLanguage)
final
Access: internal
For factory only
Since
1.42
Parameters
Language$contentLanguage

Definition at line 170 of file LogFormatter.php.

◆ setContext()

LogFormatter::setContext ( IContextSource $context)

Replace the default context.

Parameters
IContextSource$context

Definition at line 140 of file LogFormatter.php.

◆ setLinkRenderer()

LogFormatter::setLinkRenderer ( LinkRenderer $linkRenderer)
Since
1.30
Parameters
LinkRenderer$linkRenderer

Definition at line 148 of file LogFormatter.php.

◆ setShowUserToolLinks()

LogFormatter::setShowUserToolLinks ( $value)

If set to true, will produce user tool links after the user name.

This should be replaced with generic CSS/JS solution.

Parameters
bool$value

Definition at line 274 of file LogFormatter.php.

◆ setUserEditTracker()

LogFormatter::setUserEditTracker ( UserEditTracker $userEditTracker)
final
Access: internal
For factory only
Since
1.42
Parameters
UserEditTracker$userEditTracker

Definition at line 212 of file LogFormatter.php.

◆ styleRestrictedElement()

LogFormatter::styleRestrictedElement ( $content)
protected

Helper method for styling restricted element.

Parameters
string$content
Returns
string HTML or wiki text

Definition at line 839 of file LogFormatter.php.

Member Data Documentation

◆ $audience

int LogFormatter::$audience = self::FOR_PUBLIC
protected

Constant for handling log_deleted.

Definition at line 88 of file LogFormatter.php.

◆ $context

IContextSource LogFormatter::$context

Context for logging.

Definition at line 91 of file LogFormatter.php.

◆ $entry

◆ $irctext

bool LogFormatter::$irctext = false
protected

Definition at line 106 of file LogFormatter.php.

◆ $linkFlood

bool LogFormatter::$linkFlood = false
protected

Whether to output user tool links.

Definition at line 94 of file LogFormatter.php.

◆ $parsedParameters

array LogFormatter::$parsedParameters
protected
See also
LogFormatter::getMessageParameters

Definition at line 124 of file LogFormatter.php.

◆ $plaintext

bool LogFormatter::$plaintext = false
protected

Set to true if we are constructing a message text that is going to be included in page history or send to IRC feed.

Links are replaced with plaintext or with [[pagename]] kind of syntax, that is parsed by page histories and IRC feeds.

Definition at line 103 of file LogFormatter.php.

◆ FOR_PUBLIC

const LogFormatter::FOR_PUBLIC = 1

Definition at line 55 of file LogFormatter.php.

◆ FOR_THIS_USER

const LogFormatter::FOR_THIS_USER = 2

Definition at line 56 of file LogFormatter.php.


The documentation for this class was generated from the following file: