Attachment 'text_html.patch'

Download

   1 --- text_html-1.5b2.py	2005-10-31 08:39:10.000000000 +0900
   2 +++ text_html.py	2005-11-24 11:11:23.384242300 +0900
   3 @@ -39,6 +39,16 @@
   4          self._is_included = kw.get('is_included',False)
   5          self.request = request
   6          self.cfg = request.cfg
   7 +        
   8 +        # for section editing
   9 +        self._allow_section_edit = None
  10 +        if not hasattr(request, 'sectionindex'):
  11 +            request.sectionindex = 0
  12 +        
  13 +        self.sectionstack = []
  14 +        self.sectionpool = {}
  15 +        self.sectionlastdepth = 0
  16 +        self.lineno = 0
  17  
  18          if not hasattr(request, '_fmt_hd_counters'):
  19              request._fmt_hd_counters = []
  20 @@ -285,6 +295,7 @@
  21          return '<a id="%s"></a>' % (id, ) # do not add a \n here, it breaks pre sections with line_anchordef
  22  
  23      def line_anchordef(self, lineno):
  24 +        self.lineno = lineno
  25          return self.anchordef("line-%d" % lineno)
  26  
  27      def anchorlink(self, on, name='', id=None):
  28 @@ -689,6 +700,21 @@
  29          if not self._base_depth:
  30              self._base_depth = depth
  31  
  32 +        # section editing configuration
  33 +        if self._allow_section_edit is None:
  34 +            # need to add config
  35 +            self._allow_section_edit = self.cfg.allow_section_edit
  36 +            # self._allow_section_edit = 1
  37 +            sectionediting = self.request.getPragma('section-edit', '').lower()
  38 +            if sectionediting in ['off']:
  39 +                self._allow_section_edit = 0
  40 +            elif sectionediting in ['on']:
  41 +                self._allow_section_edit = 1
  42 +        
  43 +        if self._allow_section_edit:
  44 +            if not self.request.user.may.write(self.page.page_name):
  45 +                self._allow_section_edit = 0
  46 +        
  47          count_depth = max(depth - (self._base_depth - 1), 1)
  48  
  49          # check numbering, possibly changing the default
  50 @@ -707,7 +733,32 @@
  51  
  52          # closing tag, with empty line after, to make source more readable
  53          if not on:
  54 -            return self.close('h%d' % heading_depth) + '\n'
  55 +            result = self.close('h%d' % heading_depth)
  56 +            
  57 +            sectionscript = ''
  58 +            if self._allow_section_edit:
  59 +                
  60 +                self.request.sectionindex += 1
  61 +                sectionindex = self.request.sectionindex
  62 +                sectionscript = self.savesectioninfor(sectionindex, depth, self.lineno)
  63 +                
  64 +                attr = 'id="sectionedit%d"' % sectionindex
  65 +                
  66 +                backto = u''
  67 +                if self._is_included and hasattr(self.request, "_Include_backto"):
  68 +                    backto = u'&backto=%s' % wikiutil.quoteWikinameURL(self.request._Include_backto)
  69 +                
  70 +                sectioneditpage = u'%s/%s' % (self.request.getScriptname(), wikiutil.quoteWikinameURL(self.page.page_name))
  71 +                srev = self.page.current_rev()
  72 +                querystring = u'%s?action=edit%s&srev=%d&startline=%d' % (sectioneditpage, backto, srev, self.lineno)
  73 +                
  74 +                result = ('%s%s%s%s' %
  75 +                    (self.url(1, querystring, unescaped=1, title='Edit this section', attrs=attr),
  76 +                     self.icon('edit'),
  77 +                     self.url(0),
  78 +                     result))
  79 +
  80 +            return ' %s%s' % (result, sectionscript)
  81              
  82          # create section number
  83          number = ''
  84 @@ -840,6 +891,53 @@
  85              return self.open(tag, newline=1, attr=attrs)
  86          return self.close(tag)
  87  
  88 +    def savesectioninfor(self, index, depth, lineno, save=1):
  89 +        # store section information
  90 +        section = {}
  91 +        sectionscriptlist = []
  92 +        sectionscript = u'document.getElementById("sectionedit%d").href += "&endline=%d";'
  93 +        scriptresult = ''
  94 +        
  95 +        lastdepth = self.sectionlastdepth
  96 +        sectionindex = index
  97 +        
  98 +        if lastdepth >= depth:
  99 +            while 1:
 100 +                if len(self.sectionstack):
 101 +                    lastsection = self.sectionstack.pop()
 102 +                    lastdepth = lastsection['depth']    
 103 +                    if lastdepth >= depth:
 104 +                        self.sectionpool[lastsection['index']]['endlineno'] = lineno - 1
 105 +                        sectionscriptlist.append(sectionscript % (lastsection['index'], lineno - 1))
 106 +                    else:
 107 +                        self.sectionstack.append(lastsection)
 108 +                        break
 109 +                else:
 110 +                    break
 111 +                    
 112 +        if save:
 113 +            section['index'] = sectionindex
 114 +            section['startlineno'] = lineno
 115 +            section['depth'] = depth
 116 +            section['endlineno'] = -1
 117 +            self.sectionlastdepth = depth
 118 +            self.sectionpool[sectionindex] = section
 119 +            self.sectionstack.append(section)
 120 +        
 121 +        if len(sectionscriptlist) > 0:
 122 +            
 123 +            scriptresult = u"""
 124 +<script type="text/javascript">
 125 +<!--
 126 +%s
 127 +//-->
 128 +</script>
 129 +""" % u'\n'.join(sectionscriptlist)
 130 +
 131 +        return scriptresult
 132 +
 133 +        
 134 +
 135      def escapedText(self, text):
 136          return wikiutil.escape(text)
 137  

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2005-11-23 19:38:55, 0.5 KB) [[attachment:Include.patch]]
  • [get | view] (2005-11-24 11:57:17, 5.3 KB) [[attachment:PageEditor.patch]]
  • [get | view] (2005-11-24 11:57:23, 5.0 KB) [[attachment:PageGraphicalEditor.patch]]
  • [get | view] (2007-02-13 21:59:15, 19.1 KB) [[attachment:SectionEditing-1.5.4.patch]]
  • [get | view] (2007-04-18 19:03:14, 19.3 KB) [[attachment:SectionEditing-1.5.7.patch]]
  • [get | view] (2008-09-19 06:53:44, 21.3 KB) [[attachment:SectionEditing-1.7.1.patch]]
  • [get | view] (2005-11-23 19:38:14, 0.3 KB) [[attachment:multiconfig.patch]]
  • [get | view] (2005-11-29 10:18:42, 14.2 KB) [[attachment:patch-1.35.txt]]
  • [get | view] (2007-02-07 09:47:30, 55.0 KB) [[attachment:patch-1.5.6.zip]]
  • [get | view] (2005-11-29 10:18:29, 20.2 KB) [[attachment:patch-1.5b2.txt]]
  • [get | view] (2006-03-06 03:43:16, 19.7 KB) [[attachment:patch-sectioin-editing-1.5r1.txt]]
  • [get | view] (2010-01-20 00:32:20, 21.3 KB) [[attachment:section-edit-1.9-v1.1.patch]]
  • [get | view] (2010-01-22 14:57:16, 21.3 KB) [[attachment:section-edit-1.9-v1.2.patch]]
  • [get | view] (2010-10-11 19:06:34, 21.7 KB) [[attachment:section-edit-1.9-v1.4.patch]]
  • [get | view] (2010-01-15 20:38:36, 21.3 KB) [[attachment:section-edit-1.9.patch]]
  • [get | view] (2007-07-15 10:21:53, 57.1 KB) [[attachment:sectionedit_opera.png]]
  • [get | view] (2005-11-24 11:57:05, 5.2 KB) [[attachment:text_html.patch]]
  • [get | view] (2005-11-24 11:57:11, 3.6 KB) [[attachment:wikiaction.patch]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.