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

View file

@ -109,7 +109,7 @@ class Forum extends Extension {
if($hasErrors) 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); $this->theme->display_new_thread_composer($page, $_POST["message"], $_POST["title"], false);
break; break;
} }
@ -149,7 +149,7 @@ class Forum extends Extension {
if ($hasErrors) 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); $this->theme->display_new_post_composer($page, $_POST["threadID"], $_POST["message"], $_POST["title"], false);
break; break;
} }
@ -166,7 +166,7 @@ class Forum extends Extension {
{ {
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("forum/index")); $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; break;
} }
} }

View file

@ -108,7 +108,7 @@ class PrivMsg extends Extension {
$pm_id = int_escape($event->get_arg(1)); $pm_id = int_escape($event->get_arg(1));
$pm = $database->get_row("SELECT * FROM private_message WHERE id = :id", array("id" => $pm_id)); $pm = $database->get_row("SELECT * FROM private_message WHERE id = :id", array("id" => $pm_id));
if(is_null($pm)) { 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()) { else if(($pm["to_id"] == $user->id) || $user->is_admin()) {
$from_user = User::by_id(int_escape($pm["from_id"])); $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_id = int_escape($_POST["pm_id"]);
$pm = $database->get_row("SELECT * FROM private_message WHERE id = :id", array("id" => $pm_id)); $pm = $database->get_row("SELECT * FROM private_message WHERE id = :id", array("id" => $pm_id));
if(is_null($pm)) { 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()) { else if(($pm["to_id"] == $user->id) || $user->is_admin()) {
$database->execute("DELETE FROM private_message WHERE id = :id", array("id" => $pm_id)); $database->execute("DELETE FROM private_message WHERE id = :id", array("id" => $pm_id));
@ -146,7 +146,7 @@ class PrivMsg extends Extension {
} }
break; break;
default: 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; break;
} }
} }

View file

