Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F2752707
AbuseFilterRowsAndFiltersTestTrait.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
AbuseFilterRowsAndFiltersTestTrait.php
View Options
<?php
use
MediaWiki\Extension\AbuseFilter\Filter\ExistingFilter
;
use
MediaWiki\Extension\AbuseFilter\Filter\Flags
;
use
MediaWiki\Extension\AbuseFilter\Filter\LastEditInfo
;
use
MediaWiki\Extension\AbuseFilter\Filter\Specs
;
/**
* This trait contains some Filter <-> db_row correspondences, and can be used to avoid long test
* methods.
*/
trait
AbuseFilterRowsAndFiltersTestTrait
{
/**
* @return array[]
*/
public
function
getRowsAndFilters
():
array
{
static
$ret
=
null
;
if
(
$ret
!==
null
)
{
return
$ret
;
}
$rows
=
[
'no actions'
=>
(
object
)[
'af_id'
=>
42
,
'af_pattern'
=>
'false'
,
'af_user'
=>
1
,
'af_user_text'
=>
'FilterTester'
,
'af_actor'
=>
1
,
'af_timestamp'
=>
'20190826000000'
,
'af_enabled'
=>
1
,
'af_comments'
=>
''
,
'af_public_comments'
=>
'Mock filter'
,
'af_hidden'
=>
Flags
::
FILTER_PUBLIC
,
'af_hit_count'
=>
0
,
'af_throttled'
=>
0
,
'af_deleted'
=>
0
,
'af_actions'
=>
''
,
'af_global'
=>
0
,
'af_group'
=>
'default'
],
'with actions'
=>
(
object
)[
'af_id'
=>
163
,
'af_pattern'
=>
'false'
,
'af_user'
=>
1
,
'af_user_text'
=>
'FilterTester'
,
'af_actor'
=>
1
,
'af_timestamp'
=>
'20190826000000'
,
'af_enabled'
=>
1
,
'af_comments'
=>
''
,
'af_public_comments'
=>
'Mock filter'
,
'af_hidden'
=>
Flags
::
FILTER_HIDDEN
,
'af_hit_count'
=>
0
,
'af_throttled'
=>
1
,
'af_deleted'
=>
0
,
'af_actions'
=>
'disallow,blockautopromote'
,
'af_global'
=>
0
,
'af_group'
=>
'default'
]
];
foreach
(
$rows
as
$name
=>
$row
)
{
$actionKeys
=
$row
->
af_actions
?
explode
(
','
,
$row
->
af_actions
)
:
[];
$filter
=
new
ExistingFilter
(
new
Specs
(
$row
->
af_pattern
,
$row
->
af_comments
,
$row
->
af_public_comments
,
$actionKeys
,
$row
->
af_group
),
new
Flags
(
(
bool
)
$row
->
af_enabled
,
(
bool
)
$row
->
af_deleted
,
(
int
)
$row
->
af_hidden
,
(
bool
)
$row
->
af_global
),
array_fill_keys
(
$actionKeys
,
[]
),
new
LastEditInfo
(
$row
->
af_user
,
$row
->
af_user_text
,
$row
->
af_timestamp
),
$row
->
af_id
,
$row
->
af_hit_count
,
$row
->
af_throttled
);
$ret
[
$name
]
=
[
'row'
=>
$row
,
'actions'
=>
$this
->
getRowsForActions
(
$row
->
af_id
,
$actionKeys
),
'filter'
=>
$filter
];
}
// Add special cases that cannot be generalized above
$ret
=
array_merge
(
$ret
,
[
'null comments and name'
=>
[
'row'
=>
(
object
)[
'af_id'
=>
333
,
'af_pattern'
=>
'false'
,
'af_user'
=>
1
,
'af_user_text'
=>
'FilterTester'
,
'af_actor'
=>
1
,
'af_timestamp'
=>
'20190826000000'
,
'af_enabled'
=>
1
,
'af_comments'
=>
null
,
'af_public_comments'
=>
null
,
'af_hidden'
=>
Flags
::
FILTER_HIDDEN
,
'af_hit_count'
=>
100
,
'af_throttled'
=>
1
,
'af_deleted'
=>
0
,
'af_actions'
=>
'warn'
,
'af_global'
=>
0
,
'af_group'
=>
'default'
],
'actions'
=>
$this
->
getRowsForActions
(
333
,
[
'warn'
]
),
'filter'
=>
new
ExistingFilter
(
new
Specs
(
'false'
,
''
,
''
,
[
'warn'
],
'default'
),
new
Flags
(
true
,
false
,
true
,
false
),
[
'warn'
=>
[]
],
new
LastEditInfo
(
1
,
'FilterTester'
,
'20190826000000'
),
333
,
100
,
1
)
],
'no hitcount and throttled'
=>
[
'row'
=>
(
object
)[
'af_id'
=>
1000
,
'af_pattern'
=>
'"foo"'
,
'af_user'
=>
1
,
'af_user_text'
=>
'FilterTester'
,
'af_actor'
=>
1
,
'af_timestamp'
=>
'20190826000000'
,
'af_enabled'
=>
0
,
'af_comments'
=>
'foo'
,
'af_public_comments'
=>
'bar'
,
'af_hidden'
=>
Flags
::
FILTER_HIDDEN
,
'af_deleted'
=>
1
,
'af_actions'
=>
''
,
'af_global'
=>
1
,
'af_group'
=>
'default'
],
'actions'
=>
[],
'filter'
=>
new
ExistingFilter
(
new
Specs
(
'"foo"'
,
'foo'
,
'bar'
,
[],
'default'
),
new
Flags
(
false
,
true
,
true
,
true
),
[],
new
LastEditInfo
(
1
,
'FilterTester'
,
'20190826000000'
),
1000
)
],
'pattern to trim'
=>
[
'row'
=>
(
object
)[
'af_id'
=>
1000
,
'af_pattern'
=>
"
\n\t
0
\t\n
"
,
'af_user'
=>
1
,
'af_user_text'
=>
'FilterTester'
,
'af_actor'
=>
1
,
'af_timestamp'
=>
'20190826000000'
,
'af_enabled'
=>
0
,
'af_comments'
=>
'foo'
,
'af_public_comments'
=>
'bar'
,
'af_hidden'
=>
Flags
::
FILTER_HIDDEN
,
'af_hit_count'
=>
163
,
'af_throttled'
=>
1
,
'af_deleted'
=>
1
,
'af_actions'
=>
''
,
'af_global'
=>
1
,
'af_group'
=>
'default'
],
'actions'
=>
[],
'filter'
=>
new
ExistingFilter
(
new
Specs
(
'0'
,
'foo'
,
'bar'
,
[],
'default'
),
new
Flags
(
false
,
true
,
true
,
true
),
[],
new
LastEditInfo
(
1
,
'FilterTester'
,
'20190826000000'
),
1000
,
163
,
1
)
],
]
);
return
$ret
;
}
/**
* @param int $id
* @param string[] $actions
* @return stdClass[]
*/
private
function
getRowsForActions
(
int
$id
,
array
$actions
):
array
{
$ret
=
[];
foreach
(
$actions
as
$action
)
{
$ret
[]
=
(
object
)[
'afa_filter'
=>
$id
,
'afa_consequence'
=>
$action
,
'afa_parameters'
=>
''
];
}
return
$ret
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Jul 3, 20:17 (1 d, 14 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
59/10/c42c877b8d0142a4fc1a578fe790
Default Alt Text
AbuseFilterRowsAndFiltersTestTrait.php (5 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment