diff --git a/.editorconfig b/.editorconfig index 15d2c086..645a8f3e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,10 +1,3 @@ -# In retrospect I'm less of a fan of tabs for indentation, because -# while they're better when they work, they're worse when they don't -# work, and so many people use terrible editors when they don't work -# that everything is inconsistent... but tabs are what Shimmie went -# with back in the 90's, so that's what we use now, and we deal with -# the pain of making sure everybody configures their editor properly - # top-most EditorConfig file root = true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8b536d53..4d860fb8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,21 +32,15 @@ jobs: with: php-version: 8.1 - - name: Log Versions - run: ./vendor/bin/php-cs-fixer --version - - name: Format - run: ./vendor/bin/php-cs-fixer fix - - - name: Log Diff - run: git diff --exit-code + run: ./vendor/bin/php-cs-fixer fix && git diff --exit-code test: name: PHP ${{ matrix.php }} / DB ${{ matrix.database }} strategy: fail-fast: false matrix: - php: ['7.4', '8.0', '8.1'] + php: ['8.1'] database: ['pgsql', 'mysql', 'sqlite'] runs-on: ubuntu-latest @@ -112,7 +106,7 @@ jobs: vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover=data/coverage.clover - name: Upload coverage - if: matrix.php == '7.4' + if: matrix.php == '8.1' run: | wget https://scrutinizer-ci.com/ocular.phar php ocular.phar code-coverage:upload --format=php-clover data/coverage.clover diff --git a/Dockerfile b/Dockerfile index 61ccbab6..97c67322 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # "Build" shimmie (composer install - done in its own stage so that we don't # need to include all the composer fluff in the final image) -FROM debian:stable AS app -RUN apt update && apt install -y composer php7.4-gd php7.4-dom php7.4-sqlite3 php-xdebug imagemagick +FROM debian:unstable AS app +RUN apt update && apt install -y composer php8.1-gd php8.1-dom php8.1-sqlite3 php-xdebug imagemagick COPY composer.json composer.lock /app/ WORKDIR /app RUN composer install --no-dev @@ -10,8 +10,8 @@ COPY . /app/ # Tests in their own image. Really we should inherit from app and then # `composer install` phpunit on top of that; but for some reason # `composer install --no-dev && composer install` doesn't install dev -FROM debian:stable AS tests -RUN apt update && apt install -y composer php7.4-gd php7.4-dom php7.4-sqlite3 php-xdebug imagemagick +FROM debian:unstable AS tests +RUN apt update && apt install -y composer php8.1-gd php8.1-dom php8.1-sqlite3 php-xdebug imagemagick COPY composer.json composer.lock /app/ WORKDIR /app RUN composer install @@ -25,7 +25,7 @@ RUN [ $RUN_TESTS = false ] || (\ echo '=== Cleaning ===' && rm -rf data) # Build su-exec so that our final image can be nicer -FROM debian:stable AS suexec +FROM debian:unstable AS suexec RUN apt-get update && apt-get install -y --no-install-recommends gcc libc-dev curl RUN curl -k -o /usr/local/bin/su-exec.c https://raw.githubusercontent.com/ncopa/su-exec/master/su-exec.c; \ gcc -Wall /usr/local/bin/su-exec.c -o/usr/local/bin/su-exec; \ @@ -33,13 +33,13 @@ RUN curl -k -o /usr/local/bin/su-exec.c https://raw.githubusercontent.com/ncopa chmod 0755 /usr/local/bin/su-exec; # Actually run shimmie -FROM debian:stable +FROM debian:unstable EXPOSE 8000 HEALTHCHECK --interval=1m --timeout=3s CMD curl --fail http://127.0.0.1:8000/ || exit 1 ENV UID=1000 \ GID=1000 RUN apt update && apt install -y curl \ - php7.4-cli php7.4-gd php7.4-pgsql php7.4-mysql php7.4-sqlite3 php7.4-zip php7.4-dom php7.4-mbstring \ + php8.1-cli php8.1-gd php8.1-pgsql php8.1-mysql php8.1-sqlite3 php8.1-zip php8.1-dom php8.1-mbstring \ imagemagick zip unzip && \ rm -rf /var/lib/apt/lists/* COPY --from=app /app /app diff --git a/composer.json b/composer.json index 0621a3cb..75f77554 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "config": { "platform": { - "php": "7.4.0" + "php": "8.1.0" } }, @@ -31,7 +31,7 @@ ], "require" : { - "php" : "^7.4 | ^8.0", + "php" : "^8.1", "ext-pdo": "*", "ext-json": "*", "ext-fileinfo": "*", diff --git a/core/basepage.php b/core/basepage.php index 11a99a88..697fd6e1 100644 --- a/core/basepage.php +++ b/core/basepage.php @@ -3,13 +3,13 @@ declare(strict_types=1); require_once "core/event.php"; -abstract class PageMode +enum PageMode: string { - public const REDIRECT = 'redirect'; - public const DATA = 'data'; - public const PAGE = 'page'; - public const FILE = 'file'; - public const MANUAL = 'manual'; + case REDIRECT = 'redirect'; + case DATA = 'data'; + case PAGE = 'page'; + case FILE = 'file'; + case MANUAL = 'manual'; } /** @@ -22,13 +22,13 @@ abstract class PageMode */ class BasePage { - public string $mode = PageMode::PAGE; + public PageMode $mode = PageMode::PAGE; private string $mime; /** * Set what this page should do; "page", "data", or "redirect". */ - public function set_mode(string $mode): void + public function set_mode(PageMode $mode): void { $this->mode = $mode; } diff --git a/core/block.php b/core/block.php index 40e0c726..ce09be39 100644 --- a/core/block.php +++ b/core/block.php @@ -43,10 +43,10 @@ class Block */ public bool $is_content = true; - public function __construct(string $header=null, string $body=null, string $section="main", int $position=50, string $id=null) + public function __construct(string $header=null, string|\MicroHTML\HTMLElement $body=null, string $section="main", int $position=50, string $id=null) { $this->header = $header; - $this->body = $body; + $this->body = (string)$body; $this->section = $section; $this->position = $position; diff --git a/core/database.php b/core/database.php index e83b08e7..49162018 100644 --- a/core/database.php +++ b/core/database.php @@ -3,11 +3,11 @@ declare(strict_types=1); use FFSPHP\PDO; -abstract class DatabaseDriver +enum DatabaseDriverID: string { - public const MYSQL = "mysql"; - public const PGSQL = "pgsql"; - public const SQLITE = "sqlite"; + case MYSQL = "mysql"; + case PGSQL = "pgsql"; + case SQLITE = "sqlite"; } /** @@ -54,11 +54,11 @@ class Database throw new SCoreException("Can't figure out database engine"); } - if ($db_proto === DatabaseDriver::MYSQL) { + if ($db_proto === DatabaseDriverID::MYSQL->value) { $this->engine = new MySQL(); - } elseif ($db_proto === DatabaseDriver::PGSQL) { + } elseif ($db_proto === DatabaseDriverID::PGSQL->value) { $this->engine = new PostgreSQL(); - } elseif ($db_proto === DatabaseDriver::SQLITE) { + } elseif ($db_proto === DatabaseDriverID::SQLITE->value) { $this->engine = new SQLite(); } else { die_nicely( @@ -106,12 +106,12 @@ class Database return $this->engine->scoreql_to_sql($input); } - public function get_driver_name(): string + public function get_driver_id(): DatabaseDriverID { if (is_null($this->engine)) { $this->connect_engine(); } - return $this->engine->name; + return $this->engine->id; } public function get_version(): string @@ -269,7 +269,7 @@ class Database */ public function get_last_insert_id(string $seq): int { - if ($this->engine->name == DatabaseDriver::PGSQL) { + if ($this->engine->id == DatabaseDriverID::PGSQL) { $id = $this->db->lastInsertId($seq); } else { $id = $this->db->lastInsertId(); @@ -301,20 +301,20 @@ class Database $this->connect_db(); } - if ($this->engine->name === DatabaseDriver::MYSQL) { + if ($this->engine->id === DatabaseDriverID::MYSQL) { return count( $this->get_all("SHOW TABLES") ); - } elseif ($this->engine->name === DatabaseDriver::PGSQL) { + } elseif ($this->engine->id === DatabaseDriverID::PGSQL) { return count( $this->get_all("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'") ); - } elseif ($this->engine->name === DatabaseDriver::SQLITE) { + } elseif ($this->engine->id === DatabaseDriverID::SQLITE) { return count( $this->get_all("SELECT name FROM sqlite_master WHERE type = 'table'") ); } else { - throw new SCoreException("Can't count tables for database type {$this->engine->name}"); + throw new SCoreException("Can't count tables for database type {$this->engine->id}"); } } @@ -325,8 +325,8 @@ class Database public function standardise_boolean(string $table, string $column, bool $include_postgres=false): void { - $d = $this->get_driver_name(); - if ($d == DatabaseDriver::MYSQL) { + $d = $this->get_driver_id(); + if ($d == DatabaseDriverID::MYSQL) { # In mysql, ENUM('Y', 'N') is secretly INTEGER where Y=1 and N=2. # BOOLEAN is secretly TINYINT where true=1 and false=0. # So we can cast directly from ENUM to BOOLEAN which gives us a @@ -335,12 +335,12 @@ class Database $this->execute("ALTER TABLE $table MODIFY COLUMN $column BOOLEAN;"); $this->execute("UPDATE $table SET $column=0 WHERE $column=2;"); } - if ($d == DatabaseDriver::SQLITE) { + if ($d == DatabaseDriverID::SQLITE) { # SQLite doesn't care about column types at all, everything is # text, so we can in-place replace a char with a bool $this->execute("UPDATE $table SET $column = ($column IN ('Y', 1))"); } - if ($d == DatabaseDriver::PGSQL && $include_postgres) { + if ($d == DatabaseDriverID::PGSQL && $include_postgres) { $this->execute("ALTER TABLE $table ADD COLUMN ${column}_b BOOLEAN DEFAULT FALSE NOT NULL"); $this->execute("UPDATE $table SET ${column}_b = ($column = 'Y')"); $this->execute("ALTER TABLE $table DROP COLUMN $column"); diff --git a/core/dbengine.php b/core/dbengine.php index 22ea3cc0..46407595 100644 --- a/core/dbengine.php +++ b/core/dbengine.php @@ -9,7 +9,7 @@ abstract class SCORE abstract class DBEngine { - public ?string $name = null; + public DatabaseDriverID $id; public function init(PDO $db) { @@ -34,7 +34,7 @@ abstract class DBEngine class MySQL extends DBEngine { - public ?string $name = DatabaseDriver::MYSQL; + public DatabaseDriverID $id = DatabaseDriverID::MYSQL; public function init(PDO $db) { @@ -73,7 +73,7 @@ class MySQL extends DBEngine class PostgreSQL extends DBEngine { - public ?string $name = DatabaseDriver::PGSQL; + public DatabaseDriverID $id = DatabaseDriverID::PGSQL; public function init(PDO $db) { @@ -171,7 +171,7 @@ function _ln($n): float class SQLite extends DBEngine { - public ?string $name = DatabaseDriver::SQLITE; + public DatabaseDriverID $id = DatabaseDriverID::SQLITE; public function init(PDO $db) { diff --git a/core/extension.php b/core/extension.php index 0642e083..8cbd09ec 100644 --- a/core/extension.php +++ b/core/extension.php @@ -107,6 +107,12 @@ abstract class Extension } } +enum ExtensionVisibility { + case DEFAULT; + case ADMIN; + case HIDDEN; +} + abstract class ExtensionInfo { // Every credit you get costs us RAM. It stops now. @@ -119,11 +125,6 @@ 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_DEFAULT, self::VISIBLE_ADMIN, self::VISIBLE_HIDDEN]; - public string $key; public bool $core = false; @@ -135,12 +136,12 @@ abstract class ExtensionInfo public array $authors = []; public array $dependencies = []; public array $conflicts = []; - public string $visibility = self::VISIBLE_DEFAULT; + public ExtensionVisibility $visibility = ExtensionVisibility::DEFAULT; public ?string $link = null; public ?string $version = null; public ?string $documentation = null; - /** @var string[] which DBs this ext supports (blank for 'all') */ + /** @var DatabaseDriverID[] which DBs this ext supports (blank for 'all') */ public array $db_support = []; private ?bool $supported = null; private ?string $support_info = null; @@ -169,7 +170,6 @@ abstract class ExtensionInfo { assert(!empty($this->key), "key field is required"); assert(!empty($this->name), "name field is required for extension $this->key"); - assert(empty($this->visibility) || in_array($this->visibility, self::VALID_VISIBILITY), "Invalid visibility for extension $this->key"); assert(is_array($this->db_support), "db_support has to be an array for extension $this->key"); assert(is_array($this->authors), "authors has to be an array for extension $this->key"); assert(is_array($this->dependencies), "dependencies has to be an array for extension $this->key"); @@ -184,7 +184,7 @@ abstract class ExtensionInfo { global $database; $this->support_info = ""; - if (!empty($this->db_support) && !in_array($database->get_driver_name(), $this->db_support)) { + if (!empty($this->db_support) && !in_array($database->get_driver_id(), $this->db_support)) { $this->support_info .= "Database not supported. "; } if (!empty($this->conflicts)) { diff --git a/core/imageboard/event.php b/core/imageboard/event.php index 70dc0afe..2d4a1e3c 100644 --- a/core/imageboard/event.php +++ b/core/imageboard/event.php @@ -8,7 +8,6 @@ declare(strict_types=1); class ImageAdditionEvent extends Event { public User $user; - public Image $image; public bool $merged = false; /** @@ -16,10 +15,10 @@ class ImageAdditionEvent extends Event * information. Also calls TagSetEvent to set the tags for * this new image. */ - public function __construct(Image $image) - { + public function __construct( + public Image $image, + ) { parent::__construct(); - $this->image = $image; } } @@ -32,20 +31,17 @@ class ImageAdditionException extends SCoreException */ class ImageDeletionEvent extends Event { - public Image $image; - public bool $force = false; - /** * Deletes an image. * * Used by things like tags and comments handlers to * clean out related rows in their tables. */ - public function __construct(Image $image, bool $force = false) - { + public function __construct( + public Image $image, + public bool $force = false, + ) { parent::__construct(); - $this->image = $image; - $this->force = $force; } } @@ -54,9 +50,6 @@ class ImageDeletionEvent extends Event */ class ImageReplaceEvent extends Event { - public int $id; - public Image $image; - /** * Replaces an image. * @@ -64,11 +57,11 @@ class ImageReplaceEvent extends Event * file, leaving the tags and such unchanged. Also removes * the old image file and thumbnail from the disk. */ - public function __construct(int $id, Image $image) - { + public function __construct( + public int $id, + public Image $image + ) { parent::__construct(); - $this->id = $id; - $this->image = $image; } } @@ -81,20 +74,17 @@ class ImageReplaceException extends SCoreException */ class ThumbnailGenerationEvent extends Event { - public string $hash; - public string $mime; - public bool $force; public bool $generated; /** * Request a thumbnail be made for an image object */ - public function __construct(string $hash, string $mime, bool $force=false) - { + public function __construct( + public string $hash, + public string $mime, + public bool $force=false + ) { parent::__construct(); - $this->hash = $hash; - $this->mime = $mime; - $this->force = $force; $this->generated = false; } } diff --git a/core/imageboard/image.php b/core/imageboard/image.php index a18c62a3..fd9d40fb 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -650,7 +650,7 @@ class Image public function delete_tags_from_image(): void { global $database; - if ($database->get_driver_name() == DatabaseDriver::MYSQL) { + if ($database->get_driver_id() == DatabaseDriverID::MYSQL) { //mysql < 5.6 has terrible subquery optimization, using EXISTS / JOIN fixes this $database->execute( " @@ -796,7 +796,7 @@ class Image { global $database; $sq = "SELECT id FROM tags WHERE LOWER(tag) LIKE LOWER(:tag)"; - if ($database->get_driver_name() === DatabaseDriver::SQLITE) { + if ($database->get_driver_id() === DatabaseDriverID::SQLITE) { $sq .= "ESCAPE '\\'"; } return $database->get_col($sq, ["tag" => Tag::sqlify($tag)]); diff --git a/core/imageboard/search.php b/core/imageboard/search.php index 10df2ec0..32a3368b 100644 --- a/core/imageboard/search.php +++ b/core/imageboard/search.php @@ -3,13 +3,10 @@ declare(strict_types=1); class Querylet { - public string $sql; - public array $variables; - - public function __construct(string $sql, array $variables=[]) - { - $this->sql = $sql; - $this->variables = $variables; + public function __construct( + public string $sql, + public array $variables=[], + ) { } public function append(Querylet $querylet): void @@ -31,24 +28,18 @@ class Querylet class TagCondition { - public string $tag; - public bool $positive; - - public function __construct(string $tag, bool $positive) - { - $this->tag = $tag; - $this->positive = $positive; + public function __construct( + public string $tag, + public bool $positive, + ) { } } class ImgCondition { - public Querylet $qlet; - public bool $positive; - - public function __construct(Querylet $qlet, bool $positive) - { - $this->qlet = $qlet; - $this->positive = $positive; + public function __construct( + public Querylet $qlet, + public bool $positive, + ) { } } diff --git a/core/imageboard/tag.php b/core/imageboard/tag.php index 3e79e26c..d6bbdc66 100644 --- a/core/imageboard/tag.php +++ b/core/imageboard/tag.php @@ -90,7 +90,7 @@ class Tag public static function sanitize(string $tag): string { $tag = preg_replace("/\s/", "", $tag); # whitespace - $tag = preg_replace('/\x20[\x0e\x0f]/', '', $tag); # unicode RTL + $tag = preg_replace('/\x20[\x0e\x0f]/', '', $tag); # unicode RTL $tag = preg_replace("/\.+/", ".", $tag); # strings of dots? $tag = preg_replace("/^(\.+[\/\\\\])+/", "", $tag); # trailing slashes? $tag = trim($tag, ", \t\n\r\0\x0B"); @@ -159,7 +159,7 @@ class Tag public static function sqlify(string $term): string { global $database; - if ($database->get_driver_name() === DatabaseDriver::SQLITE) { + if ($database->get_driver_id() === DatabaseDriverID::SQLITE) { $term = str_replace('\\', '\\\\', $term); } $term = str_replace('_', '\_', $term); diff --git a/core/install.php b/core/install.php index 106aa537..cce71cf1 100644 --- a/core/install.php +++ b/core/install.php @@ -49,7 +49,7 @@ function get_dsn() { if (getenv("INSTALL_DSN")) { $dsn = getenv("INSTALL_DSN"); - } elseif (@$_POST["database_type"] == DatabaseDriver::SQLITE) { + } elseif (@$_POST["database_type"] == DatabaseDriverID::SQLITE) { /** @noinspection PhpUnhandledExceptionInspection */ $id = bin2hex(random_bytes(5)); $dsn = "sqlite:data/shimmie.{$id}.sqlite"; @@ -99,9 +99,9 @@ function ask_questions() $drivers = PDO::getAvailableDrivers(); if ( - !in_array(DatabaseDriver::MYSQL, $drivers) && - !in_array(DatabaseDriver::PGSQL, $drivers) && - !in_array(DatabaseDriver::SQLITE, $drivers) + !in_array(DatabaseDriverID::MYSQL, $drivers) && + !in_array(DatabaseDriverID::PGSQL, $drivers) && + !in_array(DatabaseDriverID::SQLITE, $drivers) ) { $errors[] = " No database connection library could be found; shimmie needs @@ -109,9 +109,9 @@ function ask_questions() "; } - $db_m = in_array(DatabaseDriver::MYSQL, $drivers) ? '' : ""; - $db_p = in_array(DatabaseDriver::PGSQL, $drivers) ? '' : ""; - $db_s = in_array(DatabaseDriver::SQLITE, $drivers) ? '' : ""; + $db_m = in_array(DatabaseDriverID::MYSQL, $drivers) ? '' : ""; + $db_p = in_array(DatabaseDriverID::PGSQL, $drivers) ? '' : ""; + $db_s = in_array(DatabaseDriverID::SQLITE, $drivers) ? '' : ""; $warn_msg = $warnings ? "

