changeset 5083:d963e742fdc7

TwikiDraw applet added textcha feature
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sat, 05 Sep 2009 11:58:32 +0200
parents 3e1d3367aeaa
children 7c8aa4e9c0b8
files MoinMoin/action/twikidraw.py MoinMoin/web/static/htdocs/applets/TWikiDrawPlugin/twikidraw.jar contrib/TWikiDrawPlugin/build.xml contrib/TWikiDrawPlugin/src/CH/ifa/draw/twiki/TWikiDraw.java contrib/TWikiDrawPlugin/src/CH/ifa/draw/twiki/TWikiFrame.java
diffstat 5 files changed, 67 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/twikidraw.py	Wed Sep 02 19:54:04 2009 +0200
+++ b/MoinMoin/action/twikidraw.py	Sat Sep 05 11:58:32 2009 +0200
@@ -20,6 +20,7 @@
 from MoinMoin import wikiutil
 from MoinMoin.action import AttachFile, do_show
 from MoinMoin.Page import Page
+from MoinMoin.security.textcha import TextCha
 
 action_name = __name__.split('.')[-1]
 
@@ -121,6 +122,8 @@
         _ = self._
         pagename = self.pagename
         request = self.request
+        if not TextCha(request).check_answer_from_form():
+            return _('TextCha: Wrong answer! Go back and try again...')
         if not request.user.may.write(pagename):
             return _('You are not allowed to save a drawing on this page.')
 
@@ -172,7 +175,9 @@
         helplink = Page(request, "HelpOnActions/AttachFile").url(request)
         savelink = request.href(pagename, action=action_name, do='save', target=target)
         timestamp = '&amp;ts=%s' % now
-
+        question = ''
+        if TextCha(self.request).is_enabled():
+            question = TextCha(self.request).question
         html = '''<h2> %(editdrawing)s </h2>
 <p>
 <img src="%(pngpath)s%(timestamp)s">
@@ -184,6 +189,7 @@
 <param name="basename" value="%(basename)s">
 <param name="viewpath" value="%(url)s/%(pagename)s/">
 <param name="helppath" value="%(helplink)s">
+<param name="textchaquestion" value="%(textchaquestion)s">
 <strong>NOTE:</strong> You need a Java enabled browser to edit the drawing example.
 </applet>
 </p>''' % {
@@ -198,7 +204,8 @@
     'helplink': helplink,
     'savelink': savelink,
     'basename': wikiutil.escape(target, 1),
-    'editdrawing': _("Edit drawing")
+    'editdrawing': _("Edit drawing"),
+    'textchaquestion': question,
     }
 
         title = "%s:%s" % (pagename, target)
Binary file MoinMoin/web/static/htdocs/applets/TWikiDrawPlugin/twikidraw.jar has changed
--- a/contrib/TWikiDrawPlugin/build.xml	Wed Sep 02 19:54:04 2009 +0200
+++ b/contrib/TWikiDrawPlugin/build.xml	Sat Sep 05 11:58:32 2009 +0200
@@ -12,7 +12,7 @@
     </target>
 
     <target name="build" depends="-init" description="Build TWikiDrawPlugin JAR">
-        <javac destdir="${build.home}/classes" source="1.3" target="1.1">
+        <javac destdir="${build.home}/classes" source="1.3" target="1.1" executable="/usr/bin/javac -Xlint:deprecation">
             <src path="${src.home}/packages"/>
             <src path="${src.home}/src"/>
         </javac>
--- a/contrib/TWikiDrawPlugin/src/CH/ifa/draw/twiki/TWikiDraw.java	Wed Sep 02 19:54:04 2009 +0200
+++ b/contrib/TWikiDrawPlugin/src/CH/ifa/draw/twiki/TWikiDraw.java	Sat Sep 05 11:58:32 2009 +0200
@@ -5,6 +5,8 @@
  * modified, and distributed without fee provided that this 
  * copyright notice appears in all copies.
  * Portions Copyright (C) 2001 Motorola - All Rights Reserved
+ *
+ * 2009 MoinMoin:ReimarBauer TextCha feature added
  */
 
 package CH.ifa.draw.twiki;
@@ -74,6 +76,8 @@
 	String type,
 	String path,
 	String content,
+    String textchaquestion,
+    String textchaanswer,
 	String comment)
 	throws MalformedURLException, IOException {
 
@@ -82,7 +86,7 @@
 	    sep += "x";
 
 	String message = makeMimeForm(fileName, type,
-				      path, content, comment, sep);
+				      path, content, textchaquestion, textchaanswer, comment, sep);
 
         // for test
         //URL server = new URL("http", "localhost", 80, savePath);
@@ -179,6 +183,8 @@
 	String type,
 	String path,
 	String content,
