Author: jflesch
Date: 2007-04-23 18:26:30 +0000 (Mon, 23 Apr 2007)
New Revision: 12904
Modified:
trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
trunk/apps/Thaw/src/thaw/plugins/index/Comment.java
trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
trunk/apps/Thaw/src/thaw/plugins/index/Index.java
trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java
Log:
Allow to blacklist (/moderate) comments
Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties 2007-04-23
17:31:42 UTC (rev 12903)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties 2007-04-23
18:26:30 UTC (rev 12904)
@@ -340,6 +340,10 @@
thaw.plugin.index.comment.reset=Remettre les commentaires ? 0
+thaw.plugin.index.comment.moderated=*MOD?R?*
+thaw.plugin.index.comment.moderate=Moderer
+thaw.plugin.index.comment.unmoderate=D?mod?rer
+
thaw.plugin.index.mustReinsert=Vous devez r?inserer l'index pour que les
changements fassent effet
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-04-23 17:31:42 UTC
(rev 12903)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-04-23 18:26:30 UTC
(rev 12904)
@@ -346,8 +346,10 @@
thaw.plugin.index.comment.reset=Reinit comments
+thaw.plugin.index.comment.moderated=*MODERATED*
+thaw.plugin.index.comment.moderate=Moderate
+thaw.plugin.index.comment.unmoderate=Unmoderate
-
thaw.plugin.peerMonitor.peerMonitor=Connection
thaw.plugin.peerMonitor.yourReference=Your reference:
thaw.plugin.peerMonitor.copyReference=Copy your reference to the clipboard
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2007-04-23 17:31:42 UTC
(rev 12903)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2007-04-23 18:26:30 UTC
(rev 12904)
@@ -340,6 +340,9 @@
thaw.plugin.index.comment.reset=Remettre les commentaires \u00e0 0
+thaw.plugin.index.comment.moderated=*MOD\u00c9R\u00c9*
+
+
thaw.plugin.index.mustReinsert=Vous devez r\u00e9inserer l'index pour que les
changements fassent effet
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Comment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Comment.java 2007-04-23 17:31:42 UTC
(rev 12903)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Comment.java 2007-04-23 18:26:30 UTC
(rev 12904)
@@ -140,12 +140,32 @@
private JComboBox trust;
private JButton changeTrust;
+ private JButton changeBlackListState;
+
+ private boolean blackListed;
+
+
public JPanel getPanel(CommentTab tab) {
this.tab= tab;
+ blackListed = isBlackListed();
+ boolean hasPrivateKey = (index.getPrivateKey() != null);
+
+ /**
+ * we don't display if it is blacklisted and we don't have the
private key
+ */
+ if (blackListed && !hasPrivateKey)
+ return null;
+
JPanel panel = new JPanel(new BorderLayout(10, 10));
- JTextArea text = new JTextArea(comment.trim());
+ JTextArea text;
+
+ if (!blackListed)
+ text = new JTextArea(comment.trim());
+ else
+ text = new
JTextArea(I18n.getMessage("thaw.plugin.index.comment.moderated"));
+
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"---
"+author.toString()+" ---",
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
@@ -187,11 +207,23 @@
trustPanel.add(changeTrust, BorderLayout.EAST);
}
+ JPanel bottomRightPanel = new JPanel(new BorderLayout(5, 5));
+ bottomRightPanel.add(trustPanel, BorderLayout.CENTER);
+
+ if (hasPrivateKey && (author.getX() == null || blackListed) ) {
+ changeBlackListState = new JButton(blackListed ?
+
I18n.getMessage("thaw.plugin.index.comment.unmoderate") :
+
I18n.getMessage("thaw.plugin.index.comment.moderate"));
+ changeBlackListState.addActionListener(this);
+ bottomRightPanel.add(changeBlackListState,
BorderLayout.EAST);
+ }
+
+
JPanel bottomPanel = new JPanel(new BorderLayout());
bottomPanel.add(sigPanel, BorderLayout.WEST);
bottomPanel.add(new JLabel(""), BorderLayout.CENTER);
- bottomPanel.add(trustPanel, BorderLayout.EAST);
+ bottomPanel.add(bottomRightPanel, BorderLayout.EAST);
text.setEditable(false);
@@ -210,6 +242,62 @@
}
+ public boolean isBlackListed() {
+ return isBlackListed(db, index.getId(), rev);
+ }
+
+ public void unBlackList() {
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st =
db.getConnection().prepareStatement("DELETE FROM indexCommentBlackList WHERE
rev = ? AND indexId = ?");
+ st.setInt(1, rev);
+ st.setInt(2, index.getId());
+ st.execute();
+ }
+ } catch(SQLException e) {
+ Logger.error(this, "Unable to un-blacklist comment
because: "+e.toString());
+ }
+ }
+
+
+ public void blackList() {
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st =
db.getConnection().prepareStatement("INSERT INTO indexCommentBlackList (rev,
indexId) VALUES (?, ?)");
+ st.setInt(1, rev);
+ st.setInt(2, index.getId());
+ st.execute();
+ }
+ } catch(SQLException e) {
+ Logger.error(this, "Unable to blacklist comment
because: "+e.toString());
+ }
+ }
+
+
+ /**
+ * Only index owner(s) must be able to see black listed comments
+ */
+ public static boolean isBlackListed(Hsqldb db, int indexId, int rev) {
+ try {
+ synchronized(db.dbLock) {
+
+ PreparedStatement st;
+
+ st =
db.getConnection().prepareStatement("SELECT id FROM indexCommentBlackList WHERE
indexId = ? AND rev = ? LIMIT 1");
+ st.setInt(1, indexId);
+ st.setInt(2, rev);
+
+ ResultSet set = st.executeQuery();
+
+ return set.next();
+ }
+ } catch(SQLException e) {
+ Logger.error(db, "thaw.plugins.index.Comment : Error
while checking if the message is in the blacklist :"+e.toString());
+ }
+
+ return false;
+ }
+
public void actionPerformed(ActionEvent e) {
if (e.getSource() == changeTrust) {
if (author == null)
@@ -218,6 +306,18 @@
tab.updateCommentList();
return;
}
+
+ if (e.getSource() == changeBlackListState) {
+ if (blackListed) {
+ unBlackList();
+ } else {
+ blackList();
+ }
+
+ tab.updateCommentList();
+
+ return;
+ }
}
@@ -692,7 +792,7 @@
publicKey += "comment-"+Integer.toString(rev)+"/comment.xml";
FCPClientGet get = new FCPClientGet(publicKey, 2 /* priority
*/, 2 /* persistence */,
- false /* global queue */, 5
/* max retries */,
+ false /* global queue */, 3
/* max retries */,
System.getProperty("java.io.tmpdir"),
MAX_SIZE, true /* no DDA
*/);
Modified: trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2007-04-23
17:31:42 UTC (rev 12903)
+++ trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2007-04-23
18:26:30 UTC (rev 12904)
@@ -274,6 +274,17 @@
+ "s VARBINARY(400) NOT NULL," /* signature */
+ "FOREIGN KEY (indexId) REFERENCES indexes (id),"
+ "FOREIGN KEY (authorId) REFERENCES signatures
(id))");
+
+ /**
+ * black listed comments should not be fetched.
+ * and if they are already fetched, they will be ignored at
display time
+ */
+ sendQuery(db,
+ "CREATE CACHED TABLE indexCommentBlackList ("
+ + "id INTEGER IDENTITY NOT NULL,"
+ + "rev INTEGER NOT NULL,"
+ + "indexId INTEGER NOT NULL,"
+ + "FOREIGN KEY (indexId) REFERENCES indexes (id))");
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2007-04-23 17:31:42 UTC
(rev 12903)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2007-04-23 18:26:30 UTC
(rev 12904)
@@ -409,7 +409,7 @@
public boolean getPublishPrivateKey() {
try {
- PreparedStatement st
+ PreparedStatement st
= db.getConnection().prepareStatement("SELECT
publishPrivateKey FROM indexes WHERE id = ? LIMIT 1");
st.setInt(1, id);
@@ -772,7 +772,7 @@
Logger.info(this, "Updating index ...");
- /*
+
if (key.startsWith("USK")) {
int negRev = 0;
@@ -781,13 +781,13 @@
key = FreenetURIHelper.changeUSKRevision(key,
negRev, 0);
}
}
- */
+
Logger.debug(this, "Key asked: "+key);
- clientGet = new FCPClientGet(key, 2, 2, false, -1,
+ clientGet = new FCPClientGet(key, 2, 2, false, 5,
System.getProperty("java.io.tmpdir"),
MAX_SIZE, true /* <= noDDA */);
@@ -1177,8 +1177,26 @@
infos.setAttribute("publicKey", getCommentPublicKey());
infos.setAttribute("privateKey", getCommentPrivateKey());
- /* TODO : Black list */
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+ st =
db.getConnection().prepareStatement("SELECT rev FROM indexCommentBlackList
WHERE indexId = ?");
+ st.setInt(1, id);
+
+ ResultSet set = st.executeQuery();
+
+ while (set.next()) {
+ Element bl =
xmlDoc.createElement("blackListed");
+ bl.setAttribute("rev",
set.getString("rev"));
+
+ infos.appendChild(bl);
+ }
+ }
+ } catch(SQLException e) {
+ Logger.error(this, "Unable to get comment black list
because: "+e.toString());
+ }
+
return infos;
}
@@ -1235,6 +1253,10 @@
st.setInt(1, id);
st.execute();
+ st =
db.getConnection().prepareStatement("DELETE FROM indexCommentBlackList WHERE
indexId = ?");
+ st.setInt(1, id);
+ st.execute();
+
} catch(SQLException e) {
Logger.error(this, "Hm, failure while starting
to parse the index: "+e.toString());
throw new SAXException("SQLException ; have a
nice day.");
@@ -1263,6 +1285,7 @@
private boolean ownerTag = false;
private boolean privateKeyTag = false;
+ private boolean commentsTag = false;
private boolean hasCommentTag = false;
@@ -1354,7 +1377,9 @@
insertFileSt.setLong(4, size);
insertFileSt.setInt(5, id);
- insertFileSt.execute();
+ synchronized(db.dbLock) {
+ insertFileSt.execute();
+ }
} catch(SQLException e) {
Logger.error(this, "Error while adding
file: "+e.toString());
}
@@ -1370,13 +1395,43 @@
if (pub != null && priv != null) {
hasCommentTag = true;
+ commentsTag = true;
Logger.debug(this, "Comment allowed in
this index");
setCommentKeys(pub, priv);
}
}
+ if ("blackListed".equals(rawName)) {
+ int blRev;
+ try {
+ blRev =
Integer.parseInt(attrs.getValue("rev"));
+ } catch(Exception e) {
+ /* quick and dirty */
+ return;
+ }
+
+ Logger.notice(this, "BlackListing rev
'"+Integer.toString(rev)+"'");
+
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+
+ st =
db.getConnection().prepareStatement("INSERT into indexCommentBlackList (rev,
indexId) VALUES (?, ?)");
+ st.setInt(1, blRev);
+ st.setInt(2, id);
+
+ st.execute();
+
+ }
+ } catch(SQLException e) {
+ Logger.error(this, "Error while adding
element to the blackList: "+e.toString());
+ }
+ }
+
+
+
/* ignore unknown tags */
/* et paf ! Ca fait des Chocapics(tm)(r)(c)(m)(dtc) ! */
@@ -1404,6 +1459,11 @@
privateKeyTag = false;
return;
}
+
+ if ("comments".equals(rawName)) {
+ commentsTag = false;
+ return;
+ }
}
@@ -1443,6 +1503,9 @@
return;
}
+
+
+
/* ignore unkwown stuffs */
}
@@ -1758,13 +1821,18 @@
synchronized(db.dbLock) {
PreparedStatement st;
- st =
db.getConnection().prepareStatement("DELETE FROM indexCommentKeys WHERE indexId
= ?");
+ st =
db.getConnection().prepareStatement("DELETE FROM indexCommentBlackList WHERE
indexId = ?");
st.setInt(1, id);
st.execute();
st =
db.getConnection().prepareStatement("DELETE FROM indexComments WHERE indexId =
?");
st.setInt(1, id);
st.execute();
+
+ st =
db.getConnection().prepareStatement("DELETE FROM indexCommentKeys WHERE indexId
= ?");
+ st.setInt(1, id);
+ st.execute();
+
}
} catch(SQLException e) {
Logger.error(this, "Unable to purge comment keys,
because : "+e.toString());
Modified: trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java 2007-04-23
17:31:42 UTC (rev 12903)
+++ trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java 2007-04-23
18:26:30 UTC (rev 12904)
@@ -116,7 +116,7 @@
int i;
if (x != null) {
- return
I18n.getMessage("thaw.plugin.signature.trustLevel.me");
+ return "thaw.plugin.signature.trustLevel.me";
}
for (i = 0 ; i < trustLevelInt.length ; i++) {