Warnings

".implode("\n

", $warnings) : ""; $err_msg = $errors ? "

Errors

".implode("\n

", $errors) : ""; diff --git a/core/polyfills.php b/core/polyfills.php index 9e40b64f..85b04920 100644 --- a/core/polyfills.php +++ b/core/polyfills.php @@ -344,27 +344,6 @@ function unparse_url(array $parsed_url): string return "$scheme$user$pass$host$port$path$query$fragment"; } -# finally in the core library starting from php8 -if (!function_exists('str_starts_with')) { - function str_starts_with(string $haystack, string $needle): bool - { - 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)); - } -} - -if (!function_exists('str_contains')) { - function str_contains(string $haystack, string $needle): bool - { - return '' === $needle || false !== strpos($haystack, $needle); - } -} /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Input / Output Sanitising * diff --git a/core/sanitize_php.php b/core/sanitize_php.php index db0f8654..aadc8fb3 100644 --- a/core/sanitize_php.php +++ b/core/sanitize_php.php @@ -31,7 +31,7 @@ function die_nicely($title, $body, $code=0) exit($code); } -$min_php = "7.3"; +$min_php = "8.1"; if (version_compare(phpversion(), $min_php, ">=") === false) { die_nicely("Not Supported", " Shimmie does not support versions of PHP lower than $min_php diff --git a/core/sys_config.php b/core/sys_config.php index 5511605e..6f0ff854 100644 --- a/core/sys_config.php +++ b/core/sys_config.php @@ -28,7 +28,7 @@ _d("DEBUG", false); // boolean print various debugging details _d("COOKIE_PREFIX", 'shm'); // string if you run multiple galleries with non-shared logins, give them different prefixes _d("SPEED_HAX", false); // boolean do some questionable things in the name of performance _d("WH_SPLITS", 1); // int how many levels of subfolders to put in the warehouse -_d("VERSION", "2.9.2$_g"); // string shimmie version +_d("VERSION", "2.10.0-alpha$_g"); // string shimmie version _d("TIMEZONE", null); // string timezone _d("EXTRA_EXTS", ""); // string optional extra extensions _d("BASE_HREF", null); // string force a specific base URL (default is auto-detect) diff --git a/core/user.php b/core/user.php index 6337b96c..dee4b81d 100644 --- a/core/user.php +++ b/core/user.php @@ -61,7 +61,7 @@ class User global $cache, $config, $database; $row = $cache->get("user-session:$name-$session"); if (!$row) { - if ($database->get_driver_name() === DatabaseDriver::MYSQL) { + if ($database->get_driver_id() === DatabaseDriverID::MYSQL) { $query = "SELECT * FROM users WHERE name = :name AND md5(concat(pass, :ip)) = :sess"; } else { $query = "SELECT * FROM users WHERE name = :name AND md5(pass || :ip) = :sess"; diff --git a/ext/admin/info.php b/ext/admin/info.php index 54751718..3eb6b901 100644 --- a/ext/admin/info.php +++ b/ext/admin/info.php @@ -13,5 +13,5 @@ class AdminPageInfo extends ExtensionInfo 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; + public ExtensionVisibility $visibility = ExtensionVisibility::HIDDEN; } diff --git a/ext/auto_tagger/main.php b/ext/auto_tagger/main.php index 40350fff..3b0f7903 100644 --- a/ext/auto_tagger/main.php +++ b/ext/auto_tagger/main.php @@ -142,7 +142,7 @@ class AutoTagger extends Extension additional_tags VARCHAR(2000) NOT NULL "); - if ($database->get_driver_name() == DatabaseDriver::PGSQL) { + if ($database->get_driver_id() == DatabaseDriverID::PGSQL) { $database->execute('CREATE INDEX auto_tag_lower_tag_idx ON auto_tag ((lower(tag)))'); } $this->set_version(AutoTaggerConfig::VERSION, 1); diff --git a/ext/comment/main.php b/ext/comment/main.php index 74ecb852..d275eabd 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -496,14 +496,14 @@ class CommentList extends Extension global $config, $database; // sqlite fails at intervals - if ($database->get_driver_name() === DatabaseDriver::SQLITE) { + if ($database->get_driver_id() === DatabaseDriverID::SQLITE) { return false; } $window = $config->get_int('comment_window'); $max = $config->get_int('comment_limit'); - if ($database->get_driver_name() == DatabaseDriver::MYSQL) { + if ($database->get_driver_id() == DatabaseDriverID::MYSQL) { $window_sql = "interval $window minute"; } else { $window_sql = "interval '$window minute'"; diff --git a/ext/download/info.php b/ext/download/info.php index a789f511..46fb1882 100644 --- a/ext/download/info.php +++ b/ext/download/info.php @@ -10,5 +10,5 @@ class DownloadInfo extends ExtensionInfo public string $license = self::LICENSE_WTFPL; public string $description = "System-wide download functions"; public bool $core = true; - public string $visibility = self::VISIBLE_HIDDEN; + public ExtensionVisibility $visibility = ExtensionVisibility::HIDDEN; } diff --git a/ext/emoticons_list/info.php b/ext/emoticons_list/info.php index 2645252e..e3d41392 100644 --- a/ext/emoticons_list/info.php +++ b/ext/emoticons_list/info.php @@ -13,5 +13,5 @@ class EmoticonListInfo extends ExtensionInfo public string $license = self::LICENSE_GPLV2; public string $description = "Lists available graphical smilies"; - public string $visibility = self::VISIBLE_HIDDEN; + public ExtensionVisibility $visibility = ExtensionVisibility::HIDDEN; } diff --git a/ext/et/main.php b/ext/et/main.php index a20e4f60..d205d948 100644 --- a/ext/et/main.php +++ b/ext/et/main.php @@ -71,7 +71,7 @@ class ET extends Extension 'shimmie' => VERSION, 'schema' => $config->get_int("db_version"), 'php' => phpversion(), - 'db' => $database->get_driver_name() . " " . $database->get_version(), + 'db' => $database->get_driver_id()->value . " " . $database->get_version(), 'os' => php_uname(), 'server' => $_SERVER["SERVER_SOFTWARE"] ?? 'unknown', ], diff --git a/ext/et/theme.php b/ext/et/theme.php index 7f0682d6..9bf01788 100644 --- a/ext/et/theme.php +++ b/ext/et/theme.php @@ -24,9 +24,9 @@ class ETTheme extends Themelet $page->add_block(new Block("Information:", $this->build_data_form($yaml))); } - protected function build_data_form($yaml): string + protected function build_data_form($yaml): \MicroHTML\HTMLElement { - return (string)FORM( + return FORM( ["action"=>"https://shimmie.shishnet.org/register.php", "method"=>"POST"], INPUT(["type"=>"hidden", "name"=>"registration_api", "value"=>"2"]), P( diff --git a/ext/et_server/info.php b/ext/et_server/info.php index a19945b4..0fd0e371 100644 --- a/ext/et_server/info.php +++ b/ext/et_server/info.php @@ -13,5 +13,5 @@ class ETServerInfo extends ExtensionInfo public string $license = self::LICENSE_GPLV2; public string $description = "Keep track of shimmie registrations"; public ?string $documentation = "For internal use"; - public string $visibility = self::VISIBLE_HIDDEN; + public ExtensionVisibility $visibility = ExtensionVisibility::HIDDEN; } diff --git a/ext/et_server/main.php b/ext/et_server/main.php index 485e612c..5232173d 100644 --- a/ext/et_server/main.php +++ b/ext/et_server/main.php @@ -26,7 +26,7 @@ class ETServer extends Extension foreach ($database->get_all("SELECT responded, data FROM registration ORDER BY responded DESC") as $row) { $page->add_block(new Block( $row["responded"], - (string)PRE(["style"=>"text-align: left; overflow: scroll;"], $row["data"]), + PRE(["style"=>"text-align: left; overflow: scroll;"], $row["data"]), "main", $n++ )); diff --git a/ext/ext_manager/info.php b/ext/ext_manager/info.php index 22242b86..e812694d 100644 --- a/ext/ext_manager/info.php +++ b/ext/ext_manager/info.php @@ -11,7 +11,7 @@ class ExtManagerInfo extends ExtensionInfo public string $url = self::SHIMMIE_URL; public array $authors = self::SHISH_AUTHOR; public string $license = self::LICENSE_GPLV2; - public string $visibility = self::VISIBLE_ADMIN; + public ExtensionVisibility $visibility = ExtensionVisibility::ADMIN; public string $description = "A thing for point & click extension management"; public ?string $documentation = "Allows the admin to view a list of all extensions and enable or disable them; also allows users to view the list of activated extensions and read their documentation"; public bool $core = true; diff --git a/ext/ext_manager/theme.php b/ext/ext_manager/theme.php index 2a9b6aaf..6eb183db 100644 --- a/ext/ext_manager/theme.php +++ b/ext/ext_manager/theme.php @@ -45,8 +45,8 @@ class ExtManagerTheme extends Themelet ); foreach ($extensions as $extension) { - if ((!$editable && $extension->visibility === ExtensionInfo::VISIBLE_ADMIN) - || $extension->visibility === ExtensionInfo::VISIBLE_HIDDEN) { + if ((!$editable && $extension->visibility === ExtensionVisibility::ADMIN) + || $extension->visibility === ExtensionVisibility::HIDDEN) { continue; } @@ -87,7 +87,7 @@ class ExtManagerTheme extends Themelet $page->set_title("Extensions"); $page->set_heading("Extensions"); $page->add_block(new NavBlock()); - $page->add_block(new Block("Extension Manager", (string)$form)); + $page->add_block(new Block("Extension Manager", $form)); } public function display_doc(Page $page, ExtensionInfo $info) @@ -119,6 +119,6 @@ class ExtManagerTheme extends Themelet $page->set_title("Documentation for " . html_escape($info->name)); $page->set_heading(html_escape($info->name)); $page->add_block(new NavBlock()); - $page->add_block(new Block("Documentation", (string)$html)); + $page->add_block(new Block("Documentation", $html)); } } diff --git a/ext/favorites/main.php b/ext/favorites/main.php index 778e7be3..375fdf4a 100644 --- a/ext/favorites/main.php +++ b/ext/favorites/main.php @@ -143,7 +143,7 @@ class Favorites extends Extension public function onHelpPageBuilding(HelpPageBuildingEvent $event) { if ($event->key===HelpPages::SEARCH) { - $event->add_block(new Block("Favorites", (string)$this->theme->get_help_html())); + $event->add_block(new Block("Favorites", $this->theme->get_help_html())); } } diff --git a/ext/featured/theme.php b/ext/featured/theme.php index 1268f6da..298eff06 100644 --- a/ext/featured/theme.php +++ b/ext/featured/theme.php @@ -22,11 +22,11 @@ class FeaturedTheme extends Themelet ); } - public function build_featured_html(Image $image, ?string $query=null): string + public function build_featured_html(Image $image, ?string $query=null): \MicroHTML\HTMLElement { $tsize = get_thumbnail_size($image->width, $image->height); - return (string)DIV( + return DIV( ["style"=>"text-align: center;"], A( ["href"=>make_link("post/view/{$image->id}", $query)], diff --git a/ext/four_oh_four/info.php b/ext/four_oh_four/info.php index 943fe5ef..f1c2c39a 100644 --- a/ext/four_oh_four/info.php +++ b/ext/four_oh_four/info.php @@ -11,7 +11,7 @@ class FourOhFourInfo extends ExtensionInfo public string $url = self::SHIMMIE_URL; public array $authors = self::SHISH_AUTHOR; public string $license = self::LICENSE_GPLV2; - public string $visibility = self::VISIBLE_HIDDEN; + public ExtensionVisibility $visibility = ExtensionVisibility::HIDDEN; public string $description = "If no other extension puts anything onto the page, show 404"; public bool $core = true; } diff --git a/ext/help_pages/info.php b/ext/help_pages/info.php index 01b3ddb2..17b62b25 100644 --- a/ext/help_pages/info.php +++ b/ext/help_pages/info.php @@ -11,6 +11,6 @@ class HelpPagesInfo extends ExtensionInfo public array $authors = ["Matthew Barbour"=>"matthew@darkholme.net"]; public string $license = self::LICENSE_WTFPL; public string $description = "Provides documentation screens"; - public string $visibility = self::VISIBLE_HIDDEN; + public ExtensionVisibility $visibility = ExtensionVisibility::HIDDEN; public bool $core = true; } diff --git a/ext/home/info.php b/ext/home/info.php index e2ca0ceb..dc244cbe 100644 --- a/ext/home/info.php +++ b/ext/home/info.php @@ -10,7 +10,7 @@ class HomeInfo extends ExtensionInfo public string $name = "Home Page"; public array $authors =["Bzchan"=>"bzchan@animemahou.com"]; public string $license = self::LICENSE_GPLV2; - public string $visibility = self::VISIBLE_ADMIN; + public ExtensionVisibility $visibility = ExtensionVisibility::ADMIN; public string $description = "Displays a front page with logo, search box and post count"; public ?string $documentation = "Once enabled, the page will show up at the URL \"home\", so if you want diff --git a/ext/image/info.php b/ext/image/info.php index 5cc4ac77..13f4a6db 100644 --- a/ext/image/info.php +++ b/ext/image/info.php @@ -12,6 +12,6 @@ class ImageIOInfo extends ExtensionInfo public array $authors = [self::SHISH_NAME=> self::SHISH_EMAIL, "jgen"=>"jgen.tech@gmail.com"]; public string $license = self::LICENSE_GPLV2; public string $description = "Handle the image database"; - public string $visibility = self::VISIBLE_HIDDEN; + public ExtensionVisibility $visibility = ExtensionVisibility::HIDDEN; public bool $core = true; } diff --git a/ext/image/test.php b/ext/image/test.php index be021f4f..f7ec23f8 100644 --- a/ext/image/test.php +++ b/ext/image/test.php @@ -39,6 +39,6 @@ class ImageIOTest extends ShimmiePHPUnitTestCase $image_id = $this->post_image("tests/pbx_screenshot.jpg", "test"); $_POST['image_id'] = "$image_id"; send_event(new PageRequestEvent("image/replace")); - $this->assertEquals("redirect", $page->mode); + $this->assertEquals(PageMode::REDIRECT, $page->mode); } } diff --git a/ext/index/info.php b/ext/index/info.php index c8cd8a39..ca3f79f6 100644 --- a/ext/index/info.php +++ b/ext/index/info.php @@ -13,115 +13,7 @@ class IndexInfo extends ExtensionInfo public string $license = self::LICENSE_GPLV2; public string $description = "Show a list of uploaded posts"; public bool $core = true; - public ?string $documentation = "Here is a list of the search methods available out of the box; -Shimmie extensions may provide other filters: -

-

Search items can be combined to search for posts which match both, -or you can stick \"-\" in front of an item to search for things that don't -match it. -

Metatags can be followed by \":\" rather than \"=\" if you prefer. -
I.E: \"posted:2014-01-01\", \"id:>=500\" etc. + public ?string $documentation = " etc.

Some search methods provided by extensions:

- - - + - + @@ -89,7 +89,7 @@ - + diff --git a/themes/rule34v2/home.theme.php b/themes/rule34v2/home.theme.php index e50d2036..260d9451 100644 --- a/themes/rule34v2/home.theme.php +++ b/themes/rule34v2/home.theme.php @@ -53,7 +53,7 @@ EOD "; return "
-

$sitename

+

$sitename

$main_links_html $search_html $message_html @@ -68,7 +68,7 @@ EOD $contact_link Serving $num_comma posts – - Running Shimmie2 + Running Shimmie2
";