MediaWiki master
ChangeTags Class Reference

Recent changes tagging. More...

Static Public Member Functions

static activateTagWithChecks (string $tag, string $reason, Authority $performer, bool $ignoreWarnings=false, array $logEntryTags=[])
 Activates a tag, checking whether it is allowed first, and adding a log entry afterwards.
 
static addTags ( $tags, $rc_id=null, $rev_id=null, $log_id=null, $params=null, ?RecentChange $rc=null)
 Add tags to a change given its rc_id, rev_id and/or log_id.
 
static buildTagFilterSelector ( $selected='', $ooui=false, ?IContextSource $context=null, bool $activeOnly=self::TAG_SET_ACTIVE_ONLY, bool $useAllTags=self::USE_ALL_TAGS)
 Build a text box to select a change tag.
 
static canActivateTag ( $tag, ?Authority $performer=null)
 Is it OK to allow the user to activate this tag?
 
static canAddTagsAccompanyingChange (array $tags, ?Authority $performer=null, $checkBlock=true)
 Is it OK to allow the user to apply all the specified tags at the same time as they edit/make the change?
 
static canCreateTag ( $tag, ?Authority $performer=null)
 Is it OK to allow the user to create this tag?
 
static canDeactivateTag ( $tag, ?Authority $performer=null)
 Is it OK to allow the user to deactivate this tag?
 
static canDeleteTag ( $tag, ?Authority $performer=null, int $flags=0)
 Is it OK to allow the user to delete this tag?
 
static canUpdateTags (array $tagsToAdd, array $tagsToRemove, ?Authority $performer=null)
 Is it OK to allow the user to adds and remove the given tags to/from a change?
 
static createTagWithChecks (string $tag, string $reason, Authority $performer, bool $ignoreWarnings=false, array $logEntryTags=[])
 Creates a tag by adding it to change_tag_def table.
 
static deactivateTagWithChecks (string $tag, string $reason, Authority $performer, bool $ignoreWarnings=false, array $logEntryTags=[])
 Deactivates a tag, checking whether it is allowed first, and adding a log entry afterwards.
 
static defineTag ( $tag)
 Set ctd_user_defined = 1 in change_tag_def without checking that the tag name is valid.
 
static deleteTagEverywhere ( $tag)
 Permanently removes all traces of a tag from the DB.
 
static deleteTagWithChecks (string $tag, string $reason, Authority $performer, bool $ignoreWarnings=false, array $logEntryTags=[])
 Deletes a tag, checking whether it is allowed first, and adding a log entry afterwards.
 
static formatSummaryRow ( $tags, $unused, ?MessageLocalizer $localizer=null)
 Creates HTML for the given tags.
 
static getChangeTagList (MessageLocalizer $localizer, Language $lang, bool $activeOnly=self::TAG_SET_ACTIVE_ONLY, bool $useAllTags=self::USE_ALL_TAGS)
 Get information about change tags for tag filter dropdown menus.
 
static getChangeTagListSummary (MessageLocalizer $localizer, Language $lang, bool $activeOnly=self::TAG_SET_ACTIVE_ONLY, bool $useAllTags=self::USE_ALL_TAGS)
 Get information about change tags, without parsing messages, for tag filter dropdown menus.
 
static getDisplayTableName ()
 Get the name of the change_tag table to use for modifyDisplayQuery().
 
static getSoftwareTags ( $all=false)
 Loads defined core tags, checks for invalid types (if not array), and filters for supported and enabled (if $all is false) tags only.
 
static getTags (IReadableDatabase $db, $rc_id=null, $rev_id=null, $log_id=null)
 Return all the tags associated with the given recent change ID, revision ID, and/or log entry ID.
 
static getTagsWithData (IReadableDatabase $db, $rc_id=null, $rev_id=null, $log_id=null)
 Return all the tags associated with the given recent change ID, revision ID, and/or log entry ID, along with any data stored with the tag.
 
static isTagNameValid ( $tag)
 Is the tag name valid?
 
static listDefinedTags ()
 Basically lists defined tags which count even if they aren't applied to anything.
 
static listExplicitlyDefinedTags ()
 Lists tags explicitly defined in the change_tag_def table of the database.
 
static listSoftwareActivatedTags ()
 Lists those tags which core or extensions report as being "active".
 
static listSoftwareDefinedTags ()
 Lists tags defined by core or extensions using the ListDefinedTags hook.
 
static makeTagSummarySubquery ( $tables)
 Make the tag summary subquery based on the given tables and return it.
 
static modifyDisplayQuery (&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='', bool $exclude=false)
 Applies all tags-related changes to a query.
 
static purgeTagCacheAll ()
 Invalidates the short-term cache of defined tags used by the list*DefinedTags functions, as well as the tag statistics cache.
 
static showTagEditingUI (Authority $performer)
 Indicate whether change tag editing UI is relevant.
 
static tagDescription ( $tag, MessageLocalizer $context)
 Get a short description for a tag.
 
static tagHelpLink ( $tag, MessageLocalizer $context)
 Get the tag's help link.
 
static tagLongDescriptionMessage ( $tag, MessageLocalizer $context)
 Get the message object for the tag's long description.
 
static tagShortDescriptionMessage ( $tag, MessageLocalizer $context)
 Get the message object for the tag's short description.
 
static tagUsageStatistics ()
 Returns a map of any tags used on the wiki to number of edits tagged with them, ordered descending by the hitcount.
 
