This commit is contained in:
DrudexSoftware 2013-03-10 07:01:28 +01:00
commit fccd5d249d
3 changed files with 20 additions and 11 deletions

View File

@ -665,14 +665,10 @@ class Image {
} }
} }
else { else {
$term = str_replace("*", "%", $term); $expansions = Tag::resolve_wildcard($term);
$term = str_replace("?", "_", $term); if($expansions && $positive) $positive_tag_count++;
if(!preg_match("/^[%_]+$/", $term)) { foreach($expansions as $term) {
$expansions = Tag::resolve_wildcard($term); $tag_querylets[] = new TagQuerylet($term, $positive);
if($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) { 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); 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 { else {
global $database; 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) { if(count($newtags) > 0) {
$resolved = $newtags; $resolved = $newtags;
} else { } else {

View File

@ -108,6 +108,9 @@ class AliasEditor extends Extension {
if($database->get_row("SELECT * FROM aliases WHERE oldtag=:oldtag AND lower(newtag)=lower(:newtag)", $pair)) { if($database->get_row("SELECT * FROM aliases WHERE oldtag=:oldtag AND lower(newtag)=lower(:newtag)", $pair)) {
throw new AddAliasException("That alias already exists"); throw new AddAliasException("That alias already exists");
} }
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 { else {
$database->execute("INSERT INTO aliases(oldtag, newtag) VALUES(:oldtag, :newtag)", $pair); $database->execute("INSERT INTO aliases(oldtag, newtag) VALUES(:oldtag, :newtag)", $pair);
log_info("alias_editor", "Added alias for {$event->oldtag} -> {$event->newtag}", true); log_info("alias_editor", "Added alias for {$event->oldtag} -> {$event->newtag}", true);

View File

@ -146,7 +146,7 @@ class UserPageTheme extends Themelet {
$page->set_title(html_escape($duser->name)."'s Page"); $page->set_title(html_escape($duser->name)."'s Page");
$page->set_heading(html_escape($duser->name)."'s Page"); $page->set_heading(html_escape($duser->name)."'s Page");
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
$page->add_block(new Block("Stats", join("<br>", $stats), "main", 0)); $page->add_block(new Block("Stats", join("<br>", $stats), "main", 10));
if(!$user->is_anonymous()) { if(!$user->is_anonymous()) {
if($user->id == $duser->id || $user->can("edit_user_info")) { if($user->id == $duser->id || $user->can("edit_user_info")) {