changeset 5410:dac434907110

Information about revisions (number, timestamp, editor, size) in diff viewer.
author Eugene Syromyatnikov <evgsyr@gmail.com>
date Sun, 10 Jan 2010 05:05:51 +0300
parents c3822eacfe4a
children 5b31c32179d4
files MoinMoin/action/diff.py MoinMoin/util/diff_html.py MoinMoin/web/static/htdocs/classic/css/screen.css MoinMoin/web/static/htdocs/modern/css/screen.css MoinMoin/web/static/htdocs/modernized/css/screen.css MoinMoin/web/static/htdocs/rightsidebar/css/screen.css
diffstat 6 files changed, 100 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/diff.py	Sun Jan 10 05:01:43 2010 +0300
+++ b/MoinMoin/action/diff.py	Sun Jan 10 05:05:51 2010 +0300
@@ -179,11 +179,45 @@
 
     request.write(f.rawHTML(navigation_html))
 
+    oldlog = oldpage.editlog_entry()
+    newlog = newpage.editlog_entry()
+
+    rev_info_html = """
+  <div class="diff-info diff-info-header">%(rev_header)s</div>
+  <div class="diff-info diff-info-rev-size"><span class="diff-info-caption">%(rev_size_caption)s:</span> <span class="diff-info-value">%%(rev_size)d</span></div>
+  <div class="diff-info diff-info-rev-author"><span class="diff-info-caption">%(rev_author_caption)s:</span> <span class="diff-info-value">%%(rev_author)s</span></div>
+  <div class="diff-info diff-info-rev-comment diff_info_rev1"><span class="diff-info-caption">%(rev_comment_caption)s:</span> <span class="diff-info-value">%%(rev_comment)s</span></div>
+""" % {
+    'rev_header': _('Revision %(rev)d as of %(date)s'),
+    'rev_size_caption': _('Size'),
+    'rev_author_caption': _('Editor'),
+    'rev_ts_caption': _('Date'),
+    'rev_comment_caption': _('Comment'),
+}
+
+    rev_info_old_html = rev_info_html % {
+        'rev': oldrev,
+        'rev_size': oldpage.size(),
+        'rev_author': oldlog.getEditor(request) or _('N/A'),
+        'date': request.user.getFormattedDateTime(wikiutil.version2timestamp(oldlog.ed_time_usecs)) or _('N/A'),
+        'rev_comment': wikiutil.escape(oldlog.comment) or '',
+    }
+
+    rev_info_new_html = rev_info_html % {
+        'rev': newrev,
+        'rev_size': newpage.size(),
+        'rev_author': newlog.getEditor(request) or _('N/A'),
+        'date': request.user.getFormattedDateTime(wikiutil.version2timestamp(newlog.ed_time_usecs)) or _('N/A'),
+        'rev_comment': wikiutil.escape(newlog.comment) or '',
+    }
+
     if request.user.show_fancy_diff:
         from MoinMoin.util import diff_html
-        request.write(f.rawHTML(diff_html.diff(request, oldpage.get_raw_body(), newpage.get_raw_body())))
+        request.write(f.rawHTML(diff_html.diff(request, oldpage.get_raw_body(), newpage.get_raw_body(), old_top=rev_info_old_html, new_top=rev_info_new_html)))
         newpage.send_page(count_hit=0, content_only=1, content_id="content-below-diff")
     else:
+        request.write(f.rawHTML('<table class="diff"><tr><td>%s</td><td>%s</td></tr></table>' % (rev_info_old_html, rev_info_new_html)))
+
         from MoinMoin.util import diff_text
         lines = diff_text.diff(oldpage.getlines(), newpage.getlines())
         if not lines:
--- a/MoinMoin/util/diff_html.py	Sun Jan 10 05:01:43 2010 +0300
+++ b/MoinMoin/util/diff_html.py	Sun Jan 10 05:05:51 2010 +0300
@@ -23,9 +23,16 @@
 
 
 # This code originally by Scott Moonen, used with permission.
