Revert "[upload] add rating fields to upload form"

This reverts commit 32d5274880.
This commit is contained in:
Shish 2024-02-19 22:54:11 +00:00
parent ffb0d405b4
commit c0bc11ee0c
5 changed files with 7 additions and 69 deletions

View file

@ -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)

View file

@ -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<string,string> $current_ratings
*/

View file

@ -1,18 +0,0 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
class UploadRatingBuildingEvent extends Event
{
public string $part;
public string $suffix;
public function __construct(string $suffix)
{
parent::__construct();
$this->suffix = $suffix;
}
}

View file

@ -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<string, mixed> $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));

View file

@ -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
),
)
);
}