ShowstreamAction tidying up

Lots of these changes mean that we're requiring certain values to
either by typed properly or return the expected value. If it doesn't
there should be a fatal exception thrown which we can followup in the
logs and won't go silently suppressed.
This commit is contained in:
Mikael Nordfeldth
2015-07-10 13:44:47 +02:00
parent f8877e015b
commit 9a92b58057
8 changed files with 88 additions and 70 deletions

View File

@@ -101,10 +101,10 @@ class ModLogPlugin extends Plugin
$modlog->profile_id = $profile->id;
$cur = common_current_user();
$scoped = Profile::current();
if (!empty($cur)) {
$modlog->moderator_id = $cur->id;
if ($scoped instanceof Profile) {
$modlog->moderator_id = $scoped->getID();
}
$modlog->role = $role;
@@ -118,21 +118,22 @@ class ModLogPlugin extends Plugin
function onEndShowSections(Action $action)
{
if ($action->arg('action') != 'showstream') {
if (!$action instanceof ShowstreamAction) {
// early return for actions we're not interested in
return true;
}
$cur = common_current_user();
if (empty($cur) || !$cur->hasRight(self::VIEWMODLOG)) {
$scoped = $action->getScoped();
if (!$scoped instanceof Profile || !$scoped->hasRight(self::VIEWMODLOG)) {
// only continue if we are allowed to VIEWMODLOG
return true;
}
$profile = $action->profile;
$profile = $action->getTarget();
$ml = new ModLog();
$ml->profile_id = $profile->id;
$ml->profile_id = $profile->getID();
$ml->orderBy("created");
$cnt = $ml->find();
@@ -152,13 +153,13 @@ class ModLogPlugin extends Plugin
$action->element('td', null, sprintf(($ml->is_grant) ? _('+%s') : _('-%s'), $ml->role));
$action->elementStart('td');
if ($ml->moderator_id) {
$mod = Profile::getKV('id', $ml->moderator_id);
$mod = Profile::getByID($ml->moderator_id);
if (empty($mod)) {
$action->text(_('[unknown]'));
} else {
$action->element('a', array('href' => $mod->profileurl,
'title' => $mod->fullname),
$mod->nickname);
$action->element('a', array('href' => $mod->getUrl(),
'title' => $mod->getFullname()),
$mod->getNickname());
}
} else {
$action->text(_('[unknown]'));