From c0bc11ee0c8e0c64f4c63858ed60e4a50192eba9 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 19 Feb 2024 22:54:11 +0000 Subject: [PATCH] Revert "[upload] add rating fields to upload form" This reverts commit 32d5274880a0cf992f8074b047d87bb811115e35. --- ext/rating/main.php | 7 +--- ext/rating/theme.php | 8 +---- .../events/upload_rating_building_event.php | 18 ---------- ext/upload/main.php | 36 +++---------------- ext/upload/theme.php | 7 ---- 5 files changed, 7 insertions(+), 69 deletions(-) delete mode 100644 ext/upload/events/upload_rating_building_event.php diff --git a/ext/rating/main.php b/ext/rating/main.php index df82323a..b9f45049 100644 --- a/ext/rating/main.php +++ b/ext/rating/main.php @@ -165,11 +165,6 @@ class Ratings extends Extension } } - public function onUploadRatingBuilding(UploadRatingBuildingEvent $event): void - { - $event->part = (string)$this->theme->get_upload_rater_html($event->suffix); - } - public function onDisplayingImage(DisplayingImageEvent $event): void { global $page; @@ -209,7 +204,7 @@ class Ratings extends Extension { global $user; $event->add_part( - $this->theme->get_image_rater_html( + $this->theme->get_rater_html( $event->image->id, $event->image['rating'], $user->can(Permissions::EDIT_IMAGE_RATING) diff --git a/ext/rating/theme.php b/ext/rating/theme.php index b58f6551..72f6efb1 100644 --- a/ext/rating/theme.php +++ b/ext/rating/theme.php @@ -7,7 +7,6 @@ namespace Shimmie2; use MicroHTML\HTMLElement; use function MicroHTML\emptyHTML; -use function MicroHTML\rawHTML; use function MicroHTML\{A,P,TABLE,TD,TH,TR}; class RatingsTheme extends Themelet @@ -21,7 +20,7 @@ class RatingsTheme extends Themelet return SHM_SELECT($name, !empty($ratings) ? $ratings : Ratings::get_ratings_dict(), required: true, selected_options: $selected_options); } - public function get_image_rater_html(int $image_id, string $rating, bool $can_rate): HTMLElement + public function get_rater_html(int $image_id, string $rating, bool $can_rate): HTMLElement { return SHM_POST_INFO( "Rating", @@ -30,11 +29,6 @@ class RatingsTheme extends Themelet ); } - public function get_upload_rater_html(string $suffix): HTMLElement - { - return $this->get_selection_rater_html(name:"rating${suffix}", selected_options: ["?"]); - } - /** * @param array $current_ratings */ diff --git a/ext/upload/events/upload_rating_building_event.php b/ext/upload/events/upload_rating_building_event.php deleted file mode 100644 index 9d3ae698..00000000 --- a/ext/upload/events/upload_rating_building_event.php +++ /dev/null @@ -1,18 +0,0 @@ -suffix = $suffix; - } -} diff --git a/ext/upload/main.php b/ext/upload/main.php index ff00744c..b2d620d4 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Shimmie2; require_once "config.php"; -require_once "events/upload_rating_building_event.php"; /** * Occurs when some data is being uploaded. @@ -37,9 +36,6 @@ class DataUploadEvent extends Event assert(is_string($metadata["filename"])); assert(is_array($metadata["tags"])); assert(is_string($metadata["source"]) || is_null($metadata["source"])); - if (Extension::is_enabled(RatingsInfo::KEY)) { - assert(is_string($metadata['rating'])); - } // DB limits to 255 char filenames $metadata['filename'] = substr($metadata['filename'], 0, 255); @@ -241,8 +237,7 @@ class Upload extends Extension $slot = int_escape(substr($name, 4)); $tags = $this->tags_for_upload_slot($event->POST, $slot); $source = $this->source_for_upload_slot($event->POST, $slot); - $rating = $this->rating_for_upload_slot($event->POST, $slot); - $results = array_merge($results, $this->try_upload($file, $tags, $source, $rating)); + $results = array_merge($results, $this->try_upload($file, $tags, $source)); } $urls = array_filter($event->POST, function ($value, $key) { @@ -252,8 +247,7 @@ class Upload extends Extension $slot = int_escape(substr($name, 3)); $tags = $this->tags_for_upload_slot($event->POST, $slot); $source = $this->source_for_upload_slot($event->POST, $slot); - $rating = $this->rating_for_upload_slot($event->POST, $slot); - $results = array_merge($results, $this->try_transload($value, $tags, $source, $rating)); + $results = array_merge($results, $this->try_transload($value, $tags, $source)); } $this->theme->display_upload_status($page, $results); @@ -293,22 +287,6 @@ class Upload extends Extension return null; } - /** - * @param array $params - */ - private function rating_for_upload_slot(array $params, int $id): ?string - { - if (Extension::is_enabled(RatingsInfo::KEY) && (!empty($params["rating"]) || !empty($params["rating$id"]))) { - if($params["rating$id"] != "?") { - return $params["rating$id"]; - } - if($params["rating"] != "?") { - return $params["rating"]; - } - } - return null; - } - /** * Returns a descriptive error message for the specified PHP error code. * @@ -345,7 +323,7 @@ class Upload extends Extension * @param string[] $tags * @return UploadResult[] */ - private function try_upload(array $file, array $tags, ?string $source = null, ?string $rating = null): array + private function try_upload(array $file, array $tags, ?string $source = null): array { global $page, $config, $database; @@ -374,12 +352,11 @@ class Upload extends Extension throw new UploadException($this->upload_error_message($error)); } - $new_images = $database->with_savepoint(function () use ($tmp_name, $name, $tags, $source, $rating) { + $new_images = $database->with_savepoint(function () use ($tmp_name, $name, $tags, $source) { $event = send_event(new DataUploadEvent($tmp_name, [ 'filename' => pathinfo($name, PATHINFO_BASENAME), 'tags' => $tags, 'source' => $source, - 'rating' => $rating, ])); if (count($event->images) == 0) { throw new UploadException("MIME type not supported: " . $event->mime); @@ -401,7 +378,7 @@ class Upload extends Extension * @param string[] $tags * @return UploadResult[] */ - private function try_transload(string $url, array $tags, string $source = null, ?string $rating = null): array + private function try_transload(string $url, array $tags, string $source = null): array { global $page, $config, $user, $database; @@ -425,9 +402,6 @@ class Upload extends Extension $metadata['filename'] = $filename; $metadata['tags'] = $tags; $metadata['source'] = $source; - if (Extension::is_enabled(RatingsInfo::KEY)) { - $metadata['rating'] = $rating; - } $new_images = $database->with_savepoint(function () use ($tmp_filename, $metadata) { $event = send_event(new DataUploadEvent($tmp_filename, $metadata)); diff --git a/ext/upload/theme.php b/ext/upload/theme.php index 11da7595..aa2710e3 100644 --- a/ext/upload/theme.php +++ b/ext/upload/theme.php @@ -94,7 +94,6 @@ class UploadTheme extends Themelet $upload_list = emptyHTML(); $upload_count = $config->get_int(UploadConfig::COUNT); $tl_enabled = ($config->get_string(UploadConfig::TRANSLOAD_ENGINE, "none") != "none"); - $ratings_enabled = Extension::is_enabled(RatingsInfo::KEY); $accept = $this->get_accept(); $upload_list->appendChild( @@ -104,12 +103,9 @@ class UploadTheme extends Themelet TH($tl_enabled ? "or URL" : null), TH("Post-Specific Tags"), TH("Post-Specific Source"), - TH($ratings_enabled ? "Rating" : null), ) ); - - for ($i = 0; $i < $upload_count; $i++) { $upload_list->appendChild( TR( @@ -150,9 +146,6 @@ class UploadTheme extends Themelet "value" => ($i == 0) ? @$_GET['source'] : null, ]) ), - TD( - $ratings_enabled ? rawHTML(send_event(new UploadRatingBuildingEvent((string)$i))->part) : null - ), ) ); }