@ -115,7 +115,7 @@ class ResizeImage extends Extension {
$image = Image::by_id($image_id); $image = Image::by_id($image_id);
if(is_null($image)) { 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 { } else {
/* Check if options were given to resize an image. */ /* 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")); $page->set_redirect(make_link("alias/list"));
} }
catch(AddAliasException $ex) { 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")); $page->set_redirect(make_link("alias/list"));
} }
else { 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 { 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']))); $page->set_redirect(make_link("post/view/".int_escape($_POST['image_id'])));
} }
catch(CommentPostingException $ex) { 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")); $page->set_redirect(make_link("ext_manager"));
} }
else { 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 :("); "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); $image_old = Image::by_id($image_id);
if(is_null($image_old)) { 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) { if(count($_FILES) + count($_POST) > 0) {

View file

@ -97,7 +97,7 @@ class UserPage extends Extension {
else if($event->get_arg(0) == "recover") { else if($event->get_arg(0) == "recover") {
$user = User::by_name($_POST['username']); $user = User::by_name($_POST['username']);
if(is_null($user)) { 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)) { if(is_null($user->email)) {
// //
@ -111,7 +111,7 @@ class UserPage extends Extension {
$this->theme->display_signup_page($page); $this->theme->display_signup_page($page);
} }
else if($_POST['pass1'] != $_POST['pass2']) { 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 { else {
try { try {
@ -126,7 +126,7 @@ class UserPage extends Extension {
$page->set_redirect(make_link("user")); $page->set_redirect(make_link("user"));
} }
catch(UserCreationException $ex) { 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")) { if($event->page_matches("user")) {
$display_user = ($event->count_args() == 0) ? $user : User::by_name($event->get_arg(0)); $display_user = ($event->count_args() == 0) ? $user : User::by_name($event->get_arg(0));
if($event->count_args() == 0 && $user->is_anonymous()) { 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."); "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"))) { else if(!is_null($display_user) && ($display_user->id != $config->get_int("anon_id"))) {
send_event(new UserPageBuildingEvent($display_user)); send_event(new UserPageBuildingEvent($display_user));
} }
else { 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 ". "If you typed the ID by hand, try again; if you came from a link on this ".
"site, it might be bug report time..."); "site, it might be bug report time...");
} }
@ -285,7 +285,7 @@ class UserPage extends Extension {
} }
else { else {
log_warning("user", "Failed to log in as ".html_escape($name)." [$hash]"); 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; global $database;
if($user->is_anonymous()) { 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'])) { else if(isset($_POST['id']) && isset($_POST['pass1']) && isset($_POST['pass2'])) {
$id = $_POST['id']; $id = $_POST['id'];
@ -355,11 +355,11 @@ class UserPage extends Extension {
$duser = User::by_id($id); $duser = User::by_id($id);
if((!$user->can("change_user_info")) && ($duser->name != $user->name)) { 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"); "You need to be an admin to change other people's passwords");
} }
else if($pass1 != $pass2) { 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 { else {
// FIXME: send_event() // FIXME: send_event()
@ -384,7 +384,7 @@ class UserPage extends Extension {
global $database; global $database;
if($user->is_anonymous()) { 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'])) { else if(isset($_POST['id']) && isset($_POST['address'])) {
$id = $_POST['id']; $id = $_POST['id'];
@ -393,7 +393,7 @@ class UserPage extends Extension {
$duser = User::by_id($id); $duser = User::by_id($id);
if((!$user->can("change_user_info")) && ($duser->name != $user->name)) { 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"); "You need to be an admin to change other people's addressess");
} }
else { else {

View file

@ -88,7 +88,7 @@ class ViewImage extends Extension {
$image = Image::by_id($image_id); $image = Image::by_id($image_id);
if(is_null($image)) { 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; return;
} }
@ -100,7 +100,7 @@ class ViewImage extends Extension {
} }
if(is_null($image)) { 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; return;
} }
@ -121,7 +121,7 @@ class ViewImage extends Extension {
$this->theme->display_admin_block($page, $iabbe->parts); $this->theme->display_admin_block($page, $iabbe->parts);
} }
else { 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 <?php
class Themelet { 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_title($title);
$page->set_heading($title); $page->set_heading($title);
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
@ -10,9 +12,7 @@ class Themelet {
public function display_permission_denied() { public function display_permission_denied() {
global $page; $this->display_error(403, "Permission Denied", "You do not have permission to access this 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");
} }

View file

@ -6,7 +6,9 @@ class Themelet {
/** /**
* Generic error message display * 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_title($title);
$page->set_heading($title); $page->set_heading($title);
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
@ -18,9 +20,7 @@ class Themelet {
* A specific, common error message * A specific, common error message
*/ */
public function display_permission_denied() { public function display_permission_denied() {
global $page; $this->display_error(403, "Permission Denied", "You do not have permission to access this 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");
} }

View file

@ -6,7 +6,9 @@ class Themelet {
/** /**
* Generic error message display * 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_title($title);
$page->set_heading($title); $page->set_heading($title);
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
@ -18,9 +20,7 @@ class Themelet {
* A specific, common error message * A specific, common error message
*/ */
public function display_permission_denied() { public function display_permission_denied() {
global $page; $this->display_error(403, "Permission Denied", "You do not have permission to access this 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");
} }

View file

@ -4,7 +4,9 @@ class Themelet {
/** /**
* Generic error message display * 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_title($title);
$page->set_heading($title); $page->set_heading($title);
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
@ -16,9 +18,7 @@ class Themelet {
* A specific, common error message * A specific, common error message
*/ */
public function display_permission_denied() { public function display_permission_denied() {
global $page; $this->display_error(403, "Permission Denied", "You do not have permission to access this 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");
} }

View file

@ -6,7 +6,9 @@ class Themelet {
/** /**
* Generic error message display * 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_title($title);
$page->set_heading($title); $page->set_heading($title);
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
@ -18,9 +20,7 @@ class Themelet {
* A specific, common error message * A specific, common error message
*/ */
public function display_permission_denied() { public function display_permission_denied() {
global $page; $this->display_error(403, "Permission Denied", "You do not have permission to access this 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");
} }

View file

@ -4,7 +4,9 @@ class Themelet {
/** /**
* Generic error message display * 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_title($title);
$page->set_heading($title); $page->set_heading($title);
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
@ -16,9 +18,7 @@ class Themelet {
* A specific, common error message * A specific, common error message
*/ */
public function display_permission_denied() { public function display_permission_denied() {
global $page; $this->display_error(403, "Permission Denied", "You do not have permission to access this 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");
} }

View file

@ -6,7 +6,9 @@ class Themelet {
/** /**
* Generic error message display * 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_title($title);
$page->set_heading($title); $page->set_heading($title);
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
@ -18,9 +20,7 @@ class Themelet {
* A specific, common error message * A specific, common error message
*/ */
public function display_permission_denied() { public function display_permission_denied() {
global $page; $this->display_error(403, "Permission Denied", "You do not have permission to access this 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");
} }