Attachment 'SectionEditing-1.5.7.patch'

Download

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

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.