From c741ea216f8ab61fd7fb6ec6fc59caa986916f9a Mon Sep 17 00:00:00 2001
From: shish <shish@7f39781d-f577-437e-ae19-be835c7a54ca>
Date: Tue, 29 Jul 2008 19:43:34 +0000
Subject: [PATCH] pull a bunch of r34 tweaks intro trunk

git-svn-id: file:///home/shish/svn/shimmie2/trunk@959 7f39781d-f577-437e-ae19-be835c7a54ca
---
 contrib/image_hash_ban/main.php |  5 +++--
 core/util.inc.php               | 17 ++++++++++++++++-
 ext/comment/main.php            |  6 ++++++
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/contrib/image_hash_ban/main.php b/contrib/image_hash_ban/main.php
index 4d0236bd..c58006a5 100644
--- a/contrib/image_hash_ban/main.php
+++ b/contrib/image_hash_ban/main.php
@@ -46,8 +46,9 @@ class Image_Hash_Ban extends Extension {
 		if(is_a($event, 'DataUploadEvent')) {
 			global $database;
 
-			if ($database->db->GetOne("SELECT COUNT(*) FROM image_bans WHERE hash = ?", $event->hash) == 1) {
-				$event->veto("This image has been banned!");
+			$row = $database->db->GetRow("SELECT * FROM image_bans WHERE hash = ?", $event->hash);
+			if($row) {
+				$event->veto("Image ".html_escape($row["hash"])." has been banned, reason: ".format_text($row["reason"]));
 			}
 		}
 
diff --git a/core/util.inc.php b/core/util.inc.php
index e4ca8512..a62609f8 100644
--- a/core/util.inc.php
+++ b/core/util.inc.php
@@ -162,7 +162,12 @@ function _count_execs($db, $sql, $inputarray) {
 	global $_execs;
 	if(DEBUG) {
 		$fp = fopen("sql.log", "a");
-		fwrite($fp, preg_replace('/\s+/msi', ' ', $sql)."\n");
+		if(is_array($inputarray)) {
+			fwrite($fp, preg_replace('/\s+/msi', ' ', $sql)." -- ".join(", ", $inputarray)."\n");
+		}
+		else {
+			fwrite($fp, preg_replace('/\s+/msi', ' ', $sql)."\n");
+		}
 		fclose($fp);
 	}
 	if (!is_array($inputarray)) $_execs++;
@@ -262,6 +267,12 @@ function move_upload_to_archive($event) {
 	return true;
 }
 
+function format_text($string) {
+	$tfe = new TextFormattingEvent($string);
+	send_event($tfe);
+	return $tfe->formatted;
+}
+
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
 * Debugging functions                                                       *
@@ -287,9 +298,13 @@ function get_debug_info() {
 	}
 	$i_files = count(get_included_files());
 	global $_execs;
+	global $database;
+	$hits = $database->cache_hits;
+	$miss = $database->cache_misses;
 	$debug = "<br>Took $i_utime + $i_stime seconds and {$i_mem}MB of RAM";
 	$debug .= "; Used $i_files files and $_execs queries";
 	$debug .= "; Sent $_event_count events";
+	$debug .= "; $hits cache hits and $miss misses";
 
 	return $debug;
 }
diff --git a/ext/comment/main.php b/ext/comment/main.php
index c143ebe2..50c76ce6 100644
--- a/ext/comment/main.php
+++ b/ext/comment/main.php
@@ -343,6 +343,12 @@ class CommentList extends Extension {
 		else if($this->is_dupe($image_id, $comment)) {
 			$event->veto("Someone already made that comment on that image -- try and be more original?");
 		}
+		else if(strlen($comment) > 9000) {
+			$event->veto("Comment too long~");
+		}
+		else if(strlen($comment)/strlen(gzcompress($comment)) > 10) {
+			$event->veto("Comment too repetitive~");
+		}
 		else if($user->is_anonymous() && $this->is_spam($comment)) {
 			$event->veto("Akismet thinks that your comment is spam. Try rewriting the comment, or logging in.");
 		}