MediaWiki master
MediaWiki\ChangeTags\ChangeTagsStore Class Reference

Gateway class for change_tags table. More...

Public Member Functions

 __construct (IConnectionProvider $dbProvider, NameTableStore $changeTagDefStore, WANObjectCache $wanCache, HookContainer $hookContainer, LoggerInterface $logger, UserFactory $userFactory, ServiceOptions $options)
 
 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.
 
 defineTag ( $tag)
 Set ctd_user_defined = 1 in change_tag_def without checking that the tag name is valid.
 
 deleteTagEverywhere ( $tag)
 Permanently removes all traces of a tag from the DB.
 
 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.
 
 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.
 
 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.
 
 listDefinedTags ()
 Basically lists defined tags which count even if they aren't applied to anything.
 
 listExplicitlyDefinedTags ()
 Lists tags explicitly defined in the change_tag_def table of the database.
 
 listSoftwareActivatedTags ()
 Lists those tags which core or extensions report as being "active".
 
 listSoftwareDefinedTags ()
 Lists tags defined by core or extensions using the ListDefinedTags hook.
 
 logTagManagementAction (string $action, string $tag, string $reason, UserIdentity $user, $tagCount=null, array $logEntryTags=[])
 Writes a tag action into the tag management log.
 
 makeTagSummarySubquery ( $tables)
 Make the tag summary subquery based on the given tables and return it.
 
 modifyDisplayQuery (&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='', bool $exclude=false)
 Applies all tags-related changes to a query.
 
 modifyDisplayQueryBuilder (SelectQueryBuilder $queryBuilder, $table, $filter_tag='', bool $exclude=false)
 Applies all tags-related changes to a query builder object.
 
 purgeTagCacheAll ()
 Invalidates the short-term cache of defined tags used by the list*DefinedTags functions, as well as the tag statistics cache.
 
 tagUsageStatistics ()
 Returns a map of any tags used on the wiki to number of edits tagged with them, ordered descending by the hitcount.
 
 undefineTag ( $tag)
 Update ctd_user_defined = 0 field in change_tag_def.
 
 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.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 
const DISPLAY_TABLE_ALIAS = 'changetagdisplay'
 

Detailed Description

Gateway class for change_tags table.

Since
1.41

Definition at line 49 of file ChangeTagsStore.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\ChangeTags\ChangeTagsStore::__construct ( IConnectionProvider $dbProvider,
NameTableStore $changeTagDefStore,
WANObjectCache $wanCache,
HookContainer $hookContainer,
LoggerInterface $logger,
UserFactory $userFactory,
ServiceOptions $options )

Member Function Documentation

◆ addTags()

MediaWiki\ChangeTags\ChangeTagsStore::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.

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 724 of file ChangeTagsStore.php.

References $params.

◆ defineTag()

MediaWiki\ChangeTags\ChangeTagsStore::defineTag ( $tag)

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.

Parameters
string$tagTag to create
Since
1.41

Definition at line 226 of file ChangeTagsStore.php.

◆ deleteTagEverywhere()

MediaWiki\ChangeTags\ChangeTagsStore::deleteTagEverywhere ( $tag)

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.

Parameters
string$tagTag to remove
Returns
Status The returned status will be good unless a hook changed it
Since
1.41

Definition at line 321 of file ChangeTagsStore.php.

◆ getSoftwareTags()

MediaWiki\ChangeTags\ChangeTagsStore::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.

Parameters
bool$allIf true, return all valid defined tags. Otherwise, return only enabled ones.
Returns
array Array of all defined/enabled tags.

Definition at line 124 of file ChangeTagsStore.php.

◆ getTags()

MediaWiki\ChangeTags\ChangeTagsStore::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.

Parameters
IReadableDatabase$dbthe database to query
int | null$rc_id
int | null$rev_id
int | null$log_id
Returns
string[]

Definition at line 486 of file ChangeTagsStore.php.

◆ getTagsWithData()

MediaWiki\ChangeTags\ChangeTagsStore::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.

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.41

Definition at line 153 of file ChangeTagsStore.php.

◆ listDefinedTags()

MediaWiki\ChangeTags\ChangeTagsStore::listDefinedTags ( )

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()

Returns
string[] Array of strings: tags

Definition at line 497 of file ChangeTagsStore.php.

◆ listExplicitlyDefinedTags()

MediaWiki\ChangeTags\ChangeTagsStore::listExplicitlyDefinedTags ( )

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

Tries memcached first.

Returns
string[] Array of strings: tags
Since
1.25

Definition at line 416 of file ChangeTagsStore.php.

References Wikimedia\Rdbms\IConnectionProvider\getReplicaDatabase().

