MediaWiki  1.28.1
LogFormatter Class Reference

Implements the default log formatting. More...

Inheritance diagram for LogFormatter:
Collaboration diagram for LogFormatter:

Public Member Functions

 formatParametersForApi ()
 Format parameters for API output. More...
 
 getActionLinks ()
 Returns extra links that comes after the action text, like "revert", etc. More...
 
 getActionText ()
 Gets the log action, including username. More...
 
 getComment ()
 Gets the user provided comment. More...
 
 getIRCActionComment ()
 Even uglier hack to maintain backwards compatibilty with IRC bots (bug 34508). More...
 
 getIRCActionText ()
 Even uglier hack to maintain backwards compatibilty with IRC bots (bug 34508). More...
 
 getMessageParametersForTesting ()
 
 getPerformerElement ()
 Provides the name of the user who performed the log action. More...
 
 getPlainActionText ()
 Ugly hack to produce plaintext version of the message. More...
 
 getPreloadTitles ()
 
 setAudience ($audience)
 Set the visibility restrictions for displaying content. More...
 
 setContext (IContextSource $context)
 Replace the default context. More...
 
 setShowUserToolLinks ($value)
 If set to true, will produce user tool links after the user name. More...
 

Static Public Member Functions

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

Public Attributes

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

Protected Member Functions

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

Protected Attributes

int $audience = self::FOR_PUBLIC
 Constant for handling log_deleted. More...
 
LogEntryBase $entry
 
string $irctext = false
 
bool $linkFlood = false
 Whether to output user tool links. More...
 
string $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. More...
 

Detailed Description

Implements the default log formatting.

Can be overridden by subclassing and setting:

$wgLogActionsHandlers['type/subtype'] = 'class'; or
$wgLogActionsHandlers['type/*'] = 'class';
Since
1.19

Definition at line 36 of file LogFormatter.php.

Constructor & Destructor Documentation

LogFormatter::__construct ( LogEntry  $entry)
protected

Definition at line 104 of file LogFormatter.php.

References $entry, and RequestContext\getMain().

Member Function Documentation

LogFormatter::canView (   $field)
protected

Check if a log item can be displayed.

Parameters
int$fieldLogPage::DELETED_* constant
Returns
bool

Definition at line 134 of file LogFormatter.php.

References LogEventsList\userCanBitfield().

Referenced by getActionText(), getComment(), getMessageParameters(), and getPerformerElement().

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
Returns
array

Definition at line 765 of file LogFormatter.php.

References $value, as, formatParameterValueForApi(), getParametersForApi(), ApiResult\setArrayType(), and ApiResult\setIndexedTagName().

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 Formated value
Since
1.21

Definition at line 554 of file LogFormatter.php.

References $linkFlood, $title, $type, $user, $value, makePageLink(), makeUserLink(), msg(), User\newFromName(), Title\newFromText(), Message\numParam(), Message\rawParam(), and setShowUserToolLinks().

Referenced by extractParameters().

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 790 of file LogFormatter.php.

References $name, $title, $type, $user, $value, ApiQueryBase\addTitleInfo(), msg(), User\newFromName(), Title\newFromText(), ApiResult\setArrayType(), TS_ISO_8601, and wfTimestamp().

Referenced by formatParametersForApi().

LogFormatter::getActionLinks ( )

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

Returns
string

Definition at line 454 of file LogFormatter.php.

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

Definition at line 428 of file LogFormatter.php.

References getMessageKey(), getMessageParameters(), and msg().

Referenced by getActionText().

LogFormatter::getActionText ( )

Gets the log action, including username.

Returns
string HTML

Definition at line 403 of file LogFormatter.php.

References canView(), LogPage\DELETED_ACTION, getActionMessage(), getPerformerElement(), getRestrictedElement(), msg(), and styleRestricedElement().

Referenced by getPlainActionText().

LogFormatter::getComment ( )

Gets the user provided comment.

Returns
string HTML

Definition at line 648 of file LogFormatter.php.

References $comment, canView(), Linker\commentBlock(), LogPage\DELETED_COMMENT, getRestrictedElement(), and styleRestricedElement().

LogFormatter::getIRCActionComment ( )

Even uglier hack to maintain backwards compatibilty with IRC bots (bug 34508).

See also
getActionText()
Returns
string Text

