Factor parser delegate impl into an ABC.
diff --git a/readme.txt b/readme.txt
--- a/readme.txt
+++ b/readme.txt
@@ -89,7 +89,8 @@ BUG: MUST show in the UI when edited wik
BUG: Can the <<<TOC>>> macro be made to play nice with the ContentFilter?
---
IDEA: shrink blocks by using a token map? use short token in binary rep, fixup to full 20byte hash on read / write?
-IDEA: Support links to other wikis. e.g.: fniki://fms/group/name
+IDEA: Support links to other wikis. e.g.:b fniki://fms/group/name
+ [Not quite. Should be able to support mutliple transports (fms, ft, freemail?, fproxy usk?) in same url]
IDEA: Caching in FreenetIO
Make LinkCache and interface
FreenetLinkCache extends LinkCache
@@ -105,6 +106,10 @@ IDEA: Pillage glog graph drawing code fr
IDEA: Ditch human readable name <--> SSK fixup and generate arbitrary names from
SSK public key hash (== big number). <n_first>*<m_middle>*<o_last> == big number
let n = 1000, m = 1000, o == 1000 => ???? [NOT QUITE. LOOK UP Combinatorics]
+IDEA: Staking. add a biss message that says "I say this version is good"
+ not "I published this version". Add feedback in UI to show how many nyms staked a given version.
+IDEA: Wikibot ng. Just uses its FMS trust info to decide which version is the latest and
+ send a "Stake" biss message for it.
---
Fixed bugs:
2ce3a4499a2c: BUG: No way to create an empty wiki from the UI. [requested by a real user]
diff --git a/src/fniki/wiki/WikiApp.java b/src/fniki/wiki/WikiApp.java
--- a/src/fniki/wiki/WikiApp.java
+++ b/src/fniki/wiki/WikiApp.java
@@ -270,99 +270,34 @@ public class WikiApp implements ChildCon
}
////////////////////////////////////////////////////////////
- private static class LocalParserDelegate implements FreenetWikiTextParser.ParserDelegate {
- // Pedantic. Explictly copy references instead of making this class non-static
- // so that the code uses well defined interfaces.
+ private static class LocalParserDelegate extends WikiParserDelegate {
final WikiContext mContext;
- final ArchiveManager mArchiveManager;
LocalParserDelegate(WikiContext context, ArchiveManager archiveManager) {
+ super(archiveManager);
mContext = context;
- mArchiveManager = archiveManager;
}
- public boolean processedMacro(StringBuilder sb, String text) {
- if (text.equals("LocalChanges")) {
- try {
- FileManifest.Changes changes = mArchiveManager.getLocalChanges();
- if (changes.isUnmodified()) {
- sb.append("<br>No local changes.<br>");
- return true;
- }
- appendChangesHtml(changes, containerPrefix(), sb);
- return true;
- } catch (IOException ioe) {
- sb.append("{ERROR PROCESSING LOCALCHANGES MACRO}");
- return true;
- }
- } else if (text.equals("TitleIndex")) {
- try {
- for (String name : mArchiveManager.getStorage().getNames()) {
- appendPageLink(containerPrefix(), sb, name, null, true);
- sb.append("<br>");
- }
- } catch (IOException ioe) {
- sb.append("{ERROR PROCESSING TITLEINDEX MACRO}");
- return true;
- }
- return true;
- }
-
- return false;
+ // Implement base class abstract methods to supply the functionality
+ // specific to live wikis, mostly by delegating to the WikiContext.
+ protected String getContainerPrefix() {
+ return containerPrefix(); // LATER: revisit.
}
- // CHK, SSK, USK freenet links.
- public void appendLink(StringBuilder sb, String text) {
- String fproxyPrefix = mContext.getString("fproxy_prefix", null);
-
- String[] link=split(text, '|');
- if (fproxyPrefix != null &&
- isValidFreenetUri(link[0])) {
- sb.append("<a href=\""+ makeFproxyHref(fproxyPrefix, link[0].trim()) +"\" rel=\"nofollow\">");
- sb.append(escapeHTML(unescapeHTML(link.length>=2 && !isEmpty(link[1].trim())? link[1]:link[0])));
- sb.append("</a>");
- return;
- }
- if (isAlphaNumOrUnder(link[0])) {
- // Link to an internal wiki page.
- sb.append("<a href=\""+ makeHref(mContext.makeLink("/" + link[0].trim())) +"\" rel=\"nofollow\">");
- sb.append(escapeHTML(unescapeHTML(link.length>=2 && !isEmpty(link[1].trim())? link[1]:link[0])));
- sb.append("</a>");
- return;
- }
-
- sb.append("<a href=\"" + makeHref(mContext.makeLink("/ExternalLink")) +"\" rel=\"nofollow\">");
- sb.append(escapeHTML(unescapeHTML(link.length>=2 && !isEmpty(link[1].trim())? link[1]:link[0])));
- sb.append("</a>");
+ protected String getFproxyPrefix() {
+ return mContext.getString("fproxy_prefix", null);
}
- // Only CHK and SSK freenet links.
- public void appendImage(StringBuilder sb, String text) {
- boolean allowed = mContext.getInt("allow_images", 0) != 0;
- if (!allowed) {
- sb.append("{IMAGES DISABLED. IMAGE WIKITEXT IGNORED}");
- return;
- }
+ protected boolean getImagesAllowed() {
+ return mContext.getInt("allow_images", 0) != 0;
+ }
- String fproxyPrefix = mContext.getString("fproxy_prefix", null);
- if (fproxyPrefix == null) {
- sb.append("{FPROXY PREFIX NOT SET. IMAGE WIKITEXT IGNORED}");
- return;
- }
-
- String[] link=split(text, '|');
- if (fproxyPrefix != null &&
- isValidFreenetUri(link[0]) &&
- !link[0].startsWith("freenet:USK@")) {
- String alt=escapeHTML(unescapeHTML(link.length>=2 && !isEmpty(link[1].trim())? link[1]:link[0]));
- sb.append("<img src=\"" + makeFproxyHref(fproxyPrefix, link[0].trim())
- + "\" alt=\""+alt+"\" title=\""+alt+"\" />");
- return;
- }
- sb.append("{ERROR PROCESSING IMAGE WIKITEXT}");;
+ protected String makeLink(String containerRelativePath) {
+ return mContext.makeLink(containerRelativePath);
}
}
+ // Hrrmm.. kind of weird. I can't remember why I used this static method instead of a constant.
// NO trailing slash.
private static String containerPrefix() { return "/plugins/fniki.freenet.plugin.Fniki"; }
diff --git a/src/fniki/wiki/WikiParserDelegate.java b/src/fniki/wiki/WikiParserDelegate.java
new file mode 100644
--- /dev/null
+++ b/src/fniki/wiki/WikiParserDelegate.java
@@ -0,0 +1,130 @@
+/* A base class for common parts of FreenetWikiTextParser.ParserDelegate implementations.
+ *
+ * INTENT: I did this so code could be shared between the live wiki and html dumping.
+ *
+ * Copyright (C) 2010, 2011 Darrell Karbott
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.0 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: djk@isFiaD04zgAgnrEC5XJt1i4IE7AkNPqhBG5bONi6Yks
+ *
+ * This file was developed as component of
+ * "fniki" (a wiki implementation running over Freenet).
+ */
+
+package fniki.wiki;
+
+import static ys.wikiparser.Utils.*; // DCI: clean up
+
+import java.io.IOException;
+
+import wormarc.FileManifest;
+
+import static fniki.wiki.HtmlUtils.*;
+import static fniki.wiki.Validations.*;
+
+public abstract class WikiParserDelegate implements FreenetWikiTextParser.ParserDelegate {
+ final ArchiveManager mArchiveManager;
+
+ public WikiParserDelegate(ArchiveManager archiveManager) {
+ mArchiveManager = archiveManager;
+ }
+
+ protected abstract String getContainerPrefix();
+ protected abstract String getFproxyPrefix();
+ protected abstract boolean getImagesAllowed();
+ protected abstract String makeLink(String containerRelativePath);
+
+ public boolean processedMacro(StringBuilder sb, String text) {
+ if (text.equals("LocalChanges")) {
+ try {
+ FileManifest.Changes changes = mArchiveManager.getLocalChanges();
+ if (changes.isUnmodified()) {
+ sb.append("<br>No local changes.<br>");
+ return true;
+ }
+ appendChangesHtml(changes, getContainerPrefix(), sb);
+ return true;
+ } catch (IOException ioe) {
+ sb.append("{ERROR PROCESSING LOCALCHANGES MACRO}");
+ return true;
+ }
+ } else if (text.equals("TitleIndex")) {
+ try {
+ for (String name : mArchiveManager.getStorage().getNames()) {
+ appendPageLink(getContainerPrefix(), sb, name, null, true);
+ sb.append("<br>");
+ }
+ } catch (IOException ioe) {
+ sb.append("{ERROR PROCESSING TITLEINDEX MACRO}");
+ return true;
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ // CHK, SSK, USK freenet links.
+ public void appendLink(StringBuilder sb, String text) {
+ String fproxyPrefix = getFproxyPrefix();
+
+ String[] link=split(text, '|');
+ if (fproxyPrefix != null &&
+ isValidFreenetUri(link[0])) {
+ sb.append("<a href=\""+ makeFproxyHref(fproxyPrefix, link[0].trim()) +"\" rel=\"nofollow\">");
+ sb.append(escapeHTML(unescapeHTML(link.length>=2 && !isEmpty(link[1].trim())? link[1]:link[0])));
+ sb.append("</a>");
+ return;
+ }
+ if (isAlphaNumOrUnder(link[0])) {
+ // Link to an internal wiki page.
+ sb.append("<a href=\""+ makeHref(makeLink("/" + link[0].trim())) +"\" rel=\"nofollow\">");
+ sb.append(escapeHTML(unescapeHTML(link.length>=2 && !isEmpty(link[1].trim())? link[1]:link[0])));
+ sb.append("</a>");
+ return;
+ }
+
+ sb.append("<a href=\"" + makeHref(makeLink("/ExternalLink")) +"\" rel=\"nofollow\">");
+ sb.append(escapeHTML(unescapeHTML(link.length>=2 && !isEmpty(link[1].trim())? link[1]:link[0])));
+ sb.append("</a>");
+ }
+
+ // Only CHK and SSK freenet links.
+ public void appendImage(StringBuilder sb, String text) {
+ if (!getImagesAllowed()) {
+ sb.append("{IMAGES DISABLED. IMAGE WIKITEXT IGNORED}");
+ return;
+ }
+
+ String fproxyPrefix = getFproxyPrefix();
+ if (fproxyPrefix == null) {
+ sb.append("{FPROXY PREFIX NOT SET. IMAGE WIKITEXT IGNORED}");
+ return;
+ }
+
+ String[] link=split(text, '|');
+ if (fproxyPrefix != null &&
+ isValidFreenetUri(link[0]) &&
+ !link[0].startsWith("freenet:USK@")) {
+ String alt=escapeHTML(unescapeHTML(link.length>=2 && !isEmpty(link[1].trim())? link[1]:link[0]));
+ sb.append("<img src=\"" + makeFproxyHref(fproxyPrefix, link[0].trim())
+ + "\" alt=\""+alt+"\" title=\""+alt+"\" />");
+ return;
+ }
+ sb.append("{ERROR PROCESSING IMAGE WIKITEXT}");;
+ }
+}
+