<div id="c-wiki-pages">
  <div id="a-index">
    <%= render "wiki_pages/sidebar" %>

    <section id="content">
      <h1>Wiki Pages</h1>

      <%= form_tag(diff_wiki_page_versions_path, :method => :get) do %>
        <table width="100%" class="striped">
          <thead>
            <tr>
              <% if params[:search] && params[:search][:wiki_page_id] && @wiki_page_versions.length > 1 %>
                <th width="3%"></th>
                <th width="2%"></th>
                <th width="2%"></th>
              <% end %>
              <th>Title</th>
              <th width="5%"></th>
              <% if CurrentUser.is_janitor? %>
                <th width="10%">IP Address</th>
              <% end %>
              <th width="26%">Last edited</th>
            </tr>
          </thead>
          <tbody>
            <% @wiki_page_versions.each_with_index do |wiki_page_version, i| %>
              <tr>
                <% if params[:search] && params[:search][:wiki_page_id] && @wiki_page_versions.length > 1 %>
                  <td>
                    <% if i < @wiki_page_versions.length - 1 %>
                      <%= link_to "diff", diff_wiki_page_versions_path(:otherpage => wiki_page_version.id, :thispage => @wiki_page_versions[i + 1].id) %>
                    <% else %>
                      diff
                    <% end %>
                  </td>
                  <td>
                    <% if i == 1 %>
                      <%= radio_button_tag "thispage", wiki_page_version.id, :checked => true %>
                    <% else %>
                      <%= radio_button_tag "thispage", wiki_page_version.id %>
                    <% end %>
                  </td>
                  <td>
                    <% if i == 0 %>
                      <%= radio_button_tag "otherpage", wiki_page_version.id, :checked => true %>
                    <% else %>
                      <%= radio_button_tag "otherpage", wiki_page_version.id %>
                    <% end %>
                  </td>
                <% end %>
                <td class="category-<%= wiki_page_version.category_name %>"><%= link_to wiki_page_version.title, wiki_page_version_path(wiki_page_version) %></td>
                <td><%= link_to "wiki", wiki_page_path(wiki_page_version.wiki_page_id) %></td>
                <% if CurrentUser.is_janitor? %>
                  <td>
                    <%= wiki_page_version.updater_ip_addr %>
                  </td>
                <% end %>
                <td>
                  <%= compact_time(wiki_page_version.updated_at) %>
                  <% if wiki_page_version.updater %>
                    by
                    <%= link_to_user wiki_page_version.updater %>
                  <% end %>
                </td>
              </tr>
            <% end %>
          </tbody>
        </table>

        <% if params[:search] && params[:search][:wiki_page_id] %>
          <%= submit_tag "Diff" %>
        <% end %>
      <% end %>

      <%= numbered_paginator(@wiki_page_versions) %>
    </section>
  </div>
</div>

<%= render "wiki_pages/secondary_links" %>

<% content_for(:page_title) do %>
  Wiki Page Versions - <%= Danbooru.config.app_name %>
<% end %>
