<commit_before>package ru.org.linux.site;

import java.io.IOException;
import java.net.URLEncoder;
import java.sql.*;

import ru.org.linux.util.*;

public class Comment {
  private final int msgid;
  private String title;
  private String photo;
  private String nick;
  private int userScore;
  private int userMaxScore;
  private int replyto = 0;
  private int topic;
  private boolean deleted;
  private boolean expired;
  private Timestamp postdate;
  private boolean show = true;
  private final String message;

  public Comment(ResultSet rs) throws SQLException {
    msgid=rs.getInt("msgid");
    title=StringUtil.makeTitle(rs.getString("title"));
    photo=rs.getString("photo");
    nick=rs.getString("nick");
    topic=rs.getInt("topic");
    replyto=rs.getInt("replyto");
    deleted=rs.getBoolean("deleted");
    expired=rs.getBoolean("expired");
    postdate=rs.getTimestamp("postdate");
    userScore=rs.getInt("score");
    userMaxScore=rs.getInt("max_score");
    message=rs.getString("message");
  }

  public Comment(Connection db, int msgid) throws SQLException, MessageNotFoundException {
    Statement st = db.createStatement();

    ResultSet rs=st.executeQuery("SELECT postdate, topic, nick, score, max_score, comments.id as msgid, comments.title, photo, 'f', deleted, 'f' as expired, replyto, message FROM comments, users, msgbase WHERE comments.id="+msgid+" AND comments.id=msgbase.id AND comments.userid=users.id");

    if (!rs.next()) throw new MessageNotFoundException(replyto);

    this.msgid=rs.getInt("msgid");
    title=StringUtil.makeTitle(rs.getString("title"));
    photo=rs.getString("photo");
    nick=rs.getString("nick");
    topic=rs.getInt("topic");
    replyto=rs.getInt("replyto");
    deleted=rs.getBoolean("deleted");
    expired=rs.getBoolean("expired");
    postdate=rs.getTimestamp("postdate");
    userScore=rs.getInt("score");
    userMaxScore=rs.getInt("max_score");
    message=rs.getString("message");

    st.close();
  }

