]>
git.ipfire.org Git - ipfire.org.git/blob - src/web/wiki.py
6 from . import ui_modules
8 class ActionEditHandler(base
.BaseHandler
):
9 @tornado.web
.authenticated
15 if not self
.backend
.wiki
.check_acl(path
, self
.current_user
):
16 raise tornado
.web
.HTTPError(403, "Access to %s not allowed for %s" % (path
, self
.current_user
))
19 page
= self
.backend
.wiki
.get_page(path
)
21 # Empty page if it was deleted
22 if page
and page
.was_deleted():
26 self
.render("wiki/edit.html", page
=page
, path
=path
)
28 @tornado.web
.authenticated
34 if not self
.backend
.wiki
.check_acl(path
, self
.current_user
):
35 raise tornado
.web
.HTTPError(403, "Access to %s not allowed for %s" % (path
, self
.current_user
))
37 content
= self
.get_argument("content", None)
38 changes
= self
.get_argument("changes")
40 # Create a new page in the database
41 with self
.db
.transaction():
42 page
= self
.backend
.wiki
.create_page(path
,
43 self
.current_user
, content
, changes
=changes
, address
=self
.get_remote_ip())
45 # Add user as a watcher if wanted
46 watch
= self
.get_argument("watch", False)
48 page
.add_watcher(self
.current_user
)
51 if page
.was_deleted():
54 self
.redirect(page
.url
)
58 Updates the search index after the page has been edited
60 # This is being executed in the background and after
61 # the response has been set to the client
62 with self
.db
.transaction():
63 self
.backend
.wiki
.refresh()
66 class ActionUploadHandler(base
.BaseHandler
):
67 @tornado.web
.authenticated
68 @base.ratelimit(minutes
=60, requests
=24)
70 path
= self
.get_argument("path")
73 if not self
.backend
.wiki
.check_acl(path
, self
.current_user
):
74 raise tornado
.web
.HTTPError(403, "Access to %s not allowed for %s" % (path
, self
.current_user
))
77 filename
, data
, mimetype
= self
.get_file("file")
79 # Use filename from request if any
80 filename
= self
.get_argument("filename", filename
)
82 # XXX check valid mimetypes
84 with self
.db
.transaction():
85 file = self
.backend
.wiki
.upload(path
, filename
, data
,
86 mimetype
=mimetype
, author
=self
.current_user
,
87 address
=self
.get_remote_ip())
89 except TypeError as e
:
92 self
.redirect("%s/_files" % path
)
95 class ActionDeleteHandler(base
.BaseHandler
):
96 @tornado.web
.authenticated
99 if not self
.backend
.wiki
.check_acl(path
, self
.current_user
):
100 raise tornado
.web
.HTTPError(403, "Access to %s not allowed for %s" % (path
, self
.current_user
))
103 file = self
.backend
.wiki
.get_file_by_path(path
)
105 raise tornado
.web
.HTTPError(404, "Could not find %s" % path
)
107 self
.render("wiki/confirm-delete.html", file=file)
109 @tornado.web
.authenticated
110 @base.ratelimit(minutes
=60, requests
=24)
111 def post(self
, path
):
113 if not self
.backend
.wiki
.check_acl(path
, self
.current_user
):
114 raise tornado
.web
.HTTPError(403, "Access to %s not allowed for %s" % (path
, self
.current_user
))
117 file = self
.backend
.wiki
.get_file_by_path(path
)
119 raise tornado
.web
.HTTPError(404, "Could not find %s" % path
)
121 with self
.db
.transaction():
122 file.delete(self
.current_user
)
124 self
.redirect("%s/_files" % file.path
)
127 class ActionRestoreHandler(base
.BaseHandler
):
128 @tornado.web
.authenticated
129 @base.ratelimit(minutes
=60, requests
=24)
131 path
= self
.get_argument("path")
134 if not self
.backend
.wiki
.check_acl(path
, self
.current_user
):
135 raise tornado
.web
.HTTPError(403, "Access to %s not allowed for %s" % (path
, self
.current_user
))
137 # Check if we are asked to render a certain revision
138 revision
= self
.get_argument("revision", None)
139 comment
= self
.get_argument("comment", None)
141 # Fetch the wiki page
142 page
= self
.backend
.wiki
.get_page(path
, revision
=revision
)
144 with self
.db
.transaction():
146 author
=self
.current_user
,
147 address
=self
.get_remote_ip(),
151 # Redirect back to page
152 self
.redirect(page
.page
)
155 class ActionWatchHandler(base
.BaseHandler
):
156 @tornado.web
.authenticated
157 @base.ratelimit(minutes
=60, requests
=180)
158 def get(self
, path
, action
):
162 page
= self
.backend
.wiki
.get_page(path
)
164 raise tornado
.web
.HTTPError(404, "Page does not exist: %s" % path
)
167 if not self
.backend
.wiki
.check_acl(path
, self
.current_user
):
168 raise tornado
.web
.HTTPError(403, "Access to %s not allowed for %s" % (path
, self
.current_user
))
170 with self
.db
.transaction():
171 if action
== "watch":
172 page
.add_watcher(self
.current_user
)
173 elif action
== "unwatch":
174 page
.remove_watcher(self
.current_user
)
176 # Redirect back to page
177 self
.redirect(page
.url
)
180 class ActionRenderHandler(base
.BaseHandler
):
181 def check_xsrf_cookie(self
):
184 @tornado.web
.authenticated
185 @base.ratelimit(minutes
=5, requests
=180)
186 def post(self
, path
):
190 content
= self
.get_argument("content")
193 html
= self
.backend
.wiki
.render(path
, content
)
198 class FilesHandler(base
.BaseHandler
):
199 @tornado.web
.authenticated
205 if not self
.backend
.wiki
.check_acl(path
, self
.current_user
):
206 raise tornado
.web
.HTTPError(403, "Access to %s not allowed for %s" % (path
, self
.current_user
))
208 files
= self
.backend
.wiki
.get_files(path
)
210 self
.render("wiki/files/index.html", path
=path
, files
=files
)
213 class WatchlistHandler(base
.BaseHandler
):
214 @tornado.web
.authenticated
216 pages
= self
.backend
.wiki
.get_watchlist(self
.current_user
)
218 self
.render("wiki/watchlist.html", pages
=pages
)
221 class WikiListModule(ui_modules
.UIModule
):
222 def render(self
, pages
, link_revision
=False, show_breadcrumbs
=True,
223 show_author
=True, show_changes
=False):
224 return self
.render_string("wiki/modules/list.html", link_revision
=link_revision
,
225 pages
=pages
, show_breadcrumbs
=show_breadcrumbs
,
226 show_author
=show_author
, show_changes
=show_changes
)