Edgewall Software

Ticket #152: wiki_merge_changes-r5851.diff

File wiki_merge_changes-r5851.diff, 3.6 KB (added by cboos, 5 years ago)

Adds a Merge changes action in the collision view. Probably needs more testing, but gives the idea.

  • trac/wiki/web_ui.py

     
    124124            if action == 'edit': 
    125125                if 'cancel' in req.args: 
    126126                    req.redirect(req.href.wiki(page.name)) 
    127                 elif int(version) != latest_page.version: 
    128                     return self._render_editor(context, 'collision') 
    129                 elif 'preview' in req.args: 
    130                     return self._render_editor(context, 'preview') 
    131                 elif 'diff' in req.args: 
    132                     return self._render_editor(context, 'diff') 
     127                 
     128                has_collision = int(version) != latest_page.version 
     129                for a in ('preview', 'diff', 'merge'): 
     130                    if a in req.args: 
     131                        action = a 
     132                        break 
     133                if action == 'edit' and not has_collision: 
     134                    self._do_save(context) 
    133135                else: 
    134                     self._do_save(context) 
     136                    return self._render_editor(context, action, has_collision) 
    135137            elif action == 'delete': 
    136138                self._do_delete(context) 
    137139            elif action == 'diff': 
     
    380382        }) 
    381383        return 'wiki_diff.html', data, None 
    382384 
    383     def _render_editor(self, context, action='edit'): 
     385    def _render_editor(self, context, action='edit', has_collision=False): 
     386        if has_collision: 
     387            if action == 'merge': 
     388                context = context(realm=context.realm, id=context.id, 
     389                                  version=None) 
     390                context.req.warning( 
     391                    _("There have been changes made by others since you " 
     392                      "started your edits. If you save now, you risk to " 
     393                      "revert those changes (highlighted here as deletions). " 
     394                      "Please go through all the changes and manually merge " 
     395                      "the changes you want to keep. " 
     396                      "If you're unsure about what you're doing, " 
     397                      "please press Cancel (loosing your changes) " 
     398                      "and start editing again.")) 
     399            else: 
     400                action = 'collision' 
     401 
    384402        page, req = context.resource, context.req 
    385         context.version = None # use implicit ''latest'' in links 
     403        context.version = None # always use implicit ''latest'' in links 
    386404 
    387405        if page.readonly: 
    388406            req.perm.require('WIKI_ADMIN', context) 
     
    419437            'scroll_bar_pos': req.args.get('scroll_bar_pos', ''), 
    420438            'diff': None, 
    421439        }) 
    422         if action == 'diff': 
     440        if action in ('diff', 'merge'): 
    423441            old_text = original_text and original_text.splitlines() or [] 
    424442            new_text = page.text and page.text.splitlines() or [] 
    425443            diff_data, changes = self._prepare_diff( 
  • trac/wiki/templates/wiki_edit.html

     
    113113        <div class="buttons" py:choose="action"> 
    114114          <py:when test="'collision'"> 
    115115            <input type="submit" name="preview" value="Preview" disabled="disabled" />&nbsp; 
     116            <input type="submit" name="merge" value="Merge changes" accesskey="r" />&nbsp; 
    116117            <input type="submit" name="save" value="Submit changes" disabled="disabled" />&nbsp; 
    117118          </py:when> 
    118119          <py:otherwise>