From e5f4b5ffa1cd9378b4d4bd16ceee2fe36a4a2606 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 01:57:47 +0000 Subject: [PATCH 01/27] test tweeter --- contrib/twitter_soc/test.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contrib/twitter_soc/test.php b/contrib/twitter_soc/test.php index e11bd6a2..438e530b 100644 --- a/contrib/twitter_soc/test.php +++ b/contrib/twitter_soc/test.php @@ -7,19 +7,19 @@ class TwitterSocTest extends SCoreWebTestCase { $this->set_field("_config_twitter_soc_username", "shish2k"); $this->click("Save Settings"); - /* $this->get_page("post/list"); - $this->assert_text("Note"); - $this->assert_text("kittens"); + $this->assert_text("Tweets"); + /* + $this->assert_text("kittens"); // this is loaded with javascript */ $this->get_page("setup"); $this->set_field("_config_twitter_soc_username", ""); $this->click("Save Settings"); - /* $this->get_page("post/list"); - $this->assert_no_text("Note"); + $this->assert_no_text("Tweets"); + /* $this->assert_no_text("kittens"); */ From b5bca91beea61a8d4bbf4d51809af96f4d13032f Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 02:04:15 +0000 Subject: [PATCH 02/27] toggler in default setup theme --- ext/setup/theme.php | 12 ++++++++++- themes/default/setup.theme.php | 38 ---------------------------------- 2 files changed, 11 insertions(+), 39 deletions(-) delete mode 100644 themes/default/setup.theme.php diff --git a/ext/setup/theme.php b/ext/setup/theme.php index e8b304c8..64b0903c 100644 --- a/ext/setup/theme.php +++ b/ext/setup/theme.php @@ -87,7 +87,17 @@ class SetupTheme extends Themelet { } protected function sb_to_html(SetupBlock $block) { - return "
{$block->header}
{$block->body}
\n"; + $h = $block->header; + $b = $block->body; + $i = preg_replace('/[^a-zA-Z0-9]/', '_', $h) . "-setup"; + $html = " +
+ $h +
$b
+
+ + "; + return $html; } } ?> diff --git a/themes/default/setup.theme.php b/themes/default/setup.theme.php deleted file mode 100644 index ffd82027..00000000 --- a/themes/default/setup.theme.php +++ /dev/null @@ -1,38 +0,0 @@ -header; - $b = $block->body; - $i = preg_replace('/[^a-zA-Z0-9]/', '_', $h) . "-setup"; - $html = " - -
- $h -
$b
-
- - "; - - return $html; - } -} -?> From 04bdbeb740b9018e796402ba5af2ba43547d7350 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 02:06:25 +0000 Subject: [PATCH 03/27] test that viewing the log doesn't crash horribly immediately --- contrib/log_db/test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/log_db/test.php b/contrib/log_db/test.php index 80209a75..a111c2e1 100644 --- a/contrib/log_db/test.php +++ b/contrib/log_db/test.php @@ -2,6 +2,7 @@ class LogDatabaseTest extends SCoreWebTestCase { function testLog() { $this->log_in_as_admin(); + $this->get_page("log/view"); $this->log_out(); } } From 1c4a029564a567be8b596de1f8a46e42a39b511c Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 02:08:01 +0000 Subject: [PATCH 04/27] basic oekaki test --- contrib/oekaki/test.php | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 contrib/oekaki/test.php diff --git a/contrib/oekaki/test.php b/contrib/oekaki/test.php new file mode 100644 index 00000000..f4257590 --- /dev/null +++ b/contrib/oekaki/test.php @@ -0,0 +1,9 @@ +log_in_as_user(); + $this->get_page("oekaki/create"); + $this->log_out(); + } +} +?> From 91393e003a204d137959a0f3943edab2ef2a8812 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 02:09:29 +0000 Subject: [PATCH 05/27] un-typo a test --- contrib/random_image/test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/random_image/test.php b/contrib/random_image/test.php index 9a462bf2..4d30c0e1 100644 --- a/contrib/random_image/test.php +++ b/contrib/random_image/test.php @@ -19,7 +19,7 @@ class RandomTest extends ShimmieWebTestCase { $this->log_out(); } - function tesPostListBlock() { + function testPostListBlock() { $this->log_in_as_admin(); $this->get_page("setup"); $this->set_field("_config_show_random_block", true); From bab3145fbc5f84e75bb6c7bb801b46106180a35b Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 02:13:50 +0000 Subject: [PATCH 06/27] plural() was never used --- contrib/tag_history/test.php | 4 ++-- core/util.inc.php | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/contrib/tag_history/test.php b/contrib/tag_history/test.php index 0049cbf8..17a599e1 100644 --- a/contrib/tag_history/test.php +++ b/contrib/tag_history/test.php @@ -13,8 +13,8 @@ class TagHistoryTest extends ShimmieWebTestCase { $this->click("Revert To"); $this->assert_title("Image $image_id: pbx"); - $this->get_page("tag_history"); - $this->click("Global Tag History"); + $this->get_page("tag_history/all/1"); + $this->assert_title("Global Tag History"); $this->delete_image($image_id); $this->log_out(); diff --git a/core/util.inc.php b/core/util.inc.php index d32facdb..5ebbb8d5 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -172,15 +172,6 @@ function isValidDate($date) { return false; } -/** - * Return a pluraliser if necessary - * - * @retval string - */ -function plural($num, $single_form="", $plural_form="s") { - return ($num == 1) ? $single_form : $plural_form; -} - /** * Give a HTML string which shows an IP (if the user is allowed to see IPs), * and a link to ban that IP (if the user is allowed to ban IPs) From b451f90b4729949d4d2d8c2214776c230de73411 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 02:14:33 +0000 Subject: [PATCH 07/27] ip2color() was never used --- core/util.inc.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/core/util.inc.php b/core/util.inc.php index 5ebbb8d5..5f52d6fb 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -189,19 +189,6 @@ function show_ip($ip, $ban_reason) { return $ip; } -/** - * Turn an IP address into a colour, for easily spotting samefags - * - * NOTE: this should only be shown to admins, as it can be reversed - * to get an original IP address - */ -function ip2color($ip) { - $b = explode(".", $ip); - #return sprintf("#%02x%02x%02x", $b[0]/2, $b[1]/2, $b[2]/2); - return sprintf("hsl(%d, %d%%, %d%%)", $b[3]*360/256, $b[2]*100/256, $b[1]*100/256/2); -} - - /** * Different databases have different ways to represent booleans; this * will try and standardise them From 5c36d996e068f4baedabb57ad421bc9ab3b91658 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 02:19:04 +0000 Subject: [PATCH 08/27] test 404 handler's static files too --- ext/handle_404/test.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/handle_404/test.php b/ext/handle_404/test.php index 2cbae7b2..452af8da 100644 --- a/ext/handle_404/test.php +++ b/ext/handle_404/test.php @@ -5,6 +5,9 @@ class Handle404Test extends SCoreWebTestCase { $this->assert_response(404); $this->assert_title('404'); $this->assert_text("No handler could be found for the page 'not/a/page'"); + + $this->get_page('favicon.ico'); + $this->assert_response(200); } } ?> From 77b99adca7b5a405edf886d7e282a20d2b8e446d Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 02:19:12 +0000 Subject: [PATCH 09/27] remove more unused bits --- core/util.inc.php | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/core/util.inc.php b/core/util.inc.php index 5f52d6fb..fdf97a31 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -339,27 +339,6 @@ function make_form($target, $method="POST", $multipart=False, $form_id="", $onsu return '
'.$auth; } -/** - * Make a link to a static file in the current theme's - * directory - */ -function theme_file($filepath) { - global $config; - $theme = $config->get_string("theme","default"); - return make_link('themes/'.$theme.'/'.$filepath); -} - - -function hsl_rainbow() { - $ct = Array(); - $s = 100; $l = 25; for($h= 0; $h<360; $h+=60) {$ct[] = "hsl($h, $s%, $l%);";} - $s = 100; $l = 50; for($h= 0; $h<360; $h+=60) {$ct[] = "hsl($h, $s%, $l%);";} - $s = 50; $l = 25; for($h= 0; $h<360; $h+=60) {$ct[] = "hsl($h, $s%, $l%);";} - $s = 100; $l = 25; for($h=30; $h<360; $h+=60) {$ct[] = "hsl($h, $s%, $l%);";} - $s = 100; $l = 50; for($h=30; $h<360; $h+=60) {$ct[] = "hsl($h, $s%, $l%);";} - $s = 50; $l = 25; for($h=30; $h<360; $h+=60) {$ct[] = "hsl($h, $s%, $l%);";} - return $ct; -} /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * CAPTCHA abstraction * @@ -864,23 +843,6 @@ function full_copy($source, $target) { } } -/** - * @private - */ -function weighted_random($weights) { - $total = 0; - foreach($weights as $k => $w) { - $total += $w; - } - - $r = mt_rand(0, $total); - foreach($weights as $k => $w) { - $r -= $w; - if($r <= 0) { - return $k; - } - } -} /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Event API * From 1bfa656e35ee2188ec53ceda069bb564704e1625 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 02:21:42 +0000 Subject: [PATCH 10/27] another unused function --- ext/setup/main.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ext/setup/main.php b/ext/setup/main.php index 3bf636c8..e82583f5 100644 --- a/ext/setup/main.php +++ b/ext/setup/main.php @@ -29,10 +29,6 @@ class SetupBuildingEvent extends Event { public function SetupBuildingEvent(SetupPanel $panel) { $this->panel = $panel; } - - public function get_panel() { - return $this->panel; - } } // }}} /* SetupPanel {{{ From 924eb982385025ff7f5f723aedd263bcd61576de Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 09:52:52 +0000 Subject: [PATCH 11/27] API tests --- contrib/shimmie_api/main.php | 39 +++++++++++++++--------------------- contrib/shimmie_api/test.php | 29 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 23 deletions(-) create mode 100644 contrib/shimmie_api/test.php diff --git a/contrib/shimmie_api/main.php b/contrib/shimmie_api/main.php index a3150372..decacbfa 100644 --- a/contrib/shimmie_api/main.php +++ b/contrib/shimmie_api/main.php @@ -37,7 +37,7 @@ class _SafeImage { class ShimmieApi extends Extension { public function onPageRequest(PageRequestEvent $event) { - global $database, $page; + global $database, $page, $user; if($event->page_matches("api/shimmie")) { $page->set_mode("data"); @@ -55,7 +55,7 @@ class ShimmieApi extends Extension { "SELECT tag FROM tags WHERE tag LIKE ?", array($arg."%")); } - elseif(isset($_GET['id'])){ + elseif(isset($_GET['tag'])){ $all = $database->get_all( "SELECT tag FROM tags WHERE tag LIKE ?", array($_GET['tag']."%")); @@ -76,9 +76,7 @@ class ShimmieApi extends Extension { elseif(isset($_GET['id'])){ $image = Image::by_id(int_escape($_GET['id'])); } - else{ - $image = Image::by_id(int_escape("1")); //Default to id=1 - } + // FIXME: handle null image $image->get_tag_array(); // tag data isn't loaded into the object until necessary $safe_image = new _SafeImage($image); $page->set_data(json_encode($safe_image)); @@ -98,29 +96,24 @@ class ShimmieApi extends Extension { } if($event->page_matches("api/shimmie/get_user")) { - if(isset($_GET['name'])){ - $all = $database->get_all( - "SELECT id,name,joindate,class FROM users WHERE name=?", - array($_GET['name'])); + $query = $user->id; + if($event->count_args() == 1) { + $query = $event->get_arg(0); + } + if(isset($_GET['name'])) { + $query = $_GET['name']; + } + if(isset($_GET['id'])) { + $query = $_GET['id']; } - if(isset($_GET['id'])){ - $all = $database->get_all( - "SELECT id,name,joindate,class FROM users WHERE id=?", - array($_GET['id'])); - } + $all = $database->get_row( + "SELECT id,name,joindate,class FROM users WHERE name=? OR id=?", + array($_GET['name'], int_escape($_GET['id']))); - if(!isset($_GET['id']) && !isset($_GET['name'])){ - $all = $database->get_all( - "SELECT id,name,joindate,class FROM users WHERE id=?", - array("2")); //In 99% of cases, this will be the admin. - } - - $all = $all[0]; //FIXME?: For some weird reason, get_all seems to return twice. Unsetting second value to make things look nice.. + // - it returns data as eg array(0=>1234, 'id'=>1234, 1=>'bob', 'name'=>bob, ...); for($i=0; $i<4; $i++) unset($all[$i]); - /*TODO: Might be worth making it possible just to get a certain stat (Using &stat=uploadcount or something) - This would lessen strain on DB? */ $all['uploadcount'] = Image::count_images(array("user_id=".$all['id'])); $all['uploadperday'] = sprintf("%.1f", ($all['uploadcount'] / (((time() - strtotime($all['joindate'])) / 86400) + 1))); $all['commentcount'] = $database->get_one( diff --git a/contrib/shimmie_api/test.php b/contrib/shimmie_api/test.php new file mode 100644 index 00000000..961afa0a --- /dev/null +++ b/contrib/shimmie_api/test.php @@ -0,0 +1,29 @@ +log_in_as_user(); + $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + + $this->get_page("api/shimmie/get_tags"); + $this->get_page("api/shimmie/get_tags/pb"); + $this->get_page("api/shimmie/get_tags?tag=pb"); + $this->get_page("api/shimmie/get_image/$image_id"); + $this->get_page("api/shimmie/get_image?id=$image_id"); + $this->get_page("api/shimmie/find_images"); + $this->get_page("api/shimmie/find_images/pbx"); + $this->get_page("api/shimmie/find_images/pbx/1"); + $this->get_page("api/shimmie/get_user/demo"); + $this->get_page("api/shimmie/get_user?name=demo"); + $this->get_page("api/shimmie/get_user?id=2"); + + // FIXME: test unspecified / bad values + // FIXME: test that json is encoded properly + + $this->log_out(); + + $this->log_in_as_admin(); + $this->delete_image($image_id); + $this->log_out(); + } +} +?> From 25bab5d672ff74a6626fc27b1cf7f66e9d386b38 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 12:53:23 +0000 Subject: [PATCH 12/27] if(x == true) return true else return false? return x :P --- contrib/admin/theme.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/contrib/admin/theme.php b/contrib/admin/theme.php index e72a372a..b52dbf77 100644 --- a/contrib/admin/theme.php +++ b/contrib/admin/theme.php @@ -21,13 +21,9 @@ class AdminPageTheme extends Themelet { $html = ' From df4e4050a01a4a83f78f0a84dbee7f1926b58b05 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 12:57:13 +0000 Subject: [PATCH 13/27] admin wibbles --- contrib/admin/main.php | 123 ++++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 57 deletions(-) diff --git a/contrib/admin/main.php b/contrib/admin/main.php index 7e746eb3..3122ad1c 100644 --- a/contrib/admin/main.php +++ b/contrib/admin/main.php @@ -35,6 +35,14 @@ class AdminBuildingEvent extends Event { } } +class AdminActionEvent extends Event { + var $action; + var $redirect = true; + public function __construct(/*string*/ $action) { + $this->action = $action; + } +} + class AdminPage extends Extension { public function onPageRequest(PageRequestEvent $event) { global $page, $user; @@ -44,52 +52,23 @@ class AdminPage extends Extension { $this->theme->display_permission_denied(); } else { - send_event(new AdminBuildingEvent($page)); - } - } - - if($event->page_matches("admin_utils")) { - if($user->is_admin() && $user->check_auth_token()) { - log_info("admin", "Util: {$_POST['action']}"); - set_time_limit(0); - $redirect = false; - - switch($_POST['action']) { - case 'delete by query': - $this->delete_by_query($_POST['query']); - $redirect = true; - break; - case 'lowercase all tags': - $this->lowercase_all_tags(); - $redirect = true; - break; - case 'recount tag use': - $this->recount_tag_use(); - $redirect = true; - break; - case 'purge unused tags': - $this->purge_unused_tags(); - $redirect = true; - break; - case 'convert to innodb': - $this->convert_to_innodb(); - $redirect = true; - break; - case 'database dump': - $this->dbdump($page); - break; - case 'reset image ids': - $this->reset_imageids(); - $redirect = true; - break; - case 'image dump': - $this->imgdump($page); - break; + if($event->count_args() == 0) { + send_event(new AdminBuildingEvent($page)); } + else { + $action = $event->get_arg(0); + $aae = new AdminActionEvent($action); - if($redirect) { - $page->set_mode("redirect"); - $page->set_redirect(make_link("admin")); + if($user->check_auth_token()) { + log_info("admin", "Util: $action"); + set_time_limit(0); + send_event($aae); + } + + if($aae->redirect) { + $page->set_mode("redirect"); + $page->set_redirect(make_link("admin")); + } } } } @@ -108,17 +87,30 @@ class AdminPage extends Extension { } } - private function delete_by_query(/*array(string)*/ $query) { + public function onAdminAction(AdminActionEvent $event) { + $action = $event->action; + if(function_exists($this, $action)) { + $event->redirect = $this->$action(); + } + } + + + private function delete_by_query() { global $page, $user; + $query = $_POST['query']; assert(strlen($query) > 1); + foreach(Image::find_images(0, 1000000, Tag::explode($query)) as $image) { send_event(new ImageDeletionEvent($image)); } + + return true; } private function lowercase_all_tags() { global $database; $database->execute("UPDATE tags SET tag=lower(tag)"); + return true; } private function recount_tag_use() { @@ -128,16 +120,21 @@ class AdminPage extends Extension { SET count = COALESCE( (SELECT COUNT(image_id) FROM image_tags WHERE tag_id=tags.id GROUP BY tag_id), 0 - )"); + ) + "); + return true; } private function purge_unused_tags() { global $database; $this->recount_tag_use(); $database->Execute("DELETE FROM tags WHERE count=0"); + return true; } - private function dbdump(Page $page) { + private function dump_database() { + global $page; + $matches = array(); preg_match("#^(?P\w+)\:(?:user=(?P\w+)(?:;|$)|password=(?P\w+)(?:;|$)|host=(?P[\w\.\-]+)(?:;|$)|dbname=(?P[\w_]+)(?:;|$))+#", DATABASE_DSN, $matches); $software = $matches['proto']; @@ -157,6 +154,8 @@ class AdminPage extends Extension { $page->set_type("application/x-unknown"); $page->set_filename('shimmie-'.date('Ymd').'.sql'); $page->set_data(shell_exec($cmd)); + + return false; } private function check_for_orphanned_images() { @@ -169,23 +168,29 @@ class AdminPage extends Extension { } } } + return true; } /* private function convert_to_innodb() { global $database; - if($database->engine->name == "mysql") { - $tables = $database->db->MetaTables(); - foreach($tables as $table) { - log_info("upgrade", "converting $table to innodb"); - $database->execute("ALTER TABLE $table TYPE=INNODB"); - } + + if($database->engine->name != "mysql") return; + + $tables = $database->db->MetaTables(); + foreach($tables as $table) { + log_info("upgrade", "converting $table to innodb"); + $database->execute("ALTER TABLE $table TYPE=INNODB"); } + return true; } */ - private function reset_imageids() { + private function reset_image_ids() { global $database; + + if($database->engine->name != "mysql") return; + //This might be a bit laggy on boards with lots of images (?) //Seems to work fine with 1.2k~ images though. $i = 0; @@ -221,15 +226,17 @@ class AdminPage extends Extension { } $count = (count($image)) + 1; $database->execute("ALTER TABLE images AUTO_INCREMENT=".$count); + return true; } - private function imgdump(Page $page) { - global $database; + private function download_all_images() { + global $database, $page; + $zip = new ZipArchive; $images = $database->get_all("SELECT * FROM images"); $filename = 'imgdump-'.date('Ymd').'.zip'; - if($zip->open($filename, 1 ? ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE)===TRUE){ + if($zip->open($filename, 1 ? ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE) === TRUE){ foreach($images as $img){ $hash = $img["hash"]; preg_match("^[A-Za-z0-9]{2}^", $hash, $matches); @@ -241,9 +248,11 @@ class AdminPage extends Extension { } $zip->close(); } + $page->set_mode("redirect"); $page->set_redirect(make_link($filename)); //Fairly sure there is better way to do this.. //TODO: Delete file after downloaded? + return false; // we do want a redirect, but a manual one } } ?> From 96cfda4a936ad0f94160f04dcba1507bbd9a2e5e Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 13:48:56 +0000 Subject: [PATCH 14/27] admin buttons --- contrib/admin/style.css | 18 +++++++++++++++++ contrib/admin/theme.php | 45 ++++++++++++++++++++++------------------- 2 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 contrib/admin/style.css diff --git a/contrib/admin/style.css b/contrib/admin/style.css new file mode 100644 index 00000000..996054c5 --- /dev/null +++ b/contrib/admin/style.css @@ -0,0 +1,18 @@ +.admin { + padding: 4px; + border-radius: 4px; + background: green; + margin: 6px; + width: 200px; + display: inline-block; +} +.admin.protected { + background: red; +} +.admin INPUT[type="submit"] { + width: 100%; +} +.admin.protected INPUT[type="submit"] { + width: 90%; +} + diff --git a/contrib/admin/theme.php b/contrib/admin/theme.php index b52dbf77..0b6ebd6e 100644 --- a/contrib/admin/theme.php +++ b/contrib/admin/theme.php @@ -10,6 +10,23 @@ class AdminPageTheme extends Themelet { $page->add_block(new NavBlock()); } + protected function button(/*string*/ $name, /*string*/ $action, /*boolean*/ $protected=false) { + $c_protected = $protected ? " protected" : ""; + $html = make_form(make_link("admin_utils"), "POST", false, false, false, "admin$c_protected"); + if($protected) { + $html .= ""; + } + $html .= ""; + if($protected) { + $html .= ""; + } + else { + $html .= ""; + } + $html .= "\n"; + return $html; + } + /* * Show a form which links to admin_utils with POST[action] set to one of: * 'lowercase all tags' @@ -19,27 +36,13 @@ class AdminPageTheme extends Themelet { public function display_form(Page $page) { global $user; - $html = ' - - '.make_form(make_link("admin_utils"),"post", false, false, "return imgidconfirm()")." - - - - "; + $html = ""; + $html .= $this->button("All tags to lowercase", "lowercase_all_tags", true); + $html .= $this->button("Recount tag use", "recount_tag_user", false); + $html .= $this->button("Purge unused tags", "purge_unused_tags", true); + $html .= $this->button("Download database contents", "database_dump", false); + $html .= $this->button("Reset image IDs", "reset_image_ids", true); + $html .= $this->button("Download all images", "image_dump", false); $page->add_block(new Block("Misc Admin Tools", $html)); /* First check From 0bd01e56e2272194b2729c1bd7b6fd2d85e44331 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 14:11:14 +0000 Subject: [PATCH 15/27] return x again --- contrib/admin/theme.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/contrib/admin/theme.php b/contrib/admin/theme.php index 0b6ebd6e..6688cc98 100644 --- a/contrib/admin/theme.php +++ b/contrib/admin/theme.php @@ -62,11 +62,7 @@ class AdminPageTheme extends Themelet { $html = " " From ee976ed23beade6ca4c2d563c840b599bb6d5a3c Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 14:30:49 +0000 Subject: [PATCH 16/27] better blocks testing --- contrib/blocks/test.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/contrib/blocks/test.php b/contrib/blocks/test.php index d19e2f11..396062a8 100644 --- a/contrib/blocks/test.php +++ b/contrib/blocks/test.php @@ -4,19 +4,27 @@ class BlocksTest extends SCoreWebTestCase { $this->log_in_as_admin(); $this->get_page("setup"); - $this->set_field("_config_blocks_text", "badgers"); + $this->set_field("_config_blocks_text", " +Title: some text +Area: main +Priority: 100 +Pages: * + +waffles +"); $this->click("Save Settings"); $this->get_page("post/list"); - $this->assert_text("badgers"); + $this->assert_text("some text"); + $this->assert_text("waffles"); $this->get_page("setup"); $this->set_field("_config_blocks_text", ""); $this->click("Save Settings"); $this->get_page("post/list"); - $this->assert_no_text("Note"); - $this->assert_no_text("badgers"); + $this->assert_no_text("some text"); + $this->assert_no_text("waffles"); $this->log_out(); } From 4c204a2bc109da471b9cc9adfef6ffe17fdafc9a Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 15:28:18 +0000 Subject: [PATCH 17/27] bookmarks test --- contrib/bookmarks/test.php | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 contrib/bookmarks/test.php diff --git a/contrib/bookmarks/test.php b/contrib/bookmarks/test.php new file mode 100644 index 00000000..9bd0692a --- /dev/null +++ b/contrib/bookmarks/test.php @@ -0,0 +1,9 @@ + +get_page("bookmark/add"); + $this->get_page("bookmark/remove"); + } +} +?> From d4d2afdd24ac8a0b97e5bcf2f53b320e48c0ed4d Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 15:29:42 +0000 Subject: [PATCH 18/27] ico testing --- contrib/handle_ico/test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/handle_ico/test.php b/contrib/handle_ico/test.php index 41aa190c..956ad322 100644 --- a/contrib/handle_ico/test.php +++ b/contrib/handle_ico/test.php @@ -2,10 +2,11 @@ class IcoHandlerTest extends ShimmieWebTestCase { function testPixelHander() { $this->log_in_as_user(); - $image_id = $this->post_image("favicon.ico", "shimmie favicon"); + $image_id = $this->post_image("lib/static/favicon.ico", "shimmie favicon"); $this->assert_response(302); $this->log_out(); + $raw = $this->get_page("post/view/$image_id"); // test for no crash $raw = $this->get_page("get_ico/$image_id"); // test for no crash $this->log_in_as_admin(); From 0a435449b9997ccc11a4e4af69d3a60c9e0bdc1b Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 17:39:38 +0000 Subject: [PATCH 19/27] feature testing --- contrib/featured/test.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/contrib/featured/test.php b/contrib/featured/test.php index 24c17651..293efe69 100644 --- a/contrib/featured/test.php +++ b/contrib/featured/test.php @@ -13,14 +13,21 @@ class FeaturedTest extends ShimmieWebTestCase { $this->click("Feature This"); $this->get_page("post/list"); $this->assert_text("Featured Image"); + + # FIXME: test changing from one feature to another + + $this->get_page("featured_image/download"); + $this->assert_response(200); + + $this->get_page("featured_image/view"); + $this->assert_response(200); + $this->delete_image($image_id); $this->log_out(); # after deletion, there should be no feature $this->get_page("post/list"); $this->assert_no_text("Featured Image"); - - # FIXME: test changing from one feature to another } } ?> From 582c49ee0e3fd0f16bea5623ea27bbcf134fb3ca Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 17:40:11 +0000 Subject: [PATCH 20/27] hash ban test --- contrib/image_hash_ban/test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 contrib/image_hash_ban/test.php diff --git a/contrib/image_hash_ban/test.php b/contrib/image_hash_ban/test.php new file mode 100644 index 00000000..a248b8ca --- /dev/null +++ b/contrib/image_hash_ban/test.php @@ -0,0 +1,15 @@ +log_in_as_user(); + $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $this->log_out(); + + $this->log_in_as_admin(); + $this->get_page("post/view/$image_id"); + $this->click("Ban and Delete"); + $this->log_out(); + + } +} +?> From 3801ce1becaf9b9c2a3366e20b497f06504cdd27 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 17:51:56 +0000 Subject: [PATCH 21/27] hash ban test --- contrib/image_hash_ban/test.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/contrib/image_hash_ban/test.php b/contrib/image_hash_ban/test.php index a248b8ca..9af952e8 100644 --- a/contrib/image_hash_ban/test.php +++ b/contrib/image_hash_ban/test.php @@ -10,6 +10,28 @@ class HashBanTest extends ShimmieWebTestCase { $this->click("Ban and Delete"); $this->log_out(); + $this->log_in_as_user(); + $this->get_page("post/view/$image_id"); + $this->assert_response(404); + $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $this->get_page("post/view/$image_id"); + $this->assert_response(404); + $this->log_out(); + + $this->log_in_as_admin(); + $this->get_page("image_hash_ban/list/1"); + $this->click("Remove"); + $this->log_out(); + + $this->log_in_as_user(); + $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $this->get_page("post/view/$image_id"); + $this->assert_response(200); + $this->log_out(); + + $this->log_in_as_admin(); + $this->delete_image($image_id); + $this->log_out(); } } ?> From 82414b279d31d9a79f6e70e6b7da251ecee55364 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 18:50:10 +0000 Subject: [PATCH 22/27] delete by query on admin page -> delete these images on search results --- contrib/admin/main.php | 17 ++++++++---- contrib/admin/theme.php | 59 +++++++++++++++-------------------------- lib/shimmie.js | 9 +++++++ 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/contrib/admin/main.php b/contrib/admin/main.php index 3122ad1c..5fe7cc41 100644 --- a/contrib/admin/main.php +++ b/contrib/admin/main.php @@ -75,9 +75,8 @@ class AdminPage extends Extension { } public function onAdminBuilding(AdminBuildingEvent $event) { - global $page; - $this->theme->display_page($page); - $this->theme->display_form($page); + $this->theme->display_page(); + $this->theme->display_form(); } public function onUserBlockBuilding(UserBlockBuildingEvent $event) { @@ -89,11 +88,17 @@ class AdminPage extends Extension { public function onAdminAction(AdminActionEvent $event) { $action = $event->action; - if(function_exists($this, $action)) { + if(method_exists($this, $action)) { $event->redirect = $this->$action(); } } + public function onPostListBuilding(PostListBuildingEvent $event) { + global $user; + if($user->is_admin() && !empty($event->search_terms)) { + $this->theme->display_dbq(implode(" ", $event->search_terms)); + } + } private function delete_by_query() { global $page, $user; @@ -104,7 +109,9 @@ class AdminPage extends Extension { send_event(new ImageDeletionEvent($image)); } - return true; + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/list")); + return false; } private function lowercase_all_tags() { diff --git a/contrib/admin/theme.php b/contrib/admin/theme.php index 6688cc98..a396bc8e 100644 --- a/contrib/admin/theme.php +++ b/contrib/admin/theme.php @@ -4,7 +4,9 @@ class AdminPageTheme extends Themelet { /* * Show the basics of a page, for other extensions to add to */ - public function display_page(Page $page) { + public function display_page() { + global $page; + $page->set_title("Admin Tools"); $page->set_heading("Admin Tools"); $page->add_block(new NavBlock()); @@ -12,12 +14,9 @@ class AdminPageTheme extends Themelet { protected function button(/*string*/ $name, /*string*/ $action, /*boolean*/ $protected=false) { $c_protected = $protected ? " protected" : ""; - $html = make_form(make_link("admin_utils"), "POST", false, false, false, "admin$c_protected"); + $html = make_form(make_link("admin/$action"), "POST", false, false, false, "admin$c_protected"); if($protected) { $html .= ""; - } - $html .= ""; - if($protected) { $html .= ""; } else { @@ -33,47 +32,33 @@ class AdminPageTheme extends Themelet { * 'recount tag use' * 'purge unused tags' */ - public function display_form(Page $page) { - global $user; + public function display_form() { + global $page, $database; $html = ""; $html .= $this->button("All tags to lowercase", "lowercase_all_tags", true); $html .= $this->button("Recount tag use", "recount_tag_user", false); $html .= $this->button("Purge unused tags", "purge_unused_tags", true); - $html .= $this->button("Download database contents", "database_dump", false); - $html .= $this->button("Reset image IDs", "reset_image_ids", true); $html .= $this->button("Download all images", "image_dump", false); + if($database->engine->name == "mysql") { + $html .= $this->button("Download database contents", "database_dump", false); + $html .= $this->button("Reset image IDs", "reset_image_ids", true); + } $page->add_block(new Block("Misc Admin Tools", $html)); - - /* First check - Requires you to click the checkbox to enable the delete by query form */ - $dbqcheck = 'javascript:$(function() { - if($("#dbqcheck:checked").length != 0){ - $("#dbqtags").attr("disabled", false); - $("#dbqsubmit").attr("disabled", false); - }else{ - $("#dbqtags").attr("disabled", true); - $("#dbqsubmit").attr("disabled", true); - } - });'; - - /* Second check - Requires you to confirm the deletion by clicking ok. */ - $html = " - " - - .make_form(make_link("admin_utils"),"post",false,false,"return checkform()")." - - - - + } + + public function display_dbq($terms) { + global $page; + + $h_terms = html_escape($terms); + + $html = make_form(make_link("admin/delete_by_query"), "POST") . " + + + "; - $page->add_block(new Block("Delete by Query", $html)); + $page->add_block(new Block("List Controls", $html, "left")); } } ?> diff --git a/lib/shimmie.js b/lib/shimmie.js index 8f19cd7c..de395fef 100644 --- a/lib/shimmie.js +++ b/lib/shimmie.js @@ -76,6 +76,15 @@ $(document).ready(function() { }) }); + $(".shm-unlocker").each(function(idx, elm) { + var tid = $(elm).data("unlock-id"); + var tob = $("#"+tid); + $(elm).click(function(e) { + $(elm).attr("disabled", true); + tob.attr("disabled", false); + }); + }); + if(document.location.hash.length > 3) { query = document.location.hash.substring(1); a = document.getElementById("prevlink"); From a6dbe3b7f26ef1466c56d751cfe0d92b4844353a Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 18:53:42 +0000 Subject: [PATCH 23/27] Image::locked should always be a boolean --- core/imageboard.pack.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 5ec46ef4..f7e27121 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -56,6 +56,7 @@ class Image { $this->$name = $value; // hax } $this->posted_timestamp = strtotime($this->posted); // pray + $this->locked = undb_bool($this->locked); assert(is_numeric($this->id)); assert(is_numeric($this->height)); @@ -411,8 +412,9 @@ class Image { * @retval bool */ public function is_locked() { - return ($this->locked === true || $this->locked == "Y" || $this->locked == "t"); + return $this->locked; } + public function set_locked($tf) { global $database; $ln = $tf ? "Y" : "N"; From 37672bc1ee0e00f5412f3c63ba341365e07eb490 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 18:57:35 +0000 Subject: [PATCH 24/27] comment schema wibbles --- ext/comment/main.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ext/comment/main.php b/ext/comment/main.php index 2b691c34..dbb35a8a 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -86,12 +86,12 @@ class CommentList extends Extension { FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE "); - $config->set_int("ext_comments_version", 2); + $config->set_int("ext_comments_version", 3); } - // === + // the whole history if($config->get_int("ext_comments_version") < 1) { - $database->Execute("CREATE TABLE comments ( + $database->create_table("comments", " id {$database->engine->auto_increment}, image_id INTEGER NOT NULL, owner_id INTEGER NOT NULL, @@ -99,7 +99,7 @@ class CommentList extends Extension { posted DATETIME DEFAULT NULL, comment TEXT NOT NULL, INDEX (image_id) - ) {$database->engine->create_table_extras}"); + "); $config->set_int("ext_comments_version", 1); } @@ -108,6 +108,8 @@ class CommentList extends Extension { $database->Execute("CREATE INDEX comments_posted ON comments(posted)"); $config->set_int("ext_comments_version", 2); } + + // FIXME: add foreign keys, bump to v3 } } From f62edc3e834dabc386c5a8af3d2666235842e979 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 19:07:02 +0000 Subject: [PATCH 25/27] add FKs for comments --- ext/comment/main.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ext/comment/main.php b/ext/comment/main.php index dbb35a8a..1cbf888a 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -84,7 +84,7 @@ class CommentList extends Extension { INDEX (owner_ip), INDEX (posted), FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, - FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE + FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT "); $config->set_int("ext_comments_version", 3); } @@ -109,6 +109,12 @@ class CommentList extends Extension { $config->set_int("ext_comments_version", 2); } + 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"); + } + // FIXME: add foreign keys, bump to v3 } } From a2d2ceb01523fb1a9a3f30b14cda8e3684cb61ef Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 19:07:40 +0000 Subject: [PATCH 26/27] foreign keys delete comments now --- ext/comment/main.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/ext/comment/main.php b/ext/comment/main.php index 1cbf888a..c5c84226 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -194,13 +194,6 @@ class CommentList extends Extension { ); } - public function onImageDeletion(ImageDeletionEvent $event) { - global $database; - $image_id = $event->image->id; - $database->Execute("DELETE FROM comments WHERE image_id=:image_id", array("image_id"=>$image_id)); - log_info("comment", "Deleting all comments for Image #$image_id"); - } - // TODO: split akismet into a separate class, which can veto the event public function onCommentPosting(CommentPostingEvent $event) { $this->add_comment_wrapper($event->image_id, $event->user, $event->comment); From 6c459c8323128b794c5e8be27c4a137bec6180d4 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Mar 2012 19:13:41 +0000 Subject: [PATCH 27/27] make it so --- ext/comment/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/comment/main.php b/ext/comment/main.php index c5c84226..3d813f99 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -70,7 +70,7 @@ class CommentList extends Extension { $config->set_default_int('comment_count', 5); $config->set_default_bool('comment_captcha', false); - if($config->get_int("ext_comments_version") < 2) { + if($config->get_int("ext_comments_version") < 3) { // shortcut to latest if($config->get_int("ext_comments_version") < 1) { $database->create_table("comments", "