use HTTP status codes with error messages

This commit is contained in:
Shish 2012-02-16 15:37:05 +00:00
parent 5fc7d6e574
commit af7704825b
17 changed files with 59 additions and 63 deletions

View file

@ -161,8 +161,7 @@ class Artists extends Extension {
if(!$user->is_anonymous()){
$this->theme->new_artist_composer();
}else{
$errMessage = "You must be registered and logged in to create a new artist.";
$this->theme->display_error($page, "Error", $errMessage);
$this->theme->display_error(401, "Error", "You must be registered and logged in to create a new artist.");
}
break;
}
@ -179,8 +178,7 @@ class Artists extends Extension {
$newArtistID = $this->add_artist();
if ($newArtistID == -1)
{
$errMessage = "Error when entering artist data.";
$this->theme->display_error($page, "Error", $errMessage);
$this->theme->display_error(400, "Error", "Error when entering artist data.");
}
else
{
@ -190,8 +188,7 @@ class Artists extends Extension {
}
else
{
$errMessage = "You must be registered and logged in to create a new artist.";
$this->theme->display_error($page, "Error", $errMessage);
$this->theme->display_error(401, "Error", "You must be registered and logged in to create a new artist.");
}
break;
}
@ -236,8 +233,7 @@ class Artists extends Extension {
$userIsAdmin = $user->is_admin();
$this->theme->sidebar_options("editor", $artistID, $userIsAdmin);
}else{
$errMessage = "You must be registered and logged in to edit an artist.";
$this->theme->display_error($page, "Error", $errMessage);
$this->theme->display_error(401, "Error", "You must be registered and logged in to edit an artist.");
}
break;
}

View file

@ -109,7 +109,7 @@ class Forum extends Extension {
if($hasErrors)
{
$this->theme->display_error($page, "Error", $errors);
$this->theme->display_error(500, "Error", $errors);
$this->theme->display_new_thread_composer($page, $_POST["message"], $_POST["title"], false);
break;
}
@ -149,7 +149,7 @@ class Forum extends Extension {
if ($hasErrors)
{
$this->theme->display_error($page, "Error", $errors);
$this->theme->display_error(500, "Error", $errors);
$this->theme->display_new_post_composer($page, $_POST["threadID"], $_POST["message"], $_POST["title"], false);
break;
}
@ -166,7 +166,7 @@ class Forum extends Extension {
{
$page->set_mode("redirect");
$page->set_redirect(make_link("forum/index"));
//$this->theme->display_error($page, "Invalid action", "You should check forum/index.");
//$this->theme->display_error(400, "Invalid action", "You should check forum/index.");
break;
}
}

View file

@ -108,7 +108,7 @@ class PrivMsg extends Extension {
$pm_id = int_escape($event->get_arg(1));
$pm = $database->get_row("SELECT * FROM private_message WHERE id = :id", array("id" => $pm_id));
if(is_null($pm)) {
$this->theme->display_error($page, "No such PM", "There is no PM #$pm_id");
$this->theme->display_error(404, "No such PM", "There is no PM #$pm_id");
}
else if(($pm["to_id"] == $user->id) || $user->is_admin()) {
$from_user = User::by_id(int_escape($pm["from_id"]));
@ -124,7 +124,7 @@ class PrivMsg extends Extension {
$pm_id = int_escape($_POST["pm_id"]);
$pm = $database->get_row("SELECT * FROM private_message WHERE id = :id", array("id" => $pm_id));
if(is_null($pm)) {
$this->theme->display_error($page, "No such PM", "There is no PM #$pm_id");
$this->theme->display_error(404, "No such PM", "There is no PM #$pm_id");
}
else if(($pm["to_id"] == $user->id) || $user->is_admin()) {
$database->execute("DELETE FROM private_message WHERE id = :id", array("id" => $pm_id));
@ -146,7 +146,7 @@ class PrivMsg extends Extension {
}
break;
default:
$this->theme->display_error($page, "Invalid action", "That's not something you can do with a PM");
$this->theme->display_error(400, "Invalid action", "That's not something you can do with a PM");
break;
}
}

View file

@ -115,7 +115,7 @@ class ResizeImage extends Extension {
$image = Image::by_id($image_id);
if(is_null($image)) {
$this->theme->display_error($page, "Image not found", "No image in the database has the ID #$image_id");
$this->theme->display_error(404, "Image not found", "No image in the database has the ID #$image_id");
} else {
/* Check if options were given to resize an image. */

View file

@ -37,7 +37,7 @@ class AliasEditor extends Extension {
$page->set_redirect(make_link("alias/list"));
}
catch(AddAliasException $ex) {
$this->theme->display_error($page, "Error adding alias", $ex->getMessage());
$this->theme->display_error(500, "Error adding alias", $ex->getMessage());
}
}
}
@ -91,11 +91,11 @@ class AliasEditor extends Extension {
$page->set_redirect(make_link("alias/list"));
}
else {
$this->theme->display_error($page, "No File Specified", "You have to upload a file");
$this->theme->display_error(400, "No File Specified", "You have to upload a file");
}
}
else {
$this->theme->display_error($page, "Admins Only", "Only admins can edit the alias list");
$this->theme->display_error(401, "Admins Only", "Only admins can edit the alias list");
}
}
}

View file

@ -123,7 +123,7 @@ class CommentList extends Extension {
$page->set_redirect(make_link("post/view/".int_escape($_POST['image_id'])));
}
catch(CommentPostingException $ex) {
$this->theme->display_error($page, "Comment Blocked", $ex->getMessage());
$this->theme->display_error(403, "Comment Blocked", $ex->getMessage());
}
}
}

