]> git.ipfire.org Git - ipfire.org.git/commitdiff
wiki: Create a watchlist with all pages a user has ever edited
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 3 Dec 2018 17:49:36 +0000 (17:49 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 3 Dec 2018 17:49:36 +0000 (17:49 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/wiki.py
src/templates/wiki/edit.html
src/templates/wiki/page.html
src/web/__init__.py
src/web/wiki.py

index dad4a242b9032d4e25ce28a4d87aeab3a70a6ecb..65b9d600ab8b0e2c0606e80932c73653a86278da 100644 (file)
@@ -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):
index 1336ea50d414496266ec363a4d9d32ad49dc0f57..1c6598a3064fa3e6b8c26807b6f64435031dc767 100644 (file)
                                        </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>
index 88e49dea111ace9da17af33819602f5379b5f8fa..4ccfea44627aa19ae591d487d75cdcbee5349fd5 100644 (file)
                </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 %} &bull;
+               {% 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) }}
+               &bull;
 
-                               {% if page.author %}
-                                       &bull;
+               {{ _("Last modified %s") % locale.format_date(page.timestamp) }}
 
-                                       <a href="/users/{{ page.author.uid }}">
-                                               {{ page.author }}
-                                       </a>
-                               {% end %}
-                       </p>
-               </div>
-       </div>
+               {% if page.author %}
+                       &bull;
+
+                       <a href="/users/{{ page.author.uid }}">
+                               {{ page.author }}
+                       </a>
+               {% end %}
+       </p>
 {% end block %}
index 99afa5ead246a6a25a70d3131c4430218c7b9f06..b8b363f4633d53daf8ff317d60f28990cf31e9b7 100644 (file)
@@ -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
index 7adf37566a005991b95e42111866b14b81443136..d92e4f0811c237889b00c2fb49ba07bc0f2fd62d 100644 (file)
@@ -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):