static updateTags ( $tagsToAdd, $tagsToRemove, &$rc_id=null, &$rev_id=null, &$log_id=null, $params=null, ?RecentChange $rc=null, ?UserIdentity $user=null)
 Add and remove tags to/from a change given its rc_id, rev_id and/or log_id, without verifying that the tags exist or are valid.
 
static updateTagsWithChecks ( $tagsToAdd, $tagsToRemove, $rc_id, $rev_id, $log_id, $params, string $reason, Authority $performer)
 Adds and/or removes tags to/from a given change, checking whether it is allowed first, and adding a log entry afterwards.
 

Public Attributes

const BYPASS_MAX_USAGE_CHECK = 1
 Flag for canDeleteTag().
 
const DISPLAY_TABLE_ALIAS = 'changetagdisplay'
 
const REVERT_TAGS = [ self::TAG_ROLLBACK, self::TAG_UNDO, self::TAG_MANUAL_REVERT ]
 List of tags which denote a revert of some sort.
 
const TAG_BLANK = 'mw-blank'
 The tagged edit blanks the page (replaces it with the empty string).
 
const TAG_CHANGED_REDIRECT_TARGET = 'mw-changed-redirect-target'
 The tagged edit changes the target of a redirect page.
 
const TAG_CONTENT_MODEL_CHANGE = 'mw-contentmodelchange'
 The tagged edit changes the content model of the page.
 
const TAG_MANUAL_REVERT = 'mw-manual-revert'
 The tagged edit restores the page to an earlier revision.
 
const TAG_NEW_REDIRECT = 'mw-new-redirect'
 The tagged edit creates a new redirect (either by creating a new page or turning an existing page into a redirect).
 
const TAG_RECREATE = 'mw-recreated'
 The tagged edit recreates a page that has been previously deleted.
 
const TAG_REMOVED_REDIRECT = 'mw-removed-redirect'
 The tagged edit turns a redirect page into a non-redirect.
 
const TAG_REPLACE = 'mw-replace'
 The tagged edit removes more than 90% of the content of the page.
 
const TAG_REVERTED = 'mw-reverted'
 The tagged edit is reverted by a subsequent edit (which is tagged by one of TAG_ROLLBACK, TAG_UNDO, TAG_MANUAL_REVERT).
 
const TAG_ROLLBACK = 'mw-rollback'
 The tagged edit is a rollback (undoes the previous edit and all immediately preceding edits by the same user, and was performed via the "rollback" link available to advanced users or via the rollback API).
 
const TAG_SERVER_SIDE_UPLOAD = 'mw-server-side-upload'
 This tagged edit was performed while importing media files using the importImages.php maintenance script.
 
const TAG_SET_ACTIVE_ONLY = true
 Constants that can be used to set the activeOnly parameter for calling self::buildCustomTagFilterSelect in order to improve function/parameter legibility.
 
const TAG_SET_ALL = false
 
const TAG_UNDO = 'mw-undo'
 The tagged edit is was performed via the "undo" link.
 
const USE_ALL_TAGS = true
 Constants that can be used to set the useAllTags parameter for calling self::buildCustomTagFilterSelect in order to improve function/parameter legibility.
 
const USE_SOFTWARE_TAGS_ONLY = false
 

Static Protected Member Functions

static restrictedTagError ( $msgOne, $msgMulti, $tags)
 Helper function to generate a fatal status with a 'not-allowed' type error.
 

Detailed Description

Recent changes tagging.

Definition at line 58 of file ChangeTags.php.

Member Function Documentation

◆ activateTagWithChecks()

static ChangeTags::activateTagWithChecks ( string $tag,
string $reason,
Authority $performer,
bool $ignoreWarnings = false,
array $logEntryTags = [] )
static

Activates a tag, checking whether it is allowed first, and adding a log entry afterwards.

Includes a call to ChangeTag::canActivateTag(), so your code doesn't need to do that.

Parameters
string$tag
string$reason
Authority$performerwho to check permissions and give credit for the action
bool$ignoreWarningsCan be used for API interaction, default false
array$logEntryTagsChange tags to apply to the entry that will be created in the tag management log
Returns
Status If successful, the Status contains the ID of the added log entry as its value
Since
1.25

Definition at line 894 of file ChangeTags.php.

References canActivateTag(), and MediaWiki\Permissions\Authority\getUser().

Referenced by MediaWiki\Api\ApiManageTags\execute().

◆ addTags()

static ChangeTags::addTags ( $tags,
$rc_id = null,
$rev_id = null,
$log_id = null,
$params = null,
?RecentChange $rc = null )
static

Add tags to a change given its rc_id, rev_id and/or log_id.

Deprecated
since 1.41 use ChangeTagsStore instead. Hard-deprecated since 1.44.
Parameters
string | string[]$tagsTags to add to the change
int | null$rc_idThe rc_id of the change to add the tags to
int | null$rev_idThe rev_id of the change to add the tags to
int | null$log_idThe log_id of the change to add the tags to
string | null$paramsParams to put in the ct_params field of table 'change_tag'
RecentChange | null$rcRecent change, in case the tagging accompanies the action (this should normally be the case)
Returns
bool False if no changes are made, otherwise true

Definition at line 347 of file ChangeTags.php.

References $params, and wfDeprecated().

◆ buildTagFilterSelector()

static ChangeTags::buildTagFilterSelector ( $selected = '',
$ooui = false,
?IContextSource $context = null,
bool $activeOnly = self::TAG_SET_ACTIVE_ONLY,
bool $useAllTags = self::USE_ALL_TAGS )
static

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.

