drop php7.3 support, make use of 7.4 features

joe/cache-regex-fix
Shish 2 years ago
parent c558ee3bdb
commit 77f7121e26
  1. 2
      .github/workflows/test_and_publish.yml
  2. 2
      composer.json
  3. 72
      core/basepage.php
  4. 28
      core/block.php
  5. 31
      core/cacheengine.php
  6. 6
      core/command_builder.php
  7. 12
      core/config.php
  8. 17
      core/database.php
  9. 36
      core/dbengine.php
  10. 59
      core/event.php
  11. 22
      core/exceptions.php
  12. 67
      core/extension.php
  13. 48
      core/imageboard/event.php
  14. 93
      core/imageboard/image.php
  15. 18
      core/imageboard/search.php
  16. 2
      core/install.php
  17. 21
      core/polyfills.php
  18. 4
      core/urls.php
  19. 22
      core/user.php
  20. 18
      core/userclass.php
  21. 22
      core/util.php
  22. 16
      ext/admin/info.php
  23. 14
      ext/admin/main.php
  24. 1
      ext/admin/theme.php
  25. 16
      ext/alias_editor/info.php
  26. 10
      ext/alias_editor/main.php
  27. 10
      ext/approval/info.php
  28. 2
      ext/approval/main.php
  29. 5
      ext/approval/theme.php
  30. 14
      ext/artists/info.php
  31. 13
      ext/artists/main.php
  32. 2
      ext/artists/theme.php
  33. 10
      ext/auto_tagger/info.php
  34. 10
      ext/auto_tagger/main.php
  35. 8
      ext/autocomplete/info.php
  36. 2
      ext/autocomplete/main.php
  37. 4
      ext/autocomplete/script.js
  38. 14
      ext/ban_words/info.php
  39. 16
      ext/bbcode/info.php
  40. 4
      ext/bbcode/test.php
  41. 12
      ext/biography/info.php
  42. 6
      ext/biography/main.php
  43. 1
      ext/biography/test.php
  44. 12
      ext/blocks/info.php
  45. 2
      ext/blocks/main.php
  46. 12
      ext/blotter/info.php
  47. 2
      ext/blotter/main.php
  48. 8
      ext/blotter/theme.php
  49. 16
      ext/browser_search/info.php
  50. 12
      ext/bulk_actions/info.php
  51. 17
      ext/bulk_actions/main.php
  52. 28
      ext/bulk_actions/script.js
  53. 6
      ext/bulk_actions/theme.php
  54. 14
      ext/bulk_add/info.php
  55. 6
      ext/bulk_add/main.php
  56. 2
      ext/bulk_add/theme.php
  57. 14
      ext/bulk_add_csv/info.php
  58. 2
      ext/bulk_add_csv/main.php
  59. 2
      ext/bulk_add_csv/theme.php
  60. 12
      ext/bulk_download/info.php
  61. 8
      ext/bulk_import_export/events.php
  62. 12
      ext/bulk_import_export/info.php
  63. 4
      ext/bulk_import_export/main.php
  64. 16
      ext/comment/info.php
  65. 59
      ext/comment/main.php
  66. 12
      ext/comment/theme.php
  67. 12
      ext/cron_uploader/info.php
  68. 20
      ext/cron_uploader/main.php
  69. 3
      ext/cron_uploader/theme.php
  70. 14
      ext/custom_html_headers/info.php
  71. 10
      ext/danbooru_api/info.php
  72. 15
      ext/danbooru_api/main.php
  73. 10
      ext/download/events.php
  74. 14
      ext/download/info.php
  75. 14
      ext/downtime/info.php
  76. 4
      ext/downtime/main.php
  77. 16
      ext/emoticons/info.php
  78. 14
      ext/emoticons_list/info.php
  79. 2
      ext/emoticons_list/main.php
  80. 12
      ext/eokm/info.php
  81. 1
      ext/eokm/main.php
  82. 16
      ext/et/info.php
  83. 4
      ext/et/main.php
  84. 2
      ext/et/theme.php
  85. 16
      ext/et_server/info.php
  86. 18
      ext/ext_manager/info.php
  87. 6
      ext/ext_manager/main.php
  88. 12
      ext/favorites/info.php
  89. 11
      ext/favorites/main.php
  90. 7
      ext/favorites/theme.php
  91. 14
      ext/featured/info.php
  92. 2
      ext/featured/main.php
  93. 10
      ext/forum/info.php
  94. 30
      ext/forum/main.php
  95. 3
      ext/forum/theme.php
  96. 16
      ext/four_oh_four/info.php
  97. 2
      ext/four_oh_four/main.php
  98. 14
      ext/google_analytics/info.php
  99. 2
      ext/google_analytics/main.php
  100. 12
      ext/handle_archive/info.php
  101. Some files were not shown because too many files have changed in this diff Show More