  public String printMessage(Template tmpl, Connection db, boolean showMenu, boolean masterMode, String urladd, String mainUrl, boolean moderatorMode, String user)
      throws IOException, SQLException, UtilException {
    StringBuffer out=new StringBuffer();

    out.append("\n\n<!-- ").append(msgid).append(" -->\n");

    out.append("<table width=\"100%\" cellspacing=0 cellpadding=0 border=0>");

    if (showMenu) {
      out.append("<tr class=title><td>");

      if (!deleted) {
        out.append("[<a href=\"/jump-message.jsp?msgid=").append(topic).append('#').append(msgid).append("\">#</a>]");
      }

      if (!show) {
        out.append("[hide] ");
      }

      if (!expired && !deleted) {
        if (masterMode) {
          out.append("[<a href=\"#rep\"></a>]");
        } else {
          out.append("[<a href=\"add_comment.jsp?topic=").append(topic).append("&amp;replyto=").append(msgid).append(urladd).append("\"></a>]");
        }
      }

      if (!deleted && (moderatorMode || nick.equals(user))) {
        out.append("[<a href=\"delete_comment.jsp?msgid=").append(msgid).append("\"></a>]");
      }

      if (moderatorMode) {
        out.append("[<a href=\"sameip.jsp?msgid=").append(msgid).append("\">   IP</a>]");
      }

      if (deleted) {
        DeleteInfo deleteInfo = DeleteInfo.getDeleteInfo(db, msgid);

        if (deleteInfo==null) {
          out.append("<strong> </strong>");
        } else {
          out.append("<strong>  ").append(deleteInfo.getNick()).append("   '").append(HTMLFormatter.htmlSpecialChars(deleteInfo.getReason())).append("'</strong>");
        }
      }

      out.append("&nbsp;</td></tr>");
    }

    if (replyto!=0) {
      out.append("<tr class=title><td>");
      Statement rts=db.createStatement();
      ResultSet rt=rts.executeQuery("SELECT users.nick, comments.title, comments.postdate from comments, users WHERE users.id=comments.userid AND comments.id=" + replyto);
<commit_msg>fixed ticket:13<commit_after>package ru.org.linux.site;

import java.io.IOException;
import java.net.URLEncoder;
import java.sql.*;

import ru.org.linux.util.*;

public class Comment {
  private final int msgid;
  private String title;
  private String photo;
  private String nick;
  private int userScore;
  private int userMaxScore;
  private int replyto = 0;
  private int topic;
  private boolean deleted;
  private boolean expired;
  private Timestamp postdate;
  private boolean show = true;
  private final String message;

  public Comment(ResultSet rs) throws SQLException {
    msgid=rs.getInt("msgid");
    title=StringUtil.makeTitle(rs.getString("title"));
    photo=rs.getString("photo");
    nick=rs.getString("nick");
    topic=rs.getInt("topic");
    replyto=rs.getInt("replyto");
    deleted=rs.getBoolean("deleted");
    expired=rs.getBoolean("expired");
    postdate=rs.getTimestamp("postdate");
    userScore=rs.getInt("score");
    userMaxScore=rs.getInt("max_score");
    message=rs.getString("message");
  }

  public Comment(Connection db, int msgid) throws SQLException, MessageNotFoundException {
    Statement st = db.createStatement();

    ResultSet rs=st.executeQuery("SELECT postdate, topic, nick, score, max_score, comments.id as msgid, comments.title, photo, 'f', deleted, 'f' as expired, replyto, message FROM comments, users, msgbase WHERE comments.id="+msgid+" AND comments.id=msgbase.id AND comments.userid=users.id");

    if (!rs.next()) throw new MessageNotFoundException(replyto);

    this.msgid=rs.getInt("msgid");
    title=StringUtil.makeTitle(rs.getString("title"));
    photo=rs.getString("photo");
    nick=rs.getString("nick");
    topic=rs.getInt("topic");
    replyto=rs.getInt("replyto");
    deleted=rs.getBoolean("deleted");
    expired=rs.getBoolean("expired");
    postdate=rs.getTimestamp("postdate");
    userScore=rs.getInt("score");
    userMaxScore=rs.getInt("max_score");
    message=rs.getString("message");

    st.close();
  }

  public String printMessage(Template tmpl, Connection db, boolean showMenu, boolean masterMode, String urladd, String mainUrl, boolean moderatorMode, String user)
      throws IOException, SQLException, UtilException {
    StringBuffer out=new StringBuffer();

    out.append("\n\n<!-- ").append(msgid).append(" -->\n");

    out.append("<table width=\"100%\" cellspacing=0 cellpadding=0 border=0>");

    if (showMenu) {
      out.append("<tr class=title><td>");

      if (!deleted) {
        out.append("[<a href=\"/jump-message.jsp?msgid=").append(topic).append('#').append(msgid).append("\">#</a>]");
      }

      if (!show) {
        out.append("[hide] ");
      }

      if (!expired && !deleted) {
        if (masterMode) {
          out.append("[<a href=\"#rep\"></a>]");
        } else {
          out.append("[<a href=\"add_comment.jsp?topic=").append(topic).append("&amp;replyto=").append(msgid).append(urladd).append("\"></a>]");
        }
      }

      if (!deleted && (moderatorMode || nick.equals(user))) {
        out.append("[<a href=\"delete_comment.jsp?msgid=").append(msgid).append("\"></a>]");
      }

      if (moderatorMode) {
        out.append("[<a href=\"sameip.jsp?msgid=").append(msgid).append("\">   IP</a>]");
      }

      if (deleted) {
        DeleteInfo deleteInfo = DeleteInfo.getDeleteInfo(db, msgid);

        if (deleteInfo==null) {
          out.append("<strong> </strong>");
        } else {
          out.append("<strong>  ").append(deleteInfo.getNick()).append("   '").append(HTMLFormatter.htmlSpecialChars(deleteInfo.getReason())).append("'</strong>");
        }
      }

      out.append("&nbsp;</td></tr>");
    }

    if (replyto!=0 && !masterMode) {
      out.append("<tr class=title><td>");
      Statement rts=db.createStatement();
      ResultSet rt=rts.executeQuery("SELECT users.nick, comments.title, comments.postdate from comments, users WHERE users.id=comments.userid AND comments.id=" + replyto);

{'fraction_non_alphanumeric': 0.17412241794449373, 'fraction_numerical': 0.0022810797110632366, 'mean_word_length': 3.725748502994012, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6325770', 'n_tokens_mistral': 2465, 'n_tokens_neox': 2409, 'n_words': 462}