~ubuntu-branches/ubuntu/oneiric/moin/oneiric-security

« back to all changes in this revision

Viewing changes to MoinMoin/formatter/text_html.py

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-03-30 12:55:34 UTC
  • mfrom: (0.1.17 sid)
  • Revision ID: james.westby@ubuntu.com-20100330125534-4c2ufc1rok24447l
Tags: 1.9.2-2ubuntu1
* Merge from Debian testing (LP: #521834). Based on work by Stefan Ebner.
  Remaining changes:
 - Remove python-xml from Suggests field, the package isn't anymore in
   sys.path.
 - Demote fckeditor from Recommends to Suggests; the code was previously
   embedded in moin, but it was also disabled, so there's no reason for us
   to pull this in by default currently. Note: This isn't necessary anymore
   but needs a MIR for fckeditor, so postpone dropping this change until
   lucid+1
* debian/rules:
  - Replace hardcoded python2.5 with python* and hardcore python2.6 for ln
* debian/control.in: drop versioned depends on cdbs

Show diffs side-by-side

added added

removed removed

Lines of Context:
410
410
        """
411
411
 
412
412
        if hasattr(self, 'page'):
413
 
            self.request.begin_include(self.page.page_name)
 
413
            self.request.uid_generator.begin(self.page.page_name)
414
414
 
415
415
        result = []
416
416
        # Use the content language
434
434
        result.append(self.anchordef('bottom'))
435
435
        result.append(self._close('div', newline=newline))
436
436
        if hasattr(self, 'page'):
437
 
            self.request.end_include()
 
437
            self.request.uid_generator.end()
438
438
        return ''.join(result)
439
439
 
440
440
    def lang(self, on, lang_name):
602
602
 
603
603
    # Attachments ######################################################
604
604
 
605
 
    def attachment_link(self, on, url=None, **kw):
 
605
    def attachment_link(self, on, url=None, querystr=None, **kw):
606
606
        """ Link to an attachment.
607
607
 
608
608
            @param on: 1/True=start link, 0/False=end link
610
610
        """
611
611
        assert on in (0, 1, False, True) # make sure we get called the new way, not like the 1.5 api was
612
612
        _ = self.request.getText
613
 
        querystr = kw.get('querystr', {})
 
613
        if querystr is None:
 
614
            querystr = {}
614
615
        assert isinstance(querystr, dict) # new in 1.6, only support dicts
615
616
        if 'do' not in querystr:
616
617
            querystr['do'] = 'view'
620
621
            fname = wikiutil.taintfilename(filename)
621
622
            if AttachFile.exists(self.request, pagename, fname):
622
623
                target = AttachFile.getAttachUrl(pagename, fname, self.request, do=querystr['do'])
623
 
                title = "attachment:%s" % url
624
 
                css = 'attachment'
 
624
                if not 'title' in kw:
 
625
                    kw['title'] = "attachment:%s" % url
 
626
                kw['css'] = 'attachment'
625
627
            else:
626
 
                target = AttachFile.getAttachUrl(pagename, fname, self.request, upload=True)
627
 
                title = _('Upload new attachment "%(filename)s"') % {'filename': fname}
628
 
                css = 'attachment nonexistent'
629
 
            return self.url(on, target, css=css, title=title)
 
628
                target = AttachFile.getAttachUrl(pagename, fname, self.request, do='upload_form')
 
629
                kw['title'] = _('Upload new attachment "%(filename)s"') % {'filename': fname}
 
630
                kw['css'] = 'attachment nonexistent'
 
631
            return self.url(on, target, **kw)
630
632
        else:
631
633
            return self.url(on)
632
634
 
637
639
        exists = AttachFile.exists(self.request, pagename, fname)
638
640
        if exists:
639
641
            kw['css'] = 'attachment'
640
 
            kw['src'] = AttachFile.getAttachUrl(pagename, filename, self.request, addts=1)
 
642
            kw['src'] = AttachFile.getAttachUrl(pagename, fname, self.request, addts=1)
641
643
            title = _('Inlined image: %(url)s') % {'url': self.text(url)}
642
644
            if not 'title' in kw:
643
645
                kw['title'] = title
649
651
            title = _('Upload new attachment "%(filename)s"') % {'filename': fname}
650
652
            img = self.icon('attachimg')
651
653
            css = 'nonexistent'
652
 
            target = AttachFile.getAttachUrl(pagename, fname, self.request, upload=True)
 
654
            target = AttachFile.getAttachUrl(pagename, fname, self.request, do='upload_form')
653
655
            return self.url(1, target, css=css, title=title) + img + self.url(0)
654
656
 
655
657
    def attachment_drawing(self, url, text, **kw):
656
 
        # XXX text arg is unused!
657
 
        _ = self.request.getText
658
 
        pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
659
 
        fname = wikiutil.taintfilename(filename)
660
 
        drawing = fname
661
 
        fname = fname + u".png"
662
 
        filename = filename + u".png"
663
 
        # fallback for old gif drawings (1.1 -> 1.2)
664
 
        exists = AttachFile.exists(self.request, pagename, fname)
665
 
        if not exists:
666
 
            gfname = fname[:-4] + u".gif"
667
 
            gfilename = filename[:-4] + u".gif"
668
 
            exists = AttachFile.exists(self.request, pagename, gfname)
669
 
            if exists:
670
 
                fname, filename = gfname, gfilename
671
 
 
672
 
        # check whether attachment exists, possibly point to upload form
673
 
        drawing_url = AttachFile.getAttachUrl(pagename, fname, self.request, drawing=drawing, upload=True)
674
 
        if not exists:
675
 
            title = _('Create new drawing "%(filename)s (opens in new window)"') % {'filename': fname}
676
 
            img = self.icon('attachimg')  # TODO: we need a new "drawimg" in similar grey style and size
677
 
            css = 'nonexistent'
678
 
            return self.url(1, drawing_url, css=css, title=title) + img + self.url(0)
679
 
 
680
 
        title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(fname)}
681
 
        kw['src'] = AttachFile.getAttachUrl(pagename, filename, self.request, addts=1)
682
 
        kw['css'] = 'drawing'
683
 
 
684
 
        mappath = AttachFile.getFilename(self.request, pagename, drawing + u'.map')
 
658
        # ToDo try to move this to a better place e.g. __init__
685
659
        try:
686
 
            map = file(mappath, 'r').read()
687
 
        except (IOError, OSError):
688
 
            map = ''
689
 
        if map:
690
 
            # we have a image map. inline it and add a map ref to the img tag
691
 
            mapid = 'ImageMapOf' + drawing
692
 
            map = map.replace('%MAPNAME%', mapid)
693
 
            # add alt and title tags to areas
694
 
            map = re.sub('href\s*=\s*"((?!%TWIKIDRAW%).+?)"', r'href="\1" alt="\1" title="\1"', map)
695
 
            map = map.replace('%TWIKIDRAW%"', '%s" alt="%s" title="%s"' % (drawing_url, title, title))
696
 
            # unxml, because 4.01 concrete will not validate />
697
 
            map = map.replace('/>', '>')
698
 
            title = _('Clickable drawing: %(filename)s') % {'filename': self.text(fname)}
699
 
            if 'title' not in kw:
700
 
                kw['title'] = title
701
 
            if 'alt' not in kw:
702
 
                kw['alt'] = kw['title']
703
 
            kw['usemap'] = '#'+mapid
704
 
            return map + self.image(**kw)
705
 
        else:
706
 
            if 'title' not in kw:
707
 
                kw['title'] = title
708
 
            if 'alt' not in kw:
709
 
                kw['alt'] = kw['title']
710
 
            return self.url(1, drawing_url) + self.image(**kw) + self.url(0)
711
 
 
 
660
            drawing_action = AttachFile.get_action(self.request, url, do='modify')
 
661
            assert drawing_action is not None
 
662
            attachment_drawing = wikiutil.importPlugin(self.request.cfg, 'action',
 
663
                                              drawing_action, 'attachment_drawing')
 
664
            return attachment_drawing(self, url, text, **kw)
 
665
        except (wikiutil.PluginMissingError, wikiutil.PluginAttributeError, AssertionError):
 
666
            return url
712
667
 
713
668
    # Text ##############################################################
714
669
 
904
859
</script>
905
860
"""
906
861
 
907
 
    def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1):
 
862
    def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1, msg=None):
908
863
        """Creates a formatted code region, with line numbering.
909
864
 
910
865
        This region is formatted as a <div> with a <pre> inside it.  The
917
872
 
918
873
        Call once with on=1 to start the region, and a second time
919
874
        with on=0 to end it.
 
875
 
 
876
        the msg string is not escaped
920
877
        """
921
878
        _ = self.request.getText
922
879
        res = []
930
887
            # id in here no longer used
931
888
            self._code_area_state = [None, show, start, step, start]
932
889
 
 
890
            if msg:
 
891
                attr = {'class': 'codemsg'}
 
892
                res.append(self._open('div', attr={'class': 'codemsg'}))
 
893
                res.append(msg)
 
894
                res.append(self._close('div'))
 
895
 
933
896
            # Open the code div - using left to right always!
934
897
            attr = {'class': 'codearea', 'lang': 'en', 'dir': 'ltr'}
935
898
            res.append(self._open('div', attr=attr))