MediaWiki master
MediaWiki\ChangeTags\ChangeTagsFormatter Class Reference

Formats change tags for display in HTML and use filter dropdown menus. More...

Public Member Functions

 __construct (private readonly ServiceOptions $options, private readonly ChangeTagsStore $changeTagsStore, private readonly WANObjectCache $cache, private readonly LanguageFactory $languageFactory,)
 
 buildTagFilter (string $selected, string $format, IContextSource $context, bool $activeOnly=true, bool $useAllTags=true)
 Build a text box to select a change tag.
 
 formatTagsAsSummaryList (?string $tags, MessageLocalizer $localizer, Authority $authority)
 Formats the provided tags into HTML for display to a user.
 
 getChangeTagList (LocalizationContext $localizationContext, Authority $authority, bool $activeOnly=true, bool $useAllTags=true, bool $labelsOnly=false)
 Get information about change tags for tag filter dropdown menus.
 
 getChangeTagListSummary (LocalizationContext $localizationContext, Authority $authority, bool $activeOnly=true, bool $useAllTags=true)
 Get information about change tags, without parsing messages, for tag filter dropdown menus.
 
 getTagDescription (string $tag, MessageLocalizer $localizer)
 Get a (short) description for a tag.
 

Public Attributes

const array CONSTRUCTOR_OPTIONS
 

Detailed Description

Formats change tags for display in HTML and use filter dropdown menus.

Since
1.47

Definition at line 30 of file ChangeTagsFormatter.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\ChangeTags\ChangeTagsFormatter::__construct ( private readonly ServiceOptions $options,
private readonly ChangeTagsStore $changeTagsStore,
private readonly WANObjectCache $cache,
private readonly LanguageFactory $languageFactory )

Definition at line 43 of file ChangeTagsFormatter.php.

Member Function Documentation

◆ buildTagFilter()

MediaWiki\ChangeTags\ChangeTagsFormatter::buildTagFilter ( string $selected,
string $format,
IContextSource $context,
bool $activeOnly = true,
bool $useAllTags = true )

Build a text box to select a change tag.

The tag set can be customized via the $activeOnly and $useAllTags parameters, and defaults to all active tags.

Since
1.47
Parameters
string$selectedTag to select by default
string$formatOne of the following formats:
  • ‘'ooui’: Use an OOUI {@link ComboBoxInputWidget}. You need to call {@link OutputPage::enableOOUI()} yourself. -'codex': Use a Codex CSS-only Lookup input.
  • otherwise: Plain HTML select box. @param IContextSource $context @param bool $activeOnly Iftrue, only show tags which have been used at least once @param bool $useAllTags Iftrue, use all known tags. Iffalse`, use only tags defined by MediaWiki core (excluding tags defined by extensions, users, or site config)
Returns
array{0:string,1:string|ComboBoxInputWidget}|null Two chunks of HTML (label, and dropdown menu) or null if disabled

Definition at line 177 of file ChangeTagsFormatter.php.

◆ formatTagsAsSummaryList()

MediaWiki\ChangeTags\ChangeTagsFormatter::formatTagsAsSummaryList ( ?string $tags,
MessageLocalizer $localizer,
Authority $authority )

Formats the provided tags into HTML for display to a user.

Since
1.47
Parameters
string | null$tagsComma-separated list of tags (as returned by a database query)
MessageLocalizer$localizer
Authority$authority
Returns
array{0:string,1:string[]} Array with two items: (html, classes)
  • html: String: HTML for displaying the tags (empty string when param $tags is empty or all tags have no description)
  • classes: Array of strings: CSS classes to be appended to the parent element that this HTML is appended to, one class per tag provided

Definition at line 66 of file ChangeTagsFormatter.php.

◆ getChangeTagList()

MediaWiki\ChangeTags\ChangeTagsFormatter::getChangeTagList ( LocalizationContext $localizationContext,
Authority $authority,
bool $activeOnly = true,
bool $useAllTags = true,
bool $labelsOnly = false )

Get information about change tags for tag filter dropdown menus.

This manipulates the label and description of each tag, which are parsed, stripped and (in the case of description) truncated versions of these messages. Message parsing is expensive, so to detect whether the tag list has changed, use ChangeTagsFormatter::getChangeTagListSummary() instead.

Since
1.47
Parameters
LocalizationContext$localizationContext
Authority$authority
bool$activeOnlyIf true, only show tags which have been used at least once
bool$useAllTagsIf true, use all known tags. If false, use only tags defined by MediaWiki core (excluding tags defined by extensions, users, or site config)
bool$labelsOnlyDo not parse descriptions and omit 'description' in the result
Returns
array[] Same as ChangeTagsFormatter::getChangeTagListSummary(), with messages parsed, stripped and truncated

Definition at line 364 of file ChangeTagsFormatter.php.

References MediaWiki\Language\MessageLocalizer\msg(), and wfEscapeWikiText().

◆ getChangeTagListSummary()

MediaWiki\ChangeTags\ChangeTagsFormatter::getChangeTagListSummary ( LocalizationContext $localizationContext,
Authority $authority,
bool $activeOnly = true,
bool $useAllTags = true )

Get information about change tags, without parsing messages, for tag filter dropdown menus.

By default, this will return explicitly-defined and software-defined tags that are currently active (have hits)

Message contents are the raw values (->plain()), because parsing messages is expensive. Even though we're not parsing messages, building a data structure with the contents of hundreds of i18n messages is still not cheap (see T223260#5370610), so this function caches its output in WANCache for up to 24 hours.

Returns an array of associative arrays with information about each tag:

  • name: Tag name (string)
  • labelMsg: Whether the short description message exists and is enabled (boolean)
  • label: Short description message (raw message contents), or the tag name if the short description message was disabled or did not exist
  • descriptionMsg: Whether the long description message exists and is enabled (boolean)
  • description: Long description message (raw message contents)
  • cssClass: CSS class to use for RC entries with this tag
  • helpLink: Link to a help page describing this tag (string or null)

This data is consumed by the mediawiki.rcfilters.filters.ui module, specifically mw.rcfilters.dm.FilterGroup and mw.rcfilters.dm.FilterItem.

Since
1.47
Parameters
LocalizationContext$localizationContext
Authority$authority
bool$activeOnlyIf true, only show tags which have been used at least once
bool$useAllTagsIf true, use all known tags. If false, use only tags defined by MediaWiki core (excluding tags defined by extensions, users, or site config)
Returns
array[] Information about each tag

Definition at line 278 of file ChangeTagsFormatter.php.

◆ getTagDescription()

MediaWiki\ChangeTags\ChangeTagsFormatter::getTagDescription ( string $tag,
MessageLocalizer $localizer )

Get a (short) description for a tag.

The description includes the label for the tag along with a help link if defined. If the tag description is an empty string, the tag is considered hidden.

Since
1.47

Definition at line 120 of file ChangeTagsFormatter.php.

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

const array MediaWiki\ChangeTags\ChangeTagsFormatter::CONSTRUCTOR_OPTIONS
Initial value:
= [
]
const UseTagFilter
Name constant for the UseTagFilter setting, for use with Config::get()
Access: internal
Only for use by ServiceWiring.php

Definition at line 33 of file ChangeTagsFormatter.php.


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