From e62cdb09790d5e0ecd5b55deedd90c879121bac9 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 27 Jun 2023 15:32:39 +0100 Subject: [PATCH] offset can't be null, and named args --- core/imageboard/image.php | 6 +++--- ext/artists/main.php | 2 +- ext/index/main.php | 2 +- ext/pools/main.php | 5 ++--- ext/regen_thumb/main.php | 2 +- ext/sitemap/main.php | 6 +++--- ext/tag_edit/main.php | 6 +++--- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/core/imageboard/image.php b/core/imageboard/image.php index c041fc0b..23ec8353 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -149,7 +149,7 @@ class Image if ($start < 0) { $start = 0; } - if ($limit!=null && $limit < 1) { + if ($limit !== null && $limit < 1) { $limit = 1; } @@ -166,11 +166,11 @@ class Image /** * Search for an array of images * - * @param String[] $tags + * @param string[] $tags * @return Image[] */ #[Query(name: "posts", type: "[Post!]!", args: ["tags" => "[string!]"])] - public static function find_images(?int $offset = 0, ?int $limit = null, array $tags=[]): array + public static function find_images(int $offset = 0, ?int $limit = null, array $tags=[]): array { $result = self::find_images_internal($offset, $limit, $tags); diff --git a/ext/artists/main.php b/ext/artists/main.php index 7f03941c..88c7e7b3 100644 --- a/ext/artists/main.php +++ b/ext/artists/main.php @@ -212,7 +212,7 @@ class Artists extends Extension $userIsLogged = !$user->is_anonymous(); $userIsAdmin = $user->can(Permissions::ARTISTS_ADMIN); - $images = Image::find_images(0, 4, Tag::explode($artist['name'])); + $images = Image::find_images(limit: 4, tags: Tag::explode($artist['name'])); $this->theme->show_artist($artist, $aliases, $members, $urls, $images, $userIsLogged, $userIsAdmin); /* diff --git a/ext/index/main.php b/ext/index/main.php index e28c091f..917a921e 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -166,7 +166,7 @@ class Index extends Extension } if ($event->cmd == "search") { $query = count($event->args) > 0 ? Tag::explode($event->args[0]) : []; - $items = Image::find_images(0, 1000, $query); + $items = Image::find_images(limit: 1000, tags: $query); foreach ($items as $item) { print("{$item->hash}\n"); } diff --git a/ext/pools/main.php b/ext/pools/main.php index 85fff391..a8c49110 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -357,9 +357,8 @@ class Pools extends Extension case "import": if ($this->have_permission($user, $pool)) { $images = Image::find_images( - 0, - $config->get_int(PoolsConfig::MAX_IMPORT_RESULTS, 1000), - Tag::explode($_POST["pool_tag"]) + limit: $config->get_int(PoolsConfig::MAX_IMPORT_RESULTS, 1000), + tags: Tag::explode($_POST["pool_tag"]) ); $this->theme->pool_result($page, $images, $pool); } else { diff --git a/ext/regen_thumb/main.php b/ext/regen_thumb/main.php index 76327f29..c07c9908 100644 --- a/ext/regen_thumb/main.php +++ b/ext/regen_thumb/main.php @@ -30,7 +30,7 @@ class RegenThumb extends Extension } if ($event->page_matches("regen_thumb/mass") && $user->can(Permissions::DELETE_IMAGE) && isset($_POST['tags'])) { $tags = Tag::explode(strtolower($_POST['tags']), false); - $images = Image::find_images(0, 10000, $tags); + $images = Image::find_images(limit: 10000, tags: $tags); foreach ($images as $image) { $this->regenerate_thumbnail($image); diff --git a/ext/sitemap/main.php b/ext/sitemap/main.php index 3843adc7..c3fefe18 100644 --- a/ext/sitemap/main.php +++ b/ext/sitemap/main.php @@ -42,7 +42,7 @@ class XMLSitemap extends Extension private function handle_smaller_sitemap() { /* --- Add latest images to sitemap with higher priority --- */ - $latestimages = Image::find_images(0, 50, []); + $latestimages = Image::find_images(limit: 50); if (empty($latestimages)) { return; } @@ -85,7 +85,7 @@ class XMLSitemap extends Extension $this->add_sitemap_queue($popular_tags, "monthly", "0.9" /* not sure how to deal with date here */); /* --- Add latest images to sitemap with higher priority --- */ - $latestimages = Image::find_images(0, 50, []); + $latestimages = Image::find_images(limit: 50); $latestimages_urllist = []; $latest_image = null; foreach ($latestimages as $arrayid => $image) { @@ -107,7 +107,7 @@ class XMLSitemap extends Extension $this->add_sitemap_queue($other_tags, "monthly", "0.7" /* not sure how to deal with date here */); /* --- Add all other images to sitemap with lower priority --- */ - $otherimages = Image::find_images(51, 10000000, []); + $otherimages = Image::find_images(offset: 51, limit: 10000000); $image = null; foreach ($otherimages as $arrayid => $image) { // create url from image id's diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php index 64dc16bc..83109b54 100644 --- a/ext/tag_edit/main.php +++ b/ext/tag_edit/main.php @@ -300,7 +300,7 @@ class TagEdit extends Extension log_info("tag_edit", "Mass editing tags: '$search' -> '$replace'"); if (count($search_set) == 1 && count($replace_set) == 1) { - $images = Image::find_images(0, 10, $replace_set); + $images = Image::find_images(limit: 10, tags: $replace_set); if (count($images) == 0) { log_info("tag_edit", "No images found with target tag, doing in-place rename"); $database->execute( @@ -329,7 +329,7 @@ class TagEdit extends Extension $search_forward[] = "id<$last_id"; } - $images = Image::find_images(0, 100, $search_forward); + $images = Image::find_images(limit: 100, tags: $search_forward); if (count($images) == 0) { break; } @@ -365,7 +365,7 @@ class TagEdit extends Extension $search_forward[] = "id<$last_id"; } - $images = Image::find_images(0, 100, $search_forward); + $images = Image::find_images(limit: 100, tags: $search_forward); if (count($images) == 0) { break; }