-
Notifications
You must be signed in to change notification settings - Fork 1
/
db_functions.php
116 lines (105 loc) · 4.21 KB
/
db_functions.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
<?php
namespace CluebotNG;
/*
* Copyright (C) 2015 Jacobi Carter and Chris Breneman
*
* This file is part of ClueBot NG.
*
* ClueBot NG is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* ClueBot NG is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClueBot NG. If not, see <http://www.gnu.org/licenses/>.
*/
class Db
{
public static $coreNodeCache = 0;
public static $ircRelayNodeCache = 0;
public static $coreNode = null;
public static $ircRelayNode = null;
// Returns the edit it for the vandalism
public static function detectedVandalism($user, $title, $heuristic, $reason, $url, $old_rev_id, $rev_id)
{
checkMySQL();
$query = 'INSERT INTO `vandalism` ' .
'(`id`,`user`,`article`,`heuristic`,`reason`,`diff`,`old_id`,`new_id`,`reverted`) ' .
'VALUES ' .
'(NULL,\'' . mysqli_real_escape_string(Globals::$cb_mysql, $user) . '\',' .
'\'' . mysqli_real_escape_string(Globals::$cb_mysql, $title) . '\',' .
'\'' . mysqli_real_escape_string(Globals::$cb_mysql, $heuristic) . '\',' .
'\'' . mysqli_real_escape_string(Globals::$cb_mysql, $reason) . '\',' .
'\'' . mysqli_real_escape_string(Globals::$cb_mysql, $url) . '\',' .
'\'' . mysqli_real_escape_string(Globals::$cb_mysql, $old_rev_id) . '\',' .
'\'' . mysqli_real_escape_string(Globals::$cb_mysql, $rev_id) . '\',0)';
mysqli_query(Globals::$cb_mysql, $query);
return mysqli_insert_id(Globals::$cb_mysql);
}
// Returns nothing
public static function vandalismReverted($edit_id)
{
checkMySQL();
mysqli_query(
Globals::$cb_mysql,
'UPDATE `vandalism` SET `reverted` = 1 WHERE `id` = \'' .
mysqli_real_escape_string(Globals::$cb_mysql, $edit_id) . '\''
);
}
// Returns nothing
public static function vandalismRevertBeaten($edit_id, $title, $user, $diff)
{
checkMySQL();
mysqli_query(
Globals::$cb_mysql,
'UPDATE `vandalism` SET `reverted` = 0 WHERE `id` = \'' .
mysqli_real_escape_string(Globals::$cb_mysql, $edit_id) . '\''
);
mysqli_query(
Globals::$cb_mysql,
'INSERT INTO `beaten` (`id`,`article`,`diff`,`user`) VALUES (NULL,\'' .
mysqli_real_escape_string(Globals::$cb_mysql, $title) . '\',\'' .
mysqli_real_escape_string(Globals::$cb_mysql, $diff) . '\',\'' .
mysqli_real_escape_string(Globals::$cb_mysql, $user) . '\')'
);
}
// Returns the hostname of the current core node
public static function getCurrentCoreNode()
{
if (self::$coreNodeCache > time() - 10 && self::$coreNode != null) {
return self::$coreNode;
}
checkMySQL();
self::$coreNodeCache = time();
$res = mysqli_query(Globals::$cb_mysql, 'SELECT `node` from `cluster_node` where type="core"');
if ($res !== false) {
$d = mysqli_fetch_assoc($res);
self::$coreNode = $d['node'];
return $d['node'];
}
self::$coreNode = null;
return null;
}
// Returns the hostname of the current IRC relay node
public static function getCurrentIrcRelayNode()
{
if (self::$ircRelayNodeCache > time() - 10 && self::$ircRelayNode != null) {
return self::$ircRelayNode;
}
checkMySQL();
self::$ircRelayNodeCache = time();
$res = mysqli_query(Globals::$cb_mysql, 'SELECT `node` from `cluster_node` where type="irc_relay"');
if ($res !== false) {
$d = mysqli_fetch_assoc($res);
self::$ircRelayNode = $d['node'];
return $d['node'];
}
self::$ircRelayNode = null;
return null;
}
}