Commits

Remy Blank  committed e6f5642

0.13dev: Simplified reverting a wiki page to an older version.

Closes #10099.

  • Participants
  • Parent commits 26c8b4c
  • Branches trunk

Comments (0)

Files changed (2)

File trac/wiki/templates/wiki_view.html

       xmlns:i18n="http://genshi.edgewall.org/i18n"
       xmlns:xi="http://www.w3.org/2001/XInclude"
       py:with="modify_perm = 'WIKI_MODIFY' in perm(page.resource);
-               admin_perm = 'WIKI_ADMIN' in perm(page.resource)">
+               admin_perm = 'WIKI_ADMIN' in perm(page.resource);
+               is_not_latest = page.exists and page.version != latest_version">
   <xi:include href="layout.html" />
   <head>
     <title py:if="title">$title</title>
     <meta py:if="version or page.author == 'trac'" name="ROBOTS" content="NOINDEX, NOFOLLOW" />
     <link py:if="admin_perm or (not page.readonly and modify_perm)" rel="alternate" type="application/x-wiki"
-          title="Edit this page" href="${href.wiki(page.name, action='edit')}" />
+          href="${href.wiki(page.name, action='edit', version=page.version if is_not_latest else None)}"
+          title="${_('Revert page to this version') if is_not_latest else _('Edit this page')}"/>
     <script type="text/javascript">
       jQuery(document).ready(function($) {
         $("#content").find("h1,h2,h3,h4,h5,h6").addAnchor(_("Link to this section"));
                 <div>
                   <input type="hidden" name="action" value="edit" />
                   <py:choose>
+                    <py:when test="is_not_latest">
+                      <input type="hidden" name="version" value="${page.version}"/>
+                      <input type="submit" value="${_('Revert to this version')}"/>
+                    </py:when>
                     <py:when test="page.exists">
                       <input type="submit" value="${_('Edit this page')}" accesskey="e" />
                     </py:when>
                 <input type="submit" value="${_('Rename page')}" />
               </div>
             </form>
-            <py:if test="page.exists and delete_perm">
-              <form method="get" action="${href.wiki(page.name)}">
-                <div id="delete">
-                  <input type="hidden" name="action" value="delete" />
-                  <input type="hidden" name="version" value="$page.version" />
-                  <py:if test="page.version == latest_version">
-                    <input type="submit" name="delete_version" value="${_('Delete this version')}" />
-                  </py:if>
-                  <input type="submit" value="${_('Delete page')}" />
-                </div>
-              </form>
-            </py:if>
+            <form method="get" action="${href.wiki(page.name)}" py:if="page.exists and delete_perm">
+              <div id="delete">
+                <input type="hidden" name="action" value="delete" />
+                <input type="hidden" name="version" value="$page.version" />
+                <py:if test="page.version == latest_version">
+                  <input type="submit" name="delete_version" value="${_('Delete this version')}" />
+                </py:if>
+                <input type="submit" value="${_('Delete page')}" />
+              </div>
+            </form>
           </div>
         </py:if>
       </py:with>

File trac/wiki/web_ui.py

         elif action == 'rename':
             return self._render_confirm_rename(req, page)
         elif action == 'edit':
-            return self._render_editor(req, versioned_page)
+            return self._render_editor(req, page)
         elif action == 'diff':
             return self._render_diff(req, versioned_page)
         elif action == 'history':
         else:
             req.perm(page.resource).require('WIKI_MODIFY')
         original_text = page.text
+        comment = req.args.get('comment', '')
         if 'text' in req.args:
             page.text = req.args.get('text')
         elif 'template' in req.args:
             if template_page and template_page.exists and \
                    'WIKI_VIEW' in req.perm(template_page.resource):
                 page.text = template_page.text
+        elif 'version' in req.args:
+            old_page = WikiPage(self.env, page.name,
+                                version=int(req.args['version']))
+            req.perm(page.resource).require('WIKI_VIEW')
+            page.text = old_page.text
+            comment = _("Reverted to version %(version)s.",
+                        version=req.args['version'])
         if action in ('preview', 'diff'):
             page.readonly = 'readonly' in req.args
 
         author = get_reporter_id(req, 'author')
-        comment = req.args.get('comment', '')
-
         defaults = {'editrows': 20}
         prefs = dict((key, req.session.get('wiki_%s' % key, defaults.get(key)))
                      for key in ('editrows', 'sidebyside'))