changeset 2701:398af77c7ede

fixed attachment_link api - it now has a 'on' parameter like most of the other methods
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 19 Aug 2007 22:46:10 +0200
parents a0b85757e5d0
children 458e23c1349b cdda42a9d8a8
files MoinMoin/action/AttachFile.py MoinMoin/formatter/__init__.py MoinMoin/formatter/dom_xml.py MoinMoin/formatter/text_docbook.py MoinMoin/formatter/text_gedit.py MoinMoin/formatter/text_html.py MoinMoin/formatter/text_plain.py MoinMoin/formatter/text_python.py MoinMoin/formatter/text_xml.py MoinMoin/parser/text_creole.py MoinMoin/parser/text_moin_wiki.py docs/CHANGES
diffstat 12 files changed, 84 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/AttachFile.py	Sun Aug 19 17:17:53 2007 +0200
+++ b/MoinMoin/action/AttachFile.py	Sun Aug 19 22:46:10 2007 +0200
@@ -119,6 +119,21 @@
         url = wikiutil.escape(url)
     return url
 
+def getAttachUploadUrl(pagename, filename, request, addts=0, escaped=0):
+    """ Get URL that points to attachment `filename` of page `pagename` upload url.
+    """
+    if htdocs_access(request):
+        # direct file access via webserver - we don't support uploading files,
+        # so just fake some return value:
+        return getAttachUrl(pagename, filename, request, addts=addts, escaped=escaped)
+    else:
+        url = "%s/%s?action=%s&rename=%s" % (
+            request.getScriptname(), wikiutil.quoteWikinameURL(pagename),
+            action_name, wikiutil.url_quote_plus(filename))
+    if escaped:
+        url = wikiutil.escape(url)
+    return url
+
 def getIndicator(request, pagename):
     """ Get an attachment indicator for a page (linked clip image) or
         an empty string if not attachments exist.
--- a/MoinMoin/formatter/__init__.py	Sun Aug 19 17:17:53 2007 +0200
+++ b/MoinMoin/formatter/__init__.py	Sun Aug 19 22:46:10 2007 +0200
@@ -112,7 +112,7 @@
 
     # Attachments ######################################################
 
-    def attachment_link(self, url, text, **kw):
+    def attachment_link(self, on, url=None, **kw):
         raise NotImplementedError
     def attachment_image(self, url, **kw):
         raise NotImplementedError
--- a/MoinMoin/formatter/dom_xml.py	Sun Aug 19 17:17:53 2007 +0200
+++ b/MoinMoin/formatter/dom_xml.py	Sun Aug 19 22:46:10 2007 +0200
@@ -224,10 +224,13 @@
             kw['class'] = str(css)
         return self._set_tag('a', on, **kw)
 
-    def attachment_link(self, url, text, **kw):
+    def attachment_link(self, on, url=None, **kw):
         kw['href'] = url
         kw['type'] = 'link'
-        return self._set_tag('attachment', 1, **kw) + self.text(text) + self._set_tag('attachment', 0, **kw)
+        if on:
+            return self._set_tag('attachment', 1, **kw)
+        else:
+            return self._set_tag('attachment', 0, **kw)
 
     def attachment_image(self, url, **kw):
         kw['href'] = url
--- a/MoinMoin/formatter/text_docbook.py	Sun Aug 19 17:17:53 2007 +0200
+++ b/MoinMoin/formatter/text_docbook.py	Sun Aug 19 22:46:10 2007 +0200
@@ -395,18 +395,16 @@
 
 ### Attachments ######################################################
 
-    def attachment_link(self, url, text, **kw):
+    def attachment_link(self, on, url=None, **kw):
         _ = self.request.getText
         pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
         fname = wikiutil.taintfilename(filename)
-        fpath = AttachFile.getFilename(self.request, pagename, fname)
         target = AttachFile.getAttachUrl(pagename, filename, self.request)
-        if not os.path.exists(fpath):
-            return self.text("[attachment:%s]" % url)
+        # we do not output a "upload link" when outputting docbook
+        if on:
+            return self.url(1, target, title="attachment:%s" % url)
         else:
-            return (self.url(1, target, title="attachment:%s" % url) +
-                    self.text(text) +
-                    self.url(0))
+            return self.url(0)
 
     def attachment_image(self, url, **kw):
         _ = self.request.getText
--- a/MoinMoin/formatter/text_gedit.py	Sun Aug 19 17:17:53 2007 +0200
+++ b/MoinMoin/formatter/text_gedit.py	Sun Aug 19 22:46:10 2007 +0200
@@ -62,13 +62,14 @@
         else:
             return '<span style="background-color:#ffff11">[inline:%s %s]</span>' % (url, text)
 
-    def attachment_link(self, url, text, **kw):
+    def attachment_link(self, on, url=None, **kw):
         _ = self.request.getText
-        pagename = self.page.page_name
-        target = AttachFile.getAttachUrl(pagename, url, self.request)
-        return (self.url(1, target, title="attachment:%s" % wikiutil.quoteWikinameURL(url)) +
-                self.text(text) +
-                self.url(0))
+        if on:
+            pagename = self.page.page_name
+            target = AttachFile.getAttachUrl(pagename, url, self.request)
+            return self.url(on, target, title="attachment:%s" % wikiutil.quoteWikinameURL(url))
+        else:
+            return self.url(on)
 
     def attachment_image(self, url, **kw):
         _ = self.request.getText
--- a/MoinMoin/formatter/text_html.py	Sun Aug 19 17:17:53 2007 +0200
+++ b/MoinMoin/formatter/text_html.py	Sun Aug 19 22:46:10 2007 +0200
@@ -602,23 +602,29 @@
 
     # Attachments ######################################################
 
-    def attachment_link(self, url, text, **kw):
+    def attachment_link(self, on, url=None, **kw):
+        """ Link to an attachment.
+
+            @param on: 1/True=start link, 0/False=end link
+            @param url: filename.ext or PageName/filename.ext
+        """
+        assert on in (0, 1, False, True) # make sure we get called the new way, not like the 1.5 api was
         _ = self.request.getText
-        pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
-        #self.request.log("attachment_link: url %s pagename %s filename %s" % (url, pagename, filename))
-        fname = wikiutil.taintfilename(filename)
-        if not AttachFile.exists(self.request, pagename, fname):
-            linktext = _('Upload new attachment "%(filename)s"')
-            return wikiutil.link_tag(
-                self.request,
-                ('%s?action=AttachFile&rename=%s' %
-                 (wikiutil.quoteWikinameURL(pagename),
-                  wikiutil.url_quote_plus(fname))),
-                linktext % {'filename': self.text(fname)})
-        target = AttachFile.getAttachUrl(pagename, filename, self.request)
-        return (self.url(1, target, css='attachment', title="attachment:%s" % url) +
-                self.text(text) +
-                self.url(0))
+        if on:
+            pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
+            #self.request.log("attachment_link: url %s pagename %s filename %s" % (url, pagename, filename))
+            fname = wikiutil.taintfilename(filename)
+            if AttachFile.exists(self.request, pagename, fname):
+                target = AttachFile.getAttachUrl(pagename, fname, self.request)
+                title = "attachment:%s" % url
+                css = 'attachment'
+            else:
+                target = AttachFile.getAttachUploadUrl(pagename, fname, self.request)
+                title = _('Upload new attachment "%(filename)s"') % {'filename': wikiutil.escape(fname)}
+                css = 'attachment nonexistent'
+            return self.url(on, target, css=css, title=title)
+        else:
+            return self.url(on)
 
     def attachment_image(self, url, **kw):
         _ = self.request.getText
--- a/MoinMoin/formatter/text_plain.py	Sun Aug 19 17:17:53 2007 +0200
+++ b/MoinMoin/formatter/text_plain.py	Sun Aug 19 22:46:10 2007 +0200
@@ -69,8 +69,11 @@
                 self._text = None
                 return u' [%s]' % (self._url)
 
-    def attachment_link(self, url, text, **kw):
-        return "[%s]" % text
+    def attachment_link(self, on, url=None, **kw):
+        if on:
+            return "["
+        else:
+            return "]"
 
     def attachment_image(self, url, **kw):
         title = ''
--- a/MoinMoin/formatter/text_python.py	Sun Aug 19 17:17:53 2007 +0200
+++ b/MoinMoin/formatter/text_python.py	Sun Aug 19 22:46:10 2007 +0200
@@ -142,8 +142,8 @@
             return self.__insert_code('request.write(%s.pagelink(%r, page=page, **%r))' %
                                       (self.__formatter, on, kw))
 
-    def attachment_link(self, url, text, **kw):
-        return self.__insert_fmt_call('attachment_link', url, text, **kw)
+    def attachment_link(self, on, url=None, **kw):
+        return self.__insert_fmt_call('attachment_link', on, url, **kw)
 
     def attachment_image(self, url, **kw):
         return self.__insert_fmt_call('attachment_image', url, **kw)
--- a/MoinMoin/formatter/text_xml.py	Sun Aug 19 17:17:53 2007 +0200
+++ b/MoinMoin/formatter/text_xml.py	Sun Aug 19 22:46:10 2007 +0200
@@ -67,8 +67,11 @@
             str = ''
         return ('<jump href="%s"%s>' % (self._escape(url), str), '</jump>') [not on]
 
-    def attachment_link(self, url, text, **kw):
-        return '<attachment href="%s">%s</attachment>' % (url, text)
+    def attachment_link(self, on, url=None, **kw):
+        if on:
+            return '<attachment href="%s">' % (url, )
+        else:
+            return '</attachment>'
 
     def attachment_image(self, url, **kw):
         return '<attachmentimage href="%s"></attachmentimage>' % (url, )
--- a/MoinMoin/parser/text_creole.py	Sun Aug 19 17:17:53 2007 +0200
+++ b/MoinMoin/parser/text_creole.py	Sun Aug 19 22:46:10 2007 +0200
@@ -627,7 +627,9 @@
     def attachment_emit(self, node):
         url = wikiutil.url_unquote(node.content, want_unicode=True)
         text = self.get_text(node)
-        return self.formatter.attachment_link(url, text)
+        return (self.formatter.attachment_link(1, url) +
+                self.formatter.text(text) +
+                self.formatter.attachment_link(0))
 
     def inlined_attachment_emit(self, node):
         url = wikiutil.url_unquote(node.content, want_unicode=True)
--- a/MoinMoin/parser/text_moin_wiki.py	Sun Aug 19 17:17:53 2007 +0200
+++ b/MoinMoin/parser/text_moin_wiki.py	Sun Aug 19 22:46:10 2007 +0200
@@ -238,7 +238,9 @@
                     url = AttachFile.getAttachUrl(pagename, fname, self.request, escaped=1)
                     return self.formatter.rawHTML(EmbedObject.embed(EmbedObject(macro, wikiutil.escape(fname)), mt, url))
 
-        return self.formatter.attachment_link(fname, text)
+        return (self.formatter.attachment_link(1, fname) +
+                self.formatter.text(text) +
+                self.formatter.attachment_link(0))
 
     def _u_repl(self, word):
         """Handle underline."""
--- a/docs/CHANGES	Sun Aug 19 17:17:53 2007 +0200
+++ b/docs/CHANGES	Sun Aug 19 22:46:10 2007 +0200
@@ -28,19 +28,14 @@
     and improving it and after having made a backup with some other, proven
     method. USE BOTH ON YOUR OWN RISK!
 
-Version 1.5.current:
-  Bugfixes:
-    * AttachFile overwrite mode (introduced in 1.5.7) did not check delete
-      rights, but only write rights. Now it checks that the user has write AND
-      delete rights before overwriting a file.
-
 Version 1.7.current:
     This is the active development branch. All changes get done here and
     critical stuff gets committed with -m "... (backport needed)" and then
     backported to older releases that we still maintain. :)
 
   Developer notes (these should be moved to the end in the release):
-    * ...
+    * changed formatter.attachment_link call (it is now more flexible,
+      because you can render the stuff between link start and link end yourself)
 
   New Features:
     * cfg.trusted_auth_methods
@@ -56,6 +51,9 @@
     * ...
 
   Other changes:
+    * attachment links for non-existing attachments look different now:
+      the note about the non-existing attachment moved to the link title,
+      the link is shown with nonexistent class (grey).
     * cfg.show_login is gone, see code in theme/__init__.py, this affects
       many themes!
     * needs a new userprefs/ plugin directory
@@ -523,6 +521,12 @@
     * Removed Lupy based indexed search code. If you were brave enough to
       use cfg.lupy_search, you maybe want to try cfg.xapian_search instead.
 
+Version 1.5.current:
+  Bugfixes:
+    * AttachFile overwrite mode (introduced in 1.5.7) did not check delete
+      rights, but only write rights. Now it checks that the user has write AND
+      delete rights before overwriting a file.
+
 Version 1.5.8:
   New features:
     * Added timing.log to help performance debugging. Use cfg.log_timing = True