Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F2753460
ChangeTagValidator.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
ChangeTagValidator.php
View Options
<?php
namespace
MediaWiki\Extension\AbuseFilter\ChangeTags
;
use
ChangeTags
;
use
MediaWiki\Status\Status
;
/**
* Service for testing whether filters can tag edits and other changes
* with a specific tag
* @todo Use DI when available in core (T245964)
*/
class
ChangeTagValidator
{
public
const
SERVICE_NAME
=
'AbuseFilterChangeTagValidator'
;
/** @var ChangeTagsManager */
private
$changeTagsManager
;
/**
* @param ChangeTagsManager $changeTagsManager
*/
public
function
__construct
(
ChangeTagsManager
$changeTagsManager
)
{
$this
->
changeTagsManager
=
$changeTagsManager
;
}
/**
* Check whether a filter is allowed to use a tag
*
* @param string $tag Tag name
* @return Status
*/
public
function
validateTag
(
string
$tag
):
Status
{
$tagNameStatus
=
ChangeTags
::
isTagNameValid
(
$tag
);
if
(
!
$tagNameStatus
->
isGood
()
)
{
return
$tagNameStatus
;
}
$canAddStatus
=
ChangeTags
::
canAddTagsAccompanyingChange
(
[
$tag
]
);
if
(
$canAddStatus
->
isGood
()
)
{
return
$canAddStatus
;
}
if
(
$tag
===
$this
->
changeTagsManager
->
getCondsLimitTag
()
)
{
return
Status
::
newFatal
(
'abusefilter-tag-reserved'
);
}
// note: these are both local and global tags
$alreadyDefinedTags
=
$this
->
changeTagsManager
->
getTagsDefinedByFilters
();
if
(
in_array
(
$tag
,
$alreadyDefinedTags
,
true
)
)
{
return
Status
::
newGood
();
}
// note: this check is only done for the local wiki
// global filters could interfere with existing tags on remote wikis
$canCreateTagStatus
=
ChangeTags
::
canCreateTag
(
$tag
);
if
(
$canCreateTagStatus
->
isGood
()
)
{
return
$canCreateTagStatus
;
}
return
Status
::
newFatal
(
'abusefilter-edit-bad-tags'
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Jul 3, 21:17 (22 h, 12 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
93/d9/20e06842b8d816621c66f19a4c80
Default Alt Text
ChangeTagValidator.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment