-
Notifications
You must be signed in to change notification settings - Fork 1
/
markSpamUser.php
85 lines (70 loc) · 1.91 KB
/
markSpamUser.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
<?php
/**
* @file plugins/generic/akismet/markSpamUser.php
*
* Copyright (c) University of Pittsburgh
* Distributed under the GNU GPL v2 or later. For full terms see the LICENSE file.
*
* @class markSpamUser
* @ingroup plugins_generic_akismet
*
* @brief CLI tool for marking a user as missed spam by username within Akismet.
*/
require(dirname(dirname(dirname(dirname(__FILE__)))) . '/tools/bootstrap.inc.php');
class markSpamUser extends CommandLineTool {
/** @var $username string */
var $username;
/**
* Constructor.
* @param $argv array command-line arguments
*/
function markSpamUser($argv = array()) {
parent::__construct($argv);
if (!isset($this->argv[0])) {
$this->usage();
exit(1);
}
$this->username = $this->argv[0];
}
/**
* Print command usage information.
*/
function usage() {
echo "Mark Spam User tool\n"
. "This tool will mark a user as missed spam in Akismet.\n\n"
. "Usage: {$this->scriptName} [username]\n"
. "username The user to submit to Akismet.\n";
}
/**
* Execute the merge users command.
*/
function execute() {
$plugin = PluginRegistry::getPlugin('generic', 'akismetplugin');
$userDao = DAORegistry::getDAO('UserDAO');
$user = $userDao->getByUsername($this->username);
$userId = isset($user) ? $user->getId() : null;
if (empty($userId)) {
printf("Error: '%s' is not a valid username.\n",
$this->username);
exit;
}
if (!$plugin->getAkismetData($userId)) {
printf("Error: '%s' is unknown to Akismet.\n",
$this->username);
exit;
}
// User exists and has Akismet data, proceed.
if ($plugin->reportMissedSpamUser($userId)) {
$plugin->unsetAkismetData($userId);
printf("Reported as missed spam: '%s'.\n",
$this->username
);
} else {
printf("Failed to report as missed spam: '%s'.\n",
$this->username
);
}
}
}
$tool = new markSpamUser(isset($argv) ? $argv : array());
$tool->execute();