<div class="warning" id="kumascript-errors">
{% if not request.user.is_authenticated() %}
    <p>{% trans %}
    There were scripting errors on this page. While those are being addressed by
    site editors, you can view partial content below.
    {% endtrans %}</p>
{% else %}
<p>{{ _("There are scripting messages on this page:") }}</p>
<ul>
  {% for error in kumascript_errors %}
    <li class="error error-{{ error.level }}">
      {% if error.args %}
        {% set err_type = error.args[0] %}
        <strong class="type">{{ err_type }}</strong>
        {% if err_type == 'TemplateExecutionError' %}
          {% set options = error.args[2] %}
          {% set token = options.token %}
          {% set template_name = token.name %}
          {% set template_args = token.args %}
          {% set template_slug = 'Template:{name}' | f(name=template_name) %}
          {% set template_path = ('{locale}/{slug}' | f(locale='en-US', slug=template_slug)) %}
          {% set edit_url = url('wiki.edit_document', template_path) %}
          <span>
            at document offset {{ token['offset'] }}
            in macro <code>{{ template_name }} ({{ template_args }})</code>
            ( <a href="{{ edit_url }}">edit</a> ):
          </span>
        {% endif %}
        {% if err_type == 'TemplateLoadingError' %}
          {% set options = error.args[2] %}
          {% set template_name = options.name %}
          {% set template_slug = 'Template:{name}' | f(name=template_name) %}
          {% set template_path = ('{locale}/{slug}' | f(locale='en-US', slug=template_slug)) %}
          {% set edit_url = url('wiki.edit_document', template_path) %}
          {% set new_url = url('wiki.new_document') %}
          <span>
            for <code>{{ template_slug }}</code> (
                {% if 'status 404' in error.message %}
                    <a href="{{ new_url }}?slug={{ template_slug }}">new</a>
                {% else %}
                    <a href="{{ edit_url }}">edit</a>
                {% endif %}
            ):
          </span>
        {% endif %}
      {% endif %}
      <pre class="message brush: text">{{ error.message }}</pre>
    </li>
  {% endfor %}
</ul>
{% endif %}
</div>
