Attachment 'patch-sectioin-editing-1.5r1.txt'

Download

   1 diff -r -u MoinMoin.orig/PageEditor.py MoinMoin/PageEditor.py
   2 --- MoinMoin.orig/PageEditor.py	2006-03-05 10:41:11.533854400 -0800
   3 +++ MoinMoin/PageEditor.py	2006-03-05 18:37:02.346659200 -0800
   4 @@ -136,7 +136,28 @@
   5          edit_lock_message = None
   6          preview = kw.get('preview', None)
   7          staytop = kw.get('staytop', 0)
   8 +        
   9 +        # for section editing
  10 +        issectionedit = kw.get('issectionedit', 1)
  11 +        pagetext = kw.get('pagetext', None)
  12 +        startline = int(form.get('startline', ['0'])[0])
  13 +        endline = int(form.get('endline', ['0'])[0])
  14 +        srev = int(form.get('srev', ['0'])[0])
  15 +        
  16 +        if startline or endline:
  17 +            if not startline:
  18 +                startline = 1
  19 +        
  20 +            if not endline:
  21 +                endline = -1    
  22 +        else:
  23 +            issectionedit = 0
  24  
  25 +        if issectionedit:
  26 +            # need to add config
  27 +            self._allow_section_edit = self.cfg.allow_section_edit
  28 +            # self._allow_section_edit = 1
  29 +            
  30          from MoinMoin.formatter.text_html import Formatter
  31          self.request.formatter = Formatter(self.request, store_pagelinks=1)
  32  
  33 @@ -175,7 +196,10 @@
  34              title = _('Edit "%(pagename)s"')
  35          else:
  36              title = _('Preview of "%(pagename)s"')
  37 -            self.set_raw_body(preview, modified=1)
  38 +            if issectionedit and pagetext is not None:
  39 +                self.set_raw_body(pagetext, modified=1)
  40 +            else:
  41 +                self.set_raw_body(preview, modified=1)
  42  
  43          # send header stuff
  44          lock_timeout = self.lock.timeout / 60
  45 @@ -215,9 +239,19 @@
  46                  # We don't show preview when in conflict
  47                  preview = None
  48                  
  49 +                # no section-editing any more
  50 +                if issectionedit:
  51 +                    conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.'))
  52 +                issectionedit = 0
  53 +
  54          elif self.exists():
  55              # revision of existing page
  56              rev = self.current_rev()
  57 +            
  58 +            if issectionedit and preview is None:
  59 +                if not (srev and srev == rev):
  60 +                    conflict_msg = u'%s %s' % (_('Section editing is canceled.'), _('Someone else updated this page. You are editing the updated revision.'))
  61 +                    issectionedit = 0
  62          else:
  63              # page creation
  64              rev = 0
  65 @@ -275,6 +309,12 @@
  66          # Generate default content for new pages
  67          if not raw_body:
  68              raw_body = _('Describe %s here.') % (self.page_name,)
  69 +        elif issectionedit:
  70 +            # for section editing
  71 +            if pagetext is not None:
  72 +                raw_body = preview
  73 +            else:
  74 +                raw_body = self.fetchsection(raw_body, startline, endline)
  75  
  76          # send form
  77          self.request.write('<form id="editor" method="post" action="%s/%s#preview" onSubmit="flgChange = false;">' % (
  78 @@ -292,6 +332,11 @@
  79          # Send revision of the page our edit is based on
  80          self.request.write('<input type="hidden" name="rev" value="%d">' % (rev,))
  81  
  82 +        # Send section startline and endline for section-editing
  83 +        if issectionedit:
  84 +            self.request.write('<input type="hidden" name="startline" value="%d">' % startline)
  85 +            self.request.write('<input type="hidden" name="endline" value="%d">' % endline)
  86 +        
  87          # Save backto in a hidden input
  88          backto = form.get('backto', [None])[0]
  89          if backto:
  90 @@ -393,6 +438,9 @@
  91  
  92          badwords_re = None
  93          if preview is not None:
  94 +            if issectionedit:
  95 +                self.set_raw_body(preview)
  96 +                
  97              if SpellCheck and (
  98                      form.has_key('button_spellcheck') or
  99                      form.has_key('button_newwords')):
 100 @@ -418,7 +466,12 @@
 101                  content_id = 'previewbelow'
 102              else:
 103                  content_id = 'preview'
 104 -            self.send_page(self.request, content_id=content_id, content_only=1,
 105 +
 106 +            if issectionedit:
 107 +                self.send_page(self.request, content_id=content_id, content_only=1,
 108 +                           hilite_re=badwords_re, do_cache=False)
 109 +            else:
 110 +                self.send_page(self.request, content_id=content_id, content_only=1,
 111                             hilite_re=badwords_re)
 112  
 113          self.request.write(self.request.formatter.endContent())
 114 @@ -864,7 +917,7 @@
 115                  if newtext==saved_page.get_raw_body():
 116                      msg = _("You already saved this page!")
 117                      return msg
 118 -                
 119 +
 120              msg = _("""Sorry, someone else saved the page while you edited it.
 121  
 122  Please do the following: Use the back button of your browser, and cut&paste
 123 @@ -930,7 +983,17 @@
 124          self.lock.release(force=not msg) # XXX does "not msg" make any sense?
 125    
 126          return msg
 127 -            
 128 +
 129 +    def fetchsection(self, pagetext, startline, endline):
 130 +        
 131 +        pagetext = pagetext.split('\n')
 132 +        if endline == -1:
 133 +            sectiontext = u'\n'.join(pagetext[startline-1:])
 134 +        else:
 135 +            sectiontext = u'\n'.join(pagetext[startline-1:endline])
 136 +        
 137 +        return sectiontext
 138 +        
 139              
 140  class PageLock:
 141      """
 142 Files MoinMoin.orig/PageEditor.pyc and MoinMoin/PageEditor.pyc differ
 143 diff -r -u MoinMoin.orig/PageGraphicalEditor.py MoinMoin/PageGraphicalEditor.py
 144 --- MoinMoin.orig/PageGraphicalEditor.py	2006-03-05 10:41:11.573912000 -0800
 145 +++ MoinMoin/PageGraphicalEditor.py	2006-03-05 18:37:21.013500800 -0800
 146 @@ -64,6 +64,27 @@
 147          edit_lock_message = None
 148          preview = kw.get('preview', None)
 149          staytop = kw.get('staytop', 0)
 150 +        
 151 +        # for section editing
 152 +        issectionedit = kw.get('issectionedit', 1)
 153 +        pagetext = kw.get('pagetext', None)
 154 +        startline = int(form.get('startline', ['0'])[0])
 155 +        endline = int(form.get('endline', ['0'])[0])
 156 +        srev = int(form.get('srev', ['0'])[0])
 157 +        
 158 +        if startline or endline:
 159 +            if not startline:
 160 +                startline = 1
 161 +        
 162 +            if not endline:
 163 +                endline = -1    
 164 +        else:
 165 +            issectionedit = 0
 166 +
 167 +        if issectionedit:
 168 +            # need to add config
 169 +            self._allow_section_edit = self.cfg.allow_section_edit
 170 +            # self._allow_section_edit = 1  
 171  
 172          # check edit permissions
 173          if not self.request.user.may.write(self.page_name):
 174 @@ -95,7 +116,10 @@
 175              title = _('Edit "%(pagename)s"')
 176          else:
 177              title = _('Preview of "%(pagename)s"')
 178 -            self.set_raw_body(preview, modified=1)
 179 +            if issectionedit and pagetext is not None:
 180 +                self.set_raw_body(pagetext, modified=1)
 181 +            else:
 182 +                self.set_raw_body(preview, modified=1)
 183  
 184          # send header stuff
 185          lock_timeout = self.lock.timeout / 60
 186 @@ -135,9 +159,19 @@
 187                  # We don't show preview when in conflict
 188                  preview = None
 189                  
 190 +                # no section-editing any more
 191 +                if issectionedit:
 192 +                    conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.'))
 193 +                issectionedit = 0
 194 +                
 195          elif self.exists():
 196              # revision of existing page
 197              rev = self.current_rev()
 198 +            
 199 +            if issectionedit and preview is None:
 200 +                if not (srev and srev == rev):
 201 +                    conflict_msg = u'%s %s' % (_('Section editing is canceled.'), _('Someone else updated this page. You are editing the updated revision.'))
 202 +                    issectionedit = 0
 203          else:
 204              # page creation
 205              rev = 0
 206 @@ -195,13 +229,19 @@
 207          # Generate default content for new pages
 208          if not raw_body:
 209              raw_body = _('Describe %s here.') % (self.page_name,)
 210 -
 211 +        elif issectionedit:
 212 +            # for section editing
 213 +            if pagetext is not None:
 214 +                raw_body = preview
 215 +            else:
 216 +                raw_body = self.fetchsection(raw_body, startline, endline)
 217 +                
 218          # send form
 219          self.request.write('<form id="editor" method="post" action="%s/%s#preview">' % (
 220              self.request.getScriptname(),
 221              wikiutil.quoteWikinameURL(self.page_name),
 222              ))
 223 -
 224 +        
 225          # yet another weird workaround for broken IE6 (it expands the text
 226          # editor area to the right after you begin to type...). IE sucks...
 227          # http://fplanque.net/2003/Articles/iecsstextarea/
 228 @@ -212,6 +252,11 @@
 229          # Send revision of the page our edit is based on
 230          self.request.write('<input type="hidden" name="rev" value="%d">' % (rev,))
 231  
 232 +        # Send section startline and endline for section-editing
 233 +        if issectionedit:
 234 +            self.request.write('<input type="hidden" name="startline" value="%d">' % startline)
 235 +            self.request.write('<input type="hidden" name="endline" value="%d">' % endline)
 236 +
 237          # Save backto in a hidden input
 238          backto = form.get('backto', [None])[0]
 239          if backto:
 240 @@ -330,9 +375,12 @@
 241              })
 242  
 243          self.request.write("</p>")
 244 -
 245 +        
 246          badwords_re = None
 247          if preview is not None:
 248 +            if issectionedit:
 249 +                self.set_raw_body(preview)
 250 +                
 251              if SpellCheck and (
 252                      form.has_key('button_spellcheck') or
 253                      form.has_key('button_newwords')):
 254 @@ -347,8 +395,13 @@
 255                  content_id = 'previewbelow'
 256              else:
 257                  content_id = 'preview'
 258 -            self.send_page(self.request, content_id=content_id, content_only=1,
 259 -                           hilite_re=badwords_re)
 260 +            
 261 +            if issectionedit:
 262 +                self.send_page(self.request, content_id=content_id, content_only=1,
 263 +                           hilite_re=badwords_re, do_cache=False)
 264 +            else:
 265 +                self.send_page(self.request, content_id=content_id, content_only=1,
 266 +                             hilite_re=badwords_re)
 267  
 268          self.request.write(self.request.formatter.endContent()) # end content div
 269          wikiutil.send_footer(self.request, self.page_name)
 270 Files MoinMoin.orig/formatter/.text_html.py.swp and MoinMoin/formatter/.text_html.py.swp differ
 271 diff -r -u MoinMoin.orig/formatter/text_html.py MoinMoin/formatter/text_html.py
 272 --- MoinMoin.orig/formatter/text_html.py	2006-03-05 10:41:07.758425600 -0800
 273 +++ MoinMoin/formatter/text_html.py	2006-03-05 18:43:27.089892800 -0800
 274 @@ -192,6 +192,16 @@
 275          self._is_included = kw.get('is_included', False)
 276          self.request = request
 277          self.cfg = request.cfg
 278 +        
 279 +        # for section editing
 280 +        self._allow_section_edit = None
 281 +        if not hasattr(request, 'sectionindex'):
 282 +            request.sectionindex = 0
 283 +        
 284 +        self.sectionstack = []
 285 +        self.sectionpool = {}
 286 +        self.sectionlastdepth = 0
 287 +        self.lineno = 0
 288  
 289          if not hasattr(request, '_fmt_hd_counters'):
 290              request._fmt_hd_counters = []
 291 @@ -593,6 +603,7 @@
 292          return '<span class="anchor" id="%s"></span>' % wikiutil.escape(id, 1)
 293  
 294      def line_anchordef(self, lineno):
 295 +        self.lineno = lineno
 296          if line_anchors:
 297              return self.anchordef("line-%d" % lineno)
 298          else:
 299 @@ -1181,6 +1192,21 @@
 300          if not self._base_depth:
 301              self._base_depth = depth
 302  
 303 +        # section editing configuration
 304 +        if self._allow_section_edit is None:
 305 +            # need to add config
 306 +            self._allow_section_edit = self.cfg.allow_section_edit
 307 +            # self._allow_section_edit = 1
 308 +            sectionediting = self.request.getPragma('section-edit', '').lower()
 309 +            if sectionediting in ['off']:
 310 +                self._allow_section_edit = 0
 311 +            elif sectionediting in ['on']:
 312 +                self._allow_section_edit = 1
 313 +        
 314 +        if self._allow_section_edit:
 315 +            if not self.request.user.may.write(self.page.page_name):
 316 +                self._allow_section_edit = 0
 317 +        
 318          count_depth = max(depth - (self._base_depth - 1), 1)
 319  
 320          # check numbering, possibly changing the default
 321 @@ -1199,7 +1225,32 @@
 322  
 323          # closing tag, with empty line after, to make source more readable
 324          if not on:
 325 -            return self._close('h%d' % heading_depth) + '\n'
 326 +            result = self._close('h%d' % heading_depth) + '\n'
 327 +            
 328 +            sectionscript = ''
 329 +            if self._allow_section_edit:
 330 +                
 331 +                self.request.sectionindex += 1
 332 +                sectionindex = self.request.sectionindex
 333 +                sectionscript = self.savesectioninfor(sectionindex, depth, self.lineno)
 334 +                
 335 +                attr = 'id="sectionedit%d"' % sectionindex
 336 +                
 337 +                backto = u''
 338 +                if self._is_included and hasattr(self.request, "_Include_backto"):
 339 +                    backto = u'&backto=%s' % wikiutil.quoteWikinameURL(self.request._Include_backto)
 340 +                
 341 +                sectioneditpage = u'%s/%s' % (self.request.getScriptname(), wikiutil.quoteWikinameURL(self.page.page_name))
 342 +                srev = self.page.current_rev()
 343 +                querystring = u'%s?action=edit%s&srev=%d&startline=%d' % (sectioneditpage, backto, srev, self.lineno)
 344 +                
 345 +                result = ('%s%s%s%s' %
 346 +                    (self.url(1, querystring, unescaped=1, title='Edit this section', attrs=attr),
 347 +                     self.icon('edit'),
 348 +                     self.url(0),
 349 +                     result))
 350 +
 351 +            return ' %s%s' % (result, sectionscript)
 352              
 353          # create section number
 354          number = ''
 355 @@ -1324,6 +1375,54 @@
 356                               allowed_attrs=self._allowed_table_attrs['row'],
 357                               **kw)
 358          return self._close(tag) + '\n'
 359 +
 360 +    def savesectioninfor(self, index, depth, lineno, save=1):
 361 +        # store section information
 362 +        section = {}
 363 +        sectionscriptlist = []
 364 +        sectionscript = u'document.getElementById("sectionedit%d").href += "&endline=%d";'
 365 +        scriptresult = ''
 366 +        
 367 +        lastdepth = self.sectionlastdepth
 368 +        sectionindex = index
 369 +        
 370 +        if lastdepth >= depth:
 371 +            while 1:
 372 +                if len(self.sectionstack):
 373 +                    lastsection = self.sectionstack.pop()
 374 +                    lastdepth = lastsection['depth']    
 375 +                    if lastdepth >= depth:
 376 +                        self.sectionpool[lastsection['index']]['endlineno'] = lineno - 1
 377 +                        sectionscriptlist.append(sectionscript % (lastsection['index'], lineno - 1))
 378 +                    else:
 379 +                        self.sectionstack.append(lastsection)
 380 +                        break
 381 +                else:
 382 +                    break
 383 +                    
 384 +        if save:
 385 +            section['index'] = sectionindex
 386 +            section['startlineno'] = lineno
 387 +            section['depth'] = depth
 388 +            section['endlineno'] = -1
 389 +            self.sectionlastdepth = depth
 390 +            self.sectionpool[sectionindex] = section
 391 +            self.sectionstack.append(section)
 392 +        
 393 +        if len(sectionscriptlist) > 0:
 394 +            
 395 +            scriptresult = u"""
 396 +<script type="text/javascript">
 397 +<!--
 398 +%s
 399 +//-->
 400 +</script>
 401 +""" % u'\n'.join(sectionscriptlist)
 402 +
 403 +        return scriptresult
 404 +
 405 +        
 406 +
 407      
 408      def table_cell(self, on, attrs=None, **kw):
 409          tag = 'td'
 410 Files MoinMoin.orig/formatter/text_html.pyc and MoinMoin/formatter/text_html.pyc differ
 411 Only in MoinMoin.orig/macro: .Include.py.swp
 412 diff -r -u MoinMoin.orig/macro/Include.py MoinMoin/macro/Include.py
 413 --- MoinMoin.orig/macro/Include.py	2006-03-05 10:41:10.542428800 -0800
 414 +++ MoinMoin/macro/Include.py	2006-03-05 18:36:37.681192000 -0800
 415 @@ -219,7 +219,7 @@
 416          try:
 417              cid = request.makeUniqueID("Include_%s" % wikiutil.quoteWikinameURL(inc_page.page_name))
 418              inc_page.send_page(request, content_only=1, content_id=cid,
 419 -                               omit_footnotes=True)
 420 +                               omit_footnotes=True, do_cache=False)
 421              result.append(strfile.getvalue())
 422          finally:
 423              request.redirect()
 424 diff -r -u MoinMoin.orig/multiconfig.py MoinMoin/multiconfig.py
 425 --- MoinMoin.orig/multiconfig.py	2006-03-05 10:41:11.263465600 -0800
 426 +++ MoinMoin/multiconfig.py	2006-03-05 18:37:37.577318400 -0800
 427 @@ -291,6 +291,7 @@
 428      show_login = 1
 429      show_names = True
 430      show_section_numbers = 0
 431 +    allow_section_edit = 1
 432      show_timings = 0
 433      show_version = 0
 434      siteid = 'default'
 435 Files MoinMoin.orig/multiconfig.pyc and MoinMoin/multiconfig.pyc differ
 436 diff -r -u MoinMoin.orig/wikiaction.py MoinMoin/wikiaction.py
 437 --- MoinMoin.orig/wikiaction.py	2006-03-05 10:41:19.254956800 -0800
 438 +++ MoinMoin/wikiaction.py	2006-03-05 18:38:28.710844800 -0800
 439 @@ -579,11 +579,36 @@
 440  
 441      comment = wikiutil.clean_comment(comment)
 442  
 443 +    # section editing
 444 +    startline = int(request.form.get('startline', ['0'])[0])
 445 +    endline = int(request.form.get('endline', ['0'])[0])
 446 +        
 447 +    if startline or endline:
 448 +        issectionedit = 1
 449 +        
 450 +        if not startline:
 451 +            startline = 1
 452 +        
 453 +        if not endline:
 454 +            endline = -1    
 455 +
 456 +    else:
 457 +        issectionedit = 0
 458 +
 459 +    if issectionedit:
 460 +        savetext = pg.normalizeText(savetext, stripspaces=rstrip)
 461 +        sectiontext = savetext
 462 +        savetext = mergesection(pg.get_raw_body(), savetext, startline, endline)
 463 +
 464 +
 465      # Edit was canceled
 466      if request.form.has_key('button_cancel'):
 467          pg.sendCancel(savetext or "", rev)
 468          return
 469  
 470 +    if not issectionedit:
 471 +        savetext = pg.normalizeText(savetext, stripspaces=rstrip)
 472 +    
 473      # Add category
 474  
 475      # TODO: this code does not work with extended links, and is doing
 476 @@ -619,11 +644,17 @@
 477      if (request.form.has_key('button_preview') or
 478          request.form.has_key('button_spellcheck') or
 479          request.form.has_key('button_newwords')):
 480 -        pg.sendEditor(preview=savetext, comment=comment)
 481 +        if issectionedit:
 482 +            pg.sendEditor(preview=sectiontext, comment=comment, pagetext=savetext)
 483 +        else:
 484 +            pg.sendEditor(preview=savetext, comment=comment)
 485      
 486      # Preview with mode switch
 487      elif request.form.has_key('button_switch'):
 488 -        pg.sendEditor(preview=savetext, comment=comment, staytop=1)
 489 +        if issectionedit:
 490 +            pg.sendEditor(preview=sectiontext, comment=comment, staytop=1, pagetext=savetext)
 491 +        else:
 492 +            pg.sendEditor(preview=savetext, comment=comment, staytop=1)
 493      
 494      # Save new text
 495      else:
 496 @@ -644,7 +675,10 @@
 497                                             querystr='action=diff&rev=%d' % rev)
 498                      }
 499                  # We don't send preview when we do merge conflict
 500 -                pg.sendEditor(msg=conflict_msg, comment=comment)
 501 +                if issectionedit:
 502 +                    conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.'))
 503 +                
 504 +                pg.sendEditor(msg=conflict_msg, comment=comment, issectionedit=0)
 505                  return
 506              else:
 507                  savemsg = conflict_msg
 508 @@ -893,3 +927,14 @@
 509          
 510      return handler
 511  
 512 +def mergesection(pagetext, newsectiontext, startline, endline):
 513 +    
 514 +    pagetext = pagetext.split('\n')
 515 +    
 516 +    prevtext = u'%s\n' % u'\n'.join(pagetext[:startline-1])
 517 +    if endline == -1:
 518 +        nexttext = ''
 519 +    else:
 520 +        nexttext = u'\n%s' % u'\n'.join(pagetext[endline:])
 521 +    
 522 +    return u'%s%s%s' % (prevtext, newsectiontext, nexttext)
 523 Files MoinMoin.orig/wikiaction.pyc and MoinMoin/wikiaction.pyc differ

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.