Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5994989
CheckSyntax.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
CheckSyntax.php
View Options
<?php
namespace
MediaWiki\Extension\AbuseFilter\Api
;
use
MediaWiki\Api\ApiBase
;
use
MediaWiki\Api\ApiMain
;
use
MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager
;
use
MediaWiki\Extension\AbuseFilter\Parser\Exception\UserVisibleException
;
use
MediaWiki\Extension\AbuseFilter\Parser\RuleCheckerFactory
;
use
Wikimedia\ParamValidator\ParamValidator
;
class
CheckSyntax
extends
ApiBase
{
private
RuleCheckerFactory
$ruleCheckerFactory
;
private
AbuseFilterPermissionManager
$afPermManager
;
public
function
__construct
(
ApiMain
$main
,
string
$action
,
RuleCheckerFactory
$ruleCheckerFactory
,
AbuseFilterPermissionManager
$afPermManager
)
{
parent
::
__construct
(
$main
,
$action
);
$this
->
ruleCheckerFactory
=
$ruleCheckerFactory
;
$this
->
afPermManager
=
$afPermManager
;
}
/**
* @inheritDoc
*/
public
function
execute
()
{
// "Anti-DoS"
if
(
!
$this
->
afPermManager
->
canUseTestTools
(
$this
->
getAuthority
()
)
&&
!
$this
->
afPermManager
->
canEdit
(
$this
->
getAuthority
()
)
)
{
$this
->
dieWithError
(
'apierror-abusefilter-cantcheck'
,
'permissiondenied'
);
}
$params
=
$this
->
extractRequestParams
();
$result
=
$this
->
ruleCheckerFactory
->
newRuleChecker
()->
checkSyntax
(
$params
[
'filter'
]
);
$r
=
[];
$warnings
=
[];
foreach
(
$result
->
getWarnings
()
as
$warning
)
{
$warnings
[]
=
[
'message'
=>
$this
->
msg
(
$warning
->
getMessageObj
()
)->
text
(),
'character'
=>
$warning
->
getPosition
()
];
}
if
(
$warnings
)
{
$r
[
'warnings'
]
=
$warnings
;
}
if
(
$result
->
isValid
()
)
{
// Everything went better than expected :)
$r
[
'status'
]
=
'ok'
;
}
else
{
// TODO: Improve the type here.
/** @var UserVisibleException $excep */
$excep
=
$result
->
getException
();
'@phan-var UserVisibleException $excep'
;
$r
=
[
'status'
=>
'error'
,
'message'
=>
$this
->
msg
(
$excep
->
getMessageObj
()
)->
text
(),
'character'
=>
$excep
->
getPosition
(),
];
}
$this
->
getResult
()->
addValue
(
null
,
$this
->
getModuleName
(),
$r
);
}
/**
* @codeCoverageIgnore Merely declarative
* @inheritDoc
*/
public
function
getAllowedParams
()
{
return
[
'filter'
=>
[
ParamValidator
::
PARAM_REQUIRED
=>
true
,
],
];
}
/**
* @codeCoverageIgnore Merely declarative
* @inheritDoc
*/
protected
function
getExamplesMessages
()
{
return
[
'action=abusefilterchecksyntax&filter="foo"'
=>
'apihelp-abusefilterchecksyntax-example-1'
,
'action=abusefilterchecksyntax&filter="bar"%20bad_variable'
=>
'apihelp-abusefilterchecksyntax-example-2'
,
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Oct 4 2026, 03:35 (4 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
61/4d/2dc6ef48c2e9f1d54487565e514c
Default Alt Text
CheckSyntax.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment