diff MoinMoin/wikiutil.py @ 1339:544b931cd965

new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 20 Aug 2006 13:50:27 +0200
parents 76a76def8687
children a796d366f176
line wrap: on
line diff
--- a/MoinMoin/wikiutil.py	Fri Aug 18 23:41:37 2006 +0200
+++ b/MoinMoin/wikiutil.py	Sun Aug 20 13:50:27 2006 +0200
@@ -191,7 +191,7 @@
     """
     if qstr is None:
         qstr = {}
-    if isinstance(qstr, type({})):
+    if isinstance(qstr, dict):
         qstr.update(kw)
         items = ['%s=%s' % (url_quote_plus(key, want_unicode=want_unicode), url_quote_plus(value, want_unicode=want_unicode)) for key, value in qstr.items()]
         qstr = '&'.join(items)
@@ -1458,6 +1458,8 @@
     @rtype: string
     @return: formatted link tag
     """
+    if formatter is None:
+        formatter = request.html_formatter
     if kw.has_key('css_class'):
         css_class = kw['css_class']
         del kw['css_class'] # one time is enough
@@ -1469,26 +1471,29 @@
         text = params # default
     if formatter:
         url = "%s/%s" % (request.getScriptname(), params)
+        # formatter.url will escape the url part
         if on is not None:
-            return formatter.url(on, url, css_class, **kw)
-        return (formatter.url(1, url, css_class, **kw) +
+            tag = formatter.url(on, url, css_class, **kw)
+        else:
+            tag = (formatter.url(1, url, css_class, **kw) +
                 formatter.rawHTML(text) +
                 formatter.url(0))
-    if on is not None and not on:
-        return '</a>'
-
-    attrs = ''
-    if css_class:
-        attrs += ' class="%s"' % css_class
-    if id:
-        attrs += ' id="%s"' % id
-    if name:
-        attrs += ' name="%s"' % name
-    result = '<a%s href="%s/%s">' % (attrs, request.getScriptname(), params)
-    if on:
-        return result
-    else:
-        return "%s%s</a>" % (result, text)
+    else: # this shouldn't be used any more:
+        if on is not None and not on:
+            tag = '</a>'
+        else:
+            attrs = ''
+            if css_class:
+                attrs += ' class="%s"' % css_class
+            if id:
+                attrs += ' id="%s"' % id
+            if name:
+                attrs += ' name="%s"' % name
+            tag = '<a%s href="%s/%s">' % (attrs, request.getScriptname(), params) # XXX wikiutil.escape(params) !?
+            if not on:
+                tag = "%s%s</a>" % (tag, text)
+        request.log("Warning: wikiutil.link_tag called without formatter and without request.html_formatter. tag=%r" % (tag, ))
+    return tag
 
 def containsConflictMarker(text):
     """ Returns true if there is a conflict marker in the text. """