forked from cyberpower678/Cyberbot_II
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActiveStats.php
243 lines (231 loc) · 13.8 KB
/
ActiveStats.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
ini_set('memory_limit','5G');
echo "----------STARTING UP SCRIPT----------\nStart Timestamp: ".date('r')."\n\n";
require_once( '/home/cyberpower678/Peachy/Init.php' );
require_once('/home/cyberpower678/database.inc');
$site = Peachy::newWiki( "wikidata" );
$site->set_runpage( null );
$sitemeta = Peachy::newWiki( "meta" );
$active = '#ccffcc';
$lowactive = '#ffcccc';
$inactive = '#CCCCCC';
$activecell = "| style=\"background:$active\" | ";
$lowactivecell = "| style=\"background:$lowactive\" | ";
$inactivecell = "! style=\"background:$inactive\" | ";
$logquery = array( 'list'=>'logevents', '_code'=>'le', '_limit'=>-1, 'leprop'=>'timestamp|details', 'letype'=>'rights', 'ledir'=>'older' );
$editquery = array( 'list'=>'usercontribs', 'ucstart'=>date( 'Ymdhis', strtotime('-6 months', time()) ), 'ucdir'=>'newer', 'ucnamespace'=>'8', '_limit'=>-1, '_code'=>'uc' );
while(true) {
echo "----------RUN TIMESTAMP: ".date('r')."----------\n\n";
$db = mysqli_connect( 'wikidatawiki.labsdb', $toolserver_username, $toolserver_password, 'wikidatawiki_p' );
$admins = $site->allusers( null, array('sysop'), null, false, array(), -1 );
$bureaucrats = $site->allusers( null, array('bureaucrat'), null, false, array(), -1 );
$oversighters = $site->allusers( null, array('oversight'), null, false, array(), -1 );
$cratright = array();
$adminright = array();
$outarray = array();
$timestamp = date( 'Ymdhis', strtotime('-6 months', time()) );
$out = "<big>This is a table of Administrators, Bureaucrats, and Oversighters.<br>This table provides information such as when the person became that type of user, how many actions they have performed with in the last timeframe, and if they are inactive as defined by the rules on Wikidata.<br>This table has the following parameters:<br>Activity timeframe: '''6 months'''<br>Inactivity: ''Defined as less than '''5''' admin actions''</big>\n\n{| class=\"wikitable\"\n|-\n| style=\"background:#ccffcc\" | Active\n| style=\"background:#ffcccc\" | Slipping into Inactivity\n! style=\"background:#CCCCCC\" | Inactive\n|}\n{| class=\"wikitable\"\n|-\n! Administrators !! Bureaucrats !! Oversighters\n";
//get the information
echo "Checking administrators...\n\n";
foreach( $admins as $user ) {
echo "Fetching administrator \"{$user['name']}\"...\n";
if( $user['name'] != str_ireplace( '(WM','',$user['name']) ) continue;
$tmp = mysqli_query( $db, "SELECT user_id FROM user WHERE `user_name` = '{$user['name']}';" );
$uid = mysqli_fetch_assoc( $tmp );
$uid = $uid['user_id'];
mysqli_free_result( $tmp );
$logquery['letitle'] = "User:".$user['name'];
$result = $site->listHandler( $logquery );
$since = "";
foreach( $result as $entry ) {
if( $entry['params']['oldgroups'] == str_replace( 'sysop', '', $entry['params']['oldgroups'] ) )
if( $entry['params']['newgroups'] != str_replace( 'sysop', '', $entry['params']['newgroups'] ) ) $since = strtotime($entry['timestamp']);
if( $since != "" ) break;
}
if( $since == "" ) {
$logquery['letitle'] .= "@wikidatawiki";
$result = $sitemeta->listHandler( $logquery );
foreach( $result as $entry ) {
if( $entry['params']['oldgroups'] == str_replace( 'sysop', '', $entry['params']['oldgroups'] ) )
if( $entry['params']['newgroups'] != str_replace( 'sysop', '', $entry['params']['newgroups'] ) ) $since = strtotime($entry['timestamp']);
if( $since != "" ) break;
}
}
if( $since == "" ) {
$since = "Unknown";
}
$temp = 0;
foreach( $bureaucrats as $user2 ) if( $user['userid'] == $user2['userid'] ) {
$sql2 = "SELECT COUNT(*) AS count FROM logging_userindex WHERE `log_user` = '$uid' AND `log_type` in ('delete', 'block', 'protect') AND `log_timestamp` > '$timestamp';";
$logquery['leend'] = date( 'Ymdhis', strtotime('-6 months', time()) );
unset( $logquery['letitle'] );
$logquery['leuser'] = $user['name'];
$result = $site->listHandler( $logquery );
$cratright[$user['name']] = 0;
$adminright[$user['name']] = 0;
foreach( $result as $entry ) {
$diff = array_diff( $entry['params']['oldgroups'], $entry['params']['newgroups'] );
if( in_array( 'flood', $diff ) || in_array( 'bot', $diff ) || in_array( 'translationadmin', $diff ) ) $cratright[$user['name']]++;
else {
$diff = array_diff( $entry['params']['newgroups'], $entry['params']['oldgroups'] );
if( in_array( 'flood', $diff ) || in_array( 'bot', $diff ) || in_array( 'translationadmin', $diff ) || in_array( 'sysop', $diff ) || in_array( 'bureaucrat', $diff ) ) $cratright[$user['name']]++;
else $adminright[$user['name']]++;
}
}
unset( $logquery['leend'] );
unset( $logquery['leuser'] );
break;
} else $sql2 = "SELECT COUNT(*) AS count FROM logging_userindex WHERE `log_user` = '$uid' AND `log_type` in ('delete', 'block', 'rights', 'protect') AND `log_timestamp` > '$timestamp';";
if( !isset( $adminright[$user['name']] ) ) $sql = "SELECT COUNT(*) AS count FROM logging_userindex WHERE `log_user` = '$uid' AND `log_type` in ('delete', 'block', 'rights', 'protect', 'renameuser', 'suppress') AND `log_timestamp` > '$timestamp';";
else $sql = "SELECT COUNT(*) AS count FROM logging_userindex WHERE `log_user` = '$uid' AND `log_type` in ('delete', 'block', 'protect', 'renameuser', 'suppress') AND `log_timestamp` > '$timestamp';";
$tmp = mysqli_query( $db, $sql );
$res = mysqli_fetch_assoc( $tmp );
$res = $res['count'];
mysqli_free_result( $tmp );
$tmp = mysqli_query( $db, $sql2 );
$res2 = mysqli_fetch_assoc( $tmp );
$res2 = $res2['count'];
mysqli_free_result( $tmp );
$editquery['ucuser'] = $user['name'];
$result = $site->listHandler( $editquery );
if( isset( $adminright[$user['name']] ) ) $temp+=$adminright[$user['name']];
$res2+=count($result)+$temp;
if( isset( $cratright[$user['name']] ) ) $temp+=$cratright[$user['name']];
$res+=count($result)+$temp;
$outarray['admin'][] = array( 'name'=>$user['name'], 'count'=>$res, 'count1'=>$res2, 'since'=>$since );
echo "Administrator since $since; Administrator actions: $res2\n\n";
}
echo "Checking bureaucrats...\n\n";
foreach( $bureaucrats as $user ) {
echo "Fetching bureaucrat \"{$user['name']}\"...\n";
if( $user['name'] != str_ireplace( '(WM','',$user['name']) ) continue;
$temp = 0;
$tmp = mysqli_query( $db, "SELECT user_id FROM user WHERE `user_name` = '{$user['name']}';" );
$uid = mysqli_fetch_assoc( $tmp );
$uid = $uid['user_id'];
mysqli_free_result( $tmp );
$logquery['letitle'] = "User:".$user['name'];
$result = $site->listHandler( $logquery );
$since = "";
$temp = 0;
foreach( $result as $entry ) {
if( $entry['params']['oldgroups'] == str_replace( 'bureaucrat', '', $entry['params']['oldgroups'] ) )
if( $entry['params']['newgroups'] != str_replace( 'bureaucrat', '', $entry['params']['newgroups'] ) ) $since = strtotime($entry['timestamp']);
if( $since != "" ) break;
}
if( $since == "" ) {
$logquery['letitle'] .= "@wikidatawiki";
$result = $sitemeta->listHandler( $logquery );
foreach( $result as $entry ) {
if( $entry['params']['oldgroups'] == str_replace( 'bureaucrat', '', $entry['params']['oldgroups'] ) )
if( $entry['params']['newgroups'] != str_replace( 'bureaucrat', '', $entry['params']['newgroups'] ) ) $since = strtotime($entry['timestamp']);
if( $since != "" ) break;
}
}
if( $since == "" ) {
$since = "Unknown";
}
$sql2 = "SELECT COUNT(*) AS count FROM logging_userindex WHERE `log_user` = '$uid' AND `log_type` in ('renameuser') AND `log_timestamp` > '$timestamp';";
$sql = "SELECT COUNT(*) AS count FROM logging_userindex WHERE `log_user` = '$uid' AND `log_type` in ('delete', 'block', 'protect', 'renameuser', 'suppress') AND `log_timestamp` > '$timestamp';";
$tmp = mysqli_query( $db, $sql );
$res = mysqli_fetch_assoc( $tmp );
$res = $res['count'];
mysqli_free_result( $tmp );
$tmp = mysqli_query( $db, $sql2 );
$res2 = mysqli_fetch_assoc( $tmp );
$res2 = $res2['count'];
mysqli_free_result( $tmp );
$editquery['ucuser'] = $user['name'];
$result = $site->listHandler( $editquery );
if( isset( $cratright[$user['name']] ) ) $temp+=$cratright[$user['name']];
$res2+=$temp;
if( isset( $adminright[$user['name']] ) ) $temp+=$adminright[$user['name']];
$res+=count($result)+$temp;
$outarray['crat'][] = array( 'name'=>$user['name'], 'count'=>$res, 'count1'=>$res2, 'since'=>$since );
echo "Bureaucrat since $since; Bureaucrat actions: $res2\n\n";
}
echo "Checking oversighters...\n\n";
foreach( $oversighters as $user ) {
echo "Fetching oversighter \"{$user['name']}\"...\n";
if( $user['name'] != str_ireplace( '(WM','',$user['name']) ) continue;
$tmp = mysqli_query( $db, "SELECT user_id FROM user WHERE `user_name` = '{$user['name']}';" );
$uid = mysqli_fetch_assoc( $tmp );
$uid = $uid['user_id'];
mysqli_free_result( $tmp );
$temp = 0;
$logquery['letitle'] = "User:".$user['name']."@wikidatawiki";
$result = $sitemeta->listHandler( $logquery );
foreach( $result as $entry ) {
if( $entry['params']['oldgroups'] == str_replace( 'oversight', '', $entry['params']['oldgroups'] ) )
if( $entry['params']['newgroups'] != str_replace( 'oversight', '', $entry['params']['newgroups'] ) ) $since = strtotime($entry['timestamp']);
if( $since != "" ) break;
}
if( $since == "" ) {
$since = "Unknown";
}
$sql2 = "SELECT COUNT(*) AS count FROM logging_userindex WHERE `log_user` = '$uid' AND `log_type` in ('suppress') AND `log_timestamp` > '$timestamp';";
if( !isset( $adminright[$user['name']] ) ) $sql = "SELECT COUNT(*) AS count FROM logging_userindex WHERE `log_user` = '$uid' AND `log_type` in ('delete', 'block', 'rights', 'protect', 'renameuser', 'suppress') AND `log_timestamp` > '$timestamp';";
else $sql = "SELECT COUNT(*) AS count FROM logging_userindex WHERE `log_user` = '$uid' AND `log_type` in ('delete', 'block', 'protect', 'renameuser', 'suppress') AND `log_timestamp` > '$timestamp';";
$tmp = mysqli_query( $db, $sql );
$res = mysqli_fetch_assoc( $tmp );
$res = $res['count'];
mysqli_free_result( $tmp );
$tmp = mysqli_query( $db, $sql2 );
$res2 = mysqli_fetch_assoc( $tmp );
$res2 = $res2['count'];
mysqli_free_result( $tmp );
$editquery['ucuser'] = $user['name'];
$result = $site->listHandler( $editquery );
if( isset( $cratright[$user['name']] ) ) $temp+=$cratright[$user['name']];
if( isset( $adminright[$user['name']] ) ) $temp+=$adminright[$user['name']];
$res+=count($result)+$temp;
$outarray['oversight'][] = array( 'name'=>$user['name'], 'count'=>$res, 'count1'=>$res2, 'since'=>$since );
echo "Oversighter since $since; Oversight actions: $res2\n\n";
}
//process the information into an output.
echo "Generating output...";
$count = 0;
if( isset( $outarray['admin'] ) ) if( count( $outarray['admin'] ) > $count ) $count = count( $outarray['admin'] );
if( isset( $outarray['crat'] ) ) if( count( $outarray['crat'] ) > $count ) $count = count( $outarray['crat'] );
if( isset( $outarray['oversight'] ) ) if( count( $outarray['oversight'] ) > $count ) $count = count( $outarray['oversight'] );
for( $i=0; $i<$count; $i++ ) {
$out .= "|-\n";
if( isset( $outarray['admin'] ) && isset( $outarray['admin'][$i] ) ) {
$data = "[[User:".$outarray['admin'][$i]['name']."|".$outarray['admin'][$i]['name']."]]<br>Admin since: ".( $outarray['admin'][$i]['since'] != "Unknown" ? date( 'j F Y', $outarray['admin'][$i]['since'] ) : "Unknown" )."<br>Admin actions: ".$outarray['admin'][$i]['count1']."<br>Total actions: ".$outarray['admin'][$i]['count']."\n";
if( $outarray['admin'][$i]['since'] == "Unknown" || strtotime('-6 months', time()) > $outarray['admin'][$i]['since'] ) {
if( $outarray['admin'][$i]['count'] < 5 ) $out .= $inactivecell.$data;
if( 5 <= $outarray['admin'][$i]['count'] && $outarray['admin'][$i]['count'] <= 12 ) $out .= $lowactivecell.$data;
if( $outarray['admin'][$i]['count'] > 12 ) $out .= $activecell.$data;
} else {
$out .= $activecell.$data;
}
} else $out.="|\n";
if( isset( $outarray['crat'] ) && isset( $outarray['crat'][$i] ) ) {
$data = "[[User:".$outarray['crat'][$i]['name']."|".$outarray['crat'][$i]['name']."]]<br>Bureaucrat since: ".( $outarray['crat'][$i]['since'] != "Unknown" ? date( 'j F Y', $outarray['crat'][$i]['since'] ) : "Unknown" )."<br>Bureaucrat actions: ".$outarray['crat'][$i]['count1']."<br>Total actions: ".$outarray['crat'][$i]['count']."\n";
if( $outarray['crat'][$i]['since'] == "Unknown" || strtotime('-6 months', time()) > $outarray['crat'][$i]['since'] ) {
if( $outarray['crat'][$i]['count'] < 5 ) $out .= $inactivecell.$data;
if( 5 <= $outarray['crat'][$i]['count'] && $outarray['crat'][$i]['count'] <= 12 ) $out .= $lowactivecell.$data;
if( $outarray['crat'][$i]['count'] > 12 ) $out .= $activecell.$data;
} else {
$out .= $activecell.$data;
}
} else $out.="|\n";
if( isset( $outarray['oversight'] ) && isset( $outarray['oversight'][$i] ) ) {
$data = "[[User:".$outarray['oversight'][$i]['name']."|".$outarray['oversight'][$i]['name']."]]<br>Oversighter since: ".( $outarray['oversight'][$i]['since'] != "Unknown" ? date( 'j F Y', $outarray['oversight'][$i]['since'] ) : "Unknown" )."<br>Oversight actions: Blocked Information<br>Total: ".$outarray['oversight'][$i]['count']."\n";
if( $outarray['oversight'][$i]['since'] == "Unknown" || strtotime('-6 months', time()) > $outarray['oversight'][$i]['since'] ) {
if( $outarray['oversight'][$i]['count'] < 5 ) $out .= $inactivecell.$data;
if( 5 <= $outarray['oversight'][$i]['count'] && $outarray['oversight'][$i]['count'] <= 12 ) $out .= $lowactivecell.$data;
if( $outarray['oversight'][$i]['count'] > 12 ) $out .= $activecell.$data;
} else {
$out .= $activecell.$data;
}
} else $out.="|\n";
}
$out.="|}";
echo "Done\n\n";
echo "Posting table...\n";
$site->initPage( "User:Cyberpower678/ActiveStats" )->edit( $out, "Updating active admins, crats, and oversighters." );
mysqli_close( $db );
echo "Done\n\nProgram complete!\n";
break;
}