Parameters
string$selectedTag to select by default
bool$oouiUse an OOUI TextInputWidget as selector instead of a non-OOUI input field You need to call OutputPage::enableOOUI() yourself.
IContextSource | null$context
Note
Even though it takes null as a valid argument, an IContextSource is preferred in a new code, as the null value can change in the future
Parameters
bool$activeOnlyWhether to filter for tags that have been used or not
bool$useAllTagsWhether to use all known tags or to only use software defined tags These map to ChangeTagsStore->listDefinedTags and ChangeTagsStore->getCoreDefinedTags respectively
Returns
array an array of (label, selector)

Definition at line 757 of file ChangeTags.php.

References getChangeTagList().

Referenced by MediaWiki\HTMLForm\Field\HTMLTagFilter\getDiv(), MediaWiki\Specials\SpecialRecentChanges\getExtraOptions(), MediaWiki\HTMLForm\Field\HTMLTagFilter\getOOUI(), and MediaWiki\HTMLForm\Field\HTMLTagFilter\getTableRow().

◆ canActivateTag()

static ChangeTags::canActivateTag ( $tag,
?Authority $performer = null )
static

Is it OK to allow the user to activate this tag?

Parameters
string$tagTag that you are interested in activating
Authority | null$performerwhose permission you wish to check, or null if you don't care (e.g. maintenance scripts)
Returns
Status
Since
1.25

Definition at line 847 of file ChangeTags.php.

Referenced by activateTagWithChecks(), and MediaWiki\Specials\SpecialTags\showActivateDeactivateForm().

◆ canAddTagsAccompanyingChange()

static ChangeTags::canAddTagsAccompanyingChange ( array $tags,
?Authority $performer = null,
$checkBlock = true )
static

Is it OK to allow the user to apply all the specified tags at the same time as they edit/make the change?

Extensions should not use this function, unless directly handling a user request to add a tag to a revision or log entry that the user is making.

Parameters
string[]$tagsTags that you are interested in applying
Authority | null$performerwhose permission you wish to check, or null to check for a generic non-blocked user with the relevant rights
bool$checkBlockWhether to check the blocked status of $performer
Returns
Status
Since
1.25

Definition at line 465 of file ChangeTags.php.

References restrictedTagError().

Referenced by MediaWiki\Api\ApiEditPage\execute(), MediaWiki\Api\ApiImageRotate\execute(), MediaWiki\Api\ApiImport\execute(), MediaWiki\Api\ApiManageTags\execute(), MediaWiki\Api\ApiPatrol\execute(), MediaWiki\Api\ApiProtect\execute(), MediaWiki\Api\ApiRevisionDelete\execute(), MediaWiki\Api\ApiRollback\execute(), MediaWiki\Api\ApiSetPageLanguage\execute(), MediaWiki\Api\ApiTag\execute(), MediaWiki\Api\ApiUserrights\execute(), MediaWiki\Specials\SpecialUpload\getPageTextAndTags(), MediaWiki\Page\MovePage\moveIfAllowed(), MediaWiki\Api\ApiUpload\performUpload(), MediaWiki\Content\ContentModelChange\setTags(), and MediaWiki\ParamValidator\TypeDef\TagsDef\validate().

◆ canCreateTag()

static ChangeTags::canCreateTag ( $tag,
?Authority $performer = null )
static

Is it OK to allow the user to create this tag?

Extensions should NOT use this function. In most cases, a tag can be defined using the ListDefinedTags hook without any checking.

Parameters
string$tagTag that you are interested in creating
Authority | null$performerwhose permission you wish to check, or null if you don't care (e.g. maintenance scripts)
Returns
Status
Since
1.25

Definition at line 1022 of file ChangeTags.php.

References isTagNameValid().

Referenced by createTagWithChecks().

◆ canDeactivateTag()

static ChangeTags::canDeactivateTag ( $tag,
?Authority $performer = null )
static

Is it OK to allow the user to deactivate this tag?

Parameters
string$tagTag that you are interested in deactivating
Authority | null$performerwhose permission you wish to check, or null if you don't care (e.g. maintenance scripts)
Returns
Status
Since
1.25

Definition at line 922 of file ChangeTags.php.

Referenced by deactivateTagWithChecks(), and MediaWiki\Specials\SpecialTags\showActivateDeactivateForm().

◆ canDeleteTag()

static ChangeTags::canDeleteTag ( $tag,
?Authority $performer = null,
int $flags = 0 )
static

Is it OK to allow the user to delete this tag?

Parameters
string$tagTag that you are interested in deleting
Authority | null$performerwhose permission you wish to check, or null if you don't care (e.g. maintenance scripts)
int$flagsUse ChangeTags::BYPASS_MAX_USAGE_CHECK to ignore whether there are more uses than we would normally allow to be deleted through the user interface.
Returns
Status
Since
1.25

Definition at line 1126 of file ChangeTags.php.

Referenced by deleteTagWithChecks(), DeleteTag\execute(), and MediaWiki\Specials\SpecialTags\showDeleteTagForm().

◆ canUpdateTags()

static ChangeTags::canUpdateTags ( array $tagsToAdd,
array $tagsToRemove,
?Authority $performer = null )
static

Is it OK to allow the user to adds and remove the given tags to/from a change?

Extensions should not use this function, unless directly handling a user request to add or remove tags from an existing revision or log entry.

Parameters
string[]$tagsToAddTags that you are interested in adding
string[]$tagsToRemoveTags that you are interested in removing
Authority | null$performerwhose permission you wish to check, or null to check for a generic non-blocked user with the relevant rights
Returns
Status
Since
1.25

