{# vim: set ts=2 et sts=2 sw=2: #}
{% extends "wiki/base.html" %}
{% from "wiki/includes/sidebar_modules.html" import document_tabs, document_notifications %}
{% block title %}{{ page_title(document.title) }}{% endblock %}
{% set classes = 'document' %}
{% block bodyclass %}document{% endblock %}
{% if document.parent %}
  {# If there is a parent doc, use it's URL for switching locales. #}
  {% set localizable_url = document.parent.get_absolute_url(settings.WIKI_DEFAULT_LANGUAGE) %}
{% endif %}

{% block extrahead %}
  <link rel="alternate" type="application/json" 
    href="{{ url('wiki.json_slug', document.full_path) }}">
{% endblock %}

{% block content %}
<section id="content">
  <div class="wrap">
    <div id="content-main" class="full">
      <article class="article" role="main" 
          data-current-revision="{{ document.current_revision.id }}"
          data-refresh-message="{{ _('Your changes were merged. However, something else has been edited, so this page will be refreshed to reflect the changes.') }}"
          data-cancel-edit-message="{{ _('Abort editing in progress? Your unsaved changes will be discarded.') }}">
      <header id="article-head">
        <div class="title">
            <h1 class="page-title">{{ document.title }}</h1>
        </div>
        <ul id="page-buttons">
            <li class="page-history"><a href="{{ url('wiki.document_revisions', document.full_path) }}">{{_('History')}}</a></li>
            {% if request.user.is_authenticated() %}
              <li class="page-watch"><a href="{{ url('wiki.document_watch', document.full_path) }}">{{_('Watch')}}</a></li>
            {% endif %}
            {% if document.allows_editing_by(request.user) or document.allows_revision_by(request.user) %}
              <li class="page-edit"><a href="{{ url('wiki.edit_document', document.full_path) }}">{{_('Edit')}}</a></li>
            {% endif %}
        </ul>
        {% if kumascript_errors %}
          {% include 'wiki/includes/kumascript_errors.html' %}
        {% endif %}
       </header>
        {% if redirected_from %}
          <div class="warning" id="redirected-from">
            <p>{{ _('(Redirected from <a href="{href}">{title}</a>)')|fe(href=redirected_from.get_absolute_url()|urlparams(redirect='no'), title=redirected_from.title) }}</p>
          </div>
        {% endif %}

       {#
    {% if document.is_majorly_outdated() %}
      <div class="warning-box">
        {% trans url=document.parent.get_absolute_url(), title=document.parent.title %}
          <p>This article may be out of date.</p>
          <p>
            An important change has been made to the English article on which
            this is based. Until this page is updated, you might find this
            helpful: <a href="{{ url }}">{{ title }}</a>
          </p>
        {% endtrans %}
      </div>
    {% endif %}
    #}
    
      {# There's no .has() method on review_tags; need to iterate for now #}
      {% if document.current_revision %}
        {% for tag in document.current_revision.review_tags.all() %}
          {% if 'technical' == tag.name %}
            <div class="warning review-technical">{% trans %}
              <p>This article is in need of a technical review.</p>
            {% endtrans %}</div>
          {% elif 'editorial' == tag.name %}
            <div class="warning review-editorial">{% trans %}
              <p>This article is in need of an editorial review.</p>
            {% endtrans %}</div>
          {% endif %}
        {% endfor %}
      {% endif %}

      <div id="wikiArticle" class="page-content boxed">
        {% if toc_html %}
        <div id="article-nav">
          <div class="page-toc">
            <h2>Table of Contents</h2>
            <ol>
              {{ toc_html|safe }}
            </ol>
          </div>
          <ul class="page-anchors">
            <li class="anchor-tags"><a href="#page-tags">Tags</a></li>
            <li class="anchor-files"><a href="#page-files">Files</a></li>
          </ul>
        </div>
        {% endif %}
      {% if not fallback_reason %}
        {% if document.is_template %}
          <pre class="brush: js">{{ document_html }}</pre>
        {% else %}
          {{ document_html|safe }}
        {% endif %}
      {% elif fallback_reason == 'no_translation' %}
        <div id="doc-pending-fallback" class="warning-box">
          {% trans help_link=url('wiki.document', 'localize-firefox-help'),
                   locale=settings.LOCALES[request.locale].native %}
            Our volunteers haven't translated this article into {{ locale }} yet.
            <a href="{{ help_link }}">Join us and help get the job done!</a>
          {% endtrans %}
        </div>
        {{ document_html|safe }}
      {% elif fallback_reason == 'translation_not_approved' %}
        <div id="doc-pending-fallback" class="warning-box">
          {# L10n: This is shown for existing, never-approved translations #}
          {% trans %}
            Our volunteers are working on translating this article.
            Until it's ready, maybe the English version can be of some help.
          {% endtrans %}
        </div>
        {{ document.parent.html|safe }}
      {% else %}
        {{ _("This article doesn't have approved content yet.") }}
      {% endif %}
    </div>
    <section class="page-meta">
      {% set tags = document.tags.all() %}
      {% if tags | length %}
      <section id="page-tags">
        <h2>{{ _('Tags') }}</h2>
        <div id="deki-page-tags">
          <ul class="tags">
            <li>
              {% for tag in tags %}
                <a class="text" href="{{url('wiki.tag', tag.name)}}">{{ tag.name }}</a>
              {% endfor %}
            </li>
          </ul>
        </div>
      </section>
      {% endif %}
      <section id="doc-contributors">
        {% trans contributors=user_list(contributors) %}
          Contributors to this page: {{ contributors }}
        {% endtrans %}
      </section>
    </section>
  </article>
  <form id="wiki-page-edit" class="editing" method="post" action="{{ url('wiki.edit_document', document_path=document.full_path) }}">
      <input type="hidden" name="form" id="form" value="rev" />
      <input type="hidden" name="content" id="content" value="" />
  </form>
  {#
  {% include 'wiki/includes/helpful_form.html' %}
  {% include 'wiki/includes/more_help.html' %}
  #}
    </div>
   </div>
    {% if document.allows_editing_by(request.user) %}
      <div class="edited-section-ui template">
        <a class="btn-save" href="#">{{ _('Save') }}</a>
        <a class="btn-cancel" href="#">{{ _('Cancel') }}</a>
        <div class="src"></div>
      </div>
      {# This form gets filled out and used by the inline editor when a
         conflict is detected. It needs to be server side in order to get supplied
         with a CSRF token. #}
      <form class="conflict-bouncer template" method="POST" action="">
        <input type="hidden" name="form" value="rev">
        <input type="hidden" name="current_rev" value="">
        <input type="hidden" name="content" value="">
      </form>
    {% endif %}
</section>
{% endblock %}

{% block side_top %}
  {{ document_tabs(document, document.parent, user, 'article', settings) }}

  {% if user.is_authenticated() and document %}
    <div id="doc-watch">
      {% if document.is_watched_by(user) %}
        <form action="{{ url('wiki.document_unwatch', document.full_path) }}" method="post">
          {{ csrf() }}
          <input type="submit" class="link-btn" value="{{ _('Turn off emails.') }}" />
        </form>
      {% else %}
        <form action="{{ url('wiki.document_watch', document.full_path) }}" method="post">
          {{ csrf() }}
          <input type="submit" class="link-btn" value="{{ _('Get emailed when this article changes.') }}" />
        </form>
      {% endif %}
    </div>
  {% endif %}
{% endblock %}

{% block side %}
  {% include 'wiki/includes/support_for_selectors.html' %}
{% endblock %}

{% block breadcrumbs %}
{% endblock %}
