diff --git a/core/util.inc.php b/core/util.inc.php
index 1f653574..fa2758d8 100644
--- a/core/util.inc.php
+++ b/core/util.inc.php
@@ -180,6 +180,23 @@ 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)
+ *
+ * FIXME: also check that IP ban ext is installed
+ *
+ * @retval string
+ */
+function show_ip($ip, $ban_reason) {
+ global $user;
+ $u_reason = url_escape($ban_reason);
+ $u_end = url_escape("+1 week");
+ $ban = $user->can("ban_ip") ? ", Ban" : "";
+ $ip = $user->can("view_ip") ? $ip.$ban : "";
+ return $ip;
+}
+
/**
* Different databases have different ways to represent booleans; this
diff --git a/ext/comment/theme.php b/ext/comment/theme.php
index 54e5938b..ed831dad 100644
--- a/ext/comment/theme.php
+++ b/ext/comment/theme.php
@@ -174,8 +174,7 @@ class CommentListTheme extends Themelet {
$avatar = "
";
}
$h_reply = " - Reply";
- $ban = $user->can("ban_ip") ? ", Ban" : "";
- $h_ip = $user->can("view_ip") ? "
$h_poster_ip, $ban" : "";
+ $h_ip = $user->can("view_ip") ? "
".show_ip($image->owner_ip, "Comment posted {$comment->posted}") : "";
$h_del = $user->can("delete_comment") ?
' - Del' : '';
diff --git a/ext/tag_edit/theme.php b/ext/tag_edit/theme.php
index 5d598de6..cee7268b 100644
--- a/ext/tag_edit/theme.php
+++ b/ext/tag_edit/theme.php
@@ -37,8 +37,7 @@ class TagEditTheme extends Themelet {
$h_owner = html_escape($image->get_owner()->name);
$h_av = $image->get_owner()->get_avatar_html();
$h_date = autodate($image->posted);
- $ban = $user->can("ban_ip") ? ", Ban" : "";
- $ip = $user->can("view_ip") ? " ({$image->owner_ip}$ban)" : "";
+ $ip = $user->can("view_ip") ? " (".show_ip($image->owner_ip, "Image posted {$image->posted}").")" : "";
return "