Definition at line 514 of file ChangeTags.php.

References restrictedTagError().

Referenced by updateTagsWithChecks().

◆ createTagWithChecks()

static ChangeTags::createTagWithChecks ( string $tag,
string $reason,
Authority $performer,
bool $ignoreWarnings = false,
array $logEntryTags = [] )
static

Creates a tag by adding it to change_tag_def table.

Extensions should NOT use this function; they can use the ListDefinedTags hook instead.

Includes a call to ChangeTag::canCreateTag(), so your code doesn't need to do that.

Parameters
string$tag
string$reason
Authority$performerwho to check permissions and give credit for the action
bool$ignoreWarningsCan be used for API interaction, default false
array$logEntryTagsChange tags to apply to the entry that will be created in the tag management log
Returns
Status If successful, the Status contains the ID of the added log entry as its value
Since
1.25

Definition at line 1078 of file ChangeTags.php.

References canCreateTag(), and MediaWiki\Permissions\Authority\getUser().

Referenced by MediaWiki\Api\ApiManageTags\execute(), AddChangeTag\execute(), and MediaWiki\Specials\SpecialTags\processCreateTagForm().

◆ deactivateTagWithChecks()

static ChangeTags::deactivateTagWithChecks ( string $tag,
string $reason,
Authority $performer,
bool $ignoreWarnings = false,
array $logEntryTags = [] )
static

Deactivates a tag, checking whether it is allowed first, and adding a log entry afterwards.

Includes a call to ChangeTag::canDeactivateTag(), so your code doesn't need to do that.

Parameters
string$tag
string$reason
Authority$performerwho to check permissions and give credit for the action
bool$ignoreWarningsCan be used for API interaction, default false
array$logEntryTagsChange tags to apply to the entry that will be created in the tag management log
Returns
Status If successful, the Status contains the ID of the added log entry as its value
Since
1.25

Definition at line 960 of file ChangeTags.php.

References canDeactivateTag(), and MediaWiki\Permissions\Authority\getUser().

Referenced by MediaWiki\Api\ApiManageTags\execute().

◆ defineTag()

static ChangeTags::defineTag ( $tag)
static

Set ctd_user_defined = 1 in change_tag_def without checking that the tag name is valid.

Extensions should NOT use this function; they can use the ListDefinedTags hook instead.

Deprecated
since 1.41 use ChangeTagsStore. Hard-deprecated since 1.44.
Parameters
string$tagTag to create
Since
1.25

Definition at line 833 of file ChangeTags.php.

References wfDeprecated().

◆ deleteTagEverywhere()

static ChangeTags::deleteTagEverywhere ( $tag)
static

Permanently removes all traces of a tag from the DB.

Good for removing misspelt or temporary tags.

This function should be directly called by maintenance scripts only, never by user-facing code. See deleteTagWithChecks() for functionality that can safely be exposed to users.

Deprecated
since 1.41 use ChangeTagsStore instead. Hard-deprecated since 1.44.
Parameters
string$tagTag to remove
Returns
Status The returned status will be good unless a hook changed it
Since
1.25

Definition at line 1109 of file ChangeTags.php.

References wfDeprecated().

◆ deleteTagWithChecks()

static ChangeTags::deleteTagWithChecks ( string $tag,
string $reason,
Authority $performer,
bool $ignoreWarnings = false,
array $logEntryTags = [] )
static

Deletes a tag, checking whether it is allowed first, and adding a log entry afterwards.

Includes a call to ChangeTag::canDeleteTag(), so your code doesn't need to do that.

Parameters
string$tag
string$reason
Authority$performerwho to check permissions and give credit for the action
bool$ignoreWarningsCan be used for API interaction, default false
array$logEntryTagsChange tags to apply to the entry that will be created in the tag management log
Returns
Status If successful, the Status contains the ID of the added log entry as its value
Since
1.25

Definition at line 1190 of file ChangeTags.php.

References canDeleteTag(), and MediaWiki\Permissions\Authority\getUser().

Referenced by MediaWiki\Api\ApiManageTags\execute().

◆ formatSummaryRow()

static ChangeTags::formatSummaryRow ( $tags,
$unused,
?MessageLocalizer $localizer = null )
static

Creates HTML for the given tags.

Parameters
string$tagsComma-separated list of tags
null | string$unusedUnused (formerly: $page)
MessageLocalizer | null$localizer
Note
Even though it takes null as a valid argument, a MessageLocalizer is preferred in a new code, as the null value is subject to change in the future
Returns
array Array with two items: (html, classes)
  • html: String: HTML for displaying the tags (empty string when param $tags is empty)
  • classes: Array of strings: CSS classes used in the generated html, one class for each tag

Definition at line 195 of file ChangeTags.php.

References listDefinedTags(), and tagDescription().

Referenced by MediaWiki\Specials\SpecialUndelete\formatRevisionRow(), MediaWiki\Pager\HistoryPager\formatRow(), MediaWiki\Pager\MergeHistoryPager\formatRow(), MediaWiki\Pager\NewPagesPager\formatRow(), MediaWiki\Pager\ContributionsPager\formatTags(), ChangeTagsLogItem\getHTML(), ChangeTagsRevisionItem\getHTML(), RevDelLogItem\getHTML(), RevDelRevisionItem\getHTML(), ChangesList\insertTags(), LogEventsList\logLine(), and DifferenceEngine\showDiffPage().

◆ getChangeTagList()

