Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tag/source history] privatise some functions which are only used internally #1332

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions ext/source_history/main.php
Original file line number Diff line number Diff line change
@@ -4,8 +4,6 @@

namespace Shimmie2;

use function MicroHTML\{rawHTML};

class SourceHistory extends Extension
{
/** @var SourceHistoryTheme */
@@ -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'];
@@ -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("
@@ -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(
@@ -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("
@@ -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;

@@ -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));
17 changes: 7 additions & 10 deletions ext/tag_history/main.php
Original file line number Diff line number Diff line change
@@ -4,8 +4,6 @@

namespace Shimmie2;

use function MicroHTML\rawHTML;

class TagHistory extends Extension
{
/** @var TagHistoryTheme */
@@ -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'];
@@ -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("
@@ -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(
@@ -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("
@@ -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("
@@ -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;

@@ -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.']');
3 changes: 1 addition & 2 deletions ext/tag_history/theme.php
Original file line number Diff line number Diff line change
@@ -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"]);
}