From: Michael Tremer Date: Mon, 3 Dec 2018 17:49:36 +0000 (+0000) Subject: wiki: Create a watchlist with all pages a user has ever edited X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d64a1e354887fabf655df9b5c4bccebb43aadb04;p=ipfire.org.git wiki: Create a watchlist with all pages a user has ever edited Signed-off-by: Michael Tremer --- diff --git a/src/backend/wiki.py b/src/backend/wiki.py index dad4a242..65b9d600 100644 --- a/src/backend/wiki.py +++ b/src/backend/wiki.py @@ -358,6 +358,28 @@ class Page(misc.Object): parts.pop() + # Watchers + + def is_watching(self, account): + res = self.db.get("SELECT 1 FROM wiki_watchlist \ + WHERE page = %s AND uid = %s", self.page, account.uid) + + if res: + return True + + return False + + def add_watcher(self, account): + if self.is_watching(account): + return + + self.db.execute("INSERT INTO wiki_watchlist(page, uid) \ + VALUES(%s, %s)", self.page, account.uid) + + def remove_watcher(self, account): + self.db.execute("DELETE FROM wiki_watchlist \ + WHERE page = %s AND uid = %s", self.page, account.uid) + class File(misc.Object): def init(self, id, data): diff --git a/src/templates/wiki/edit.html b/src/templates/wiki/edit.html index 1336ea50..1c6598a3 100644 --- a/src/templates/wiki/edit.html +++ b/src/templates/wiki/edit.html @@ -34,6 +34,11 @@ +
+ + +
+ diff --git a/src/templates/wiki/page.html b/src/templates/wiki/page.html index 88e49dea..4ccfea44 100644 --- a/src/templates/wiki/page.html +++ b/src/templates/wiki/page.html @@ -23,27 +23,29 @@ {% end %} -
- +

+ {% if current_user %} + {% if page.is_watching(current_user) %} + + {% else %} + + {% end %} • + {% end %} + + + {{ _("Older Revisions") }} + -

-

- {{ _("Last modified %s") % locale.format_date(page.timestamp) }} + • - {% if page.author %} - • + {{ _("Last modified %s") % locale.format_date(page.timestamp) }} - - {{ page.author }} - - {% end %} -

-
-
+ {% if page.author %} + • + + + {{ page.author }} + + {% end %} +

{% end block %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 99afa5ea..b8b363f4 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -290,6 +290,7 @@ class Application(tornado.web.Application): # Actions (r"/actions/edit", wiki.ActionEditHandler), + (r"/action/(watch|unwatch)(.*)", wiki.ActionWatchHandler), (r"/actions/upload", wiki.ActionUploadHandler), # Handlers diff --git a/src/web/wiki.py b/src/web/wiki.py index 7adf3756..d92e4f08 100644 --- a/src/web/wiki.py +++ b/src/web/wiki.py @@ -24,6 +24,11 @@ class ActionEditHandler(auth.CacheMixin, base.BaseHandler): page = self.backend.wiki.create_page(path, self.current_user, content, changes=changes, address=self.get_remote_ip()) + # Add user as a watcher if wanted + watch = self.get_argument("watch", False) + if watch: + page.add_watcher(self.current_user) + # Redirect back if page.was_deleted(): self.redirect("/") @@ -65,6 +70,23 @@ class ActionUploadHandler(auth.CacheMixin, base.BaseHandler): self.redirect("%s/files" % path) +class ActionWatchHandler(auth.CacheMixin, base.BaseHandler): + @tornado.web.authenticated + def get(self, action, path): + page = self.backend.wiki.get_page(path) + if not page: + raise tornado.web.HTTPError(404, "Page does not exist: %s" % path) + + with self.db.transaction(): + if action == "watch": + page.add_watcher(self.current_user) + elif action == "unwatch": + page.remove_watcher(self.current_user) + + # Redirect back to page + self.redirect(page.url) + + class FilesHandler(auth.CacheMixin, base.BaseHandler): @tornado.web.authenticated def get(self, path):