static ChangeTags::getChangeTagList ( MessageLocalizer $localizer,
Language $lang,
bool $activeOnly = self::TAG_SET_ACTIVE_ONLY,
bool $useAllTags = self::USE_ALL_TAGS )
static

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 getChangeTagListSummary() instead.

Parameters
MessageLocalizer$localizer
Language$lang
bool$activeOnly
bool$useAllTags
Returns
array[] Same as getChangeTagListSummary(), with messages parsed, stripped and truncated

Definition at line 1405 of file ChangeTags.php.

References getChangeTagListSummary(), MessageLocalizer\msg(), and MediaWiki\Language\Language\truncateForVisual().

Referenced by buildTagFilterSelector(), and MediaWiki\SpecialPage\ChangesListSpecialPage\getRcFiltersConfigVars().

◆ getChangeTagListSummary()

static ChangeTags::getChangeTagListSummary ( MessageLocalizer $localizer,
Language $lang,
bool $activeOnly = self::TAG_SET_ACTIVE_ONLY,
bool $useAllTags = self::USE_ALL_TAGS )
static

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: Short description message (Message object, or false for hidden tags)
  • label: Short description message (raw message contents)
  • descriptionMsg: Long description message (Message object)
  • 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)
  • hits: Number of RC entries that have this tag

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

Parameters
MessageLocalizer$localizer
Language$lang
bool$activeOnly
bool$useAllTags
Returns
array[] Information about each tag

Definition at line 1331 of file ChangeTags.php.

References MediaWiki\Language\Language\getCode(), tagHelpLink(), tagLongDescriptionMessage(), and tagShortDescriptionMessage().

Referenced by getChangeTagList(), and MediaWiki\SpecialPage\ChangesListSpecialPage\getRcFiltersConfigSummary().

◆ getDisplayTableName()

static ChangeTags::getDisplayTableName ( )
static

Get the name of the change_tag table to use for modifyDisplayQuery().

This also does first-call initialisation of the table in testing mode.

Deprecated
since 1.41 use ChangeTags::CHANGE_TAG or 'change_tag' instead. Note that directly querying this table is discouraged, try using one of the existing functions instead. Hard-deprecated since 1.44.
Returns
string

Definition at line 724 of file ChangeTags.php.

References wfDeprecated().

◆ getSoftwareTags()

static ChangeTags::getSoftwareTags ( $all = false)
static

Loads defined core tags, checks for invalid types (if not array), and filters for supported and enabled (if $all is false) tags only.

Parameters
bool$allIf true, return all valid defined tags. Otherwise, return only enabled ones.
Returns
array Array of all defined/enabled tags.
Deprecated
since 1.41 use ChangeTagsStore::getSoftwareTags() instead. Hard-deprecated since 1.44.

Definition at line 177 of file ChangeTags.php.

References wfDeprecated().

◆ getTags()

static ChangeTags::getTags ( IReadableDatabase $db,
$rc_id = null,
$rev_id = null,
$log_id = null )
static

Return all the tags associated with the given recent change ID, revision ID, and/or log entry ID.

Deprecated
since 1.41 use ChangeTagsStore::getTags(). Hard-deprecated since 1.44.
Parameters
IReadableDatabase$dbthe database to query
int | null$rc_id
int | null$rev_id
int | null$log_id
Returns
string[]

Definition at line 426 of file ChangeTags.php.

References wfDeprecated().

◆ getTagsWithData()

static ChangeTags::getTagsWithData ( IReadableDatabase $db,
$rc_id = null,
$rev_id = null,
$log_id = null )
static

Return all the tags associated with the given recent change ID, revision ID, and/or log entry ID, along with any data stored with the tag.

Deprecated
since 1.41 use ChangeTagsStore::getTagsWithData(). Hard-deprecated since 1.44.
Parameters
IReadableDatabase$dbthe database to query
int | null$rc_id
int | null$rev_id
int | null$log_id
Returns
string[] Tag name => data. Data format is tag-specific.
Since
1.36

Definition at line 408 of file ChangeTags.php.

References wfDeprecated().

◆ isTagNameValid()

static ChangeTags::isTagNameValid ( $tag)
static

Is the tag name valid?

Parameters
string$tagTag that you are interested in creating
Returns
Status
Since
1.30

Definition at line 986 of file ChangeTags.php.

References NS_MEDIAWIKI.

Referenced by canCreateTag().

◆ listDefinedTags()

static ChangeTags::listDefinedTags ( )
static

Basically lists defined tags which count even if they aren't applied to anything.

It returns a union of the results of listExplicitlyDefinedTags() and listSoftwareDefinedTags()

Deprecated
since 1.41 use ChangeTagsStore instead. Hard-deprecated since 1.44.
Returns
string[] Array of strings: tags

Definition at line 1239 of file ChangeTags.php.

References wfDeprecated().

Referenced by formatSummaryRow().

◆ listExplicitlyDefinedTags()

static ChangeTags::listExplicitlyDefinedTags ( )
static

Lists tags explicitly defined in the change_tag_def table of the database.

Tries memcached first.

Deprecated
since 1.41 use ChangeTagsStore instead. Hard-deprecated since 1.44.
Returns
string[] Array of strings: tags
Since
1.25

Definition at line 1253 of file ChangeTags.php.

References wfDeprecated().

◆ listSoftwareActivatedTags()

static ChangeTags::listSoftwareActivatedTags ( )
static

Lists those tags which core or extensions report as being "active".

Deprecated
since 1.41 use ChangeTagsStore instead. Hard-deprecated since 1.44.
Returns
array
Since
1.25

Definition at line 1226 of file ChangeTags.php.

References wfDeprecated().

