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 $cur = common_current_user();
107 $modlog->moderator_id = $cur->id;
110 $modlog->role = $role;
111 $modlog->is_grant = 0;
112 $modlog->created = common_sql_now();
119 function onEndShowSections($action)
121 if ($action->arg('action') != 'showstream') {
125 $cur = common_current_user();
127 if (empty($cur) || !$cur->hasRight(self::VIEWMODLOG)) {
131 $profile = $action->profile;
135 $ml->profile_id = $profile->id;
136 $ml->orderBy("created");
142 $action->elementStart('div', array('id' => 'entity_mod_log',
143 'class' => 'section'));
145 $action->element('h2', null, _('Moderation'));
147 $action->elementStart('table');
149 while ($ml->fetch()) {
150 $action->elementStart('tr');
151 $action->element('td', null, strftime('%y-%m-%d', strtotime($ml->created)));
152 $action->element('td', null, sprintf(($ml->is_grant) ? _('+%s') : _('-%s'), $ml->role));
153 $action->elementStart('td');
154 if ($ml->moderator_id) {
155 $mod = Profile::getKV('id', $ml->moderator_id);
157 $action->text(_('[unknown]'));
159 $action->element('a', array('href' => $mod->profileurl,
160 'title' => $mod->fullname),
164 $action->text(_('[unknown]'));
166 $action->elementEnd('td');
167 $action->elementEnd('tr');
170 $action->elementEnd('table');
172 $action->elementEnd('div');
176 function onUserRightsCheck($profile, $right, &$result) {
178 case self::VIEWMODLOG:
179 $result = ($profile->hasRole(Profile_role::MODERATOR) || $profile->hasRole('modhelper'));
186 function onPluginVersion(&$versions)
188 $versions[] = array('name' => 'ModLog',
189 'version' => GNUSOCIAL_VERSION,
190 'author' => 'Evan Prodromou',
191 'homepage' => 'http://status.net/wiki/Plugin:ModLog',
193 _m('Show the moderation history for a profile in the sidebar'));