+    String textchaquestion,
+    String textchaanswer,
 	String comment,
 	String sep) {
 
@@ -203,6 +209,12 @@
 	    + binary + NL
 	    + content
 	    + mime_sep
+        + "Content-Disposition: form-data; name=\"textcha-question\"" + NLNL
+	    + textchaquestion
+        + mime_sep
+        + "Content-Disposition: form-data; name=\"textcha-answer\"" + NLNL
+	    + textchaanswer
+        + mime_sep
 	    + "Content-Disposition: form-data; name=\"filecomment\"" + NLNL
 	    + comment
 	    + NL + "--" + sep + "--" + NL;
--- a/contrib/TWikiDrawPlugin/src/CH/ifa/draw/twiki/TWikiFrame.java	Wed Sep 02 19:54:04 2009 +0200
+++ b/contrib/TWikiDrawPlugin/src/CH/ifa/draw/twiki/TWikiFrame.java	Sat Sep 05 11:58:32 2009 +0200
@@ -5,6 +5,8 @@
  * modified, and distributed without fee provided that this 
  * copyright notice appears in all copies.
  * Portions Copyright (C) 2001 Motorola - All Rights Reserved
+ *
+ * 2009 MoinMoin:ReimarBauer TextCha feature added
  */
 
 package CH.ifa.draw.twiki;
@@ -34,6 +36,8 @@
      * Parameter names
      */
     static private String UNTITLED_PARAMETER   = "untitled";
+    static private String TEXTCHA_QUESTION_PARAMETER   = "textchaquestion";
+    static private String TEXTCHA_SEND_PARAMETER   = "textchaanswer";
     static private String DRAWPATH_PARAMETER   = "drawpath";
     static private String GIFPATH_PARAMETER    = "gifpath";
     static private String PNGPATH_PARAMETER    = "pngpath";
@@ -43,7 +47,8 @@
     static private String HELPPATH_PARAMETER   = "helppath";
     static private String BORDERSIZE_PARAMETER = "bordersize";
 
-    private Label fStatusLabel;
+    private Label fStatusLabel, fTextChaLabel;
+    private TextField fTextChaTextField;
 
     public TWikiFrame(Application applet) {
         super("TWikiDraw", applet);
@@ -240,7 +245,16 @@
 
         button = new CommandButton(new SendToBackCommand("Send To Back", view()));
         buttons.add(button);
-
+        
+        String question = getApplication().getParameter(TEXTCHA_QUESTION_PARAMETER);
+        if (question.length() > 0) {
+            fTextChaLabel = new Label(question);
+            panel.add(fTextChaLabel);
+            fTextChaTextField = new TextField(40);
+            panel.add(fTextChaTextField);
+        };
+                
+        
         button = new Button("Help");
 	button.addActionListener(
 	    new ActionListener() {
@@ -261,7 +275,7 @@
 	else
 	    getApplication().showStatus(s);
     }
-
+    
     /**
      * Workaround to get it work without update button
      */
@@ -337,8 +351,8 @@
 	
     public boolean doSaveDrawing() {
 		TWikiDraw app = (TWikiDraw)getApplication();
-		boolean savedDraw, savedSvg, savedGif, savedPng, savedMap;
-		savedDraw = savedSvg = savedGif = savedPng = savedMap = false;
+		boolean savedDraw, savedSvg, savedGif, savedPng, savedMap, savedTextCha, sendTextCha;
+		savedDraw = savedSvg = savedGif = savedPng = savedMap = savedTextCha = sendTextCha = false;
 		
 		// set wait cursor
 		setCursor(new Cursor(Cursor.WAIT_CURSOR));
@@ -362,7 +376,21 @@
 			String savePath = app.getParameter(SAVEPATH_PARAMETER);
 			if (savePath == null)
 				savePath = "";
-			
+
+            // textcha question
+            String textchaquestion = getApplication().getParameter(TEXTCHA_QUESTION_PARAMETER);
+            if (textchaquestion == null)
+				textchaquestion = "";
+
+			// sends textcha Answer
+            String textchaanswer = "";
+            if (textchaquestion.length() > 0) {
+                textchaanswer =  fTextChaTextField.getText();
+			    if (textchaanswer == null)
+				    textchaanswer = "";
+            } 
+
+
 			// gets base filename
 			String baseName = app.getParameter(BASENAME_PARAMETER);
 			if (baseName == null)
@@ -370,10 +398,10 @@
 			
 			// submit POST command to the server three times:
 			// *.draw, *.map and *.gif
-			// first upload *.draw file
 			showStatus("Saving " + baseName + ".draw");
-			savedDraw = app.post(savePath, baseName + ".draw", "text/plain", drawingPath,
-								 out.toString(), "TWikiDraw draw file");
+			savedDraw = app.post(savePath, baseName + ".draw", "text/plain", 
+                        drawingPath, out.toString(), textchaquestion,
+                        textchaanswer, "TWikiDraw draw file");
 			
 			// calculate the minimum size of the gif image
 			Dimension d = new Dimension(0, 0); // not this.view().getSize();
@@ -421,12 +449,14 @@
 					(d.width + iBorder) + "," + (d.height + iBorder) +
 					"\" href=\"%TWIKIDRAW%\" />\n" +
 					"</map>";
-				savedMap = app.post(savePath, baseName + ".map", "text/plain", mapPath + ".map",
-									map, "TWikiDraw map file");
+				savedMap = app.post(savePath, baseName + ".map", "text/plain",
+                                    mapPath + ".map", map, textchaquestion,
+                                    textchaanswer, "TWikiDraw map file");
 			} else {
 				// erase any previous map file
 				String mapPath = drawingPath.substring(0, drawingPath.length() - 5);
-				savedMap = app.post( savePath, baseName + ".map", "text/plain", mapPath + ".map", "", "");
+				savedMap = app.post( savePath, baseName + ".map", "text/plain",
+                        mapPath + ".map", "", textchaquestion,  textchaanswer, "");
             }
 			
             // get pathname of the SVG file
@@ -475,6 +505,7 @@
 					// upload *.png file
 					savedPng = app.post(savePath, baseName + ".png", "image/png",
 										pngPath, String.valueOf( aChar, 0, size),
+                                        textchaquestion,  textchaanswer,
 										"TWikiDraw PNG file");
 				}
 				
@@ -495,7 +526,7 @@
 					// upload *.gif file
 					savedGif = app.post(savePath, baseName + ".gif", "image/gif",
 										gifPath, String.valueOf( aChar, 0, size),
-										"TWikiDraw GIF file");
+										textchaquestion,  textchaanswer, "TWikiDraw GIF file");
 				}
 			}
 		} catch (MalformedURLException e) {