changeset 5088:a2a51a2ebd6e

twikidraw/anywikidraw action: make code more similar, clean up removed unused attrs, more conistent naming of attrs fixed comments remove h2 so that we have more space for anywikidraw add "Edit drawing" to title adjust w/h for anywikidraw so that there are no scrollbars add text hint for anywikidraw if there is no java add html escaping for values (urls, basename, ...)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 12 Sep 2009 18:38:37 +0200
parents d094bbd6c7c4
children 899b4b2cd7d5
files MoinMoin/action/anywikidraw.py MoinMoin/action/twikidraw.py
diffstat 2 files changed, 78 insertions(+), 89 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/anywikidraw.py	Sat Sep 12 08:33:37 2009 +0200
+++ b/MoinMoin/action/anywikidraw.py	Sat Sep 12 18:38:37 2009 +0200
@@ -134,7 +134,7 @@
         ci = AttachFile.ContainerItem(request, pagename, target + '.adraw')
         filecontent = file_upload.stream
         content_length = None
-        if ext == '.svg': # TWikiDraw POSTs this first
+        if ext == '.svg': # AnyWikiDraw POSTs this first
             AttachFile._addLogEntry(request, 'ATTDRW', pagename, target + '.adraw')
             ci.truncate()
             filecontent = filecontent.read() # read file completely into memory
@@ -159,61 +159,53 @@
         request = self.request
         pagename = self.pagename
         target = self.target
-        url = request.getQualifiedURL()
-        target_url = ''
-        drawing_name = ''
-
-        htdocs = "%s%s" % (request.cfg.url_prefix_static, '/applets/anywikidraw')
         ci = AttachFile.ContainerItem(request, pagename, target + '.adraw')
         if ci.exists():
-            drawing_name = "%s.svg" % target
-            target_url = ci.member_url('drawing.svg')
+            drawurl = ci.member_url('drawing.svg')
+        else:
+            drawurl = ''
+        pageurl = request.href(pagename)
+        saveurl = request.href(pagename, action=action_name, do='save', target=target)
+        helpurl = request.href("HelpOnActions/AttachFile")
+        #if TextCha(request).is_enabled():
+        #    textchaquestion = TextCha(request).question
+        #else:
+        #    textchaquestion = ''
 
         html = """
-    <h2> %(editdrawing)s </h2>
-<!--
-    Document   : anywikidraw_for_twiki_demo
-    Created on : May 13, 2008, 7:32:27 AM
-    Author     : werni
-    Version    : $Id: anywikidraw_for_twiki_demo.html 107 2009-06-15 19:33:05Z rawcoder $
-
-    adjusted for MoinMoin 2009-08-29 ReimarBauer
--->
-        <applet codebase="."
-                archive="%(htdocs)s/lib/AnyWikiDrawForTWiki.jar"
-                code=org.anywikidraw.twiki.TWikiDrawingApplet.class
-                width="800" height="600">
+<p>
+<applet code="org.anywikidraw.twiki.TWikiDrawingApplet.class" codebase="."
+        archive="%(htdocs)s/applets/anywikidraw/lib/AnyWikiDrawForTWiki.jar" width="800" height="620">
 
-           <!-- The following parameters are used to tell AnyWikiDraw how to communicate with MoinMoin.
-           -->
-           <param name="DrawingName" value="%(target)s.svg"/>
-           <param name="DrawingWidth" value="800"/>
-           <param name="DrawingHeight" value="600"/>
-           <param name="DrawingURL" value="%(target_url)s"/>
-           <param name="PageURL" value="%(url)s/%(pagename)s">
-           <param name="UploadURL" value="%(pagename)s?action=anywikidraw&do=save&target=%(target)s"/>
-
-           <!-- The following parameters are used to configure the drawing applet -->
-           <param name="Locale" value="en"/>
+    <!-- The following parameters are used to tell AnyWikiDraw how to communicate with MoinMoin. -->
+    <param name="DrawingName" value="%(basename)s.svg">
+    <param name="DrawingURL" value="%(drawurl)s">
+    <param name="DrawingWidth" value="640">
+    <param name="DrawingHeight" value="480">
+    <param name="PageURL" value="%(pageurl)s">
+    <param name="UploadURL" value="%(saveurl)s">
 
-           <!-- The following parameters are used to configure Sun's Java Plug-In -->
-           <param name="codebase_lookup" value="false"/>
-           <param name="classloader_cache" value="false"/>
-           <param name="java_arguments" value="-Djnlp.packEnabled=true"/>
-           <param name="image" value="lib/Splash.gif"/>
-           <param name="boxborder" value="false"/>
-           <param name="centerimage" value="true"/>
-        </applet>
-""" % {'htdocs': htdocs,
-       'pagename': pagename,
-       'target': target,
-       'drawing_name': drawing_name,
-       'target_url': target_url,
-       'url': url,
-       'editdrawing': _('Edit drawing'),
-       }
+    <!-- The following parameters are used to configure the drawing applet -->
+    <param name="Locale" value="en">
 
