def _fillcomments(context): r = context.getcache(atom_comkey) if r is not None: return r cutpoint = get_cutpoint(context) #dl = context.model.comments_children(context.page.me()) dl = comments.cached_comments_children(context, context.page.me()) # Force the generator to be expanded to a full list, so we can # sort it. dl = list(dl) utils.sort_timelist(dl) if not dl: context.setcache(atom_comkey, []) return [] # Virtualization of comments means that we restrict the pages # that the comments are on to be within the virtualization # range. We cannot simply use pageranges.filter_files() on # the comments list itself, because the timestamps in that # are the *comment* timestamps, not the *page* timestamps. filterComments = False filterD = {} if pageranges.is_restriction(context): filterComments = True for ts, p in context.page.descendants(context): filterD[p] = True res = [] count = 0 for ts, path, cname in dl: if count > cutpoint: break if filterComments and path not in filterD: continue np = context.model.get_page(path) # We drop entirely pages that can't be accessed with # the current (lack of) permissions, rather than # insert a message about denied content; this seems # better. if not np.displayable() or np.is_redirect() or \ not np.access_ok(context): continue c = context.model.get_comment(np, cname) if not c: continue count += 1 res.append((ts, path, cname, c)) context.setcache(atom_comkey, res) return res
def rec_comment_pages(rend, args): """List pages with recent comments. Arguments are the same as for RecentChanges.""" rend.markComplex() cutoff = recentArgsFixer(rend, args) startpath = reduce(common_pref_reduce, args[1:], None) if startpath is None: startpath = '' spage = rend.mod.get_page(startpath) #cl = rend.mod.comments_children(spage) cl = comments.cached_comments_children(rend.ctx, spage) # There is no point checking cl, because it is always a generator. # Now we get to condense it from a list of recent comments # down to a list of pages with recent comments. d = {} fargs = args[1:] for com in cl: ppath = com[1] if ppath in d or \ (fargs and file_matches_args(ppath, fargs)): continue d[ppath] = com[0] cl = [(d[x], x) for x in d.keys()] utils.sort_timelist(cl) # Unlike RecentChanges, we know that these should be real pages. # (If they're not, we have problems.) if cutoff > 0 and cl: cl = cl[:cutoff] if cl: rend.ctx.newtime(cl[0][0]) cl = [z[1] for z in cl] # We list with full names unless we're in short display # more. view = rend.ctx.comment_view() if rend.useLists: pagelist_paths(rend, cl, view) else: pagelist_names(rend, cl, view) elif not rend.useLists: rend.addPiece("(none)") return True
def recentcomments(rend, args): """List recent comments. Arguments are the same as for RecentChanges. Use with _Striped_ is somewhat dubious.""" rend.markComplex() cutoff = recentArgsFixer(rend, args) startpath = reduce(common_pref_reduce, args[1:], None) if startpath is None: startpath = '' spage = rend.mod.get_page(startpath) #cl = rend.mod.comments_children(spage) cl = comments.cached_comments_children(rend.ctx, spage) # There is no point checking cl, because it is always a generator. if len(args) > 1: fargs = args[1:] cl = [x for x in cl if file_matches_args(x[1], fargs)] cl = list(cl) utils.sort_timelist(cl) if cutoff > 0: cl = cl[:cutoff] if not cl: if not rend.useLists: rend.addPiece("(none)") return True view = rend.ctx.comment_view() rend.ctx.newtime(cl[0][0]) def _cominfo(ppath, cname): npage = rend.mod.get_page(ppath) c = rend.mod.get_comment(npage, cname) if not c: return (None, None, None) url = rend.ctx.url(npage, view) ca = comments.anchor_for(c) url += '#%s' % ca return (c, npage, url, ca) def _lif((ts, ppath, cname)): (c, npage, url, ca) = _cominfo(ppath, cname) if not c: return rend.addPiece('<a href="%s">' % url) if c.username and not c.is_anon(rend.ctx): rend.text("%s (%s)" % (c.username, c.user), "none") elif not c.is_anon(rend.ctx): rend.text(c.user, "none") elif c.username: rend.text(c.username, "none") else: rend.text(c.ip, "none") tstr = time.strftime("%Y-%m-%d %H:%M", time.localtime(c.time)) rend.addPiece(" at "+tstr) rend.addPiece("</a>, on ") url2 = rend.ctx.url(npage, view) rend.makelink(url2, npage.name) rend.addPiece("\n") def _bf((ts, ppath, cname)): (c, npage, url, ca) = _cominfo(ppath, cname) if not c: return rend.addPiece('<a href="%s">' % url) rend.text(ca, "none") rend.addPiece("</a>") rend.macro_list(_lif, _bf, cl) return True
def recentcomments(rend, args): """List recent comments. Arguments are the same as for RecentChanges. Use with _Striped_ is somewhat dubious.""" rend.markComplex() cutoff = recentArgsFixer(rend, args) startpath = reduce(common_pref_reduce, args[1:], None) if startpath is None: startpath = '' spage = rend.mod.get_page(startpath) #cl = rend.mod.comments_children(spage) cl = comments.cached_comments_children(rend.ctx, spage) # There is no point checking cl, because it is always a generator. if len(args) > 1: fargs = args[1:] cl = [x for x in cl if file_matches_args(x[1], fargs)] cl = list(cl) utils.sort_timelist(cl) if cutoff > 0: cl = cl[:cutoff] if not cl: if not rend.useLists: rend.addPiece("(none)") return True view = rend.ctx.comment_view() rend.ctx.newtime(cl[0][0]) def _cominfo(ppath, cname): npage = rend.mod.get_page(ppath) c = rend.mod.get_comment(npage, cname) if not c: return (None, None, None) url = rend.ctx.url(npage, view) ca = comments.anchor_for(c) url += '#%s' % ca return (c, npage, url, ca) def _lif((ts, ppath, cname)): (c, npage, url, ca) = _cominfo(ppath, cname) if not c: return rend.addPiece('<a href="%s">' % url) if c.username and not c.is_anon(rend.ctx): rend.text("%s (%s)" % (c.username, c.user), "none") elif not c.is_anon(rend.ctx): rend.text(c.user, "none") elif c.username: rend.text(c.username, "none") else: rend.text(c.ip, "none") tstr = time.strftime("%Y-%m-%d %H:%M", time.localtime(c.time)) rend.addPiece(" at " + tstr) rend.addPiece("</a>, on ") url2 = rend.ctx.url(npage, view) rend.makelink(url2, npage.name) rend.addPiece("\n") def _bf((ts, ppath, cname)): (c, npage, url, ca) = _cominfo(ppath, cname) if not c: return rend.addPiece('<a href="%s">' % url) rend.text(ca, "none") rend.addPiece("</a>") rend.macro_list(_lif, _bf, cl) return True