diff options
| author | raven <citrons@mondecitronne.com> | 2026-11-02 02:24:43 -0600 |
|---|---|---|
| committer | raven <citrons@mondecitronne.com> | 2026-11-02 04:01:06 -0600 |
| commit | d322e6b1eb03b0054e94d9e16b24e1d69f0d1a1f (patch) | |
| tree | 64b27c83db19781688eae82650ab511d42a2ec9e | |
| parent | 787367195431ac9a2c30106c193582b1b9a1ff99 (diff) | |
wiki pages have a unique name, and their URL is derived from this name
| -rw-r--r-- | apioforum/forum.py | 27 | ||||
| -rw-r--r-- | apioforum/thread.py | 32 | ||||
| -rw-r--r-- | apioforum/wiki.py | 2 |
3 files changed, 55 insertions, 6 deletions
diff --git a/apioforum/forum.py b/apioforum/forum.py index 425d148..500b1f5 100644 --- a/apioforum/forum.py +++ b/apioforum/forum.py @@ -12,6 +12,7 @@ from .mdrender import render from .roles import get_forum_roles,has_permission,is_bureaucrat,get_user_role, permissions as role_permissions from .permissions import is_admin from . import read +from . import wiki from sqlite3 import OperationalError import datetime import math @@ -304,6 +305,14 @@ def create_thread(forum): elif 'lock' in request.form and not has_permission(forum['id'], g.user, "p_manage_threads"): err = "you do not have permission to lock threads" + wiki_path = wiki.normalize_page_name(title) + if thread_type == "wiki page": + existing = db.execute(""" + SELECT * FROM wiki_pages WHERE path = ? AND forum = ?; + """,(wiki_path,forum['id'])).fetchone() + if existing: + err = "there's already a page with that name" + if err is None: lock = int(request.form.get('lock','0')) cur = db.cursor() @@ -323,6 +332,10 @@ def create_thread(forum): """, (cur.lastrowid,g.user,content,"(created)")) if thread_type == "wiki page": db.execute("UPDATE posts SET wiki = 1 WHERE id = ?;", (cur.lastrowid,)) + db.execute(""" + INSERT INTO wiki_pages (path, forum, thread) + VALUES (?,?,?) + """, (wiki_path,forum['id'],thread_id)) thread = {'id': thread_id, 'forum': forum['id']} apply_selected_tags(thread, request.form) db.commit() @@ -342,6 +355,20 @@ def create_thread(forum): content=content, avail_tags=get_avail_tags(forum['id'])) +from .thread import do_view_thread + +@bp.route("/<int:forum_id>/wiki/<path>") +def view_wiki_page(forum_id, path): + db = get_db() + if path != wiki.normalize_page_name(path): + redirect(url_for('thread.view_thread_wiki', forum_id, path)) + wiki_page = db.execute(""" + SELECT * FROM wiki_pages WHERE forum = ? AND path = ?; + """,(forum_id,path)).fetchone() + if not wiki_page: + abort(404) + return do_view_thread(wiki_page['thread']) + @forum_route("roles",methods=("GET","POST")) @requires_bureaucrat def edit_roles(forum): diff --git a/apioforum/thread.py b/apioforum/thread.py index 88cc426..fc355ab 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -10,6 +10,7 @@ from .db import get_db from .roles import has_permission from . import webhooks from . import forum +from . import wiki from .forum import get_avail_tags bp = Blueprint("thread", __name__, url_prefix="/thread") @@ -48,9 +49,7 @@ def thread_info(thread_id): db = get_db() return db.execute("SELECT * FROM threads WHERE id = ?;",(thread_id,)).fetchone() -@bp.route("/<int:thread_id>") -@bp.route("/<int:thread_id>/page/<int:page>") -def view_thread(thread_id,page=1): +def do_view_thread(thread_id,page=1): db = get_db() thread = thread_info(thread_id) if thread is None: @@ -138,6 +137,15 @@ def view_thread(thread_id,page=1): max_pageno=max_pageno, ) +@bp.route("/<int:thread_id>") +@bp.route("/<int:thread_id>/page/<int:page>") +def view_thread(thread_id, page=1): + db = get_db() + wiki_page = db.execute("SELECT * FROM wiki_pages WHERE thread = ?;",(thread_id,)).fetchone() + if page == 1 and wiki_page: + return redirect(url_for('forum.view_wiki_page', forum_id=wiki_page['forum'], path=wiki_page['path'])) + return do_view_thread(thread_id, page) + def register_vote(thread,pollval): if pollval is None or pollval == 'dontvote': return @@ -481,9 +489,21 @@ def config_thread(thread_id): if len(title.strip()) == 0: err.append("title can't be empty") else: - db.execute("update threads set title = ? where id = ?;",(title,thread_id)) - flash("title updated titledly") - db.commit() + ok = True + wiki_path = wiki.normalize_page_name(title) + if thread['type'] == "wiki page": + existing = db.execute(""" + SELECT * FROM wiki_pages WHERE path = ? AND forum = ?; + """,(wiki_path,thread['forum'])).fetchone() + if existing and existing['thread'] != thread_id: + err.append("there's already a page with that name") + ok = False + if ok: + if thread['type'] == "wiki page": + db.execute("UPDATE wiki_pages SET path = ? WHERE thread = ?;",(wiki_path,thread_id)) + db.execute("update threads set title = ? where id = ?;",(title,thread_id)) + flash("title updated titledly") + db.commit() if apply_selected_tags(thread, request.form): db.commit() diff --git a/apioforum/wiki.py b/apioforum/wiki.py new file mode 100644 index 0000000..9cd2b8e --- /dev/null +++ b/apioforum/wiki.py @@ -0,0 +1,2 @@ +def normalize_page_name(name): + return name.lower().replace(" ", "_").replace("/", "_") |
