MediaWiki master
RightsLogFormatter Class Reference

This class formats rights log entries. More...

Inherits LogFormatter.

Collaboration diagram for RightsLogFormatter:

Public Member Functions

 formatParametersForApi ()
 Format parameters for API output.
 
- Public Member Functions inherited from LogFormatter
 __construct (LogEntry $entry)
 
 canViewLogType ()
 Check if a log item type can be displayed.
 
 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)
 

Protected Member Functions

 classifyGroupChanges (array $oldGroups, array $newGroups)
 Compares the user groups from before and after this log entry and splits them into four categories: granted, revoked, expiry-changed and kept.
 
 formatChangesToGroups (array $groupChanges, string $performerName, string $targetName, string $messagePrefix='logentry-rights-rights-')
 Wraps the changes to user groups into a human-readable messages, so that they can be passed as a parameter to the log entry message.
 
 getMessageKey ()
 Returns a key to be used for formatting the action sentence.
 
 getMessageParameters ()
 Formats parameters intended for action message from array of all parameters.
 
 getNewGroups (array $params)
 Returns the new groups related to this log entry together with their expiry times.
 
 getOldGroups (array $params)
 Returns the old groups related to this log entry together with their expiry times.
 
 getParametersForApi ()
 Get the array of parameters, converted from legacy format if necessary.
 
 joinGroupsWithExpiries ( $groupNames, array $metadata)
 Joins group names from one array with their expiry times from the another.
 
 makePageLink (?Title $title=null, $parameters=[], $html=null)
 Helper to make a link to the page, taking the plaintext value in consideration.
 
 replaceGroupsWithMemberNames (array &$groupNames)
 Replaces the group names in the array with their localized member names.
 
 shouldProcessParams (array $params)
 Checks whether the additional message parameters should be processed.
 
- Protected Member Functions inherited from LogFormatter
 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.
 
 getRestrictedElement ( $message)
 Helper method for displaying restricted element.
 
 makeUserLink (UserIdentity $user, $toolFlags=0)
 
 msg ( $key,... $params)
 Shortcut for wfMessage which honors local context.
 
 styleRestrictedElement ( $content)
 Helper method for styling restricted element.
 

Additional Inherited Members

- Static Public Member Functions inherited from LogFormatter
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 inherited from LogFormatter
IContextSource $context
 Context for logging.
 
const FOR_PUBLIC = 1
 
const FOR_THIS_USER = 2
 
- Protected Attributes inherited from LogFormatter
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 null $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

This class formats rights log entries.

Stability: stable
to extend Since 1.44
Since
1.21

Definition at line 38 of file RightsLogFormatter.php.

Member Function Documentation

◆ classifyGroupChanges()

RightsLogFormatter::classifyGroupChanges ( array $oldGroups,
array $newGroups )
protected

Compares the user groups from before and after this log entry and splits them into four categories: granted, revoked, expiry-changed and kept.

The returned array has the following keys:

  • granted: groups that were granted
  • revoked: groups that were revoked
  • expiry-changed: groups that had their expiry time changed
  • kept: groups that were kept without changes All, except 'expiry-changed', is of form [ group => expiry ], while 'expiry-changed' is of form [ group => [ old_expiry, new_expiry ] ]
    Since
    1.44
    Parameters
    array$oldGroups
    array$newGroups
    Returns
    array

Definition at line 245 of file RightsLogFormatter.php.

Referenced by getMessageParameters().

◆ formatChangesToGroups()

RightsLogFormatter::formatChangesToGroups ( array $groupChanges,
string $performerName,
string $targetName,
string $messagePrefix = 'logentry-rights-rights-' )
protected

Wraps the changes to user groups into a human-readable messages, so that they can be passed as a parameter to the log entry message.

Since
1.44
Parameters
array$groupChanges
string$performerName
string$targetName
string$messagePrefix
Returns
string

Definition at line 282 of file RightsLogFormatter.php.

References LogFormatter\msg().

Referenced by getMessageParameters().

◆ formatParametersForApi()

RightsLogFormatter::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 from LogFormatter.

Definition at line 454 of file RightsLogFormatter.php.

◆ getMessageKey()

RightsLogFormatter::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 from LogFormatter.

Definition at line 69 of file RightsLogFormatter.php.

References $params, and getMessageParameters().

◆ getMessageParameters()

RightsLogFormatter::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 from LogFormatter.

Definition at line 80 of file RightsLogFormatter.php.

References $params, classifyGroupChanges(), formatChangesToGroups(), getNewGroups(), getOldGroups(), LogFormatter\msg(), and shouldProcessParams().

Referenced by getMessageKey().

◆ getNewGroups()

RightsLogFormatter::getNewGroups ( array $params)
protected

Returns the new groups related to this log entry together with their expiry times.

The returned array is indexed by the group name in a ready-to-display form (eg. localized)

Since
1.44
Stability: stable
to override
Parameters
array$paramsExtracted parameters
Returns
array [ group_name => expiry|null ]

Definition at line 173 of file RightsLogFormatter.php.

References $params, and joinGroupsWithExpiries().

Referenced by getMessageParameters().

◆ getOldGroups()

RightsLogFormatter::getOldGroups ( array $params)
protected

Returns the old groups related to this log entry together with their expiry times.

The returned array is indexed by the group name in a ready-to-display form (eg. localized)

Since
1.44
Stability: stable
to override
Parameters
array$paramsExtracted parameters
Returns
array [ group_name => expiry|null ]

Definition at line 155 of file RightsLogFormatter.php.

References $params, and joinGroupsWithExpiries().

Referenced by getMessageParameters().

◆ getParametersForApi()

RightsLogFormatter::getParametersForApi ( )
protected

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

Since
1.25
Stability: stable
to override
Returns
array

Reimplemented from LogFormatter.

Definition at line 396 of file RightsLogFormatter.php.

References LogFormatter\$entry, $params, and LogEntry\getParameters().

◆ joinGroupsWithExpiries()

RightsLogFormatter::joinGroupsWithExpiries ( $groupNames,
array $metadata )
protected

Joins group names from one array with their expiry times from the another.

Expects that corresponding elements in both arrays are at the same index. The expiry times are looked up in the 'expiry' key of the elements int the metadata array. If membership is permanent, the expiry time is null. If this formatter is not plaintext, the group names are replaced with localized member names.

Since
1.44
Parameters
array | string$groupNames
array$metadata
Returns
array

Definition at line 194 of file RightsLogFormatter.php.

References replaceGroupsWithMemberNames().

Referenced by getNewGroups(), and getOldGroups().

◆ makePageLink()

RightsLogFormatter::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 from LogFormatter.

Definition at line 39 of file RightsLogFormatter.php.

References LogFormatter\getContentLanguage().

◆ replaceGroupsWithMemberNames()

RightsLogFormatter::replaceGroupsWithMemberNames ( array & $groupNames)
protected

Replaces the group names in the array with their localized member names.

The array is modified in place.

Since
1.44
Stability: stable
to override
Parameters
array&$groupNames

Definition at line 222 of file RightsLogFormatter.php.

Referenced by joinGroupsWithExpiries().

◆ shouldProcessParams()

RightsLogFormatter::shouldProcessParams ( array $params)
protected

Checks whether the additional message parameters should be processed.

Typical reason for not processing the parameters is that the log entry is of legacy format with e.g. some of them missing.

Since
1.44
Stability: stable
to override
Parameters
array$paramsExtracted parameters
Returns
bool

Definition at line 142 of file RightsLogFormatter.php.

References $params.

Referenced by getMessageParameters().


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