##This file is based on the template from the SimpleWiki source which carries the GPL license

<%inherit file="simplewiki_base.html"/>

<%block name="title"><title>${"Revision history of " + wiki_title + " - " if wiki_title is not UNDEFINED else ""}Wiki – MITx 6.002x</title></%block>

<%!
    from django.core.urlresolvers import reverse
%>

<%block name="wiki_page_title">
<h1>
${ wiki_article.title }
</h1>
</%block>

<%block name="wiki_body">
<form method="POST">
<div style="display:none">
    <input type="hidden" name="csrfmiddlewaretoken" value="${csrf_token}"/>
</div>
<table id="wiki_history_table" class="wiki-history">
    <thead>
        <tr>
            <th id="revision">Revision</th>
            <th id="comment">Comment</th>
            <th id="diff">Diff</th>
            <th id="modified">Modified</th>
        </tr>
    </thead>
    <tbody>
      <% loopCount = 0 %>
      %for revision in wiki_history:
      %if revision.deleted < 2 or show_delete_revision:
      <% loopCount += 1 %>
      <tr style="border-top: 1px" class="${'dark ' if (loopCount % 2) == 0 else ''}${'deleted ' if (revision.deleted==2) else ''}" >
        <td width="15px">
          <input  type="radio" name="revision" id="${revision.id}" value="${revision.id}"${"checked" if wiki_article.current_revision.id == revision.id else ""}/>
          <label for="${revision.id}">
            ${ revision }
            %if revision.previous_revision:
            %if not revision.counter == revision.previous_revision.counter + 1:
            <br/>(based on ${revision.previous_revision})
            %endif
            %endif
          </label>
        </td>
        <td>
          ${ revision.revision_text if revision.revision_text else "<i>None</i>" }</td>
        <td class="diff">
          %for x in revision.get_diff():
          ${x|h}<br/>
          %endfor </td>
        <td>${revision.get_user()}
          <br/>
          ${revision.revision_date.strftime("%b %d, %Y, %I:%M %p")}
        </td>
      </tr>
      %endif
        %endfor
    </tbody>
    %if wiki_prev_page or wiki_next_page:
        <tfoot>
            <tr>
                <td colspan="4">
                    %if wiki_prev_page:
                        <a href="${reverse("wiki_history", args=[wiki_article.get_url(), wiki_prev_page])}">Previous page</a>
                    %endif
                    %if wiki_next_page:
                        <a href="${reverse("wiki_history", args=[wiki_article.get_url(), wiki_next_page])}">Next page</a>
                    %endif
                </td>
            </tr>
        </tfoot>
    %endif
</table>
<div class="history-controls"><input type="submit" name="view" value="View revision"/>
  <input type="submit" name="change" value="Change to revision"
  %if not wiki_write:
    disabled="true"
  %endif
  />
  %if show_delete_revision:
  <input type="submit" name="delete" value="Delete revision"/>
  <input type="submit" name="restore" value="Restore revision"/>
  <input type="submit" name="delete_all" value="Delete all revisions">
  <input type="submit" name="lock_article" value="${'Lock Article' if not wiki_article.locked else 'Unlock Article'}">
  %endif
</div>
</form>
</%block>