Definition at line 174 of file LogFormatter.php.

References $comment, getIRCActionText(), and wfMessage().

LogFormatter::getIRCActionText ( )

Even uglier hack to maintain backwards compatibilty with IRC bots (bug 34508).

See also
getActionText()
Returns
string Text

Definition at line 195 of file LogFormatter.php.

References $entry, $flags, $wgContLang, BlockLogFormatter\formatBlockFlags(), LogEntry\getParameters(), getPlainActionText(), LogEntry\getSubtype(), LogEntry\getTarget(), LogEntry\getType(), global, LogEntryBase\isLegacy(), text, and wfMessage().

Referenced by getIRCActionComment().

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.

Returns
string Message key

Definition at line 442 of file LogFormatter.php.

References $type.

Referenced by getActionMessage().

LogFormatter::getMessageParameters ( )
protected

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

There are three hardcoded parameters (array is zero-indexed, this list not):

  • 1: user name with premade link
  • 2: usable for gender magic function
  • 3: target page with premade link
    Returns
    array

Definition at line 510 of file LogFormatter.php.

References $entry, $params, canView(), LogPage\DELETED_USER, extractParameters(), LogEntry\getPerformer(), getPerformerElement(), LogEntry\getTarget(), makePageLink(), and Message\rawParam().

Referenced by getActionMessage(), TagLogFormatter\getMessageKey(), and getMessageParametersForTesting().

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

Definition at line 735 of file LogFormatter.php.

References getMessageParameters().

LogFormatter::getParametersForApi ( )
protected

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

Since
1.25
Returns
array

Definition at line 747 of file LogFormatter.php.

Referenced by formatParametersForApi().

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 630 of file LogFormatter.php.

References canView(), LogPage\DELETED_USER, getRestrictedElement(), makeUserLink(), and styleRestricedElement().

Referenced by LegacyLogFormatter\getActionMessage(), getActionText(), and getMessageParameters().

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 160 of file LogFormatter.php.

References getActionText().

Referenced by getIRCActionText().

LogFormatter::getPreloadTitles ( )
Returns
array Array of titles that should be preloaded with LinkBatch

Definition at line 728 of file LogFormatter.php.

LogFormatter::getRestrictedElement (   $message)
protected

Helper method for displaying restricted element.

Parameters
string$message
Returns
string HTML or wiki text

Definition at line 668 of file LogFormatter.php.

References $attribs, $content, msg(), and Html\rawElement().

Referenced by getActionText(), getComment(), and getPerformerElement().

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

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

Parameters
Title$titleThe page
array$parametersQuery parameters
string | null$htmlLinktext of the link as raw html
Exceptions
MWException
Returns
string

Definition at line 611 of file LogFormatter.php.

References $html, $link, $title, and Linker\link().

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

static LogFormatter::newFromRow (   $row)
static
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 123 of file LogFormatter.php.

LogFormatter::setContext ( IContextSource  $context)

Replace the default context.

Parameters
IContextSource$context

Definition at line 113 of file LogFormatter.php.

References $context.

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 149 of file LogFormatter.php.

References $value.

Referenced by formatParameterValue().

LogFormatter::styleRestricedElement (   $content)
protected

Helper method for styling restricted element.

Parameters
string$content
Returns
string HTML or wiki text

Definition at line 684 of file LogFormatter.php.

References $attribs, $content, and Html\rawElement().

Referenced by getActionText(), getComment(), and getPerformerElement().

Member Data Documentation

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

Constant for handling log_deleted.

Definition at line 84 of file LogFormatter.php.

IContextSource LogFormatter::$context

Context for logging.

Definition at line 87 of file LogFormatter.php.

Referenced by setContext().

string LogFormatter::$irctext = false
protected

Definition at line 102 of file LogFormatter.php.

bool LogFormatter::$linkFlood = false
protected

Whether to output user tool links.

Definition at line 90 of file LogFormatter.php.

Referenced by formatParameterValue().

string 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 99 of file LogFormatter.php.

const LogFormatter::FOR_PUBLIC = 1

Definition at line 38 of file LogFormatter.php.

const LogFormatter::FOR_THIS_USER = 2

Definition at line 39 of file LogFormatter.php.

Referenced by ChangeTagsLogItem\getHTML(), and RevDelLogItem\getHTML().


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