diff --git a/README.txt b/README.txt index 84f62cbc..26e403b2 100644 --- a/README.txt +++ b/README.txt @@ -26,7 +26,7 @@ because the feature doesn't work yet :P Requirements ~~~~~~~~~~~~ MySQL 5.1+ (with experimental support for PostgreSQL 8+ and SQLite 3) -PHP 5.2+ +PHP 5.2.6+ GD or ImageMagick diff --git a/contrib/admin/main.php b/contrib/admin/main.php index 5fe7cc41..a7a45e2d 100644 --- a/contrib/admin/main.php +++ b/contrib/admin/main.php @@ -139,7 +139,7 @@ class AdminPage extends Extension { return true; } - private function dump_database() { + private function database_dump() { global $page; $matches = array(); @@ -150,11 +150,17 @@ class AdminPage extends Extension { $hostname = $matches['host']; $database = $matches['dbname']; - // TODO: Support more than just MySQL.. switch($software) { case 'mysql': $cmd = "mysqldump -h$hostname -u$username -p$password $database"; break; + case 'pgsql': + putenv("PGPASSWORD=$password"); + $cmd = "pg_dump -h $hostname -U $username $database"; + break; + case 'sqlite': + $cmd = "sqlite3 $database .dump"; + break; } $page->set_mode("data"); diff --git a/contrib/admin/test.php b/contrib/admin/test.php index 13718ae3..caa75ad8 100644 --- a/contrib/admin/test.php +++ b/contrib/admin/test.php @@ -23,12 +23,10 @@ class AdminPageTest extends ShimmieWebTestCase { $this->get_page('admin'); $this->assert_title("Admin Tools"); - $this->set_field("action", "lowercase all tags"); - $this->click("Go"); + $this->click("All tags to lowercase"); $this->get_page("post/view/$image_id_1"); - // FIXME: doesn't work? - //$this->assert_title("Image $image_id_1: testcase$ts"); + $this->assert_title("Image $image_id_1: testcase$ts"); $this->delete_image($image_id_1); $this->log_out(); @@ -39,8 +37,7 @@ class AdminPageTest extends ShimmieWebTestCase { $this->log_in_as_admin(); $this->get_page('admin'); $this->assert_title("Admin Tools"); - $this->set_field("action", "recount tag use"); - $this->click("Go"); + $this->click("Recount tag use"); $this->log_out(); } @@ -48,8 +45,7 @@ class AdminPageTest extends ShimmieWebTestCase { $this->log_in_as_admin(); $this->get_page('admin'); $this->assert_title("Admin Tools"); - $this->set_field("action", "purge unused tags"); - $this->click("Go"); + $this->click("Purge unused tags"); $this->log_out(); } @@ -57,8 +53,28 @@ class AdminPageTest extends ShimmieWebTestCase { $this->log_in_as_admin(); $this->get_page('admin'); $this->assert_title("Admin Tools"); - $this->set_field("action", "database dump"); - $this->click("Go"); + $this->click("Download database contents"); + $this->assert_response(200); + $this->log_out(); + } + + function testDBQ() { + $this->log_in_as_user(); + $image_id_1 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "test"); + $image_id_2 = $this->post_image("ext/simpletest/data/bedroom_workshop.jpg", "test2"); + $image_id_3 = $this->post_image("ext/simpletest/data/favicon.png", "test"); + + $this->get_page("post/list/test/1"); + $this->click("Delete All These Images"); + + $this->get_page("post/view/$image_id_1"); + $this->assert_response(404); + $this->get_page("post/view/$image_id_2"); + $this->assert_response(200); + $this->get_page("post/view/$image_id_3"); + $this->assert_response(404); + + $this->delete_image($image_id_2); $this->log_out(); } } diff --git a/contrib/artists/main.php b/contrib/artists/main.php index 1717ec27..a4b3d6c3 100644 --- a/contrib/artists/main.php +++ b/contrib/artists/main.php @@ -54,47 +54,50 @@ class Artists extends Extension { public function try_install() { global $config, $database; - if ($config->get_int("ext_artists_version") < 1) - { - $database->create_table("artists", - "id SCORE_AIPK - , user_id INTEGER NOT NULL - , name VARCHAR(255) NOT NULL - , created DATETIME NOT NULL - , updated DATETIME NOT NULL - , notes TEXT - , INDEX(id) - "); - $database->create_table("artist_members", - "id SCORE_AIPK - , artist_id INTEGER NOT NULL - , user_id INTEGER NOT NULL - , name VARCHAR(255) NOT NULL - , created DATETIME NOT NULL - , updated DATETIME NOT NULL - , INDEX (id) - , FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE - "); - $database->create_table("artist_alias", - "id SCORE_AIPK - , artist_id INTEGER NOT NULL - , user_id INTEGER NOT NULL - , created DATETIME - , updated DATETIME - , alias VARCHAR(255) - , INDEX (id) - , FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE - "); - $database->create_table("artist_urls", - "id SCORE_AIPK - , artist_id INTEGER NOT NULL - , user_id INTEGER NOT NULL - , created DATETIME NOT NULL - , updated DATETIME NOT NULL - , url VARCHAR(1000) NOT NULL - , INDEX (id) - , FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE - "); + if ($config->get_int("ext_artists_version") < 1) { + $database->create_table("artists", " + id SCORE_AIPK, + user_id INTEGER NOT NULL, + name VARCHAR(255) NOT NULL, + created DATETIME NOT NULL, + updated DATETIME NOT NULL, + notes TEXT, + INDEX(id), + FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE + "); + $database->create_table("artist_members", " + id SCORE_AIPK, + artist_id INTEGER NOT NULL, + user_id INTEGER NOT NULL, + name VARCHAR(255) NOT NULL, + created DATETIME NOT NULL, + updated DATETIME NOT NULL, + INDEX (id), + FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE + "); + $database->create_table("artist_alias", " + id SCORE_AIPK, + artist_id INTEGER NOT NULL, + user_id INTEGER NOT NULL, + created DATETIME, + updated DATETIME, + alias VARCHAR(255), + INDEX (id), + FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE + "); + $database->create_table("artist_urls", " + id SCORE_AIPK, + artist_id INTEGER NOT NULL, + user_id INTEGER NOT NULL, + created DATETIME NOT NULL, + updated DATETIME NOT NULL, + url VARCHAR(1000) NOT NULL, + INDEX (id), + FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE + "); $database->execute("ALTER TABLE images ADD COLUMN author VARCHAR(255) NULL", array()); $config->set_int("artistsPerPage", 20); diff --git a/contrib/artists/test.php b/contrib/artists/test.php new file mode 100644 index 00000000..7f794343 --- /dev/null +++ b/contrib/artists/test.php @@ -0,0 +1,8 @@ +get_page("post/list/author=bob/1"); + } +} +?> diff --git a/contrib/artists/theme.php b/contrib/artists/theme.php index 17fc9496..1bb9e2ed 100644 --- a/contrib/artists/theme.php +++ b/contrib/artists/theme.php @@ -3,7 +3,15 @@ class ArtistsTheme extends Themelet { public function get_author_editor_html(/*string*/ $author) { $h_author = html_escape($author); - return "Author"; + return " + + Author + + $h_author + + + + "; } public function display_artists(){ @@ -11,7 +19,7 @@ class ArtistsTheme extends Themelet { $page->set_title("Artists"); $page->set_heading("Artists"); - $page->add_block(new Block("Artists", $html, "main", 10)); + $page->add_block(new Block("Artists", $html, "main", 10)); //$this->display_paginator($page, "artist/list", null, $pageNumber, $totalPages); } diff --git a/contrib/browser_search/main.php b/contrib/browser_search/main.php old mode 100755 new mode 100644 index 78c3b878..266c7cd1 --- a/contrib/browser_search/main.php +++ b/contrib/browser_search/main.php @@ -34,7 +34,7 @@ class BrowserSearch extends Extension { $search_title = $config->get_string('title'); $search_form_url = make_link('post/list/{searchTerms}'); $suggenton_url = make_link('browser_search/')."{searchTerms}"; - $icon_b64 = base64_encode(file_get_contents("favicon.ico")); + $icon_b64 = base64_encode(file_get_contents("lib/static/favicon.ico")); // Now for the XML $xml = " diff --git a/contrib/danbooru_api/test.php b/contrib/danbooru_api/test.php new file mode 100644 index 00000000..bbc4c2d6 --- /dev/null +++ b/contrib/danbooru_api/test.php @@ -0,0 +1,26 @@ +log_in_as_admin(); + + $image_id = $this->post_image("ext/simpletest/data/bedroom_workshop.jpg", "data"); + + $this->get_page("post/list/md5:17fc89f372ed3636e28bd25cc7f3bac1/1"); + $this->assert_title(new PatternExpectation("/^Image \d+: data/")); + $this->click("Delete"); + + $this->get_page("api/danbooru/find_posts"); + $this->get_page("api/danbooru/find_posts?id=$image_id"); + $this->get_page("api/danbooru/find_posts?md5=17fc89f372ed3636e28bd25cc7f3bac1"); + + $this->get_page("api/danbooru/find_tags"); + $this->get_page("api/danbooru/find_tags?id=1"); + $this->get_page("api/danbooru/find_tags?name=data"); + + $this->get_page("api/danbooru/post/show/$image_id"); + $this->assert_response(302); + + $this->log_out(); + } +} +?> diff --git a/contrib/favorites/main.php b/contrib/favorites/main.php index a3d683e5..35d3c7f0 100644 --- a/contrib/favorites/main.php +++ b/contrib/favorites/main.php @@ -161,8 +161,8 @@ class Favorites extends Extension { $database->Execute("DELETE FROM user_favorites WHERE image_id NOT IN (SELECT id FROM images)"); log_info("favorites", "Adding foreign keys to user favourites"); - $database->Execute("ALTER TABLE user_favorites ADD CONSTRAINT foreign_user_favorites_user_id FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;"); - $database->Execute("ALTER TABLE user_favorites ADD CONSTRAINT user_favorites_image_id FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE;"); + $database->Execute("ALTER TABLE user_favorites ADD FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;"); + $database->Execute("ALTER TABLE user_favorites ADD FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE;"); $config->set_int("ext_favorites_version", 2); } } diff --git a/contrib/forum/main.php b/contrib/forum/main.php index 5593db9e..cee5d5c8 100644 --- a/contrib/forum/main.php +++ b/contrib/forum/main.php @@ -9,42 +9,48 @@ */ class Forum extends Extension { - public function onInitExt(InitExtEvent $event) { + public function onInitExt(InitExtEvent $event) { global $config, $database; // shortcut to latest - - if ($config->get_int("forum_version") < 1) - { - $database->create_table("forum_threads", " - id SCORE_AIPK, - sticky SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, - title VARCHAR(255) NOT NULL, - user_id INTEGER NOT NULL, - date DATETIME NOT NULL, - uptodate DATETIME NOT NULL, - INDEX (date) - "); - $database->create_table("forum_posts", - " id SCORE_AIPK, - thread_id INTEGER NOT NULL, - user_id INTEGER NOT NULL, - date DATETIME NOT NULL, - message TEXT, - INDEX (date), - FOREIGN KEY (thread_id) REFERENCES forum_threads (id) ON UPDATE CASCADE ON DELETE CASCADE - "); + if ($config->get_int("forum_version") < 1) { + $database->create_table("forum_threads", " + id SCORE_AIPK, + sticky SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, + title VARCHAR(255) NOT NULL, + user_id INTEGER NOT NULL, + date DATETIME NOT NULL, + uptodate DATETIME NOT NULL, + INDEX (date), + FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE RESTRICT + "); - $config->set_int("forum_version", 1); - $config->set_int("forumTitleSubString", 25); - $config->set_int("forumThreadsPerPage", 15); - $config->set_int("forumPostsPerPage", 15); - - $config->set_int("forumMaxCharsPerPost", 512); - - log_info("forum", "extension installed"); - } + $database->create_table("forum_posts", " + id SCORE_AIPK, + thread_id INTEGER NOT NULL, + user_id INTEGER NOT NULL, + date DATETIME NOT NULL, + message TEXT, + INDEX (date), + FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE RESTRICT, + FOREIGN KEY (thread_id) REFERENCES forum_threads (id) ON UPDATE CASCADE ON DELETE CASCADE + "); + + $config->set_int("forum_version", 2); + $config->set_int("forumTitleSubString", 25); + $config->set_int("forumThreadsPerPage", 15); + $config->set_int("forumPostsPerPage", 15); + + $config->set_int("forumMaxCharsPerPost", 512); + + log_info("forum", "extension installed"); + } + if ($config->get_int("forum_version") < 2) { + $database->execute("ALTER TABLE forum_threads ADD FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE RESTRICT"); + $database->execute("ALTER TABLE forum_posts ADD FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE RESTRICT"); + $config->set_int("forum_version", 2); + } } public function onSetupBuilding(SetupBuildingEvent $event) { diff --git a/contrib/ipban/main.php b/contrib/ipban/main.php index d0329034..4dd485ed 100644 --- a/contrib/ipban/main.php +++ b/contrib/ipban/main.php @@ -159,6 +159,11 @@ class IPBan extends Extension { $database->execute("ALTER TABLE bans CHANGE ip ip VARCHAR(15)"); $config->set_int("ext_ipban_version", 6); } + + if($config->get_int("ext_ipban_version") == 6) { + $database->Execute("ALTER TABLE bans ADD FOREIGN KEY (banner_id) REFERENCES users(id) ON DELETE CASCADE"); + $config->set_int("ext_ipban_version", 7); + } } // }}} // deal with banned person {{{ diff --git a/contrib/log_db/test.php b/contrib/log_db/test.php index a111c2e1..f2e9b8dd 100644 --- a/contrib/log_db/test.php +++ b/contrib/log_db/test.php @@ -3,6 +3,10 @@ class LogDatabaseTest extends SCoreWebTestCase { function testLog() { $this->log_in_as_admin(); $this->get_page("log/view"); + $this->get_page("log/view?module=core-image"); + $this->get_page("log/view?time=2012-03-01"); + $this->get_page("log/view?user=demo"); + $this->get_page("log/view?priority=10"); $this->log_out(); } } diff --git a/contrib/not_a_tag/main.php b/contrib/not_a_tag/main.php index ba18c04b..d2696da3 100644 --- a/contrib/not_a_tag/main.php +++ b/contrib/not_a_tag/main.php @@ -10,7 +10,7 @@ class NotATag extends Extension { public function get_priority() {return 30;} // before ImageUploadEvent and tag_history public function onImageAddition(ImageAdditionEvent $event) { - $this->scan($event->image->tags); + $this->scan($event->image->get_tag_array()); } public function onTagSet(TagSetEvent $event) { diff --git a/contrib/notes/main.php b/contrib/notes/main.php index aa960c1d..5bc09ef6 100644 --- a/contrib/notes/main.php +++ b/contrib/notes/main.php @@ -27,6 +27,7 @@ class Notes extends Extension { width INTEGER NOT NULL, note TEXT NOT NULL, INDEX (image_id), + FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE "); @@ -36,6 +37,7 @@ class Notes extends Extension { user_id INTEGER NOT NULL, date DATETIME NOT NULL, INDEX (image_id), + FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE "); @@ -54,6 +56,7 @@ class Notes extends Extension { width INTEGER NOT NULL, note TEXT NOT NULL, INDEX (image_id), + FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE "); diff --git a/contrib/pm/main.php b/contrib/pm/main.php index 563efdd2..29e4b941 100644 --- a/contrib/pm/main.php +++ b/contrib/pm/main.php @@ -61,7 +61,7 @@ class PrivMsg extends Extension { FOREIGN KEY (from_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY (to_id) REFERENCES users(id) ON DELETE CASCADE "); - $config->set_int("pm_version", 1); + $config->set_int("pm_version", 2); log_info("pm", "extension installed"); } @@ -70,8 +70,8 @@ class PrivMsg extends Extension { $database->Execute("delete from private_message where to_id not in (select id from users);"); $database->Execute("delete from private_message where from_id not in (select id from users);"); $database->Execute("ALTER TABLE private_message - ADD CONSTRAINT foreign_private_message_from_id FOREIGN KEY (from_id) REFERENCES users(id) ON DELETE CASCADE, - ADD CONSTRAINT foreign_private_message_to_id FOREIGN KEY (to_id) REFERENCES users(id) ON DELETE CASCADE;"); + ADD FOREIGN KEY (from_id) REFERENCES users(id) ON DELETE CASCADE, + ADD FOREIGN KEY (to_id) REFERENCES users(id) ON DELETE CASCADE;"); $config->set_int("pm_version", 2); log_info("pm", "extension installed"); } diff --git a/contrib/pools/main.php b/contrib/pools/main.php index 585fd3ad..b161e8bb 100644 --- a/contrib/pools/main.php +++ b/contrib/pools/main.php @@ -35,12 +35,15 @@ class Pools extends Extension { description TEXT, date DATETIME NOT NULL, posts INTEGER NOT NULL DEFAULT 0, - INDEX (id) + INDEX (id), + FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE "); $database->create_table("pool_images", " pool_id INTEGER NOT NULL, image_id INTEGER NOT NULL, - image_order INTEGER NOT NULL DEFAULT 0 + image_order INTEGER NOT NULL DEFAULT 0, + FOREIGN KEY (pool_id) REFERENCES pools(id) ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (image_id) REFERENCES images(id) ON UPDATE CASCADE ON DELETE CASCADE "); $database->create_table("pool_history", " id SCORE_AIPK, @@ -50,7 +53,9 @@ class Pools extends Extension { images TEXT, count INTEGER NOT NULL DEFAULT 0, date DATETIME NOT NULL, - INDEX (id) + INDEX (id), + FOREIGN KEY (pool_id) REFERENCES pools(id) ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE "); // Set the defaults for the pools extension diff --git a/contrib/shimmie_api/main.php b/contrib/shimmie_api/main.php index decacbfa..e7ddc59e 100644 --- a/contrib/shimmie_api/main.php +++ b/contrib/shimmie_api/main.php @@ -4,8 +4,8 @@ * Author: Shish * Description: A JSON interface to shimmie data [WARNING] * Documentation: - * Admin Warning: this exposes private data, eg IP addresses - *