View file

@ -99,7 +99,7 @@ class ExtManager extends Extension {
$page->set_redirect(make_link("ext_manager"));
}
else {
$this->theme->display_error($page, "File Operation Failed",
$this->theme->display_error(500, "File Operation Failed",
"The extension folder isn't writable by the web server :(");
}
}

View file

@ -141,7 +141,7 @@ class Upload extends Extension {
$image_old = Image::by_id($image_id);
if(is_null($image_old)) {
$this->theme->display_error($page, "Image not found", "No image in the database has the ID #$image_id");
$this->theme->display_error(404, "Image not found", "No image in the database has the ID #$image_id");
}
if(count($_FILES) + count($_POST) > 0) {

View file

@ -97,7 +97,7 @@ class UserPage extends Extension {
else if($event->get_arg(0) == "recover") {
$user = User::by_name($_POST['username']);
if(is_null($user)) {
$this->theme->display_error($page, "Error", "There's no user with that name");
$this->theme->display_error(404, "Error", "There's no user with that name");
}
if(is_null($user->email)) {
//
@ -111,7 +111,7 @@ class UserPage extends Extension {
$this->theme->display_signup_page($page);
}
else if($_POST['pass1'] != $_POST['pass2']) {
$this->theme->display_error($page, "Password Mismatch", "Passwords don't match");
$this->theme->display_error(400, "Password Mismatch", "Passwords don't match");
}
else {
try {
@ -126,7 +126,7 @@ class UserPage extends Extension {
$page->set_redirect(make_link("user"));
}
catch(UserCreationException $ex) {
$this->theme->display_error($page, "User Creation Error", $ex->getMessage());
$this->theme->display_error(400, "User Creation Error", $ex->getMessage());
}
}
}
@ -155,14 +155,14 @@ class UserPage extends Extension {
if($event->page_matches("user")) {
$display_user = ($event->count_args() == 0) ? $user : User::by_name($event->get_arg(0));
if($event->count_args() == 0 && $user->is_anonymous()) {
$this->theme->display_error($page, "Not Logged In",
$this->theme->display_error(401, "Not Logged In",
"You aren't logged in. First do that, then you can see your stats.");
}
else if(!is_null($display_user) && ($display_user->id != $config->get_int("anon_id"))) {
send_event(new UserPageBuildingEvent($display_user));
}
else {
$this->theme->display_error($page, "No Such User",
$this->theme->display_error(404, "No Such User",
"If you typed the ID by hand, try again; if you came from a link on this ".
"site, it might be bug report time...");
}
@ -285,7 +285,7 @@ class UserPage extends Extension {
}
else {
log_warning("user", "Failed to log in as ".html_escape($name)." [$hash]");
$this->theme->display_error($page, "Error", "No user with those details was found");
$this->theme->display_error(401, "Error", "No user with those details was found");
}
}
@ -345,7 +345,7 @@ class UserPage extends Extension {
global $database;
if($user->is_anonymous()) {
$this->theme->display_error($page, "Error", "You aren't logged in");
$this->theme->display_error(401, "Error", "You aren't logged in");
}
else if(isset($_POST['id']) && isset($_POST['pass1']) && isset($_POST['pass2'])) {
$id = $_POST['id'];
@ -355,11 +355,11 @@ class UserPage extends Extension {
$duser = User::by_id($id);
if((!$user->can("change_user_info")) && ($duser->name != $user->name)) {
$this->theme->display_error($page, "Error",
$this->theme->display_error(401, "Error",
"You need to be an admin to change other people's passwords");
}
else if($pass1 != $pass2) {
$this->theme->display_error($page, "Error", "Passwords don't match");
$this->theme->display_error(400, "Error", "Passwords don't match");
}
else {
// FIXME: send_event()
@ -384,7 +384,7 @@ class UserPage extends Extension {
global $database;
if($user->is_anonymous()) {
$this->theme->display_error($page, "Error", "You aren't logged in");
$this->theme->display_error(401, "Error", "You aren't logged in");
}
else if(isset($_POST['id']) && isset($_POST['address'])) {
$id = $_POST['id'];
@ -393,7 +393,7 @@ class UserPage extends Extension {
$duser = User::by_id($id);
if((!$user->can("change_user_info")) && ($duser->name != $user->name)) {
$this->theme->display_error($page, "Error",
$this->theme->display_error(401, "Error",
"You need to be an admin to change other people's addressess");
}
else {

View file

@ -88,7 +88,7 @@ class ViewImage extends Extension {
$image = Image::by_id($image_id);
if(is_null($image)) {
$this->theme->display_error($page, "Image not found", "Image $image_id could not be found");
$this->theme->display_error(404, "Image not found", "Image $image_id could not be found");
return;
}
@ -100,7 +100,7 @@ class ViewImage extends Extension {
}
if(is_null($image)) {
$this->theme->display_error($page, "Image not found", "No more images");
$this->theme->display_error(404, "Image not found", "No more images");
return;
}
@ -121,7 +121,7 @@ class ViewImage extends Extension {
$this->theme->display_admin_block($page, $iabbe->parts);
}
else {
$this->theme->display_error($page, "Image not found", "No image in the database has the ID #$image_id");
$this->theme->display_error(404, "Image not found", "No image in the database has the ID #$image_id");
}
}

View file

@ -1,7 +1,9 @@
<?php
class Themelet {
public function display_error(Page $page, $title, $message) {
public function display_error(/*int*/ $code, /*string*/ $title, /*string*/ $message) {
global $page;
$page->add_http_header("HTTP/1.0 $code $title");
$page->set_title($title);
$page->set_heading($title);
$page->add_block(new NavBlock());
@ -10,9 +12,7 @@ class Themelet {
public function display_permission_denied() {
global $page;
$page->add_http_header("HTTP/1.0 403 Permission Denied");
$this->display_error($page, "Permission Denied", "You do not have permission to access this page");
$this->display_error(403, "Permission Denied", "You do not have permission to access this page");
}

View file

@ -6,7 +6,9 @@ class Themelet {
/**
* Generic error message display
*/
public function display_error(Page $page, $title, $message) {
public function display_error(/*int*/ $code, /*string*/ $title, /*string*/ $message) {
global $page;
$page->add_http_header("HTTP/1.0 $code $title");
$page->set_title($title);
$page->set_heading($title);
$page->add_block(new NavBlock());
@ -18,9 +20,7 @@ class Themelet {
* A specific, common error message
*/
public function display_permission_denied() {
global $page;
$page->add_http_header("HTTP/1.0 403 Permission Denied");
$this->display_error($page, "Permission Denied", "You do not have permission to access this page");
$this->display_error(403, "Permission Denied", "You do not have permission to access this page");
}

View file

@ -6,7 +6,9 @@ class Themelet {
/**
* Generic error message display
*/
public function display_error(Page $page, $title, $message) {
public function display_error(/*int*/ $code, /*string*/ $title, /*string*/ $message) {
global $page;
$page->add_http_header("HTTP/1.0 $code $title");
$page->set_title($title);
$page->set_heading($title);
$page->add_block(new NavBlock());
@ -18,9 +20,7 @@ class Themelet {
* A specific, common error message
*/
public function display_permission_denied() {
global $page;
$page->add_http_header("HTTP/1.0 403 Permission Denied");
$this->display_error($page, "Permission Denied", "You do not have permission to access this page");
$this->display_error(403, "Permission Denied", "You do not have permission to access this page");
}

View file

@ -4,7 +4,9 @@ class Themelet {
/**
* Generic error message display
*/
public function display_error(Page $page, $title, $message) {
public function display_error(/*int*/ $code, /*string*/ $title, /*string*/ $message) {
global $page;
$page->add_http_header("HTTP/1.0 $code $title");
$page->set_title($title);
$page->set_heading($title);
$page->add_block(new NavBlock());
@ -16,9 +18,7 @@ class Themelet {
* A specific, common error message
*/
public function display_permission_denied() {
global $page;
$page->add_http_header("HTTP/1.0 403 Permission Denied");
$this->display_error($page, "Permission Denied", "You do not have permission to access this page");
$this->display_error(403, "Permission Denied", "You do not have permission to access this page");
}

View file

@ -6,7 +6,9 @@ class Themelet {
/**
* Generic error message display
*/
public function display_error(Page $page, $title, $message) {
public function display_error(/*int*/ $code, /*string*/ $title, /*string*/ $message) {
global $page;
$page->add_http_header("HTTP/1.0 $code $title");
$page->set_title($title);
$page->set_heading($title);
$page->add_block(new NavBlock());
@ -18,9 +20,7 @@ class Themelet {
* A specific, common error message
*/
public function display_permission_denied() {
global $page;
$page->add_http_header("HTTP/1.0 403 Permission Denied");
$this->display_error($page, "Permission Denied", "You do not have permission to access this page");
$this->display_error(403, "Permission Denied", "You do not have permission to access this page");
}

View file

@ -4,7 +4,9 @@ class Themelet {
/**
* Generic error message display
*/
public function display_error(Page $page, $title, $message) {
public function display_error(/*int*/ $code, /*string*/ $title, /*string*/ $message) {
global $page;
$page->add_http_header("HTTP/1.0 $code $title");
$page->set_title($title);
$page->set_heading($title);
$page->add_block(new NavBlock());
@ -16,9 +18,7 @@ class Themelet {
* A specific, common error message
*/
public function display_permission_denied() {
global $page;
$page->add_http_header("HTTP/1.0 403 Permission Denied");
$this->display_error($page, "Permission Denied", "You do not have permission to access this page");
$this->display_error(403, "Permission Denied", "You do not have permission to access this page");
}

View file

@ -6,7 +6,9 @@ class Themelet {
/**
* Generic error message display
*/
public function display_error(Page $page, $title, $message) {
public function display_error(/*int*/ $code, /*string*/ $title, /*string*/ $message) {
global $page;
$page->add_http_header("HTTP/1.0 $code $title");
$page->set_title($title);
$page->set_heading($title);
$page->add_block(new NavBlock());
@ -18,9 +20,7 @@ class Themelet {
* A specific, common error message
*/
public function display_permission_denied() {
global $page;
$page->add_http_header("HTTP/1.0 403 Permission Denied");
$this->display_error($page, "Permission Denied", "You do not have permission to access this page");
$this->display_error(403, "Permission Denied", "You do not have permission to access this page");
}