-        title = '%s:%s' % (pagename, target)
+    <!-- The following parameters are used to configure Sun's Java Plug-In -->
+    <param name="codebase_lookup" value="false">
+    <param name="classloader_cache" value="false">
+    <param name="java_arguments" value="-Djnlp.packEnabled=true">
+    <param name="boxborder" value="false">
+    <param name="centerimage" value="true">
+    <strong>NOTE:</strong> You need a Java enabled browser to edit the drawing.
+</applet>
+</p>
+""" % dict(
+    htdocs=request.cfg.url_prefix_static,
+    basename=wikiutil.escape(target, 1),
+    drawurl=wikiutil.escape(drawurl, 1),
+    pageurl=wikiutil.escape(pageurl, 1),
+    saveurl=wikiutil.escape(saveurl, 1),
+)
+
+        title = '%s %s:%s' % (_('Edit drawing'), pagename, target)
         request.theme.send_title(title, page=request.page, pagename=pagename)
         request.write(request.formatter.startContent("content"))
         request.write(request.formatter.rawHTML(html))
--- a/MoinMoin/action/twikidraw.py	Sat Sep 12 08:33:37 2009 +0200
+++ b/MoinMoin/action/twikidraw.py	Sat Sep 12 18:38:37 2009 +0200
@@ -12,7 +12,7 @@
                 2005-2009 MoinMoin:ReimarBauer,
     @license: GNU GPL, see COPYING for details.
 """
-import os, re, time
+import os, re
 
 from MoinMoin import log
 logging = log.getLogger(__name__)
@@ -166,50 +166,47 @@
         request = self.request
         pagename = self.pagename
         target = self.target
-        url = request.getQualifiedURL()
-        now = time.time()
-        htdocs = "%s%s" % (request.cfg.url_prefix_static, "/applets/TWikiDrawPlugin")
         ci = AttachFile.ContainerItem(request, pagename, target + '.tdraw')
-        drawpath = ci.member_url('drawing.draw')
-        pngpath = ci.member_url('drawing.png')
-        pagelink = request.href(pagename, action=action_name, ts=now)
-        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>
+        if ci.exists():
+            drawurl = ci.member_url('drawing.draw')
+            pngurl = ci.member_url('drawing.png')
+        else:
+            drawurl = 'drawing.draw'
+            pngurl = 'drawing.png'
+        pageurl = request.href(pagename)
+        saveurl = request.href(pagename, action=action_name, do='save', target=target)
+        helpurl = request.href("HelpOnActions/AttachFile")
+        if TextCha(request).is_enabled():
+            textchaquestion = TextCha(request).question
+        else:
+            textchaquestion = ''
+
+        html = """
 <p>
-<img src="%(pngpath)s%(timestamp)s">
 <applet code="CH.ifa.draw.twiki.TWikiDraw.class"
-        archive="%(htdocs)s/twikidraw.jar" width="640" height="480">
-<param name="drawpath" value="%(drawpath)s">
-<param name="pngpath"  value="%(pngpath)s">
-<param name="savepath" value="%(savelink)s">
-<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.
+        archive="%(htdocs)s/applets/TWikiDrawPlugin/twikidraw.jar" width="640" height="480">
+    <param name="drawpath" value="%(drawurl)s">
+    <param name="pngpath"  value="%(pngurl)s">
+    <param name="savepath" value="%(saveurl)s">
+    <param name="basename" value="%(basename)s">
+    <param name="viewpath" value="%(pageurl)s">
+    <param name="helppath" value="%(helpurl)s">
+    <param name="textchaquestion" value="%(textchaquestion)s">
+    <strong>NOTE:</strong> You need a Java enabled browser to edit the drawing.
 </applet>
-</p>''' % {
-    'pagename': pagename,
-    'url': url,
-    'target': target,
-    'pngpath': pngpath,
-    'timestamp': timestamp,
-    'htdocs': htdocs,
-    'drawpath': drawpath,
-    'pagelink': pagelink,
-    'helplink': helplink,
-    'savelink': savelink,
-    'basename': wikiutil.escape(target, 1),
-    'editdrawing': _("Edit drawing"),
-    'textchaquestion': question,
-    }
+</p>
+""" % dict(
+    htdocs=request.cfg.url_prefix_static,
+    basename=wikiutil.escape(target, 1),
+    drawurl=wikiutil.escape(drawurl, 1),
+    pngurl=wikiutil.escape(pngurl, 1),
+    pageurl=wikiutil.escape(pageurl, 1),
+    saveurl=wikiutil.escape(saveurl, 1),
+    helpurl=wikiutil.escape(helpurl, 1),
+    textchaquestion=wikiutil.escape(textchaquestion, 1),
+)
 
-        title = "%s:%s" % (pagename, target)
+        title = "%s %s:%s" % (_("Edit drawing"), pagename, target)
         request.theme.send_title(title, page=request.page, pagename=pagename)
         request.write(request.formatter.startContent("content"))
         request.write(request.formatter.rawHTML(html))