Skip to content

Commit

Permalink
[tag/source history] privatise some functions which are only used int…
Browse files Browse the repository at this point in the history
…ernally
  • Loading branch information
shish committed Dec 12, 2024
1 parent afc9194 commit 9807a5f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
18 changes: 6 additions & 12 deletions ext/source_history/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Shimmie2;

use function MicroHTML\{rawHTML};

class SourceHistory extends Extension
{
/** @var SourceHistoryTheme */
Expand Down Expand Up @@ -170,7 +168,7 @@ private function process_revert_request(int $revert_id): void
$page->set_redirect(make_link('post/view/'.$stored_image_id));
}

protected function process_bulk_revert_request(): void
private function process_bulk_revert_request(): void
{
if (isset($_POST['revert_name']) && !empty($_POST['revert_name'])) {
$revert_name = $_POST['revert_name'];
Expand Down Expand Up @@ -212,7 +210,7 @@ protected function process_bulk_revert_request(): void
/**
* @return array<string, mixed>|null
*/
public function get_source_history_from_revert(int $revert_id): ?array
private function get_source_history_from_revert(int $revert_id): ?array
{
global $database;
$row = $database->get_row("
Expand All @@ -226,7 +224,7 @@ public function get_source_history_from_revert(int $revert_id): ?array
/**
* @return array<string, mixed>
*/
public function get_source_history_from_id(int $image_id): array
private function get_source_history_from_id(int $image_id): array
{
global $database;
return $database->get_all(
Expand All @@ -243,7 +241,7 @@ public function get_source_history_from_id(int $image_id): array
/**
* @return array<string, mixed>
*/
public function get_global_source_history(int $page_id): array
private function get_global_source_history(int $page_id): array
{
global $database;
return $database->get_all("
Expand All @@ -258,7 +256,7 @@ public function get_global_source_history(int $page_id): array
/**
* This function attempts to revert all changes by a given IP within an (optional) timeframe.
*/
public function process_revert_all_changes(?string $name, ?string $ip, ?string $date): void
private function process_revert_all_changes(?string $name, ?string $ip, ?string $date): void
{
global $database;

Expand Down Expand Up @@ -327,11 +325,7 @@ public function process_revert_all_changes(?string $name, ?string $ip, ?string $

log_debug("source_history", 'Reverting source of >>'.$stored_image_id.' to ['.$stored_source.']');

$image = Image::by_id($stored_image_id);

if (is_null($image)) {
die('Error: No image with the id ('.$stored_image_id.') was found. Perhaps the image was deleted while processing this request.');
}
$image = Image::by_id_ex($stored_image_id);

// all should be ok so we can revert by firing the SetSources event.
send_event(new SourceSetEvent($image, $stored_source));
Expand Down
17 changes: 7 additions & 10 deletions ext/tag_history/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Shimmie2;

use function MicroHTML\rawHTML;

class TagHistory extends Extension
{
/** @var TagHistoryTheme */
Expand Down Expand Up @@ -216,7 +214,7 @@ private function process_revert_request(int $revert_id): void
$page->set_redirect(make_link('post/view/'.$stored_image_id));
}

protected function process_bulk_revert_request(): void
private function process_bulk_revert_request(): void
{
if (isset($_POST['revert_name']) && !empty($_POST['revert_name'])) {
$revert_name = $_POST['revert_name'];
Expand Down Expand Up @@ -258,7 +256,7 @@ protected function process_bulk_revert_request(): void
/**
* @return array<string, mixed>|null
*/
public function get_tag_history_from_revert(int $revert_id): ?array
private function get_tag_history_from_revert(int $revert_id): ?array
{
global $database;
$row = $database->get_row("
Expand All @@ -272,7 +270,7 @@ public function get_tag_history_from_revert(int $revert_id): ?array
/**
* @return array<string, mixed>
*/
public function get_tag_history_from_id(int $image_id): array
private function get_tag_history_from_id(int $image_id): array
{
global $database;
return $database->get_all(
Expand All @@ -289,7 +287,7 @@ public function get_tag_history_from_id(int $image_id): array
/**
* @return array<string, mixed>
*/
public function get_global_tag_history(int $page_id): array
private function get_global_tag_history(int $page_id): array
{
global $database;
return $database->get_all("
Expand All @@ -304,7 +302,7 @@ public function get_global_tag_history(int $page_id): array
/**
* @return array<string, mixed>|null
*/
public function get_previous_tags(int $image_id, int $id): ?array
public static function get_previous_tags(int $image_id, int $id): ?array
{
global $database;
$row = $database->get_row("
Expand All @@ -320,7 +318,7 @@ public function get_previous_tags(int $image_id, int $id): ?array
/**
* This function attempts to revert all changes by a given IP within an (optional) timeframe.
*/
public function process_revert_all_changes(?string $name, ?string $ip, ?string $date): void
private function process_revert_all_changes(?string $name, ?string $ip, ?string $date): void
{
global $database;

Expand Down Expand Up @@ -388,9 +386,8 @@ public function process_revert_all_changes(?string $name, ?string $ip, ?string $
$stored_tags = $result['tags'];

$image = Image::by_id($stored_image_id);
if (!$image instanceof Image) {
if (is_null($image)) {
continue;
//throw new ImageDoesNotExist("Error: cannot find any image with the ID = ". $stored_image_id);
}

log_debug("tag_history", 'Reverting tags of >>'.$stored_image_id.' to ['.$stored_tags.']');
Expand Down
3 changes: 1 addition & 2 deletions ext/tag_history/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ protected function history_entry(array $fields, bool $selected): string
: null;
$setter = A(["href" => make_link("user/" . url_escape($name))], $name);

$th = new TagHistory();
$pt = $th->get_previous_tags($image_id, $current_id);
$pt = TagHistory::get_previous_tags($image_id, $current_id);
if ($pt) {
$previous_tags = explode(" ", $pt["tags"]);
}
Expand Down

0 comments on commit 9807a5f

Please sign in to comment.