-def diff(request, old, new):
+def diff(request, old, new, old_top='', new_top='', old_bottom='', new_bottom=''):
     """ Find changes between old and new and return
         HTML markup visualising them.
+
+        @param old: old text [unicode]
+        @param new: new text [unicode]
+        @param old_top: Custom html for adding ontop of old revision column (optional)
+        @param old_bottom: Custom html for adding at bottom of old revision column (optional)
+        @param new_top: Custom html for adding ontop of new revision column (optional)
+        @param new_bottom: Custom html for adding at bottom of new revision column (optional)
     """
     _ = request.getText
     t_line = _("Line") + " %d"
@@ -44,6 +51,12 @@
 
     result = """
 <table class="diff">
+"""
+
+    if old_top or new_top:
+        result += "<tr><td>%s</td><td>%s</td></tr>" % (old_top, new_top)
+
+    result += """
 <tr>
 <td class="diff-removed">
 <span>
@@ -138,6 +151,9 @@
 
         lastmatch = (match[0] + match[2], match[1] + match[2])
 
+    if old_bottom or new_bottom:
+        result += "<tr><td>%s</td><td>%s</td></tr>" % (old_bottom, new_bottom)
+
     result += '</table>\n'
     return result
 
--- a/MoinMoin/web/static/htdocs/classic/css/screen.css	Sun Jan 10 05:01:43 2010 +0300
+++ b/MoinMoin/web/static/htdocs/classic/css/screen.css	Sun Jan 10 05:05:51 2010 +0300
@@ -415,6 +415,18 @@
 	background-color: #FFFF80;
 }
 
+div.diff-info {
+    white-space:nowrap;
+}
+
+div.diff-info-header {
+    background-color:#E8E8E8;
+    width:100%;
+    padding:0.25em 0.5em;
+    margin:-0.25em -0.5em;
+    margin-bottom:0.25em;
+}
+
 .searchresult dd span {
 	font-weight: bold;
 }
--- a/MoinMoin/web/static/htdocs/modern/css/screen.css	Sun Jan 10 05:01:43 2010 +0300
+++ b/MoinMoin/web/static/htdocs/modern/css/screen.css	Sun Jan 10 05:05:51 2010 +0300
@@ -475,6 +475,18 @@
     background-color: #FFFF80;
 }
 
+div.diff-info {
+    white-space:nowrap;
+}
+
+div.diff-info-header {
+    background-color:#E8E8E8;
+    width:100%;
+    padding:0.25em 0.5em;
+    margin:-0.25em -0.5em;
+    margin-bottom:0.25em;
+}
+
 table.navigation {
     float: right;
     margin: 2px;
--- a/MoinMoin/web/static/htdocs/modernized/css/screen.css	Sun Jan 10 05:01:43 2010 +0300
+++ b/MoinMoin/web/static/htdocs/modernized/css/screen.css	Sun Jan 10 05:05:51 2010 +0300
@@ -431,6 +431,18 @@
     background-color: #FFFF80;
 }
 
+div.diff-info {
+    white-space:nowrap;
+}
+
+div.diff-info-header {
+    background-color:#E8E8E8;
+    width:100%;
+    padding:0.25em 0.5em;
+    margin:-0.25em -0.5em;
+    margin-bottom:0.25em;
+}
+
 table.navigation {
     float: right;
     margin: 2px;
--- a/MoinMoin/web/static/htdocs/rightsidebar/css/screen.css	Sun Jan 10 05:01:43 2010 +0300
+++ b/MoinMoin/web/static/htdocs/rightsidebar/css/screen.css	Sun Jan 10 05:05:51 2010 +0300
@@ -366,6 +366,18 @@
 	background-color: #FFFF80;
 }
 
+div.diff-info {
+    white-space:nowrap;
+}
+
+div.diff-info-header {
+    background-color:#E8E8E8;
+    width:100%;
+    padding:0.25em 0.5em;
+    margin:-0.25em -0.5em;
+    margin-bottom:0.25em;
+}
+
 .searchresult dd span {
 	font-weight: bold;
 }