From 54067f02a477c0303c84ecc813e35f286aa199a3 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 29 Sep 2019 14:50:31 +0100 Subject: [PATCH] fix merge --- core/_bootstrap.php | 12 ++++++------ core/extension.php | 5 +++-- core/imageboard/image.php | 2 +- ext/comment/main.php | 2 +- ext/rating/main.php | 2 -- ext/trash/main.php | 5 ----- ext/user_config/main.php | 4 ++-- index.php | 1 - tests/bootstrap.php | 3 --- 9 files changed, 13 insertions(+), 23 deletions(-) diff --git a/core/_bootstrap.php b/core/_bootstrap.php index 5db01d08..11cfc193 100644 --- a/core/_bootstrap.php +++ b/core/_bootstrap.php @@ -37,6 +37,12 @@ unset($_shm_files); unset($_shm_filename); $_tracer->end(); +// connect to the database +$_tracer->begin("Connecting to DB"); +$database = new Database(); +$config = new DatabaseConfig($database); +$_tracer->end(); + $_tracer->begin("Loading extension info"); ExtensionInfo::load_all_extension_info(); Extension::determine_enabled_extensions(); @@ -53,12 +59,6 @@ unset($_shm_files); unset($_shm_filename); $_tracer->end(); -// connect to the database -$_tracer->begin("Connecting to DB"); -$database = new Database(); -$config = new DatabaseConfig($database); -$_tracer->end(); - // load the theme parts $_tracer->begin("Loading themelets"); foreach (_get_themelet_files(get_theme()) as $themelet) { diff --git a/core/extension.php b/core/extension.php index 2986df03..428ef2f8 100644 --- a/core/extension.php +++ b/core/extension.php @@ -137,9 +137,10 @@ abstract class Extension explode(",", EXTRA_EXTS) ) as $key) { $ext = ExtensionInfo::get_by_key($key); - if ($ext===null) { + if ($ext===null || !$ext->is_supported()) { continue; } + // FIXME: error if one of our dependencies isn't supported self::$enabled_extensions[] = $ext->key; if (!empty($ext->dependencies)) { foreach ($ext->dependencies as $dep) { @@ -253,7 +254,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_name(), $this->db_support)) { $this->support_info .= "Database not supported. "; } // Additional checks here as needed diff --git a/core/imageboard/image.php b/core/imageboard/image.php index ac0284d1..33804a60 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -302,7 +302,7 @@ class Image ["tag"=>$tags[0]] ); } else { - if (ext_is_live("Ratings")) { + if (Extension::is_enabled(RatingsInfo::KEY)) { $tags[] = "rating:*"; } list($tag_conditions, $img_conditions) = self::terms_to_conditions($tags); diff --git a/ext/comment/main.php b/ext/comment/main.php index a09a0be6..ffaccb15 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -398,7 +398,7 @@ class CommentList extends Extension LIMIT :limit OFFSET :offset ", ["limit"=>$threads_per_page, "offset"=>$start]); - $user_ratings = Extension::is_enabled(RatingsInfo::KEY) ? Ratings::get_user_privs($user) : ""; + $user_ratings = Extension::is_enabled(RatingsInfo::KEY) ? Ratings::get_user_class_privs($user) : ""; $images = []; while ($row = $result->fetch()) { diff --git a/ext/rating/main.php b/ext/rating/main.php index 4a870721..4e649b24 100644 --- a/ext/rating/main.php +++ b/ext/rating/main.php @@ -101,8 +101,6 @@ abstract class RatingsConfig class Ratings extends Extension { - protected $db_support = [DatabaseDriver::MYSQL, DatabaseDriver::PGSQL]; - public const UNRATED_KEYWORDS = ["unknown","unrated"]; private $search_regexp; diff --git a/ext/trash/main.php b/ext/trash/main.php index 79c95167..2fc7febf 100644 --- a/ext/trash/main.php +++ b/ext/trash/main.php @@ -7,8 +7,6 @@ abstract class TrashConfig class Trash extends Extension { - protected $db_support = [DatabaseDriver::MYSQL, DatabaseDriver::PGSQL]; - public function get_priority(): int { // Needs to be early to intercept delete events @@ -24,7 +22,6 @@ class Trash extends Extension } } - public function onPageRequest(PageRequestEvent $event) { global $page, $user; @@ -45,8 +42,6 @@ class Trash extends Extension } } - - public function onDisplayingImage(DisplayingImageEvent $event) { global $user, $page; diff --git a/ext/user_config/main.php b/ext/user_config/main.php index b3022d39..91aa375e 100644 --- a/ext/user_config/main.php +++ b/ext/user_config/main.php @@ -31,12 +31,12 @@ class UserConfig extends Extension } } - public function onInitUserConfig(InitUserConfigEvent $event) + public function onUserLogin(UserLoginEvent $event) { global $database, $user_config; $user_config = new DatabaseConfig($database, "user_config", "user_id", $event->user->id); - $event->user_config = $user_config; + send_event(new InitUserConfigEvent($event->user, $user_config)); } private function install(): void diff --git a/index.php b/index.php index af8d8182..51f3a7a7 100644 --- a/index.php +++ b/index.php @@ -91,7 +91,6 @@ try { // start the page generation waterfall $user = _get_user(); send_event(new UserLoginEvent($user)); - send_event(new InitUserConfigEvent($user)); if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') { send_event(new CommandEvent($argv)); } else { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a5c6ac32..dfb761c8 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -134,7 +134,6 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase $user = User::by_name('demo'); $this->assertNotNull($user); send_event(new UserLoginEvent($user)); - send_event(new InitUserConfigEvent($user)); } protected function log_in_as_user() @@ -143,7 +142,6 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase $user = User::by_name('test'); $this->assertNotNull($user); send_event(new UserLoginEvent($user)); - send_event(new InitUserConfigEvent($user)); } protected function log_out() @@ -152,7 +150,6 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase $user = User::by_id($config->get_int("anon_id", 0)); $this->assertNotNull($user); send_event(new UserLoginEvent($user)); - send_event(new InitUserConfigEvent($user)); } // post things