◆ listSoftwareActivatedTags()

MediaWiki\ChangeTags\ChangeTagsStore::listSoftwareActivatedTags ( )

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

Returns
array
Since
1.41

Definition at line 737 of file ChangeTagsStore.php.

References Wikimedia\Rdbms\IConnectionProvider\getReplicaDatabase(), and MediaWiki\HookContainer\HookRunner\onChangeTagsListActive().

◆ listSoftwareDefinedTags()

MediaWiki\ChangeTags\ChangeTagsStore::listSoftwareDefinedTags ( )

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.

Returns
string[] Array of strings: tags
Since
1.25

Definition at line 452 of file ChangeTagsStore.php.

References Wikimedia\Rdbms\IConnectionProvider\getReplicaDatabase(), and MediaWiki\HookContainer\HookRunner\onListDefinedTags().

◆ logTagManagementAction()

MediaWiki\ChangeTags\ChangeTagsStore::logTagManagementAction ( string $action,
string $tag,
string $reason,
UserIdentity $user,
$tagCount = null,
array $logEntryTags = [] )

Writes a tag action into the tag management log.

Parameters
string$action
string$tag
string$reason
UserIdentity$userWho to attribute the action to
int | null$tagCountFor deletion only, how many usages the tag had before it was deleted.
array$logEntryTagsChange tags to apply to the entry that will be created in the tag management log
Returns
int ID of the inserted log entry
Since
1.41

Definition at line 284 of file ChangeTagsStore.php.

References $params.

◆ makeTagSummarySubquery()

MediaWiki\ChangeTags\ChangeTagsStore::makeTagSummarySubquery ( $tables)

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

Parameters
string | array$tablesTable names, see Database::select
Returns
string tag summary subqeury

Definition at line 192 of file ChangeTagsStore.php.

◆ modifyDisplayQuery()

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

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
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 786 of file ChangeTagsStore.php.

◆ modifyDisplayQueryBuilder()

MediaWiki\ChangeTags\ChangeTagsStore::modifyDisplayQueryBuilder ( SelectQueryBuilder $queryBuilder,
$table,
$filter_tag = '',
bool $exclude = false )

Applies all tags-related changes to a query builder object.

Handles selecting tags, and filtering.

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.

Parameters
SelectQueryBuilder$queryBuilderQuery builder to add the join
string$tableTable name. Must be either of 'recentchanges', 'logging', 'revision', or 'archive'
string | array | false | null$filter_tagTag(s) to select on (OR)
bool$excludeIf true, exclude tag(s) from $filter_tag (NOR)

Definition at line 881 of file ChangeTagsStore.php.

References Wikimedia\Rdbms\SelectQueryBuilder\distinct(), Wikimedia\Rdbms\SelectQueryBuilder\field(), Wikimedia\Rdbms\JoinGroupBase\join(), Wikimedia\Rdbms\JoinGroupBase\leftJoin(), and Wikimedia\Rdbms\SelectQueryBuilder\where().

◆ purgeTagCacheAll()

MediaWiki\ChangeTags\ChangeTagsStore::purgeTagCacheAll ( )

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

Since
1.41

Definition at line 362 of file ChangeTagsStore.php.

◆ tagUsageStatistics()

MediaWiki\ChangeTags\ChangeTagsStore::tagUsageStatistics ( )

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.

Returns
array Array of string => int

Definition at line 377 of file ChangeTagsStore.php.

References Wikimedia\Rdbms\IConnectionProvider\getReplicaDatabase().

◆ undefineTag()

MediaWiki\ChangeTags\ChangeTagsStore::undefineTag ( $tag)

Update ctd_user_defined = 0 field in change_tag_def.

The tag may remain in use by extensions, and may still show up as 'defined' if an extension is setting it from the ListDefinedTags hook.

Parameters
string$tagTag to remove
Since
1.41

Definition at line 252 of file ChangeTagsStore.php.

◆ updateTags()

MediaWiki\ChangeTags\ChangeTagsStore::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.

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.

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

Definition at line 530 of file ChangeTagsStore.php.

References $params.

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\ChangeTags\ChangeTagsStore::CONSTRUCTOR_OPTIONS
Initial value:
= [
]
const UseTagFilter
Name constant for the UseTagFilter setting, for use with Config::get()
const SoftwareTags
Name constant for the SoftwareTags setting, for use with Config::get()
Access: internal
For use by ServiceWiring

Definition at line 66 of file ChangeTagsStore.php.

◆ DISPLAY_TABLE_ALIAS

const MediaWiki\ChangeTags\ChangeTagsStore::DISPLAY_TABLE_ALIAS = 'changetagdisplay'

Definition at line 61 of file ChangeTagsStore.php.


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