Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wiki tagging #407

Merged
merged 12 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion mainpage/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@
WIKI_LOCK_DURATION = 30
WIKI_URL_RE = r"[:\-\w ]+"
WIKI_WORD_RE = r"[:\-\w ]+"
# List pages below the URL '/wiki/...' here if they are dynamically created
WIKI_SPECIAL_PAGES = [
"list",
"search",
"history",
"feeds",
"observe",
"edit",
"tag_list",
]

######################
# User configuration #
Expand Down Expand Up @@ -203,9 +213,14 @@
####################
# threadedcomments #
####################

DEFAULT_MARKUP = 1 # "markdown"

##################
# django-tagging #
##################
FORCE_LOWERCASE_TAGS = True
MAX_TAG_LENGTH = 20

##################################
# Uploading files and validation #
##################################
Expand Down
2 changes: 1 addition & 1 deletion mainpage/templatetags/wl_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _classify_link(tag):
return

# Wiki special pages are also not counted
if article_name in ["list", "search", "history", "feeds", "observe", "edit"]:
if article_name in settings.WIKI_SPECIAL_PAGES:
tag["class"] = "specialLink"
return

Expand Down
2 changes: 1 addition & 1 deletion wiki/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.contrib.contenttypes.fields import GenericRelation, GenericForeignKey

from tagging.fields import TagField
from tagging.models import Tag

from wlimages.models import Image

try:
Expand Down
4 changes: 2 additions & 2 deletions wiki/static/css/wiki.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
float: right;
max-width: 20em;
}

.toc ul {
padding-left: 1.8em;
}
Expand Down Expand Up @@ -59,7 +59,7 @@
text-align: left;
}

#edit_wiki_page_form #id_title,#id_comment {
#edit_wiki_page_form #id_title, #id_comment, #id_tags {
width: 100%;
}

Expand Down
26 changes: 19 additions & 7 deletions wiki/templates/wiki/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

