3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2012, StatusNet, Inc.
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * @category Moderation
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2012 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
40 * Shows a history of moderation for this user in the sidebar
42 * @category Moderation
44 * @author Evan Prodromou <evan@status.net>
45 * @copyright 2012 StatusNet, Inc.
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
47 * @link http://status.net/
50 class ModLogPlugin extends Plugin
52 const VIEWMODLOG = 'ModLogPlugin::VIEWMODLOG';
55 * Database schema setup
57 * We keep a moderation log table
62 * @return boolean hook value; true means continue processing, false means stop.
65 function onCheckSchema()
67 $schema = Schema::get();
69 $schema->ensureTable('mod_log', ModLog::schemaDef());
74 function onEndGrantRole($profile, $role)
76 $modlog = new ModLog();
78 $modlog->id = UUID::gen();
79 $modlog->profile_id = $profile->id;
81 $cur = common_current_user();
84 $modlog->moderator_id = $cur->id;
87 $modlog->role = $role;
88 $modlog->is_grant = 1;
89 $modlog->created = common_sql_now();
96 function onEndRevokeRole($profile, $role)
98 $modlog = new ModLog();
100 $modlog->id = UUID::gen();
102 $modlog->profile_id = $profile->id;
104 $scoped = Profile::current();
106 if ($scoped instanceof Profile) {
107 $modlog->moderator_id = $scoped->getID();
110 $modlog->role = $role;
111 $modlog->is_grant = 0;
112 $modlog->created = common_sql_now();
119 function onEndShowSections(Action $action)
121 if (!$action instanceof ShowstreamAction) {
122 // early return for actions we're not interested in
126 $scoped = $action->getScoped();
127 if (!$scoped instanceof Profile || !$scoped->hasRight(self::VIEWMODLOG)) {
128 // only continue if we are allowed to VIEWMODLOG
132 $profile = $action->getTarget();
136 $ml->profile_id = $profile->getID();
137 $ml->orderBy("created");
143 $action->elementStart('div', array('id' => 'entity_mod_log',
144 'class' => 'section'));
146 $action->element('h2', null, _('Moderation'));
148 $action->elementStart('table');
150 while ($ml->fetch()) {
151 $action->elementStart('tr');
152 $action->element('td', null, strftime('%y-%m-%d', strtotime($ml->created)));
153 $action->element('td', null, sprintf(($ml->is_grant) ? _('+%s') : _('-%s'), $ml->role));
154 $action->elementStart('td');
155 if ($ml->moderator_id) {
156 $mod = Profile::getByID($ml->moderator_id);
158 $action->text(_('[unknown]'));
160 $action->element('a', array('href' => $mod->getUrl(),
161 'title' => $mod->getFullname()),
162 $mod->getNickname());
165 $action->text(_('[unknown]'));
167 $action->elementEnd('td');
168 $action->elementEnd('tr');
171 $action->elementEnd('table');
173 $action->elementEnd('div');
177 function onUserRightsCheck($profile, $right, &$result) {
179 case self::VIEWMODLOG:
180 $result = ($profile->hasRole(Profile_role::MODERATOR) || $profile->hasRole('modhelper'));
187 function onPluginVersion(array &$versions)
189 $versions[] = array('name' => 'ModLog',
190 'version' => GNUSOCIAL_VERSION,
191 'author' => 'Evan Prodromou',
192 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/ModLog',
194 _m('Show the moderation history for a profile in the sidebar'));