# HG changeset patch # User Paul Boddie # Date 1396563660 -7200 # Node ID 4ec0da93d8d58afa96c6b8cb2285e1d3eadff55b # Parent 4233e4fa5ee61111c0ada6a076e6eabcd1f68da1 Eliminated empty parts from the display representation. Prevented the HTML sanitizer from writing links to ReadMessage URLs for messages not originating from message stores associated with wiki pages. diff -r 4233e4fa5ee6 -r 4ec0da93d8d5 MoinShare.py --- a/MoinShare.py Thu Apr 03 23:37:56 2014 +0200 +++ b/MoinShare.py Fri Apr 04 00:21:00 2014 +0200 @@ -393,6 +393,7 @@ update = Update() update.updated = getDateTimeFromRFC2822(part.get("date")) update.title = part.get("subject", "Update #%d" % message_number) + update.message_number = message_number update.content, update.content_type, update.parts, actual_author = \ @@ -625,21 +626,18 @@ # NOTE: Some control over the HTML and XHTML should be exercised. - if update.content: - if update.content_type == "text/html" and update.message_number is not None: - parsers = [get_make_parser(update.page, update.message_number)] - else: - parsers = getParsersForContentType(request.cfg, update.content_type) + if update.content_type == "text/html" and update.page is not None and update.message_number is not None: + parsers = [get_make_parser(update.page, update.message_number)] + else: + parsers = getParsersForContentType(request.cfg, update.content_type) - if parsers: - for parser_cls in parsers: - if hasattr(parser_cls, "formatForOutputType"): - return formatTextForOutputType(update.content, request, parser_cls, "text/html") - else: - return formatText(update.content, request, fmt, parser_cls=parser_cls) - break - else: - return None + if parsers: + for parser_cls in parsers: + if hasattr(parser_cls, "formatForOutputType"): + return formatTextForOutputType(update.content, request, parser_cls, "text/html") + else: + return formatText(update.content, request, fmt, parser_cls=parser_cls) + break else: return None @@ -662,11 +660,12 @@ first = True for update_part in updates: - append(fmt.url(1, "#%s" % update_part.unique_id())) - append(fmt.text(update_part.content_type)) - append(fmt.url(0)) + if update_part.content: + append(fmt.url(1, "#%s" % update_part.unique_id())) + append(fmt.text(update_part.content_type)) + append(fmt.url(0)) - first = False + first = False append(fmt.div(on=0)) @@ -675,21 +674,22 @@ first = True for update_part in updates: + if update_part.content: - # Encapsulate each alternative if many exist. + # Encapsulate each alternative if many exist. - if not single: - css_class = first and "moinshare-default" or "moinshare-other" - append(fmt.div(on=1, css_class="moinshare-alternative %s" % css_class, id=update_part.unique_id())) + if not single: + css_class = first and "moinshare-default" or "moinshare-other" + append(fmt.div(on=1, css_class="moinshare-alternative %s" % css_class, id=update_part.unique_id())) - # Include the content. + # Include the content. - append(formatUpdatePart(update_part, request, fmt)) + append(formatUpdatePart(update_part, request, fmt)) - if not single: - append(fmt.div(on=0)) + if not single: + append(fmt.div(on=0)) - first = False + first = False return "".join(result) @@ -740,9 +740,24 @@ class IncomingHTMLSanitizer(HTMLSanitizer): - "An HTML parser that rewrites references to attachments." + """ + An HTML parser that rewrites references to attachments. Instead of referring + to content identifier URLs with a scheme of "cid:", the resulting HTML will + refer to action URLs that extract parts from messages in message stores. + + NOTE: This rewriting does not occur for other sources of HTML bundles + NOTE: because other actions would be required to support the extraction of + NOTE: resources from such sources. + """ def __init__(self, out, request, page, message_number): + + """ + Initialise the sanitizer with an 'out' stream for output, the given + 'request', a 'page' from which the HTML originates, together with the + 'message_number' providing the content. + """ + HTMLSanitizer.__init__(self, out) self.request = request self.message_number = message_number