From 239e02866221fc8f713d2d2a92eb497360784c2d Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 10 Jun 2012 04:21:03 +0100 Subject: [PATCH] flash messages everywhere~ --- core/util.inc.php | 32 ++++++++++++++++++++++++++------ ext/admin/main.php | 5 +++++ ext/alias_editor/main.php | 5 +++-- ext/comment/main.php | 2 ++ ext/ext_manager/main.php | 1 + ext/favorites/main.php | 9 ++++++++- ext/featured/main.php | 1 + ext/numeric_score/main.php | 2 +- ext/pm/main.php | 3 ++- ext/setup/main.php | 1 + 10 files changed, 50 insertions(+), 11 deletions(-) diff --git a/core/util.inc.php b/core/util.inc.php index c420c380..1d03f5e0 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -689,6 +689,12 @@ function set_prefixed_cookie($name, $value, $time, $path) { /** * Set (or extend) a flash-message cookie + * + * This can optionally be done at the same time as saving a log message with log_*() + * + * Generally one should flash a message in onPageRequest and log a message wherever + * the action actually takes place (eg onWhateverElse) - but much of the time, actions + * are taken from within onPageRequest... */ function flash_message(/*string*/ $text, /*string*/ $type="info") { $current = get_prefixed_cookie("flash_message"); @@ -819,17 +825,31 @@ define("SCORE_LOG_NOTSET", 0); /** * A shorthand way to send a LogEvent + * + * When parsing a user request, a flash message should give info to the user + * When taking action, a log event should be stored by the server + * Quite often, both of these happen at once, hence log_*() having $flash + * + * $flash = null (default) - log to server only, no flash message + * $flash = true - show the message to the user as well + * $flash = "some string" - log the message, flash the string */ -function log_msg(/*string*/ $section, /*int*/ $priority, /*string*/ $message) { +function log_msg(/*string*/ $section, /*int*/ $priority, /*string*/ $message, $flash=null) { send_event(new LogEvent($section, $priority, $message)); + if($flash === True) { + flash_message($message); + } + else if(!is_null($flash)) { + flash_message($flash); + } } // More shorthand ways of logging -function log_debug(/*string*/ $section, /*string*/ $message) {log_msg($section, SCORE_LOG_DEBUG, $message);} -function log_info(/*string*/ $section, /*string*/ $message) {log_msg($section, SCORE_LOG_INFO, $message);} -function log_warning(/*string*/ $section, /*string*/ $message) {log_msg($section, SCORE_LOG_WARNING, $message);} -function log_error(/*string*/ $section, /*string*/ $message) {log_msg($section, SCORE_LOG_ERROR, $message);} -function log_critical(/*string*/ $section, /*string*/ $message) {log_msg($section, SCORE_LOG_CRITICAL, $message);} +function log_debug( /*string*/ $section, /*string*/ $message, $flash=null) {log_msg($section, SCORE_LOG_DEBUG, $message, $flash);} +function log_info( /*string*/ $section, /*string*/ $message, $flash=null) {log_msg($section, SCORE_LOG_INFO, $message, $flash);} +function log_warning( /*string*/ $section, /*string*/ $message, $flash=null) {log_msg($section, SCORE_LOG_WARNING, $message, $flash);} +function log_error( /*string*/ $section, /*string*/ $message, $flash=null) {log_msg($section, SCORE_LOG_ERROR, $message, $flash);} +function log_critical(/*string*/ $section, /*string*/ $message, $flash=null) {log_msg($section, SCORE_LOG_CRITICAL, $message, $flash);} /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ diff --git a/ext/admin/main.php b/ext/admin/main.php index f70e77bf..be3f3275 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -101,9 +101,12 @@ class AdminPage extends Extension { assert(strlen($query) > 1); log_warning("admin", "Mass deleting: $query"); + $count = 0; foreach(Image::find_images(0, 1000000, Tag::explode($query)) as $image) { send_event(new ImageDeletionEvent($image)); + $count++; } + log_debug("admin", "Deleted $count images", true); $page->set_mode("redirect"); $page->set_redirect(make_link("post/list")); @@ -113,6 +116,7 @@ class AdminPage extends Extension { private function lowercase_all_tags() { global $database; $database->execute("UPDATE tags SET tag=lower(tag)"); + log_warning("admin", "Set all tags to lowercase", true); return true; } @@ -126,6 +130,7 @@ class AdminPage extends Extension { ) "); $database->Execute("DELETE FROM tags WHERE count=0"); + log_warning("admin", "Re-counted tags", true); return true; } diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index 539bafde..7ba38656 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -46,7 +46,7 @@ class AliasEditor extends Extension { if($user->can("manage_alias_list")) { if(isset($_POST['oldtag'])) { $database->execute("DELETE FROM aliases WHERE oldtag=:oldtag", array("oldtag" => $_POST['oldtag'])); - log_info("alias_editor", "Deleted alias for ".$_POST['oldtag']); + log_info("alias_editor", "Deleted alias for ".$_POST['oldtag'], true); $page->set_mode("redirect"); $page->set_redirect(make_link("alias/list")); @@ -87,6 +87,7 @@ class AliasEditor extends Extension { $tmp = $_FILES['alias_file']['tmp_name']; $contents = file_get_contents($tmp); $this->add_alias_csv($database, $contents); + log_info("alias_editor", "Imported aliases from file", true); # FIXME: how many? $page->set_mode("redirect"); $page->set_redirect(make_link("alias/list")); } @@ -109,7 +110,7 @@ class AliasEditor extends Extension { } else { $database->execute("INSERT INTO aliases(oldtag, newtag) VALUES(:oldtag, :newtag)", $pair); - log_info("alias_editor", "Added alias for {$event->oldtag} -> {$event->newtag}"); + log_info("alias_editor", "Added alias for {$event->oldtag} -> {$event->newtag}", true); } } diff --git a/ext/comment/main.php b/ext/comment/main.php index 4253c5c0..211167af 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -140,6 +140,7 @@ class CommentList extends Extension { // FIXME: post, not args if($event->count_args() === 3) { send_event(new CommentDeletionEvent($event->get_arg(1))); + flash_message("Deleted comment"); $page->set_mode("redirect"); if(!empty($_SERVER['HTTP_REFERER'])) { $page->set_redirect($_SERVER['HTTP_REFERER']); @@ -163,6 +164,7 @@ class CommentList extends Extension { foreach($cids as $cid) { send_event(new CommentDeletionEvent($cid)); } + flash_message("Deleted $num comments"); $page->set_mode("redirect"); $page->set_redirect(make_link("admin")); diff --git a/ext/ext_manager/main.php b/ext/ext_manager/main.php index 851ebdbf..ace892a7 100644 --- a/ext/ext_manager/main.php +++ b/ext/ext_manager/main.php @@ -98,6 +98,7 @@ class ExtManager extends Extension { if($event->get_arg(0) == "set" && $user->check_auth_token()) { if(is_writable("data/config")) { $this->set_things($_POST); + log_warning("ext_manager", "Active extensions changed", true); $page->set_mode("redirect"); $page->set_redirect(make_link("ext_manager")); } diff --git a/ext/favorites/main.php b/ext/favorites/main.php index 35d3c7f0..aee35d6a 100644 --- a/ext/favorites/main.php +++ b/ext/favorites/main.php @@ -60,7 +60,14 @@ class Favorites extends Extension { if($event->page_matches("change_favorite") && !$user->is_anonymous() && $user->check_auth_token()) { $image_id = int_escape($_POST['image_id']); if((($_POST['favorite_action'] == "set") || ($_POST['favorite_action'] == "unset")) && ($image_id > 0)) { - send_event(new FavoriteSetEvent($image_id, $user, ($_POST['favorite_action'] == "set"))); + if($_POST['favorite_action'] == "set") { + send_event(new FavoriteSetEvent($image_id, $user, true)); + log_debug("favourite", "Favourite set for $image_id", "Favourite added"); + } + else { + send_event(new FavoriteSetEvent($image_id, $user, false)); + log_debug("favourite", "Favourite removed for $image_id", "Favourite removed"); + } } $page->set_mode("redirect"); $page->set_redirect(make_link("post/view/$image_id")); diff --git a/ext/featured/main.php b/ext/featured/main.php index 57c9f4f8..21fdb319 100644 --- a/ext/featured/main.php +++ b/ext/featured/main.php @@ -33,6 +33,7 @@ class Featured extends Extension { $id = int_escape($_POST['image_id']); if($id > 0) { $config->set_int("featured_id", $id); + log_info("featured", "Featured image set to $id", "Featured image set"); $page->set_mode("redirect"); $page->set_redirect(make_link("post/view/$id")); } diff --git a/ext/numeric_score/main.php b/ext/numeric_score/main.php index 5ce8640e..9897aa4f 100644 --- a/ext/numeric_score/main.php +++ b/ext/numeric_score/main.php @@ -174,7 +174,7 @@ class NumericScore extends Extension { public function onNumericScoreSet(NumericScoreSetEvent $event) { global $user; - log_debug("numeric_score", "Rated Image #{$event->image_id} as {$event->score}"); + log_debug("numeric_score", "Rated Image #{$event->image_id} as {$event->score}", true); $this->add_vote($event->image_id, $user->id, $event->score); } diff --git a/ext/pm/main.php b/ext/pm/main.php index ad37b06a..6a709afe 100644 --- a/ext/pm/main.php +++ b/ext/pm/main.php @@ -130,7 +130,7 @@ class PrivMsg extends Extension { else if(($pm["to_id"] == $user->id) || $user->can("view_other_pms")) { $database->execute("DELETE FROM private_message WHERE id = :id", array("id" => $pm_id)); $database->cache->delete("pm-count-{$user->id}"); - log_info("pm", "Deleted PM #$pm_id"); + log_info("pm", "Deleted PM #$pm_id", "PM deleted"); $page->set_mode("redirect"); $page->set_redirect($_SERVER["HTTP_REFERER"]); } @@ -143,6 +143,7 @@ class PrivMsg extends Extension { $subject = $_POST["subject"]; $message = $_POST["message"]; send_event(new SendPMEvent(new PM($from_id, $_SERVER["REMOTE_ADDR"], $to_id, $subject, $message))); + flash_message("PM sent"); $page->set_mode("redirect"); $page->set_redirect($_SERVER["HTTP_REFERER"]); } diff --git a/ext/setup/main.php b/ext/setup/main.php index 83f7c235..c2ca62d0 100644 --- a/ext/setup/main.php +++ b/ext/setup/main.php @@ -184,6 +184,7 @@ class Setup extends Extension { if($event->get_arg(0) == "save" && $user->check_auth_token()) { send_event(new ConfigSaveEvent($config)); $config->save(); + flash_message("Config saved"); $page->set_mode("redirect"); $page->set_redirect(make_link("setup"));