@ -22,7 +22,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.3', '7.4', '8.0']
php: ['7.4', '8.0']
database: ['pgsql', 'mysql', 'sqlite']
runs-on: ubuntu-latest

@ -31,7 +31,7 @@
],
"require" : {
"php" : "^7.3 | ^8.0",
"php" : "^7.4 | ^8.0",
"ext-pdo": "*",
"ext-json": "*",
"ext-fileinfo": "*",

@ -20,10 +20,8 @@ abstract class PageMode
*/
class BasePage
{
/** @var string */
public $mode = PageMode::PAGE;
/** @var string */
private $mime;
public string $mode = PageMode::PAGE;
private string $mime;
/**
* Set what this page should do; "page", "data", or "redirect".
@ -52,19 +50,11 @@ class BasePage
// ==============================================
/** @var string; public only for unit test */
public $data = "";
/** @var string */
private $file = null;
/** @var bool */
private $file_delete = false;
/** @var string */
private $filename = null;
private $disposition = null;
public string $data = ""; // public only for unit test
private ?string $file = null;
private bool $file_delete = false;
private ?string $filename = null;
private ?string $disposition = null;
/**
* Set the raw data to be sent.
@ -91,8 +81,7 @@ class BasePage
// ==============================================
/** @var string */
public $redirect = "";
public string $redirect = "";
/**
* Set the URL to redirect to (remember to use make_link() if linking
@ -105,32 +94,25 @@ class BasePage
// ==============================================
/** @var int */
public $code = 200;
/** @var string */
public $title = "";
/** @var string */
public $heading = "";
/** @var string */
public $subheading = "";
public int $code = 200;
public string $title = "";
public string $heading = "";
public string $subheading = "";
/** @var string[] */
public $html_headers = [];
public array $html_headers = [];
/** @var string[] */
public $http_headers = [];
public array $http_headers = [];
/** @var string[][] */
public $cookies = [];
public array $cookies = [];
/** @var Block[] */
public $blocks = [];
public array $blocks = [];
/** @var string[] */
public $flash = [];
public array $flash = [];
/**
* Set the HTTP status code
@ -428,7 +410,7 @@ class BasePage
$this->add_html_header("<script defer src='$data_href/$js_cache_file' type='text/javascript'></script>", 44);
}
protected function get_nav_links()
protected function get_nav_links(): array
{
$pnbe = send_event(new PageNavBuildingEvent());
@ -574,7 +556,7 @@ EOD;
class PageNavBuildingEvent extends Event
{
public $links = [];
public array $links = [];
public function add_nav_link(string $name, Link $link, string $desc, ?bool $active = null, int $order = 50)
{
@ -584,9 +566,9 @@ class PageNavBuildingEvent extends Event
class PageSubNavBuildingEvent extends Event
{
public $parent;
public string $parent;
public $links = [];
public array $links = [];
public function __construct(string $parent)
{
@ -602,11 +584,11 @@ class PageSubNavBuildingEvent extends Event
class NavLink
{
public $name;
public $link;
public $description;
public $order;
public $active = false;
public string $name;
public Link $link;
public string $description;
public int $order;
public bool $active = false;
public function __construct(String $name, Link $link, String $description, ?bool $active = null, int $order = 50)
{
@ -663,7 +645,7 @@ class NavLink
}
}
function sort_nav_links(NavLink $a, NavLink $b)
function sort_nav_links(NavLink $a, NavLink $b): int
{
return $a->order - $b->order;
}

@ -9,49 +9,37 @@ class Block
{
/**
* The block's title.
*
* @var string
*/
public $header;
public ?string $header;
/**
* The content of the block.
*
* @var string
*/
public $body;
public ?string $body;
/**
* Where the block should be placed. The default theme supports
* "main" and "left", other themes can add their own areas.
*
* @var string
*/
public $section;
public string $section;
/**
* How far down the section the block should appear, higher
* numbers appear lower. The scale is 0-100 by convention,
* though any number will work.
*
* @var int
*/
public $position;
public int $position;
/**
* A unique ID for the block.
*
* @var string
*/
public $id;
public string $id;
/**
* Should this block count as content for the sake of
* the 404 handler
*
* @var boolean
*/
public $is_content = true;
public bool $is_content = true;
public function __construct(string $header=null, string $body=null, string $section="main", int $position=50, string $id=null)
{
@ -63,7 +51,9 @@ class Block
if (is_null($id)) {
$id = (empty($header) ? md5($body ?? '') : $header) . $section;
}
$this->id = preg_replace('/[^\w-]/', '', str_replace(' ', '_', $id));
$str_id = preg_replace('/[^\w-]/', '', str_replace(' ', '_', $id));
assert(is_string($str_id));
$this->id = $str_id;
}
/**

@ -2,8 +2,8 @@
interface CacheEngine
{
public function get(string $key);
public function set(string $key, $val, int $time=0);
public function delete(string $key);
public function set(string $key, $val, int $time=0): void;
public function delete(string $key): void;
}
class NoCache implements CacheEngine
@ -12,18 +12,17 @@ class NoCache implements CacheEngine
{
return false;
}
public function set(string $key, $val, int $time=0)
public function set(string $key, $val, int $time=0): void
{
}
public function delete(string $key)
public function delete(string $key): void
{
}
}
class MemcachedCache implements CacheEngine
{
/** @var ?Memcached */
public $memcache=null;
public ?Memcached $memcache=null;
public function __construct(string $args)
{
@ -52,7 +51,7 @@ class MemcachedCache implements CacheEngine
}
}
public function set(string $key, $val, int $time=0)
public function set(string $key, $val, int $time=0): void
{
$key = urlencode($key);
@ -63,7 +62,7 @@ class MemcachedCache implements CacheEngine
}
}
public function delete(string $key)
public function delete(string $key): void
{
$key = urlencode($key);
@ -87,12 +86,12 @@ class APCCache implements CacheEngine
return apc_fetch($key);
}
public function set(string $key, $val, int $time=0)
public function set(string $key, $val, int $time=0): void
{
apc_store($key, $val, $time);
}
public function delete(string $key)
public function delete(string $key): void
{
apc_delete($key);
}
@ -100,7 +99,7 @@ class APCCache implements CacheEngine
class RedisCache implements CacheEngine
{
private $redis=null;
private Redis $redis;
public function __construct(string $args)
{
@ -116,7 +115,7 @@ class RedisCache implements CacheEngine
return $this->redis->get($key);
}
public function set(string $key, $val, int $time=0)
public function set(string $key, $val, int $time=0): void
{
if ($time > 0) {
$this->redis->setEx($key, $time, $val);
@ -125,7 +124,7 @@ class RedisCache implements CacheEngine
}
}
public function delete(string $key)
public function delete(string $key): void
{
$this->redis->del($key);
}
@ -134,9 +133,9 @@ class RedisCache implements CacheEngine
class Cache
{
public $engine;
public $hits=0;
public $misses=0;
public $time=0;
public int $hits=0;
public int $misses=0;
public int $time=0;
public function __construct(?string $dsn)
{

@ -5,9 +5,9 @@
// quotes are only needed if the path to convert contains a space; some other times, quotes break things, see github bug #27
class CommandBuilder
{
private $executable;
private $args = [];
public $output;
private string $executable;
private array $args = [];
public array $output;
public function __construct(String $executable)
{

@ -130,7 +130,7 @@ interface Config
*/
abstract class BaseConfig implements Config
{
public $values = [];
public array $values = [];
public function set_int(string $name, ?int $value): void
{
@ -256,12 +256,10 @@ abstract class BaseConfig implements Config
*/
class DatabaseConfig extends BaseConfig
{
/** @var Database */
private $database = null;
private $table_name;
private $sub_column;
private $sub_value;
private Database $database;
private string $table_name;
private ?string $sub_column;
private ?string $sub_value;
public function __construct(
Database $database,

@ -13,30 +13,23 @@ abstract class DatabaseDriver
*/
class Database
{
/** @var string */
private $dsn;
private string $dsn;
/**
* The PDO database connection object, for anyone who wants direct access.
* @var null|PDO
*/
private $db = null;
/**
* @var float
*/
public $dbtime = 0.0;
private ?PDO $db = null;
public float $dbtime = 0.0;
/**
* Meta info about the database engine.
* @var DBEngine|null
*/
private $engine = null;
private ?DBEngine $engine = null;
/**
* How many queries this DB object has run
*/
public $query_count = 0;
public int $query_count = 0;
public function __construct(string $dsn)
{

@ -7,16 +7,15 @@ abstract class SCORE
abstract class DBEngine
{
/** @var null|string */
public $name = null;
public ?string $name = null;
public function init(PDO $db)
{
}
public function scoreql_to_sql(string $scoreql): string
public function scoreql_to_sql(string $data): string
{
return $scoreql;
return $data;
}
public function create_table_sql(string $name, string $data): string
@ -33,8 +32,7 @@ abstract class DBEngine
class MySQL extends DBEngine
{
/** @var string */
public $name = DatabaseDriver::MYSQL;
public ?string $name = DatabaseDriver::MYSQL;
public function init(PDO $db)
{
@ -73,8 +71,7 @@ class MySQL extends DBEngine
class PostgreSQL extends DBEngine
{
/** @var string */
public $name = DatabaseDriver::PGSQL;
public ?string $name = DatabaseDriver::PGSQL;
public function init(PDO $db)
{
@ -122,19 +119,19 @@ class PostgreSQL extends DBEngine
}
// shimmie functions for export to sqlite
function _unix_timestamp($date)
function _unix_timestamp($date): int
{
return strtotime($date);
}
function _now()
function _now(): string
{
return date("Y-m-d H:i:s");
}
function _floor($a)
function _floor($a): float
{
return floor($a);
}
function _log($a, $b=null)
function _log($a, $b=null): float
{
if (is_null($b)) {
return log($a);
@ -142,35 +139,34 @@ function _log($a, $b=null)
return log($a, $b);
}
}
function _isnull($a)
function _isnull($a): bool
{
return is_null($a);
}
function _md5($a)
function _md5($a): string
{
return md5($a);
}
function _concat($a, $b)
function _concat($a, $b): string
{
return $a . $b;
}
function _lower($a)
function _lower($a): string
{
return strtolower($a);
}
function _rand()
function _rand(): int
{
return rand();
}
function _ln($n)
function _ln($n): float
{
return log($n);
}
class SQLite extends DBEngine
{
/** @var string */
public $name = DatabaseDriver::SQLITE;
public ?string $name = DatabaseDriver::SQLITE;
public function init(PDO $db)
{

@ -6,13 +6,13 @@
*/
abstract class Event
{
public $stop_processing = false;
public bool $stop_processing = false;
public function __construct()
{
}
public function __toString()
public function __toString(): string
{
return var_export($this, true);
}
@ -42,19 +42,11 @@ class InitExtEvent extends Event
class PageRequestEvent extends Event
{
/**
* @var array
* @var string[]
*/
public $args;
/**
* @var int
*/
public $arg_count;
/**
* @var int
*/
public $part_count;
public int $arg_count;
public int $part_count;
public function __construct(string $path)
{
@ -179,15 +171,12 @@ class PageRequestEvent extends Event
*/
class CommandEvent extends Event
{
/**
* @var string
*/
public $cmd = "help";
public string $cmd = "help";
/**
* @var array
* @var string[]
*/
public $args = [];
public array $args = [];
/**
* #param string[] $args
@ -256,24 +245,18 @@ class TextFormattingEvent extends Event
{
/**
* For reference
*
* @var string
*/
public $original;
public string $original;
/**
* with formatting applied
*
* @var string
*/
public $formatted;
public string $formatted;
/**
* with formatting removed
*
* @var string
*/
public $stripped;
public string $stripped;
public function __construct(string $text)
{
@ -296,38 +279,30 @@ class LogEvent extends Event
{
/**
* a category, normally the extension name
*
* @var string
*/
public $section;
public string $section;
/**
* See python...
*
* @var int
*/
public $priority = 0;
public int $priority = 0;
/**
* Free text to be logged
*
* @var string
*/
public $message;
public string $message;
/**
* The time that the event was created
*
* @var int
*/
public $time;
public int $time;
/**
* Extra data to be held separate
*
* @var array
* @var string[]
*/
public $args;
public array $args;
public function __construct(string $section, int $priority, string $message)
{

@ -7,11 +7,8 @@
*/
class SCoreException extends RuntimeException
{
/** @var string|null */
public $query;
/** @var string */
public $error;
public ?string $query;
public string $error;
public function __construct(string $msg, ?string $query=null)
{
@ -23,21 +20,16 @@ class SCoreException extends RuntimeException
class InstallerException extends RuntimeException
{
/** @var string */
public $title;
/** @var string */
public $body;
/** @var int */
public $code;
public string $title;
public string $body;
public int $exit_code;
public function __construct(string $title, string $body, int $code)
public function __construct(string $title, string $body, int $exit_code)
{
parent::__construct($body);
$this->title = $title;
$this->body = $body;
$this->code = $code;
$this->exit_code = $exit_code;
}
}

@ -13,16 +13,11 @@
*/
abstract class Extension
{
/** @var string */
public $key;
public string $key;
protected ?Themelet $theme;
public ?ExtensionInfo $info;
/** @var Themelet */
protected $theme;
/** @var ExtensionInfo */
public $info;
private static $enabled_extensions = [];
private static array $enabled_extensions = [];
public function __construct($class = null)
{
@ -122,35 +117,31 @@ abstract class ExtensionInfo
public const LICENSE_MIT = "MIT";
public const LICENSE_WTFPL = "WTFPL";
public const VISIBLE_DEFAULT = "default";
public const VISIBLE_ADMIN = "admin";
public const VISIBLE_HIDDEN = "hidden";
private const VALID_VISIBILITY = [self::VISIBLE_ADMIN, self::VISIBLE_HIDDEN];
public $key;
public $core = false;
public $beta = false;
private const VALID_VISIBILITY = [self::VISIBLE_DEFAULT, self::VISIBLE_ADMIN, self::VISIBLE_HIDDEN];
public $name;
public $authors = [];
public $link;
public $license;
public $version;
public $dependencies = [];
public $conflicts = [];
public $visibility;
public $description;
public $documentation;
public string $key;
/** @var array which DBs this ext supports (blank for 'all') */
public $db_support = [];
public bool $core = false;
public bool $beta = false;
/** @var bool */
private $supported = null;
public string $name;
public string $license;
public string $description;
public array $authors = [];
public array $dependencies = [];
public array $conflicts = [];
public string $visibility = self::VISIBLE_DEFAULT;
public ?string $link = null;
public ?string $version = null;
public ?string $documentation = null;
/** @var string */
private $support_info = null;
/** @var string[] which DBs this ext supports (blank for 'all') */
public array $db_support = [];
private ?bool $supported = null;
private ?string $support_info = null;
public function is_supported(): bool
{
@ -168,9 +159,9 @@ abstract class ExtensionInfo
return $this->support_info;
}
private static $all_info_by_key = [];
private static $all_info_by_class = [];
private static $core_extensions = [];
private static array $all_info_by_key = [];
private static array $all_info_by_class = [];
private static array $core_extensions = [];
protected function __construct()
{
@ -283,7 +274,7 @@ abstract class FormatterExtension extends Extension
*/
abstract class DataHandlerExtension extends Extension
{
protected $SUPPORTED_MIME = [];
protected array $SUPPORTED_MIME = [];
protected function move_upload_to_archive(DataUploadEvent $event)
{
@ -335,7 +326,9 @@ abstract class DataHandlerExtension extends Extension
}
send_event(new ImageReplaceEvent($event->replace_id, $image));
$event->image_id = $event->replace_id;
$_id = $event->replace_id;
assert(!is_null($_id));
$event->image_id = $_id;
} else {
$image = $this->create_image_from_data(warehouse_path(Image::IMAGE_DIR, $event->hash), $event->metadata);
if (is_null($image)) {

@ -5,13 +5,9 @@
*/
class ImageAdditionEvent extends Event
{
/** @var User */
public $user;
/** @var Image */
public $image;
public $merged = false;
public User $user;
public Image $image;
public bool $merged = false;
/**
* Inserts a new image into the database with its associated
@ -34,11 +30,8 @@ class ImageAdditionException extends SCoreException
*/
class ImageDeletionEvent extends Event
{
/** @var Image */
public $image;
/** @var bool */
public $force = false;
public Image $image;
public bool $force = false;
/**
* Deletes an image.
@ -59,10 +52,8 @@ class ImageDeletionEvent extends Event
*/
class ImageReplaceEvent extends Event
{
/** @var int */
public $id;
/** @var Image */
public $image;
public int $id;
public Image $image;
/**
* Replaces an image.
@ -88,15 +79,10 @@ class ImageReplaceException extends SCoreException
*/
class ThumbnailGenerationEvent extends Event
{
/** @var string */
public $hash;
/** @var string */
public $mime;
/** @var bool */
public $force;
/** @var bool */
public $generated;
public string $hash;
public string $mime;
public bool $force;
public bool $generated;
/**
* Request a thumbnail be made for an image object
@ -121,14 +107,10 @@ class ThumbnailGenerationEvent extends Event
*/
class ParseLinkTemplateEvent extends Event
{
/** @var string */
public $link;
/** @var string */
public $text;
/** @var string */
public $original;
/** @var Image */
public $image;
public string $link;
public string $text;
public string $original;
public Image $image;
public function __construct(string $link, Image $image)
{

@ -13,68 +13,31 @@ class Image
public const IMAGE_DIR = "images";
public const THUMBNAIL_DIR = "thumbs";
/** @var null|int */
public $id = null;
/** @var int */
public $height;
/** @var int */
public $width;
/** @var string */
public $hash;
/** @var int */
public $filesize;
/** @var string */
public $filename;
/** @var string */
private $ext;
/** @var string */
private $mime;
public ?int $id = null;
public int $height;
public int $width;
public string $hash;
public int $filesize;
public string $filename;
private string $ext;
private string $mime;
/** @var string[]|null */
public $tag_array;
/** @var int */
public $owner_id;
/** @var string */
public $owner_ip;
/** @var string */
public $posted;
/** @var string */
public $source;
/** @var boolean */
public $locked = false;
/** @var boolean */
public $lossless = null;
/** @var boolean */
public $video = null;
/** @var string */
public $video_codec = null;
/** @var boolean */
public $image = null;
/** @var boolean */
public $audio = null;
/** @var int */
public $length = null;
public static $bool_props = ["locked", "lossless", "video", "audio"];
public static $int_props = ["id", "owner_id", "height", "width", "filesize", "length"];
public ?array $tag_array;
public int $owner_id;
public string $owner_ip;
public string $posted;
public ?string $source;
public bool $locked = false;
public ?bool $lossless = null;
public ?bool $video = null;
public ?string $video_codec = null;
public ?bool $image = null;
public ?bool $audio = null;
public ?int $length = null;
public static array $bool_props = ["locked", "lossless", "video", "audio", "image"];
public static array $int_props = ["id", "owner_id", "height", "width", "filesize", "length"];
/**
* One will very rarely construct an image directly, more common
@ -145,7 +108,7 @@ class Image
private static function find_images_internal(int $start = 0, ?int $limit = null, array $tags=[]): iterable
{
global $database, $user, $config;
global $database, $user;
if ($start < 0) {
$start = 0;
@ -161,9 +124,7 @@ class Image
}
$querylet = Image::build_search_querylet($tags, $limit, $start);
$result = $database->get_all_iterable($querylet->sql, $querylet->variables);
return $result;
return $database->get_all_iterable($querylet->sql, $querylet->variables);
}
/**
@ -625,7 +586,9 @@ class Image
public function set_mime($mime): void
{
$this->mime = $mime;
$this->ext = FileExtension::get_for_mime($this->get_mime());
$ext = FileExtension::get_for_mime($this->get_mime());
assert($ext != null);
$this->ext = $ext;
}

@ -1,10 +1,8 @@
<?php declare(strict_types=1);
class Querylet
{
/** @var string */
public $sql;
/** @var array */
public $variables;
public string $sql;
public array $variables;
public function __construct(string $sql, array $variables=[])
{
@ -31,10 +29,8 @@ class Querylet
class TagCondition
{
/** @var string */
public $tag;
/** @var bool */
public $positive;
public string $tag;
public bool $positive;
public function __construct(string $tag, bool $positive)
{
@ -45,10 +41,8 @@ class TagCondition
class ImgCondition
{
/** @var Querylet */
public $qlet;
/** @var bool */
public $positive;
public Querylet $qlet;
public bool $positive;
public function __construct(Querylet $qlet, bool $positive)
{

@ -68,7 +68,7 @@ function do_install($dsn)
create_tables(new Database($dsn));
write_config($dsn);
} catch (InstallerException $e) {
die_nicely($e->title, $e->body, $e->code);
die_nicely($e->title, $e->body, $e->exit_code);
}
}

@ -246,21 +246,22 @@ function find_header(array $headers, string $name): ?string
if (!function_exists('mb_strlen')) {
// TODO: we should warn the admin that they are missing multibyte support
function mb_strlen($str, $encoding)
/** @noinspection PhpUnusedParameterInspection */
function mb_strlen($str, $encoding): int
{
return strlen($str);
}
function mb_internal_encoding($encoding)
function mb_internal_encoding($encoding): void
{
}
function mb_strtolower($str)
function mb_strtolower($str): string
{
return strtolower($str);
}
}
/** @noinspection PhpUnhandledExceptionInspection */
function get_subclasses_of(string $parent)
function get_subclasses_of(string $parent): array
{
$result = [];
foreach (get_declared_classes() as $class) {
@ -327,7 +328,7 @@ function get_base_href(): string
/**
* The opposite of the standard library's parse_url
*/
function unparse_url($parsed_url)
function unparse_url(array $parsed_url): string
{
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
@ -345,14 +346,14 @@ function unparse_url($parsed_url)
if (!function_exists('str_starts_with')) {
function str_starts_with(string $haystack, string $needle): bool
{
return \strncmp($haystack, $needle, \strlen($needle)) === 0;
return strncmp($haystack, $needle, strlen($needle)) === 0;
}
}
if (!function_exists('str_ends_with')) {
function str_ends_with(string $haystack, string $needle): bool
{
return $needle === '' || $needle === \substr($haystack, - \strlen($needle));
return $needle === '' || $needle === substr($haystack, - strlen($needle));
}
}
@ -520,13 +521,9 @@ function parse_shorthand_int(string $limit): int
/** @noinspection PhpMissingBreakStatementInspection */
case 't': $value *= 1024; // fall through
/** @noinspection PhpMissingBreakStatementInspection */
// no break
case 'g': $value *= 1024; // fall through
/** @noinspection PhpMissingBreakStatementInspection */
// no break
case 'm': $value *= 1024; // fall through
/** @noinspection PhpMissingBreakStatementInspection */
// no break
case 'k': $value *= 1024; break;
default: $value = -1;
}
@ -800,7 +797,7 @@ function iterator_map_to_array(callable $callback, iterator $iter): array
return iterator_to_array(iterator_map($callback, $iter));
}
function stringer($s)
function stringer($s): string
{
if (is_array($s)) {
if (isset($s[0])) {

@ -2,8 +2,8 @@
class Link
{
public $page;
public $query;
public ?string $page;
public ?string $query;
public function __construct(?string $page=null, ?string $query=null)
{

@ -15,22 +15,12 @@ function _new_user(array $row): User
*/
class User
{
/** @var int */
public $id;
/** @var string */
public $name;
/** @var string */
public $email;
public $join_date;
/** @var string */
public $passhash;
/** @var UserClass */
public $class;
public int $id;
public string $name;
public ?string $email;
public string $join_date;
public ?string $passhash;
public UserClass $class;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Initialisation *

@ -10,21 +10,9 @@ $_shm_user_classes = [];
*/
class UserClass
{
/**
* @var ?string
*/
public $name = null;
/**
* @var ?UserClass
*/
public $parent = null;
/**
* @var array
*/
public $abilities = [];
public ?string $name = null;
public ?UserClass $parent = null;
public array $abilities = [];
public function __construct(string $name, string $parent = null, array $abilities = [])
{

@ -12,6 +12,7 @@ use function MicroHTML\TFOOT;
use function MicroHTML\TR;
use function MicroHTML\TH;
use function MicroHTML\TD;
use MicroHTML\HTMLElement;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Misc *
@ -359,7 +360,7 @@ function path_to_tags(string $path): string
}
function join_url(string $base, string ...$paths)
function join_url(string $base, string ...$paths): string
{
$output = $base;
foreach ($paths as $path) {
@ -410,7 +411,7 @@ function remove_empty_dirs(string $dir): bool
}
}
if ($result===true) {
$result = $result && rmdir($dir);
$result = rmdir($dir);
}
return $result;
}
@ -584,7 +585,6 @@ function _get_themelet_files(string $_theme): array
/**
* Used to display fatal errors to the web user.
* @noinspection PhpPossiblePolymorphicInvocationInspection
*/
function _fatal_error(Exception $e): void
{
@ -703,7 +703,7 @@ function make_form(string $target, string $method="POST", bool $multipart=false,
return '<form action="'.$target.'" method="'.$method.'" '.$extra.'>'.$extra_inputs;
}
function SHM_FORM(string $target, string $method="POST", bool $multipart=false, string $form_id="", string $onsubmit="")
function SHM_FORM(string $target, string $method="POST", bool $multipart=false, string $form_id="", string $onsubmit=""): HTMLElement
{
global $user;
@ -728,19 +728,19 @@ function SHM_FORM(string $target, string $method="POST", bool $multipart=false,
);
}
function SHM_SIMPLE_FORM($target, ...$children)
function SHM_SIMPLE_FORM($target, ...$children): HTMLElement
{
$form = SHM_FORM($target);
$form->appendChild(emptyHTML(...$children));
return $form;
}
function SHM_SUBMIT(string $text)
function SHM_SUBMIT(string $text): HTMLElement
{
return INPUT(["type"=>"submit", "value"=>$text]);
}
function SHM_COMMAND_EXAMPLE(string $ex, string $desc)
function SHM_COMMAND_EXAMPLE(string $ex, string $desc): HTMLElement
{
return DIV(
["class"=>"command_example"],
@ -749,7 +749,7 @@ function SHM_COMMAND_EXAMPLE(string $ex, string $desc)
);
}
function SHM_USER_FORM(User $duser, string $target, string $title, $body, $foot)
function SHM_USER_FORM(User $duser, string $target, string $title, $body, $foot): HTMLElement
{
if (is_string($foot)) {
$foot = TFOOT(TR(TD(["colspan"=>"2"], INPUT(["type"=>"submit", "value"=>$foot]))));
@ -769,16 +769,16 @@ function SHM_USER_FORM(User $duser, string $target, string $title, $body, $foot)
}
const BYTE_DENOMINATIONS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
function human_filesize(int $bytes, $decimals = 2)
function human_filesize(int $bytes, $decimals = 2): string
{
$factor = floor((strlen(strval($bytes)) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @BYTE_DENOMINATIONS[$factor];
}
/*
/**
* Generates a unique key for the website to prevent unauthorized access.
*/
function generate_key(int $length = 20)
function generate_key(int $length = 20): string
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';

@ -4,12 +4,12 @@ class AdminPageInfo extends ExtensionInfo
{
public const KEY = "admin";
public $key = self::KEY;
public $name = "Admin Controls";
public $url = self::SHIMMIE_URL;
public $authors = self::SHISH_AUTHOR;
public $license = self::LICENSE_GPLV2;
public $description = "Provides a base for various small admin functions";
public $core = true;
public $visibility = self::VISIBLE_HIDDEN;
public string $key = self::KEY;
public string $name = "Admin Controls";
public string $url = self::SHIMMIE_URL;
public array $authors = self::SHISH_AUTHOR;
public string $license = self::LICENSE_GPLV2;
public string $description = "Provides a base for various small admin functions";
public bool $core = true;
public string $visibility = self::VISIBLE_HIDDEN;
}

@ -1,13 +1,11 @@
<?php /** @noinspection PhpUnusedPrivateMethodInspection */
declare(strict_types=1);
<?php declare(strict_types=1);
/**
* Sent when the admin page is ready to be added to
*/
class AdminBuildingEvent extends Event
{
/** @var Page */
public $page;
public Page $page;
public function __construct(Page $page)
{
@ -18,10 +16,8 @@ class AdminBuildingEvent extends Event
class AdminActionEvent extends Event
{
/** @var string */