/
_generic.php
100 lines (69 loc) · 2.16 KB
/
_generic.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
#
# A MediaWiki bot - used for automated tasks on sites powered by MediaWiki.
# Line framework - Generic User Filter class
#
# Author: Grigor Gatchev <grigor at gatchev dot info>
# Licensed under GNU Affero Public License, version 3.0 or any later.
#
# ---------------------------------------------------------------------------- #
require_once ( dirname ( __FILE__ ) . '/../_generic.php' );
require_once ( dirname ( __FILE__ ) . '/../../../fetchers/_auto/user.php' );
abstract class Filter_User extends Filter_Sieving
{
protected $user_autofetcher;
# ----- Constructor ----- #
function __construct ( $core, $checker_params )
{
$this->user_autofetcher = new Autofetcher_User ( $core,
"Filter " . $this->signal_log_slot_name(),
array ( $this, "autofetcher_check" ) );
parent::__construct ( $core, $checker_params );
}
# ----- Tools ----- #
public function autofetcher_check ( &$signal )
{
$data_type = $signal->data_type ( $this->default_data_key );
$result = ( strpos ( $data_type, "/user" ) === false );
if ( $result )
{
$this->log ( "Element is not a user array or object - must fetch the user",
LL_DEBUG );
}
else
{
$result = is_null ( $this->element_to_check ( $signal ) );
if ( $result )
$this->log ( "User aspect '" . $this->data_property .
"' is not set - must (re-)fetch the user", LL_DEBUG );
}
return $result;
}
# ----- Instantiating ----- #
protected function slotname_preface ()
{
return "User";
}
protected function element_id_string ( &$signal )
{
$data = parent::element_to_check ( $signal );
if ( is_array ( $data ) && isset ( $data['name'] ) )
$name = $data['name'];
elseif ( is_object ( $data ) && isset ( $data->name ) )
$name = $data->name;
elseif ( is_string ( $data ) )
$name = $data;
else
$name = "---unknown username (something must be wrong!)---";
return "user '" . $name . "'";
}
# ----- Access point ----- #
public function process_data ( &$signal )
{
if ( $this->user_autofetcher->check_and_fetch ( $signal ) )
return parent::process_data ( $signal );
else
return NULL;
}
# $this->data_property should be set to what is being checked
}