◆ listSoftwareDefinedTags()

static ChangeTags::listSoftwareDefinedTags ( )
static

Lists tags defined by core or extensions using the ListDefinedTags hook.

Extensions need only define those tags they deem to be in active use.

Tries memcached first.

Deprecated
since 1.41 use ChangeTagsStore instead. Hard-deprecated since 1.44.
Returns
string[] Array of strings: tags
Since
1.25

Definition at line 1268 of file ChangeTags.php.

References wfDeprecated().

◆ makeTagSummarySubquery()

static ChangeTags::makeTagSummarySubquery ( $tables)
static

Make the tag summary subquery based on the given tables and return it.

Deprecated
since 1.41 use ChangeTagsStore instead. Hard-deprecated since 1.44.
Parameters
string | array$tablesTable names, see Database::select
Returns
string tag summary subqeury

Definition at line 737 of file ChangeTags.php.

References wfDeprecated().

◆ modifyDisplayQuery()

static ChangeTags::modifyDisplayQuery ( & $tables,
& $fields,
& $conds,
& $join_conds,
& $options,
$filter_tag = '',
bool $exclude = false )
static

Applies all tags-related changes to a query.

Handles selecting tags, and filtering. Needs $tables to be set up properly, so we can figure out which join conditions to use.

WARNING: If $filter_tag contains more than one tag and $exclude is false, this function will add DISTINCT, which may cause performance problems for your query unless you put the ID field of your table at the end of the ORDER BY, and set a GROUP BY equal to the ORDER BY. For example, if you had ORDER BY foo_timestamp DESC, you will now need GROUP BY foo_timestamp, foo_id ORDER BY foo_timestamp DESC, foo_id DESC.

Deprecated
since 1.41 use ChangeTagsStore::modifyDisplayQueryBuilder instead. Hard-deprecated since 1.44.
Parameters
string | array&$tablesTable names, see Database::select
string | array&$fieldsFields used in query, see Database::select
string | array&$condsConditions used in query, see Database::select
array&$join_condsJoin conditions, see Database::select
string | array&$optionsOptions, see Database::select
string | array | false | null$filter_tagTag(s) to select on (OR)
bool$excludeIf true, exclude tag(s) from $filter_tag (NOR)

Definition at line 700 of file ChangeTags.php.

References wfDeprecated().

◆ purgeTagCacheAll()

static ChangeTags::purgeTagCacheAll ( )
static

Invalidates the short-term cache of defined tags used by the list*DefinedTags functions, as well as the tag statistics cache.

Deprecated
since 1.41 use ChangeTagsStore instead. Hard-deprecated since 1.44.
Since
1.25

Definition at line 1279 of file ChangeTags.php.

References wfDeprecated().

◆ restrictedTagError()

static ChangeTags::restrictedTagError ( $msgOne,
$msgMulti,
$tags )
staticprotected

Helper function to generate a fatal status with a 'not-allowed' type error.

Parameters
string$msgOneMessage key to use in the case of one tag
string$msgMultiMessage key to use in the case of more than one tag
string[]$tagsRestricted tags (passed as $1 into the message, count of $tags passed as $2)
Returns
Status
Since
1.25

Definition at line 441 of file ChangeTags.php.

Referenced by canAddTagsAccompanyingChange(), and canUpdateTags().

◆ showTagEditingUI()

static ChangeTags::showTagEditingUI ( Authority $performer)
static

Indicate whether change tag editing UI is relevant.

Returns true if the user has the necessary right and there are any editable tags defined.

This intentionally doesn't check "any addable || any deletable", because it seems like it would be more confusing than useful if the checkboxes suddenly showed up because some abuse filter stopped defining a tag and then suddenly disappeared when someone deleted all uses of that tag.

Parameters
Authority$performer
Returns
bool

Definition at line 1451 of file ChangeTags.php.

References MediaWiki\Permissions\Authority\isAllowed().

Referenced by LogEventsList\__construct(), and MediaWiki\Pager\HistoryPager\__construct().

◆ tagDescription()

static ChangeTags::tagDescription ( $tag,
MessageLocalizer $context )
static

Get a short description for a tag.

The description combines the label from tagShortDescriptionMessage() with the link from tagHelpLink() (unless the label already contains some links).

Parameters
string$tag
MessageLocalizer$context
Returns
string|false Tag description or false if tag is to be hidden.
Since
1.25 Returns false if tag is to be hidden.

Definition at line 303 of file ChangeTags.php.

References tagHelpLink(), and tagShortDescriptionMessage().

Referenced by MediaWiki\Api\ApiQueryTags\execute(), and formatSummaryRow().

◆ tagHelpLink()

static ChangeTags::tagHelpLink ( $tag,
MessageLocalizer $context )
static

Get the tag's help link.

Checks if message key "mediawiki:tag-$tag-helppage" exists in content language. If it does, and contains a URL or a page title, return a (possibly relative) link URL that points there. Otherwise return null.

Since
1.43
Parameters
string$tag
MessageLocalizer$context
Returns
string|null Tag link, or null if not provided or invalid

Definition at line 284 of file ChangeTags.php.

References Skin\makeInternalOrExternalUrl(), and MessageLocalizer\msg().

Referenced by getChangeTagListSummary(), and tagDescription().

◆ tagLongDescriptionMessage()

static ChangeTags::tagLongDescriptionMessage ( $tag,
MessageLocalizer $context )
static

Get the message object for the tag's long description.

Checks if message key "mediawiki:tag-$tag-description" exists. If it does not, or if message is disabled, returns false. Otherwise, returns the message object for the long description.

Parameters
string$tag
MessageLocalizer$context
Returns
Message|false Message object of the tag long description or false if there is no description.

Definition at line 328 of file ChangeTags.php.

References MessageLocalizer\msg().

Referenced by getChangeTagListSummary().

◆ tagShortDescriptionMessage()

static ChangeTags::tagShortDescriptionMessage ( $tag,
MessageLocalizer $context )
static

Get the message object for the tag's short description.

Checks if message key "mediawiki:tag-$tag" exists. If it does not, returns the tag name in a RawMessage. If the message exists, it is used, provided it is not disabled. If the message is disabled, we consider the tag hidden, and return false.

Since
1.34
Parameters
string$tag
MessageLocalizer$context
Returns
Message|false Tag description, or false if tag is to be hidden.

Definition at line 255 of file ChangeTags.php.

References MessageLocalizer\msg().

Referenced by getChangeTagListSummary(), and tagDescription().

◆ tagUsageStatistics()

static ChangeTags::tagUsageStatistics ( )
static

Returns a map of any tags used on the wiki to number of edits tagged with them, ordered descending by the hitcount.

This does not include tags defined somewhere that have never been applied.

Deprecated
since 1.41 use ChangeTagsStore. Hard-deprecated since 1.44.
Returns
array Array of string => int

Definition at line 1292 of file ChangeTags.php.

References wfDeprecated().

◆ updateTags()

static ChangeTags::updateTags ( $tagsToAdd,
$tagsToRemove,
& $rc_id = null,
& $rev_id = null,
& $log_id = null,
$params = null,
?RecentChange $rc = null,
?UserIdentity $user = null )
static

Add and remove tags to/from a change given its rc_id, rev_id and/or log_id, without verifying that the tags exist or are valid.

If a tag is present in both $tagsToAdd and $tagsToRemove, it will be removed.

This function should only be used by extensions to manipulate tags they have registered using the ListDefinedTags hook. When dealing with user input, call updateTagsWithChecks() instead.

Deprecated
since 1.41 use ChangeTagsStore::updateTags(). Hard-deprecated since 1.44.
Parameters
string | array | null$tagsToAddTags to add to the change
string | array | null$tagsToRemoveTags to remove from the change
int | null&$rc_idThe rc_id of the change to add the tags to. Pass a variable whose value is null if the rc_id is not relevant or unknown.
int | null&$rev_idThe rev_id of the change to add the tags to. Pass a variable whose value is null if the rev_id is not relevant or unknown.
int | null&$log_idThe log_id of the change to add the tags to. Pass a variable whose value is null if the log_id is not relevant or unknown.
string | null$paramsParams to put in the ct_params field of table 'change_tag' when adding tags
RecentChange | null$rcRecent change being tagged, in case the tagging accompanies the action
UserIdentity | null$userTagging user, in case the tagging is subsequent to the tagged action
Returns
array Index 0 is an array of tags actually added, index 1 is an array of tags actually removed, index 2 is an array of tags present on the revision or log entry before any changes were made
Since
1.25

Definition at line 386 of file ChangeTags.php.

References $params, and wfDeprecated().

◆ updateTagsWithChecks()

static ChangeTags::updateTagsWithChecks ( $tagsToAdd,
$tagsToRemove,
$rc_id,
$rev_id,
$log_id,
$params,
string $reason,
Authority $performer )
static

Adds and/or removes tags to/from a given change, checking whether it is allowed first, and adding a log entry afterwards.

Includes a call to ChangeTags::canUpdateTags(), so your code doesn't need to do that. However, it doesn't check whether the *_id parameters are a valid combination. That is up to you to enforce. See ApiTag::execute() for an example.

Extensions should generally avoid this function. Call ChangeTagsStore->updateTags() instead, unless directly handling a user request to add or remove tags from an existing revision or log entry.

Parameters
array | null$tagsToAddIf none, pass [] or null
array | null$tagsToRemoveIf none, pass [] or null
int | null$rc_idThe rc_id of the change to add the tags to
int | null$rev_idThe rev_id of the change to add the tags to
int | null$log_idThe log_id of the change to add the tags to
string | null$paramsParams to put in the ct_params field of table 'change_tag' when adding tags
string$reasonComment for the log
Authority$performerwho to check permissions and give credit for the action
Returns
Status If successful, the value of this Status object will be an object (stdClass) with the following fields:
  • logId: the ID of the added log entry, or null if no log entry was added (i.e. no operation was performed)
  • addedTags: an array containing the tags that were actually added
  • removedTags: an array containing the tags that were actually removed
Since
1.25

Definition at line 589 of file ChangeTags.php.

References $params, MediaWiki\Permissions\Authority\authorizeAction(), canUpdateTags(), MediaWiki\Permissions\Authority\getUser(), and RevDelLogList\suggestTarget().

Referenced by MediaWiki\Api\ApiTag\processIndividual(), ChangeTagsLogList\updateChangeTagsOnAll(), and ChangeTagsRevisionList\updateChangeTagsOnAll().

Member Data Documentation

◆ BYPASS_MAX_USAGE_CHECK

const ChangeTags::BYPASS_MAX_USAGE_CHECK = 1

Flag for canDeleteTag().

Definition at line 130 of file ChangeTags.php.

Referenced by DeleteTag\execute().

◆ DISPLAY_TABLE_ALIAS

const ChangeTags::DISPLAY_TABLE_ALIAS = 'changetagdisplay'

Definition at line 144 of file ChangeTags.php.