$(document).ready(function() {
// Insert rendered markup for preview
$("#id_preview").click(function(){
$("#id_preview").click(function(){
// Activate preview
$("#preview").html("<h3>Preview</h3>\n<hr>\n<div class=\"wiki_article\" id=\"content_preview\">Loading...</div>\n<hr>");
$("#content_preview").load( "{% url 'wiki_preview' %}",
$("#content_preview").load( "{% url 'wiki_preview' %}",
{"body": $("#id_content").val()});
});

{% ifequal new_article 0 %}
// Insert diff
$("#id_diff").click(function(){
{% ifequal new_article 0 %}
// Insert diff
$("#id_diff").click(function(){
// Activate preview
$("#diff").html("<h3>Diff</h3>\n<hr>\n<div id=\"content_diff\">Loading...</div>\n<hr>");
$("#content_diff").load( "{% url 'wiki_preview_diff' %}",
$("#content_diff").load( "{% url 'wiki_preview_diff' %}",
{"body": $("#id_content").val(), "article": {{ object_id }} });
});
{%endifequal%}
Expand All @@ -54,6 +54,7 @@ <h1>{% trans "Editing" %} {{ article.title }}</h1>
{% endif %}
<p>
You can edit the wiki pages contents using the syntax described on the <a href="/wiki/WikiSyntax">WikiSyntax</a>.
For a description of the input fields see: <a href="/wiki/WikiHelp">WikiHelp</a>
</p>

<div id="preview"></div>
Expand All @@ -70,6 +71,17 @@ <h1>{% trans "Editing" %} {{ article.title }}</h1>
<!-- Content -->
<tr><th colspan="2"><label for="id_content">{% trans "Content" %}:</label></th></tr>
<tr><td colspan="2" class="errormessage">{{ form.content.errors }}{{ form.content }}</td></tr>
<!-- Tags -->
<tr>
<th colspan="2">
<label for={{ form.tags.id_for_label }}>Tags:</label>
<a href="/wiki/WikiHelp/#tagging" title="Help (new window)" style="float: right;" target="_blank">
<img src="{% static "img/menu_help_borderless.png" %}" alt="Help for tags" class="middle">
Help for Tags
</a>
</th>
</tr>
<tr><td colspan="2" class="errormessage">{{ form.tags.errors }}{{ form.tags }}</td></tr>
<!-- Summary -->
<tr><th colspan="2"><label for="id_summary">{% trans "Page Summary" %}:</label></th></tr>
<tr><td colspan="2" class="errormessage">{{ form.summary.errors }}{{ form.summary }}</td></tr>
Expand All @@ -91,7 +103,7 @@ <h1>{% trans "Editing" %} {{ article.title }}</h1>
<input type="submit" value="{% trans "Save" %}" />
</div>
{% csrf_token %}
</form>
</form>
<br />
<h3>Images</h3>
{% if new_article %}
Expand Down
2 changes: 2 additions & 0 deletions wiki/templates/wiki/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ <h1>Wiki: Index</h1>
<th>{% trans "Page" %}</th>
<th>{% trans "Summary" %}</th>
<th>{% trans "Last update" %}</th>
<th>{% trans "Tagged with" %}</th>
Noordfrees marked this conversation as resolved.
Show resolved Hide resolved
</tr>
</thead>
<tbody>
Expand All @@ -26,6 +27,7 @@ <h1>Wiki: Index</h1>
<td><a href="{% url 'wiki_article' article.title %}">{{ article.title }}</a></td>
<td>{{ article.summary }}</td>
<td>{{ article.last_update|custom_date:user }}</td>
<td>{% include "wiki/inlines/tag_urls.html" %}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
11 changes: 11 additions & 0 deletions wiki/templates/wiki/inlines/tag_urls.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% load tagging_tags %}

{% tags_for_object article as tag_list %}
{% for t in tag_list %}
{% if t != tag %}
{% comment %}the forloop.last needs to be in every line to prevent a space after the tag {% endcomment %}
<a href="{% url 'article_tag_detail' t.name %}">{{t.name}}</a>{% if not forloop.last %},{% endif %}
{% else %}
<span class="grey">{{ t.name }}</span>{% if not forloop.last %},{% endif %}
{% endif %}
{% endfor %}
33 changes: 33 additions & 0 deletions wiki/templates/wiki/tag_view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% extends 'wiki/base.html' %}
{% load i18n %}
{% load wiki_extras %}

{% block title %}
{{ article.title }} - {{block.super}}
{% endblock %}


{% block content_header %}
<h1>Articles with tag '{{ tag.name }}'</h1>
{% endblock %}

{% block content_main %}
<div class="blogEntry">
<table>
<thead>
<tr>
<th>Article name</th>
<th>Tagged with</th>
</tr>
</thead>
<tbody>
{% for article in object_list %}
<tr>
<td><a href="{% url 'wiki_article' article %}">{{ article }}</a></td>
<td>{% include "wiki/inlines/tag_urls.html" %}</td>
</tr>
</tbody>
{% endfor %}
</table>
{% endblock %}

12 changes: 12 additions & 0 deletions wiki/templates/wiki/view.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends 'wiki/base.html' %}
{% load i18n %}
{% load wiki_extras %}
{% load tagging_tags %}

{% block title %}
{{ article.title }} - {{block.super}}
Expand Down Expand Up @@ -43,7 +44,18 @@ <h1>{{ article.title }}</h1>
({% trans "Viewing revision " %} {{ revision }})
</p>
{% endif %}
{% if outdated %}
<h2 class="errormessage">Outdated</h2>
<p class="errormessage">This article is marked as outdated.
If you are familiar with this topic, please consider updating and improving this page.
In case of any questions, please ask in the forum! For pointers see <a href="/wiki/WikiHelp">WikiHelp</a> in our wiki.
After finishing your work remove the 'outdated' tag.</p>
{% endif %}
{% render_content article %}
{% tags_for_object article as tag_list %}
{% if tag_list %}
<div class="right">Tagged with: {% include "wiki/inlines/tag_urls.html" %}</div>
{% endif %}
</div>
{% endblock %}

12 changes: 12 additions & 0 deletions wiki/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
RssArticleHistoryFeed,
AtomArticleHistoryFeed,
)
from wiki.models import Article
from tagging.views import TaggedObjectList


urlpatterns = [
# Redirects
Expand Down Expand Up @@ -96,4 +99,13 @@
views.backlinks,
name="backlinks",
),
url(
r"^tag_list/(?P<tag>[^/]+(?u))/$",
TaggedObjectList.as_view(
model=Article,
allow_empty=True,
template_name="wiki/tag_view.html",
),
name="article_tag_detail",
),
]
7 changes: 7 additions & 0 deletions wiki/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from mainpage.wl_utils import get_real_ip
from mainpage.wl_utils import get_valid_cache_key

from tagging.models import Tag

import re
import urllib.request, urllib.parse, urllib.error

Expand Down Expand Up @@ -226,11 +228,16 @@ def view_article(
changeset = get_object_or_404(article.changeset_set, revision=revision)
article.content = changeset.get_content()

outdated = False
tags = [x.name for x in Tag.objects.get_for_object(article)]
if "outdated" in tags:
outdated = True
template_params = {
"article": article,
"revision": revision,
"redirected_from": redirected_from,
"allow_write": allow_write,
"outdated": outdated,
}

if notification is not None:
Expand Down