dedupe some referer handling

This commit is contained in:
Shish 2020-03-27 19:41:34 +00:00
parent 5ea7cc5b36
commit c16e3fd939
7 changed files with 15 additions and 17 deletions

View file

@ -116,3 +116,8 @@ function make_http(string $link): string
return $link;
}
function referer_or(string $dest): string
{
return $_SERVER['HTTP_REFERER'] ?? $dest;
}

View file

@ -182,10 +182,7 @@ class BulkActions extends Extension
}
$page->set_mode(PageMode::REDIRECT);
if (!isset($_SERVER['HTTP_REFERER'])) {
$_SERVER['HTTP_REFERER'] = make_link();
}
$page->set_redirect($_SERVER['HTTP_REFERER']);
$page->set_redirect(referer_or(make_link()));
}
}

View file

@ -226,11 +226,7 @@ class CommentList extends Extension
send_event(new CommentDeletionEvent(int_escape($event->get_arg(1))));
$page->flash("Deleted comment");
$page->set_mode(PageMode::REDIRECT);
if (!empty($_SERVER['HTTP_REFERER'])) {
$page->set_redirect($_SERVER['HTTP_REFERER']);
} else {
$page->set_redirect(make_link("post/view/" . $event->get_arg(2)));
}
$page->set_redirect(referer_or(make_link("post/view/" . $event->get_arg(2))));
}
} else {
$this->theme->display_permission_denied();

View file

@ -105,7 +105,7 @@ class ImageBan extends Extension
}
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect($_SERVER['HTTP_REFERER']);
$page->set_redirect(referer_or(make_link()));
}
} elseif ($event->get_arg(0) == "remove") {
$user->ensure_authed();
@ -113,7 +113,7 @@ class ImageBan extends Extension
send_event(new RemoveImageHashBanEvent($input['d_hash']));
$page->flash("Image ban removed");
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect($_SERVER['HTTP_REFERER']);
$page->set_redirect(referer_or(make_link()));
} elseif ($event->get_arg(0) == "list") {
$t = new HashBanTable($database->raw_db());
$t->token = $user->get_auth_token();

View file

@ -113,7 +113,7 @@ class NotATag extends Extension
["tag"=>$input['c_tag'], "redirect"=>$input['c_redirect']]
);
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect($_SERVER['HTTP_REFERER']);
$page->set_redirect(referer_or(make_link()));
} elseif ($event->get_arg(0) == "remove") {
$user->ensure_authed();
$input = validate_input(["d_tag"=>"string"]);
@ -123,7 +123,7 @@ class NotATag extends Extension
);
$page->flash("Image ban removed");
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect($_SERVER['HTTP_REFERER']);
$page->set_redirect(referer_or(make_link()));
} elseif ($event->get_arg(0) == "list") {
$t = new NotATagTable($database->raw_db());
$t->token = $user->get_auth_token();

View file

@ -167,7 +167,7 @@ class PrivMsg extends Extension
$cache->delete("pm-count-{$user->id}");
log_info("pm", "Deleted PM #$pm_id", "PM deleted");
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect($_SERVER["HTTP_REFERER"]);
$page->set_redirect(referer_or(make_link()));
}
}
}
@ -182,7 +182,7 @@ class PrivMsg extends Extension
send_event(new SendPMEvent(new PM($from_id, $_SERVER["REMOTE_ADDR"], $to_id, $subject, $message)));
$page->flash("PM sent");
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect($_SERVER["HTTP_REFERER"]);
$page->set_redirect(referer_or(make_link()));
}
}
break;

View file

@ -118,14 +118,14 @@ class Rule34 extends Extension
['is_admin'=>$input['is_admin'] ? 't' : 'f', 'id'=>$input['user_id']]
);
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(@$_SERVER['HTTP_REFERER']);
$page->set_redirect(referer_or(make_link()));
}
}
if ($event->page_matches("tnc_agreed")) {
setcookie("ui-tnc-agreed", "true", 0, "/");
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(@$_SERVER['HTTP_REFERER'] ?? "/");
$page->set_redirect(referer_or("/"));
}
if ($event->page_matches("admin/cache_purge")) {