From 72a82c74870f3aa673801bcb9dfa9504cdd6fa60 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 3 Mar 2013 18:26:47 +0000 Subject: [PATCH 1/5] saner wildcard handling, and only handle '*' --- core/imageboard.pack.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index a11c1620..6362de14 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -665,14 +665,10 @@ class Image { } } else { - $term = str_replace("*", "%", $term); - $term = str_replace("?", "_", $term); - if(!preg_match("/^[%_]+$/", $term)) { - $expansions = Tag::resolve_wildcard($term); - if($positive) $positive_tag_count++; - foreach($expansions as $term) { - $tag_querylets[] = new TagQuerylet($term, $positive); - } + $expansions = Tag::resolve_wildcard($term); + if($expansions && $positive) $positive_tag_count++; + foreach($expansions as $term) { + $tag_querylets[] = new TagQuerylet($term, $positive); } } } @@ -1024,12 +1020,22 @@ class Tag { } public static function resolve_wildcard($tag) { - if(strpos($tag, "%") === false && strpos($tag, "_") === false) { + // if there is no wildcard, return the tag + if(strpos($tag, "*") === false) { return array($tag); } + + // if the whole match is wild, return null to save the database + else if(str_replace("*", "", $tag) == "")) { + return array(); + } + + // else find some matches else { global $database; - $newtags = $database->get_col("SELECT tag FROM tags WHERE tag LIKE ?", array($tag)); + $db_wild_tag = str_replace("%", "\%", $tag); + $db_wild_tag = str_replace("*", "%", $tag); + $newtags = $database->get_col($database->scoreql_to_sql("SELECT tag FROM tags WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(?)"), array($db_wild_tag)); if(count($newtags) > 0) { $resolved = $newtags; } else { From d5bc06835d54629572689d58fc6e24e486786027 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 3 Mar 2013 18:27:06 +0000 Subject: [PATCH 2/5] reserve block slot #0 for site announcements --- ext/user/theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/user/theme.php b/ext/user/theme.php index f129d284..2f0c0363 100644 --- a/ext/user/theme.php +++ b/ext/user/theme.php @@ -146,7 +146,7 @@ class UserPageTheme extends Themelet { $page->set_title(html_escape($duser->name)."'s Page"); $page->set_heading(html_escape($duser->name)."'s Page"); $page->add_block(new NavBlock()); - $page->add_block(new Block("Stats", join("
", $stats), "main", 0)); + $page->add_block(new Block("Stats", join("
", $stats), "main", 10)); if(!$user->is_anonymous()) { if($user->id == $duser->id || $user->can("edit_user_info")) { From e013d86b56891319346472b5ef5d9469b208469b Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 3 Mar 2013 18:32:56 +0000 Subject: [PATCH 3/5] disallow aliases to other aliases --- ext/alias_editor/main.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index 7ba38656..4034fda8 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -108,6 +108,9 @@ class AliasEditor extends Extension { if($database->get_row("SELECT * FROM aliases WHERE oldtag=:oldtag AND lower(newtag)=lower(:newtag)", $pair)) { throw new AddAliasException("That alias already exists"); } + else if($database->get_row("SELECT * FROM aliases WHERE oldtag=:newtag", $pair)) { + throw new AddAliasException("{$event->newtag} is itself an alias"); + } else { $database->execute("INSERT INTO aliases(oldtag, newtag) VALUES(:oldtag, :newtag)", $pair); log_info("alias_editor", "Added alias for {$event->oldtag} -> {$event->newtag}", true); From 7ff0ae51a177e9fb519a7fb2625b1391ac50eda2 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 3 Mar 2013 18:34:27 +0000 Subject: [PATCH 4/5] fixup wildcards --- core/imageboard.pack.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 6362de14..8b81812a 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -1026,7 +1026,7 @@ class Tag { } // if the whole match is wild, return null to save the database - else if(str_replace("*", "", $tag) == "")) { + else if(str_replace("*", "", $tag) == "") { return array(); } From e49e90f9ab2b325546bfa2709a1c3fbbfabca2d6 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 7 Mar 2013 03:23:35 +0000 Subject: [PATCH 5/5] fff, php --- ext/alias_editor/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index 4034fda8..4ef4e565 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -108,7 +108,7 @@ class AliasEditor extends Extension { if($database->get_row("SELECT * FROM aliases WHERE oldtag=:oldtag AND lower(newtag)=lower(:newtag)", $pair)) { throw new AddAliasException("That alias already exists"); } - else if($database->get_row("SELECT * FROM aliases WHERE oldtag=:newtag", $pair)) { + else if($database->get_row("SELECT * FROM aliases WHERE oldtag=:newtag", array("newtag" => $event->newtag))) { throw new AddAliasException("{$event->newtag} is itself an alias"); } else {