diff MoinMoin/wikiaction.py @ 51:54d5932d5a03

merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action Patches applied: * arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-930 fix error handling in plugins, fix broken chart action * nirs@freeshell.org--2005/moin--fix--1.3--patch-50 merge from main * nirs@freeshell.org--2005/moin--fix--1.3--patch-51 fix error handling in plugins * nirs@freeshell.org--2005/moin--fix--1.3--patch-52 merge from main * nirs@freeshell.org--2005/moin--fix--1.3--patch-53 update changes with chart action fix imported from: moin--main--1.5--patch-52
author Nir Soffer <nirs@freeshell.org>
date Thu, 29 Sep 2005 00:36:27 +0000
parents 9f6c1868c0c8
children 699811601bed
line wrap: on
line diff
--- a/MoinMoin/wikiaction.py	Thu Sep 29 00:09:43 2005 +0000
+++ b/MoinMoin/wikiaction.py	Thu Sep 29 00:36:27 2005 +0000
@@ -830,13 +830,14 @@
         mimetype = u"text/plain"
 
     # try to load the formatter
-    Formatter = wikiutil.importPlugin(request.cfg, "formatter",
-        mimetype.translate({ord(u'/'): u'_', ord(u'.'): u'_'}), "Formatter")
-    if Formatter is None:
+    formatterName = mimetype.translate({ord(u'/'): u'_', ord(u'.'): u'_'})
+    try:
+        Formatter = wikiutil.importPlugin(request.cfg, "formatter",
+                                          formatterName, "Formatter")
+    except ImportError:
         # default to plain text formatter
-        del Formatter
         mimetype = "text/plain"
-        from formatter.text_plain import Formatter
+        from MoinMoin.formatter.text_plain import Formatter
 
     if "xml" in mimetype:
         mimetype = "text/xml"
@@ -847,10 +848,31 @@
 
 
 def do_chart(pagename, request):
-    if request.user.may.read(pagename) and request.cfg.chart_options:
-        chart_type = request.form['type'][0]
-        func = pysupport.importName("MoinMoin.stats." + chart_type, "draw")
-        func(pagename, request)
+    """ Show page charts 
+    
+    TODO: add support for text charts?
+    """
+    _ = request.getText
+    if not request.user.may.read(pagename):
+        msg = _("You are not allowed to view this page.")
+        return request.page.send_page(request, msg=msg)
+    
+    if not request.cfg.chart_options:
+        msg = _("Charts are not available!")
+        return request.page.send_page(request, msg=msg)
+    
+    chart_type = request.form.get('type', [''])[0].strip()
+    if not chart_type:
+        msg = _('You need to provide a chart type!')
+        return request.page.send_page(request, msg=msg)
+    
+    try:
+        func = pysupport.importName("MoinMoin.stats." + chart_type, 'draw')
+    except (ImportError, AttributeError):
+        msg = _('Bad chart type "%s"!') % chart_type
+        return request.page.send_page(request, msg=msg)
+    
+    func(pagename, request)
     raise MoinMoinNoFooter
 
 
@@ -929,8 +951,10 @@
     from MoinMoin.formatter.text_html import Formatter
     request.formatter = Formatter(request)
 
-    handler = wikiutil.importPlugin(request.cfg, "action", action, identifier)
-    if handler is None:
+    try:
+        handler = wikiutil.importPlugin(request.cfg, "action", action,
+                                        identifier)
+    except ImportError:
         handler = globals().get('do_' + action)
         
     return handler