]> git.ipfire.org Git - ipfire.org.git/commitdiff
wiki: Show recent changes
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 12 Nov 2018 17:22:26 +0000 (17:22 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 12 Nov 2018 17:23:36 +0000 (17:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/backend/wiki.py
src/templates/base.html
src/templates/wiki/modules/list.html [new file with mode: 0644]
src/templates/wiki/recent-changes.html [new file with mode: 0644]
src/web/__init__.py
src/web/wiki.py

index 6bbd6078ba52bef95948094e84f204c5e3e05b55..08ef93a844f42a664c272abfbf95c5eb47864dc3 100644 (file)
@@ -255,11 +255,13 @@ templates_staticdir = $(templatesdir)/static
 
 templates_wiki_DATA = \
        src/templates/wiki/base.html \
-       src/templates/wiki/page.html
+       src/templates/wiki/page.html \
+       src/templates/wiki/recent-changes.html
 
 templates_wikidir = $(templatesdir)/wiki
 
 templates_wiki_modules_DATA = \
+       src/templates/wiki/modules/list.html \
        src/templates/wiki/modules/navbar.html
 
 templates_wiki_modulesdir = $(templates_wikidir)/modules
index 9dabb55c13a8c4b01d419dcb1d153226e0879945..26d96b4ec9da188c19cd5d584b05e9445817e985 100644 (file)
@@ -48,9 +48,10 @@ class Wiki(misc.Object):
                if res:
                        return Page(self.backend, res.id, data=res)
 
-       def get_recent_changes(self):
+       def get_recent_changes(self, limit=None):
                return self._get_pages("SELECT * FROM wiki \
-                       WHERE timestamp >= NOW() - INTERVAL '4 weeks' ORDER BY timestamp DESC")
+                       WHERE timestamp >= NOW() - INTERVAL '4 weeks' \
+                       ORDER BY timestamp DESC LIMIT %s", limit)
 
        def create_page(self, page, author, markdown):
                page = Page.sanitise_page_name(page)
index 858dca2b747e61fa6f56cfe492e4615cbd5a3d41..7a7c314b37b31f014b1add1b1072141ad99d09c0 100644 (file)
                                                </button>
 
                                                <div class="collapse navbar-collapse" id="navbar">
-                                                       <form class="form-inline ml-lg-auto my-2 my-lg-0" action="/search" method="GET">
+                                                       <ul class="navbar-nav ml-auto">
+                                                               <li class="nav-item">
+                                                                       <a class="nav-link {% if request.path == "/recent-changes" %}active{% end %}" href="/recent-changes">
+                                                                               {{ _("Recent Changes") }}
+                                                                       </a>
+                                                               </li>
+                                                       </ul>
+
+                                                       <form class="form-inline my-2 my-lg-0" action="/search" method="GET">
                                                                <input class="form-control form-control-sm" type="search" name="q"
                                                                        placeholder="{{ _("Search...") }}" aria-label="{{ _("Search") }}" value="{% try %}{{ q }}{% except %}{% end %}">
                                                        </form>
diff --git a/src/templates/wiki/modules/list.html b/src/templates/wiki/modules/list.html
new file mode 100644 (file)
index 0000000..7e0a3a3
--- /dev/null
@@ -0,0 +1,14 @@
+{% for page in pages %}
+       <strong class="mb-0">
+               <a href="{{ page.url }}">{{ page.title }}</a>
+       </strong>
+
+       <p class="text-muted small">
+               {{ locale.format_date(page.timestamp, shorter=True, relative=False) }}
+
+               {% if page.author %}
+                       {{ _("by") }}
+                       <a href="/users/{{ page.author.uid }}">{{ page.author }}</a>
+               {% end %}
+       </p>
+{% end %}
diff --git a/src/templates/wiki/recent-changes.html b/src/templates/wiki/recent-changes.html
new file mode 100644 (file)
index 0000000..b333f4a
--- /dev/null
@@ -0,0 +1,21 @@
+{% extends "../base.html" %}
+
+{% block title %}{{ _("Recent Changes") }}{% end block %}
+
+{% block content %}
+       <section>
+               <div class="container">
+                       <div class="row">
+                               <div class="col col-lg-6">
+                                       <h1>{{ _("Recent Changes") }}</h1>
+                               </div>
+                       </div>
+               </div>
+       </section>
+
+       <div class="card">
+               <div class="card-body">
+                       {% module WikiList(recent_changes) %}
+               </div>
+       </div>
+{% end block %}
index 88ee2ca2558612aedc29c829a94204c5a5ab5c05..f961c3bfa91dfd59285875739d8ff40570241c28 100644 (file)
@@ -91,6 +91,7 @@ class Application(tornado.web.Application):
 
                                # Wiki
                                "WikiNavbar"           : wiki.WikiNavbarModule,
+                               "WikiList"             : wiki.WikiListModule,
 
                                # Misc
                                "Map"                  : ui_modules.MapModule,
@@ -283,7 +284,11 @@ class Application(tornado.web.Application):
                self.add_handlers(r"wiki(\.dev)?\.ipfire\.org",
                        authentication_handlers + [
 
+                       # Handlers
+                       (r"/recent\-changes", wiki.RecentChangesHandler),
                        (r"/search", wiki.SearchHandler),
+
+                       # Render pages
                        (r"([A-Za-z0-9\-_\/]+)?", wiki.PageHandler),
                ])
 
index e2b5a57a12585a8982c8164292aed523c8be03b6..5ba76af0afd8117f228d7fb70258324bdccf326a 100644 (file)
@@ -51,6 +51,18 @@ class SearchHandler(auth.CacheMixin, base.BaseHandler):
                self.render("wiki/search-results.html", q=q, pages=pages)
 
 
+class RecentChangesHandler(auth.CacheMixin, base.BaseHandler):
+       def get(self):
+               recent_changes = self.backend.wiki.get_recent_changes(limit=50)
+
+               self.render("wiki/recent-changes.html", recent_changes=recent_changes)
+
+
+class WikiListModule(ui_modules.UIModule):
+       def render(self, pages):
+               return self.render_string("wiki/modules/list.html", pages=pages)
+
+
 class WikiNavbarModule(ui_modules.UIModule):
        def render(self, page, suffix=None):
                breadcrumbs = self.backend.wiki.make_breadcrumbs(page.url)