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):
</div>
</div>
+ <div class="form-group form-check">
+ <input type="checkbox" class="form-check-input" name="watch" id="watch" checked>
+ <label class="form-check-label" for="watch">{{ _("Watch this page") }}</label>
+ </div>
+
<button type="submit" class="btn btn-primary btn-block">
{% if page %}{{ _("Save Page") }}{% else %}{{ _("Create Page") }}{% end %}
</button>
</a>
{% end %}
- <div class="row">
- <div class="col-12 col-sm-6">
- <p class="small">
- <a href="{{ request.path }}?action=revisions">
- {{ _("Older Revisions") }}
- </a>
- </p>
- </div>
+ <p class="small">
+ {% if current_user %}
+ {% if page.is_watching(current_user) %}
+ <a href="/action/unwatch{{ page.url }}"><span class="fas fa-star" title="{{ _("Stop watching this page") }}"></span></a>
+ {% else %}
+ <a href="/action/watch{{ page.url }}"><span class="far fa-star" title="{{ _("Watch this page") }}"></span></a>
+ {% end %} •
+ {% end %}
+
+ <a href="{{ request.path }}?action=revisions">
+ {{ _("Older Revisions") }}
+ </a>
- <div class="col-12 col-sm-6">
- <p class="small text-right">
- {{ _("Last modified %s") % locale.format_date(page.timestamp) }}
+ •
- {% if page.author %}
- •
+ {{ _("Last modified %s") % locale.format_date(page.timestamp) }}
- <a href="/users/{{ page.author.uid }}">
- {{ page.author }}
- </a>
- {% end %}
- </p>
- </div>
- </div>
+ {% if page.author %}
+ •
+
+ <a href="/users/{{ page.author.uid }}">
+ {{ page.author }}
+ </a>
+ {% end %}
+ </p>
{% end block %}
# Actions
(r"/actions/edit", wiki.ActionEditHandler),
+ (r"/action/(watch|unwatch)(.*)", wiki.ActionWatchHandler),
(r"/actions/upload", wiki.ActionUploadHandler),
# Handlers
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("/")
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):