From 93e06f76dfa2cb49a2edfcb6b70dd3c6cf3272d6 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 5 May 2012 22:32:18 +0200 Subject: Rework file deletion; allow to delete multiple IDs at once This removes the old form which was used to delete a single upload and replaces it with checkboxes on the history page. All checked IDs will be removed at once, instead of requiring the user to click through multiple pages. The old file/delete page is kept for compatibility with CLI clients. Signed-off-by: Florian Pritz --- application/controllers/file.php | 65 +++++++++++++++++------- application/views/file/deleted.php | 13 ++++- application/views/file/file_info.php | 65 ++++++++++-------------- application/views/file/upload_history.php | 47 +++++++++-------- application/views/file_plaintext/delete_form.php | 2 - application/views/file_plaintext/deleted.php | 9 +++- 6 files changed, 119 insertions(+), 82 deletions(-) delete mode 100644 application/views/file_plaintext/delete_form.php diff --git a/application/controllers/file.php b/application/controllers/file.php index 079802dbc..2a56df96c 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -180,37 +180,64 @@ class File extends CI_Controller { echo $cached; } - // Allow users to delete their own IDs - function delete() + function do_delete() { $this->muser->require_access(); - $id = $this->uri->segment(3); - $this->data["id"] = $id; + $ids = $this->input->post("ids"); + $errors = array(); + $msgs = array(); + $deleted_count = 0; + $total_count = 0; - $process = $this->input->post("process"); - if ($this->var->cli_client) { - $process = true; + if (!$ids) { + show_error("No IDs specified"); } - if ($id && !$this->file_mod->id_exists($id)) { - $this->output->set_status_header(404); - $this->data["msg"] = "Unknown ID."; - } elseif ($process) { + foreach ($ids as $id) { + $total_count++; + + if (!$this->file_mod->id_exists($id)) { + $errors[] = "'$id' didn't exist anymore."; + continue; + } + if ($this->file_mod->delete_id($id)) { - $this->load->view($this->var->view_dir.'/header', $this->data); - $this->load->view($this->var->view_dir.'/deleted', $this->data); - $this->load->view($this->var->view_dir.'/footer', $this->data); - return; + $msgs[] = "'$id' has been removed."; + $deleted_count++; } else { - $this->data["msg"] = "Deletion failed. Do you really own that file?"; + $errors[] = "'$id' couldn't be deleted."; } } - $this->data["filedata"] = $this->file_mod->get_filedata($id); - $this->data["can_delete"] = $this->data["filedata"]["user"] == $this->muser->get_userid(); + $this->data["errors"] = $errors; + $this->data["msgs"] = $msgs; + $this->data["deleted_count"] = $deleted_count; + $this->data["total_count"] = $total_count; + + $this->load->view($this->var->view_dir.'/header', $this->data); + $this->load->view($this->var->view_dir.'/deleted', $this->data); + $this->load->view($this->var->view_dir.'/footer', $this->data); + } + + function delete() + { + $this->muser->require_access(); + + $id = $this->uri->segment(3); + $this->data["id"] = $id; + + if ($id && !$this->file_mod->id_exists($id)) { + $this->output->set_status_header(404); + echo "Unknown ID '$id'.\n"; + return; + } - $this->file_mod->display_info($id); + if ($this->file_mod->delete_id($id)) { + echo "$id has been deleted.\n"; + } else { + echo "Deletion failed. Do you really own that file?\n"; + } } // Handle pastes diff --git a/application/views/file/deleted.php b/application/views/file/deleted.php index f12433808..ef02398d9 100644 --- a/application/views/file/deleted.php +++ b/application/views/file/deleted.php @@ -1,3 +1,14 @@
-

has been deleted.

+ "; + echo implode("
\n", $errors); + echo "

"; + } ?> + "; + echo implode("
\n", $msgs); + echo "

"; + } ?> + +

of deleted.

diff --git a/application/views/file/file_info.php b/application/views/file/file_info.php index 1e9d9fdfd..779ece854 100644 --- a/application/views/file/file_info.php +++ b/application/views/file/file_info.php @@ -1,39 +1,30 @@
- - ".$msg."

"; ?> - - -

You are about to delete the following upload:

- - - - - - - - - - - - - - - - - - - - - - - - - - -
ID
Filename
Date of upload
Date of removal
Size
Mimetype
- - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID
Filename
Date of upload
Date of removal
Size
Mimetype
+
diff --git a/application/views/file/upload_history.php b/application/views/file/upload_history.php index 8f0f8e3d7..2f0d0f41f 100644 --- a/application/views/file/upload_history.php +++ b/application/views/file/upload_history.php @@ -1,23 +1,26 @@ - - - - - - - - - + +
IDFilenameMimetype - DateHashSize
+ + + + + + + + - $item): ?> - - - - - - - - - - -
IDFilenameMimetype + DateHashSize
">/">
+ $item): ?> + + ]" value="" /> + /"> + + + + + + + + + + diff --git a/application/views/file_plaintext/delete_form.php b/application/views/file_plaintext/delete_form.php deleted file mode 100644 index ba736078c..000000000 --- a/application/views/file_plaintext/delete_form.php +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/application/views/file_plaintext/deleted.php b/application/views/file_plaintext/deleted.php index e5683b9d4..347766092 100644 --- a/application/views/file_plaintext/deleted.php +++ b/application/views/file_plaintext/deleted.php @@ -1 +1,8 @@ - has been deleted. + + + + of deleted. -- cgit v1.2.3-24-g4f1b