Referenced by MediaWiki\Specials\SpecialRecentChanges\doMainQuery().

◆ REVERT_TAGS

const ChangeTags::REVERT_TAGS = [ self::TAG_ROLLBACK, self::TAG_UNDO, self::TAG_MANUAL_REVERT ]

List of tags which denote a revert of some sort.

(See also TAG_REVERTED.)

Definition at line 125 of file ChangeTags.php.

Referenced by MediaWiki\Rest\Handler\PageHistoryCountHandler\getRevertedCount(), and MediaWiki\Rest\Handler\PageHistoryHandler\run().

◆ TAG_BLANK

const ChangeTags::TAG_BLANK = 'mw-blank'

The tagged edit blanks the page (replaces it with the empty string).

Definition at line 79 of file ChangeTags.php.

◆ TAG_CHANGED_REDIRECT_TARGET

const ChangeTags::TAG_CHANGED_REDIRECT_TARGET = 'mw-changed-redirect-target'

The tagged edit changes the target of a redirect page.

Definition at line 75 of file ChangeTags.php.

◆ TAG_CONTENT_MODEL_CHANGE

const ChangeTags::TAG_CONTENT_MODEL_CHANGE = 'mw-contentmodelchange'

The tagged edit changes the content model of the page.

Definition at line 62 of file ChangeTags.php.

◆ TAG_MANUAL_REVERT

const ChangeTags::TAG_MANUAL_REVERT = 'mw-manual-revert'

The tagged edit restores the page to an earlier revision.

The associated tag data is a JSON containing the edit result (see EditResult::jsonSerialize()).

Definition at line 108 of file ChangeTags.php.

◆ TAG_NEW_REDIRECT

const ChangeTags::TAG_NEW_REDIRECT = 'mw-new-redirect'

The tagged edit creates a new redirect (either by creating a new page or turning an existing page into a redirect).

Definition at line 67 of file ChangeTags.php.

◆ TAG_RECREATE

const ChangeTags::TAG_RECREATE = 'mw-recreated'

The tagged edit recreates a page that has been previously deleted.

Definition at line 87 of file ChangeTags.php.

◆ TAG_REMOVED_REDIRECT

const ChangeTags::TAG_REMOVED_REDIRECT = 'mw-removed-redirect'

The tagged edit turns a redirect page into a non-redirect.

Definition at line 71 of file ChangeTags.php.

◆ TAG_REPLACE

const ChangeTags::TAG_REPLACE = 'mw-replace'

The tagged edit removes more than 90% of the content of the page.

Definition at line 83 of file ChangeTags.php.

◆ TAG_REVERTED

const ChangeTags::TAG_REVERTED = 'mw-reverted'

The tagged edit is reverted by a subsequent edit (which is tagged by one of TAG_ROLLBACK, TAG_UNDO, TAG_MANUAL_REVERT).

Multiple edits might be reverted by the same edit.

The associated tag data is a JSON containing the edit result (see EditResult::jsonSerialize()) with an extra 'revertId' field containing the revision ID of the reverting edit.

Definition at line 116 of file ChangeTags.php.

Referenced by MediaWiki\Storage\RevertedTagUpdate\doUpdate().

◆ TAG_ROLLBACK

const ChangeTags::TAG_ROLLBACK = 'mw-rollback'

The tagged edit is a rollback (undoes the previous edit and all immediately preceding edits by the same user, and was performed via the "rollback" link available to advanced users or via the rollback API).

The associated tag data is a JSON containing the edit result (see EditResult::jsonSerialize()).

Definition at line 95 of file ChangeTags.php.

◆ TAG_SERVER_SIDE_UPLOAD

const ChangeTags::TAG_SERVER_SIDE_UPLOAD = 'mw-server-side-upload'

This tagged edit was performed while importing media files using the importImages.php maintenance script.

Definition at line 120 of file ChangeTags.php.

Referenced by ImportImages\execute().

◆ TAG_SET_ACTIVE_ONLY

const ChangeTags::TAG_SET_ACTIVE_ONLY = true

Constants that can be used to set the activeOnly parameter for calling self::buildCustomTagFilterSelect in order to improve function/parameter legibility.

If TAG_SET_ACTIVE_ONLY is used then the hit count for each tag will be checked against and only tags with hits will be returned Otherwise if TAG_SET_ALL is used then all tags will be returned regardlesss of if they've ever been used or not

Definition at line 155 of file ChangeTags.php.

◆ TAG_SET_ALL

const ChangeTags::TAG_SET_ALL = false

Definition at line 156 of file ChangeTags.php.

◆ TAG_UNDO

const ChangeTags::TAG_UNDO = 'mw-undo'

The tagged edit is was performed via the "undo" link.

(Usually this means that it undoes some previous edit, but the undo workflow includes an edit step so it could be anything.)

The associated tag data is a JSON containing the edit result (see EditResult::jsonSerialize()).

Definition at line 102 of file ChangeTags.php.

◆ USE_ALL_TAGS

const ChangeTags::USE_ALL_TAGS = true

Constants that can be used to set the useAllTags parameter for calling self::buildCustomTagFilterSelect in order to improve function/parameter legibility.

If USE_ALL_TAGS is used then all on-wiki tags will be returned Otherwise if USE_SOFTWARE_TAGS_ONLY is used then only mediawiki core-defined tags will be returned

Definition at line 166 of file ChangeTags.php.

◆ USE_SOFTWARE_TAGS_ONLY

const ChangeTags::USE_SOFTWARE_TAGS_ONLY = false

Definition at line 167 of file ChangeTags.php.


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