Skip to content
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
11 changes: 8 additions & 3 deletions jottit/blueprints/secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@
)
secret_bp.add_url_rule("/site/changes", endpoint="site_changes", view_func=site_views.changes)
secret_bp.add_url_rule(
"/site/changes.atom",
endpoint="site_changes_atom",
view_func=site_views.changes_atom,
"/site/changes.rss",
endpoint="site_changes_rss",
view_func=site_views.changes_rss,
)
secret_bp.add_url_rule(
"/site/changes.json",
endpoint="site_changes_json",
view_func=site_views.changes_json,
)
secret_bp.add_url_rule(
"/site/hide-primer",
Expand Down
3 changes: 2 additions & 1 deletion jottit/blueprints/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
site_bp.add_url_rule("/forgot-password", view_func=views.forgot_password, methods=["GET", "POST"])
site_bp.add_url_rule("/change-password", view_func=views.change_password, methods=["GET", "POST"])
site_bp.add_url_rule("/changes", view_func=views.changes)
site_bp.add_url_rule("/changes.atom", view_func=views.changes_atom)
site_bp.add_url_rule("/changes.rss", view_func=views.changes_rss)
site_bp.add_url_rule("/changes.json", view_func=views.changes_json)
site_bp.add_url_rule("/hide-primer", view_func=views.hide_primer, methods=["POST"])
68 changes: 68 additions & 0 deletions jottit/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,74 @@ def get_revision(
return conn.execute(stmt.limit(1)).first()


def get_revisions(
conn: Connection,
*,
page_id: int,
before: int | None = None,
limit: int = 20,
) -> list[Row]:
"""List revisions for a page in newest-first order.

`before` filters to revisions strictly less than the given revision
number — used to page back through history (the original called this
`start`). `limit` is per-page; the default of 20 matches the 2007 UI.
"""
stmt = (
select(revisions)
.where(revisions.c.page_id == page_id, revisions.c.revision > 0)
.order_by(revisions.c.revision.desc())
.limit(limit)
)
if before is not None:
stmt = stmt.where(revisions.c.revision < before)
return list(conn.execute(stmt).all())


def get_revisions_count(conn: Connection, *, page_id: int) -> int:
"""Count of non-sentinel revisions for a page; used for history pagination."""
return conn.execute(
select(func.count())
.select_from(revisions)
.where(revisions.c.page_id == page_id, revisions.c.revision > 0)
).scalar_one()


def get_changes(
conn: Connection,
*,
site_id: int,
before: int | None = None,
limit: int = 20,
) -> list[Row]:
"""Site-wide activity feed: every revision across every page, newest first.

Each row carries `page_name`, `page_deleted`, the revision fields, and
`id` of the revision (for the `before=` cursor). The 2007 implementation
of this was stubbed out with `return []` and a comment marking the query
as impossible at the time; modern Postgres handles it without issue.
"""
stmt = (
select(
revisions.c.id,
revisions.c.revision,
revisions.c.content,
revisions.c.changes,
revisions.c.ip,
revisions.c.created,
pages.c.name.label("page_name"),
pages.c.deleted.label("page_deleted"),
)
.select_from(revisions.join(pages, revisions.c.page_id == pages.c.id))
.where(pages.c.site_id == site_id, revisions.c.revision > 0)
.order_by(revisions.c.created.desc(), revisions.c.id.desc())
.limit(limit)
)
if before is not None:
stmt = stmt.where(revisions.c.id < before)
return list(conn.execute(stmt).all())


def new_page(
conn: Connection,
*,
Expand Down
30 changes: 30 additions & 0 deletions jottit/templates/changes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Recent changes</title>
</head>
<body>
<h1>Recent changes</h1>
{% if changes %}
<ul>
{% for c in changes %}
<li>
<a href="{{ site_root_path }}{{ page_slug(c.page_name) }}?r={{ c.revision }}">
{{ c.page_name or "Home" }} &mdash; revision {{ c.revision }}
</a>
<small>{{ c.created.strftime("%Y-%m-%d %H:%M") }} UTC</small>
{% if c.page_deleted %}<em>(page since deleted)</em>{% endif %}
{% if c.changes %}<span class="changes">{{ c.changes|safe }}</span>{% endif %}
</li>
{% endfor %}
</ul>
{% if older_before %}
<p><a href="?before={{ older_before }}">Older &rarr;</a></p>
{% endif %}
{% else %}
<p>No changes yet.</p>
{% endif %}
<p><a href="{{ site_root_path }}">Back to site</a></p>
</body>
</html>
18 changes: 18 additions & 0 deletions jottit/templates/diff.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Diff: {{ page_name or "Home" }}</title>
</head>
<body>
<h1>Diff: {{ page_name or "Home" }}</h1>
<p>
Comparing
<a href="{{ site_root_path }}{{ page_name }}?r={{ a.revision }}">revision {{ a.revision }}</a>
with
<a href="{{ site_root_path }}{{ page_name }}?r={{ b.revision }}">revision {{ b.revision }}</a>.
</p>
<article>{{ diff_html|safe }}</article>
<p><a href="{{ site_root_path }}{{ page_name }}?m=history">Back to history</a></p>
</body>
</html>
18 changes: 18 additions & 0 deletions jottit/templates/feeds/changes.rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ site_title|e }} — recent changes</title>
<link>{{ site_url|e }}</link>
<atom:link href="{{ feed_url|e }}" rel="self" type="application/rss+xml" />
<description>Recent changes across all pages.</description>
{% for c in changes %}
<item>
<title>{{ (c.page_name or "Home")|e }} — revision {{ c.revision }}</title>
<link>{{ absolute_url(page_slug(c.page_name) + "?r=" + c.revision|string)|e }}</link>
<guid isPermaLink="true">{{ absolute_url(page_slug(c.page_name) + "?r=" + c.revision|string)|e }}</guid>
<pubDate>{{ c.created.strftime("%a, %d %b %Y %H:%M:%S GMT") }}</pubDate>
{% if c.changes %}<description><![CDATA[{{ c.changes }}]]></description>{% endif %}
</item>
{% endfor %}
</channel>
</rss>
18 changes: 18 additions & 0 deletions jottit/templates/feeds/history.rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ site_title|e }} — {{ page_label|e }} history</title>
<link>{{ page_url|e }}</link>
<atom:link href="{{ feed_url|e }}" rel="self" type="application/rss+xml" />
<description>Revision history for {{ page_label|e }}.</description>
{% for r in revisions %}
<item>
<title>Revision {{ r.revision }}</title>
<link>{{ page_url|e }}?r={{ r.revision }}</link>
<guid isPermaLink="true">{{ page_url|e }}?r={{ r.revision }}</guid>
<pubDate>{{ r.created.strftime("%a, %d %b %Y %H:%M:%S GMT") }}</pubDate>
{% if r.changes %}<description><![CDATA[{{ r.changes }}]]></description>{% endif %}
</item>
{% endfor %}
</channel>
</rss>
24 changes: 24 additions & 0 deletions jottit/templates/history.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>History: {{ page_name or "Home" }}</title>
</head>
<body>
<h1>History: {{ page_name or "Home" }}</h1>
<p>{{ total }} revision{{ "s" if total != 1 }}.</p>
<ul>
{% for r in revisions %}
<li>
<a href="{{ site_root_path }}{{ page_name }}?r={{ r.revision }}">Revision {{ r.revision }}</a>
<small>{{ r.created.strftime("%Y-%m-%d %H:%M") }} UTC</small>
{% if r.changes %}<span class="changes">{{ r.changes|safe }}</span>{% endif %}
</li>
{% endfor %}
</ul>
{% if older_before %}
<p><a href="?m=history&amp;before={{ older_before }}">Older &rarr;</a></p>
{% endif %}
<p><a href="{{ site_root_path }}{{ page_name }}">Back to page</a></p>
</body>
</html>
Loading
Loading