Developer Warning: the API is unstable; notably, private data may get hidden + * Admin Warning - this exposes private data, eg IP addresses + *

Developer Warning - the API is unstable; notably, private data may get hidden *

Usage: *

get_tags - List of all tags. (May contain unused tags) *

diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index 0eb6e30d..db0b1b34 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -330,13 +330,13 @@ class Tag_History extends Extension { // if the image has no history, make one with the old tags $entries = $database->get_one("SELECT COUNT(*) FROM tag_histories WHERE image_id = ?", array($image->id)); - if($entries == 0){ - /* We have no tag history for this image, so we will use the new_tags as the starting tags for this image. */ + if($entries == 0 && !empty($old_tags)) { + /* We have no tag history for this image, so we will use the old_tags as the starting tags for this image. */ /* these two queries could probably be combined */ $database->execute(" INSERT INTO tag_histories(image_id, tags, user_id, user_ip, date_set) VALUES (?, ?, ?, ?, now())", - array($image->id, $new_tags, 1, '127.0.0.1')); // TODO: Pick appropriate user id + array($image->id, $old_tags, 1, '127.0.0.1')); // TODO: Pick appropriate user id $entries++; } diff --git a/contrib/wiki/main.php b/contrib/wiki/main.php index 920588b9..f289f04d 100644 --- a/contrib/wiki/main.php +++ b/contrib/wiki/main.php @@ -69,7 +69,7 @@ class Wiki extends Extension { locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, body TEXT NOT NULL, UNIQUE (title, revision), - FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE + FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT "); $config->set_int("ext_wiki_version", 2); } diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index f7e27121..bf1c7662 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -967,10 +967,9 @@ class Tag { // do nothing //} - $tags = array_map("trim", $tags); - $tag_array = array(); foreach($tags as $tag) { + $tag = trim($tag, ", \t\n\r\0\x0B"); if(is_string($tag) && !empty($tag)) { $tag_array[] = $tag; } diff --git a/core/util.inc.php b/core/util.inc.php index fdf97a31..e9a8583d 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -907,12 +907,7 @@ $_load_start = microtime(true); function get_debug_info() { global $config, $_event_count, $database, $_execs, $_load_start; - if(function_exists('memory_get_usage')) { - $i_mem = sprintf("%5.2f", ((memory_get_usage()+512)/1024)/1024); - } - else { - $i_mem = "???"; - } + $i_mem = sprintf("%5.2f", ((memory_get_peak_usage(true)+512)/1024)/1024); if($config->get_string("commit_hash", "unknown") == "unknown"){ $commit = ""; @@ -1276,7 +1271,7 @@ function _end_coverage() { $n = 0; $t = time(); while(file_exists("$absolute_path/$t.$n.log")) $n++; - file_put_contents("$absolute_path/$t.$n.log", serialize(xdebug_get_code_coverage())); + file_put_contents("$absolute_path/$t.$n.log", gzdeflate(serialize(xdebug_get_code_coverage()))); } } ?> diff --git a/ext/comment/main.php b/ext/comment/main.php index 3d813f99..93a867df 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -111,8 +111,8 @@ class CommentList extends Extension { if($config->get_int("ext_comments_version") == 2) { $config->set_int("ext_comments_version", 3); - $database->Execute("ALTER TABLE comments ADD CONSTRAINT foreign_comments_image_id FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE"); - $database->Execute("ALTER TABLE comments ADD CONSTRAINT foreign_comments_owner_id FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT"); + $database->Execute("ALTER TABLE comments ADD FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE"); + $database->Execute("ALTER TABLE comments ADD FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT"); } // FIXME: add foreign keys, bump to v3 diff --git a/ext/upgrade/main.php b/ext/upgrade/main.php index a77494e9..5471d573 100644 --- a/ext/upgrade/main.php +++ b/ext/upgrade/main.php @@ -57,7 +57,7 @@ class Upgrade extends Extension { $config->set_int("db_version", 10); log_info("upgrade", "Adding foreign keys to images"); - $database->Execute("ALTER TABLE images ADD CONSTRAINT foreign_images_owner_id FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT"); + $database->Execute("ALTER TABLE images ADD FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT"); log_info("upgrade", "Database at version 10"); $config->set_bool("in_upgrade", false); diff --git a/ext/user/main.php b/ext/user/main.php index 27e59e01..c926184b 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -287,6 +287,11 @@ class UserPage extends Extension { $pass = $_POST['pass']; $hash = md5(strtolower($name) . $pass); + if(empty($name) || empty($pass)) { + $this->theme->display_error(400, "Error", "Username or password left blank"); + return; + } + $duser = User::by_name_and_hash($name, $hash); if(!is_null($duser)) { $user = $duser; diff --git a/index.php b/index.php index 06663820..9895d7c7 100644 --- a/index.php +++ b/index.php @@ -100,6 +100,8 @@ try { $page->display(); $database->db->commit(); + // saving cache data and profiling data to disk can happen later + if(function_exists("fastcgi_finish_request")) fastcgi_finish_request(); _end_cache(); ctx_log_endok(); } diff --git a/install.php b/install.php index 404517ed..142fa9f5 100644 --- a/install.php +++ b/install.php @@ -332,7 +332,7 @@ function create_tables() { // {{{ INDEX(owner_id), INDEX(width), INDEX(height), - CONSTRAINT foreign_images_owner_id FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT + FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT "); $db->create_table("tags", " id SCORE_AIPK, @@ -345,8 +345,8 @@ function create_tables() { // {{{ INDEX(image_id), INDEX(tag_id), UNIQUE(image_id, tag_id), - CONSTRAINT foreign_image_tags_image_id FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, - CONSTRAINT foreign_image_tags_tag_id FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE + FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, + FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE "); $db->execute("INSERT INTO config(name, value) VALUES('db_version', 11)"); }