comparison 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
comparison
equal deleted inserted replaced
50:69dfbae549ac 51:54d5932d5a03
828 mimetype = request.form['mimetype'][0] 828 mimetype = request.form['mimetype'][0]
829 else: 829 else:
830 mimetype = u"text/plain" 830 mimetype = u"text/plain"
831 831
832 # try to load the formatter 832 # try to load the formatter
833 Formatter = wikiutil.importPlugin(request.cfg, "formatter", 833 formatterName = mimetype.translate({ord(u'/'): u'_', ord(u'.'): u'_'})
834 mimetype.translate({ord(u'/'): u'_', ord(u'.'): u'_'}), "Formatter") 834 try:
835 if Formatter is None: 835 Formatter = wikiutil.importPlugin(request.cfg, "formatter",
836 formatterName, "Formatter")
837 except ImportError:
836 # default to plain text formatter 838 # default to plain text formatter
837 del Formatter
838 mimetype = "text/plain" 839 mimetype = "text/plain"
839 from formatter.text_plain import Formatter 840 from MoinMoin.formatter.text_plain import Formatter
840 841
841 if "xml" in mimetype: 842 if "xml" in mimetype:
842 mimetype = "text/xml" 843 mimetype = "text/xml"
843 request.http_headers(["Content-Type: %s; charset=%s" % (mimetype, config.charset)]) 844 request.http_headers(["Content-Type: %s; charset=%s" % (mimetype, config.charset)])
844 845
845 Page(request, pagename, formatter=Formatter(request)).send_page(request) 846 Page(request, pagename, formatter=Formatter(request)).send_page(request)
846 raise MoinMoinNoFooter 847 raise MoinMoinNoFooter
847 848
848 849
849 def do_chart(pagename, request): 850 def do_chart(pagename, request):
850 if request.user.may.read(pagename) and request.cfg.chart_options: 851 """ Show page charts
851 chart_type = request.form['type'][0] 852
852 func = pysupport.importName("MoinMoin.stats." + chart_type, "draw") 853 TODO: add support for text charts?
853 func(pagename, request) 854 """
855 _ = request.getText
856 if not request.user.may.read(pagename):
857 msg = _("You are not allowed to view this page.")
858 return request.page.send_page(request, msg=msg)
859
860 if not request.cfg.chart_options:
861 msg = _("Charts are not available!")
862 return request.page.send_page(request, msg=msg)
863
864 chart_type = request.form.get('type', [''])[0].strip()
865 if not chart_type:
866 msg = _('You need to provide a chart type!')
867 return request.page.send_page(request, msg=msg)
868
869 try:
870 func = pysupport.importName("MoinMoin.stats." + chart_type, 'draw')
871 except (ImportError, AttributeError):
872 msg = _('Bad chart type "%s"!') % chart_type
873 return request.page.send_page(request, msg=msg)
874
875 func(pagename, request)
854 raise MoinMoinNoFooter 876 raise MoinMoinNoFooter
855 877
856 878
857 def do_dumpform(pagename, request): 879 def do_dumpform(pagename, request):
858 data = util.dumpFormData(request.form) 880 data = util.dumpFormData(request.form)
927 return None 949 return None
928 950
929 from MoinMoin.formatter.text_html import Formatter 951 from MoinMoin.formatter.text_html import Formatter
930 request.formatter = Formatter(request) 952 request.formatter = Formatter(request)
931 953
932 handler = wikiutil.importPlugin(request.cfg, "action", action, identifier) 954 try:
933 if handler is None: 955 handler = wikiutil.importPlugin(request.cfg, "action", action,
956 identifier)
957 except ImportError:
934 handler = globals().get('do_' + action) 958 handler = globals().get('do_' + action)
935 959
936 return handler 960 return handler
937 961
938 962