From f50795029acecc5e059dea6555b337f324675a20 Mon Sep 17 00:00:00 2001 From: discomrade <83621080+discomrade@users.noreply.github.com> Date: Sun, 16 Jun 2024 14:10:44 +0000 Subject: [PATCH] [tag_history] add diff colour-coding to tag changes --- ext/tag_history/main.php | 16 ++++++++++++++++ ext/tag_history/style.css | 2 ++ ext/tag_history/theme.php | 24 ++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 ext/tag_history/style.css diff --git a/ext/tag_history/main.php b/ext/tag_history/main.php index 91c0c353..cf8d3e42 100644 --- a/ext/tag_history/main.php +++ b/ext/tag_history/main.php @@ -301,6 +301,22 @@ class TagHistory extends Extension ", ["offset" => ($page_id - 1) * 100]); } + /** + * @return array|null + */ + public function get_previous_tags(int $image_id, int $id): ?array + { + global $database; + $row = $database->get_row(" + SELECT tags + FROM tag_histories + WHERE image_id = :image_id AND id < :id + ORDER BY id DESC + LIMIT 1 + ", ["image_id" => $image_id, "id" => $id]); + return ($row ? $row : null); + } + /** * This function attempts to revert all changes by a given IP within an (optional) timeframe. */ diff --git a/ext/tag_history/style.css b/ext/tag_history/style.css new file mode 100644 index 00000000..506c9d7d --- /dev/null +++ b/ext/tag_history/style.css @@ -0,0 +1,2 @@ +.added-tag{background:lightgreen;} +.deleted-tag{background:pink;text-decoration:line-through;} \ No newline at end of file diff --git a/ext/tag_history/theme.php b/ext/tag_history/theme.php index ed20cc9c..7f428ff4 100644 --- a/ext/tag_history/theme.php +++ b/ext/tag_history/theme.php @@ -132,10 +132,30 @@ class TagHistoryTheme extends Themelet : null; $setter = A(["href" => make_link("user/" . url_escape($name))], $name); + $th = new TagHistory(); + $pt = $th->get_previous_tags($image_id, $current_id); + if ($pt) { + $previous_tags = Tag::explode($pt["tags"]); + } $current_tags = Tag::explode($current_tags); + if ($pt) { + $tags = array_unique(array_merge($current_tags, $previous_tags)); + sort($tags); + } else { + $tags = $current_tags; + } $taglinks = SPAN(); - foreach ($current_tags as $tag) { - $taglinks->appendChild(A(["href" => search_link([$tag])], $tag)); + foreach ($tags as $tag) { + $class = ""; + if ($pt) { + if (!in_array($tag, $previous_tags)) { + $class = "added-tag"; + } + if (!in_array($tag, $current_tags)) { + $class = "deleted-tag"; + } + } + $taglinks->appendChild(A(["href" => search_link([$tag]), "class" => $class], $tag)); $taglinks->appendChild(" "); }