|
|
|
@ -56,7 +56,6 @@ import de.anomic.data.wiki.abstractWikiParser;
|
|
|
|
|
import de.anomic.data.wiki.wikiParser;
|
|
|
|
|
import de.anomic.plasma.plasmaSwitchboard;
|
|
|
|
|
import de.anomic.server.serverCore;
|
|
|
|
|
import de.anomic.yacy.yacyCore;
|
|
|
|
|
|
|
|
|
|
/** This class provides methods to handle texts that have been posted in the yacyWiki or other
|
|
|
|
|
* parts of YaCy that use this class, like the blog or the profile.
|
|
|
|
@ -107,11 +106,12 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
protected String transform(
|
|
|
|
|
BufferedReader reader,
|
|
|
|
|
int length,
|
|
|
|
|
String publicAddress,
|
|
|
|
|
plasmaSwitchboard switchboard) throws IOException {
|
|
|
|
|
StringBuffer out = new StringBuffer(length);
|
|
|
|
|
String line;
|
|
|
|
|
while ((line = reader.readLine()) != null)
|
|
|
|
|
out.append(transformLine(line, switchboard)).append(serverCore.crlfString);
|
|
|
|
|
out.append(transformLine(line, publicAddress, switchboard)).append(serverCore.crlfString);
|
|
|
|
|
return out.insert(0, directory()).toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -395,7 +395,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
/** This method processes links and images.
|
|
|
|
|
*/
|
|
|
|
|
//contributed by [AS] except where stated otherwise
|
|
|
|
|
private String linksAndImages(String result, plasmaSwitchboard switchboard){
|
|
|
|
|
private String linksAndImages(String result, String publicAddress, plasmaSwitchboard switchboard) {
|
|
|
|
|
|
|
|
|
|
// create links
|
|
|
|
|
String kl, kv, alt, align;
|
|
|
|
@ -448,7 +448,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
// or an image DATA/HTDOCS/grafics/kaskelix.jpg with [[Image:grafics/kaskelix.jpg]]
|
|
|
|
|
// you are free to use other sub-paths of DATA/HTDOCS
|
|
|
|
|
if (kl.indexOf("://")<1) {
|
|
|
|
|
kl = "http://" + yacyCore.seedDB.mySeed.getPublicAddress().trim() + "/" + kl;
|
|
|
|
|
kl = "http://" + publicAddress.trim() + "/" + kl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = result.substring(0, p0) + "<img src=\"" + kl + "\"" + align + alt + ">" + result.substring(p1 + 2);
|
|
|
|
@ -463,10 +463,11 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
} else {
|
|
|
|
|
kv = kl;
|
|
|
|
|
}
|
|
|
|
|
if (switchboard.wikiDB.read(kl) != null)
|
|
|
|
|
if (switchboard != null && switchboard.wikiDB.read(kl) != null) {
|
|
|
|
|
result = result.substring(0, p0) + "<a class=\"known\" href=\"Wiki.html?page=" + kl + "\">" + kv + "</a>" + result.substring(p1 + 2);
|
|
|
|
|
else
|
|
|
|
|
} else {
|
|
|
|
|
result = result.substring(0, p0) + "<a class=\"unknown\" href=\"Wiki.html?page=" + kl + "&edit=Edit\">" + kv + "</a>" + result.substring(p1 + 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -488,8 +489,8 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
// using the wikicode [share/page.html]
|
|
|
|
|
// or a file DATA/HTDOCS/www/page.html with [www/page.html]
|
|
|
|
|
// you are free to use other sub-paths of DATA/HTDOCS
|
|
|
|
|
if (kl.indexOf("://")<1) {
|
|
|
|
|
kl = "http://" + yacyCore.seedDB.mySeed.getPublicAddress().trim() + "/" + kl;
|
|
|
|
|
if (kl.indexOf("://") < 1) {
|
|
|
|
|
kl = "http://" + publicAddress.trim() + "/" + kl;
|
|
|
|
|
}
|
|
|
|
|
result = result.substring(0, p0) + "<a class=\"extern\" href=\"" + kl + "\">" + kv + "</a>" + result.substring(p1 + 1);
|
|
|
|
|
}
|
|
|
|
@ -498,7 +499,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
|
|
|
|
|
/** This method handles the escape tags [= =] */
|
|
|
|
|
//contributed by [MN]
|
|
|
|
|
private String escapeTag(String result, plasmaSwitchboard switchboard){
|
|
|
|
|
private String escapeTag(String result, String publicAddress, plasmaSwitchboard switchboard){
|
|
|
|
|
int p0 = 0;
|
|
|
|
|
int p1 = 0;
|
|
|
|
|
//both [= and =] in the same line
|
|
|
|
@ -506,16 +507,16 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
if(p0<p1){
|
|
|
|
|
String escapeText = result.substring(p0+2,p1);
|
|
|
|
|
escapeText = escapeText.replaceAll("!esc!", "!esc!!");
|
|
|
|
|
result = transformLine(result.substring(0,p0).replaceAll("!esc!", "!esc!!")+"!esc!txt!"+result.substring(p1+2).replaceAll("!esc!", "!esc!!"), switchboard);
|
|
|
|
|
result = transformLine(result.substring(0,p0).replaceAll("!esc!", "!esc!!")+"!esc!txt!"+result.substring(p1+2).replaceAll("!esc!", "!esc!!"), publicAddress, switchboard);
|
|
|
|
|
result = result.replaceAll("!esc!txt!", escapeText);
|
|
|
|
|
result = result.replaceAll("!esc!!", "!esc!");
|
|
|
|
|
}
|
|
|
|
|
//handles cases like [=[= =]=] [= =] that would cause an exception otherwise
|
|
|
|
|
else{
|
|
|
|
|
escape = true;
|
|
|
|
|
String temp1 = transformLine(result.substring(0,p0-1).replaceAll("!tmp!","!tmp!!")+"!tmp!txt!", switchboard);
|
|
|
|
|
String temp1 = transformLine(result.substring(0,p0-1).replaceAll("!tmp!","!tmp!!")+"!tmp!txt!", publicAddress, switchboard);
|
|
|
|
|
nolist = true;
|
|
|
|
|
String temp2 = transformLine(result.substring(p0), switchboard);
|
|
|
|
|
String temp2 = transformLine(result.substring(p0), publicAddress, switchboard);
|
|
|
|
|
nolist = false;
|
|
|
|
|
result = temp1.replaceAll("!tmp!txt!",temp2);
|
|
|
|
|
result = result.replaceAll("!tmp!!", "!tmp!");
|
|
|
|
@ -535,7 +536,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
escindented++;
|
|
|
|
|
bq = bq + "<blockquote>";
|
|
|
|
|
}
|
|
|
|
|
result = transformLine(result.substring(escindented,p0).replaceAll("!esc!", "!esc!!")+"!esc!txt!", switchboard);
|
|
|
|
|
result = transformLine(result.substring(escindented,p0).replaceAll("!esc!", "!esc!!")+"!esc!txt!", publicAddress, switchboard);
|
|
|
|
|
result = bq + result.replaceAll("!esc!txt!", escapeText);
|
|
|
|
|
result = result.replaceAll("!esc!!", "!esc!");
|
|
|
|
|
escape = false;
|
|
|
|
@ -553,7 +554,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
bq = bq + "</blockquote>";
|
|
|
|
|
escindented--;
|
|
|
|
|
}
|
|
|
|
|
result = transformLine("!esc!txt!"+result.substring(p0+2).replaceAll("!esc!", "!esc!!"), switchboard);
|
|
|
|
|
result = transformLine("!esc!txt!"+result.substring(p0+2).replaceAll("!esc!", "!esc!!"), publicAddress, switchboard);
|
|
|
|
|
result = result.replaceAll("!esc!txt!", escapeText) + bq;
|
|
|
|
|
result = result.replaceAll("!esc!!", "!esc!");
|
|
|
|
|
escaped = false;
|
|
|
|
@ -563,14 +564,14 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
while((p0 = result.indexOf("=]"))>=0){
|
|
|
|
|
result = result.substring(0,p0)+result.substring(p0+2);
|
|
|
|
|
}
|
|
|
|
|
result = transformLine(result, switchboard);
|
|
|
|
|
result = transformLine(result, publicAddress, switchboard);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** This method handles the preformatted tags <pre> </pre> */
|
|
|
|
|
//contributed by [MN]
|
|
|
|
|
private String preformattedTag(String result, plasmaSwitchboard switchboard){
|
|
|
|
|
private String preformattedTag(String result, String publicAddress, plasmaSwitchboard switchboard){
|
|
|
|
|
int p0 = 0;
|
|
|
|
|
int p1 = 0;
|
|
|
|
|
//implementation very similar to escape code (see above)
|
|
|
|
@ -579,16 +580,16 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
if(p0<p1){
|
|
|
|
|
String preformattedText = "<pre style=\"border:dotted;border-width:thin\">"+result.substring(p0+11,p1)+"</pre>";
|
|
|
|
|
preformattedText = preformattedText.replaceAll("!pre!", "!pre!!");
|
|
|
|
|
result = transformLine(result.substring(0,p0).replaceAll("!pre!", "!pre!!")+"!pre!txt!"+result.substring(p1+12).replaceAll("!pre!", "!pre!!"), switchboard);
|
|
|
|
|
result = transformLine(result.substring(0,p0).replaceAll("!pre!", "!pre!!")+"!pre!txt!"+result.substring(p1+12).replaceAll("!pre!", "!pre!!"), publicAddress, switchboard);
|
|
|
|
|
result = result.replaceAll("!pre!txt!", preformattedText);
|
|
|
|
|
result = result.replaceAll("!pre!!", "!pre!");
|
|
|
|
|
}
|
|
|
|
|
//handles cases like <pre><pre> </pre></pre> <pre> </pre> that would cause an exception otherwise
|
|
|
|
|
else{
|
|
|
|
|
preformatted = true;
|
|
|
|
|
String temp1 = transformLine(result.substring(0,p0-1).replaceAll("!tmp!","!tmp!!")+"!tmp!txt!", switchboard);
|
|
|
|
|
String temp1 = transformLine(result.substring(0,p0-1).replaceAll("!tmp!","!tmp!!")+"!tmp!txt!", publicAddress, switchboard);
|
|
|
|
|
nolist = true;
|
|
|
|
|
String temp2 = transformLine(result.substring(p0), switchboard);
|
|
|
|
|
String temp2 = transformLine(result.substring(p0), publicAddress, switchboard);
|
|
|
|
|
nolist = false;
|
|
|
|
|
result = temp1.replaceAll("!tmp!txt!",temp2);
|
|
|
|
|
result = result.replaceAll("!tmp!!", "!tmp!");
|
|
|
|
@ -607,7 +608,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
preindented++;
|
|
|
|
|
bq = bq + "<blockquote>";
|
|
|
|
|
}
|
|
|
|
|
result = transformLine(result.substring(preindented,p0).replaceAll("!pre!", "!pre!!")+"!pre!txt!", switchboard);
|
|
|
|
|
result = transformLine(result.substring(preindented,p0).replaceAll("!pre!", "!pre!!")+"!pre!txt!", publicAddress, switchboard);
|
|
|
|
|
result = bq + result.replaceAll("!pre!txt!", preformattedText);
|
|
|
|
|
result = result.replaceAll("!pre!!", "!pre!");
|
|
|
|
|
preformattedSpan = true;
|
|
|
|
@ -624,7 +625,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
bq = bq + "</blockquote>";
|
|
|
|
|
preindented--;
|
|
|
|
|
}
|
|
|
|
|
result = transformLine("!pre!txt!"+result.substring(p0+12).replaceAll("!pre!", "!pre!!"), switchboard);
|
|
|
|
|
result = transformLine("!pre!txt!"+result.substring(p0+12).replaceAll("!pre!", "!pre!!"), publicAddress, switchboard);
|
|
|
|
|
result = result.replaceAll("!pre!txt!", preformattedText) + bq;
|
|
|
|
|
result = result.replaceAll("!pre!!", "!pre!");
|
|
|
|
|
preformatted = false;
|
|
|
|
@ -634,7 +635,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
while((p0 = result.indexOf("</pre>"))>=0){
|
|
|
|
|
result = result.substring(0,p0)+result.substring(p0+12);
|
|
|
|
|
}
|
|
|
|
|
result = transformLine(result, switchboard);
|
|
|
|
|
result = transformLine(result, publicAddress, switchboard);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@ -773,7 +774,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
* @param switchboard
|
|
|
|
|
* @return the line of text with HTML tags instead of wiki tags
|
|
|
|
|
*/
|
|
|
|
|
public String transformLine(String result, plasmaSwitchboard switchboard) {
|
|
|
|
|
public String transformLine(String result, String publicAddress, plasmaSwitchboard switchboard) {
|
|
|
|
|
//If HTML has not bee replaced yet (can happen if method gets called in recursion), replace now!
|
|
|
|
|
if (!replacedHTML || preformattedSpan){
|
|
|
|
|
result = htmlTools.replaceXMLEntities(result);
|
|
|
|
@ -787,12 +788,12 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
|
|
|
|
|
//check if line contains escape symbols([= =]) or if we are in an escape sequence already.
|
|
|
|
|
if ((result.indexOf("[=")>=0)||(result.indexOf("=]")>=0)||(escapeSpan)){
|
|
|
|
|
result = escapeTag(result, switchboard);
|
|
|
|
|
result = escapeTag(result, publicAddress, switchboard);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//check if line contains preformatted symbols or if we are in a preformatted sequence already.
|
|
|
|
|
else if ((result.indexOf("<pre>")>=0)||(result.indexOf("</pre>")>=0)||(preformattedSpan)){
|
|
|
|
|
result = preformattedTag(result, switchboard);
|
|
|
|
|
result = preformattedTag(result, publicAddress, switchboard);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//transform page as usual
|
|
|
|
@ -831,7 +832,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
|
|
|
|
|
result = orderedList(result);
|
|
|
|
|
result = definitionList(result);
|
|
|
|
|
|
|
|
|
|
result = linksAndImages(result, switchboard);
|
|
|
|
|
result = linksAndImages(result, publicAddress, switchboard);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|