示例#1
0
def atomfeed(context):
	"""Generate a link to the Atom feed for the current page if
	the current page is a directory or the wiki root."""
	if not hasatomfeed(context):
		return ''
	curl = context.url(true_atom_page(context), "atom")
	return htmlrends.makelink("Recent Pages", curl, True, atomCType)
示例#2
0
文件: blogdir.py 项目: xakon/dwiki
def directory(ctx):
    """List the contents of the current directory, with links to each
	page and subdirectory. Supports VirtualDirectory restrictions, but
	always shows subdirectories."""
    res = []
    if ctx.page.type != "dir" or not ctx.page.displayable():
        return ''

    # Just in case:
    ctx.newtime(ctx.page.timestamp)
    dl = ctx.page.children()
    if not dl:
        return ''
    # Restrict the results if we've been asked to. This is complicated
    # by our need to preserve directories *always*, because we don't
    # know if they have any files within the restriction inside them.
    if pageranges.is_restriction(ctx):
        dirl = [z for z in dl if z.type == 'dir']
        tl = pageranges.filter_files(ctx, [(z.timestamp, z.path)
                                           for z in dl if z.type != 'dir'])
        if not tl and not dirl:
            return ''
        dl = [ctx.model.get_page(z[1]) for z in tl]
        dl.extend(dirl)
        dl.sort(key=lambda x: x.name)

    res.append("<ul>")
    for de in dl:
        res.append("\n<li> ")
        res.append(htmlrends.makelink(de.name, ctx.url(de)))
    res.append("\n</ul>\n")
    return ''.join(res)
示例#3
0
def directory(ctx):
	"""List the contents of the current directory, with links to each
	page and subdirectory. Supports VirtualDirectory restrictions, but
	always shows subdirectories."""
	res = []
	if ctx.page.type != "dir" or not ctx.page.displayable():
		return ''

	# Just in case:
	ctx.newtime(ctx.page.timestamp)
	dl = ctx.page.children()
	if not dl:
		return ''
	# Restrict the results if we've been asked to. This is complicated
	# by our need to preserve directories *always*, because we don't
	# know if they have any files within the restriction inside them.
	if pageranges.is_restriction(ctx):
		dirl = [z for z in dl if z.type == 'dir']
		tl = pageranges.filter_files(ctx, [(z.timestamp, z.path)
						   for z in dl
						   if z.type != 'dir'])
		if not tl and not dirl:
			return ''
		dl = [ctx.model.get_page(z[1]) for z in tl]
		dl.extend(dirl)
		dl.sort(key=lambda x: x.name)

	res.append("<ul>")
	for de in dl:
		res.append("\n<li> ")
		res.append(htmlrends.makelink(de.name, ctx.url(de)))
	res.append("\n</ul>\n")
	return ''.join(res)
示例#4
0
文件: comments.py 项目: xakon/dwiki
def _gencountlink(context, abs):
    res = countcomments(context)
    if not res:
        return ''
    f = abs and context.uri or context.url
    url = f(context.page, context.comment_view()) + "#comments"
    return htmlrends.makelink(res, url)
示例#5
0
文件: atomgen.py 项目: xakon/dwiki
def atomfeed(context):
    """Generate a link to the Atom feed for the current page if
	the current page is a directory or the wiki root."""
    if not hasatomfeed(context):
        return ''
    curl = context.url(true_atom_page(context), "atom")
    return htmlrends.makelink("Recent Pages", curl, True, atomCType)
示例#6
0
def _gencountlink(context, abs):
	res = countcomments(context)
	if not res:
		return ''
	f = abs and context.uri or context.url
	url = f(context.page, context.comment_view()) + "#comments"
	return htmlrends.makelink(res, url)
示例#7
0
def datecrumbs(context):
	"""Create date breadcrumbs for the blog directory if the
	current page is in a blog directory but is not being
	displayed inside a virtual directory. The 'blog directory'
	is the directory that made the blog view the default view."""
	if context.page.type != "file":
		return ''
	if is_virtualized(context):
		return ''
	# Utility pages make relatively little sense to generate
	# date breadcrumbs on, because we don't really consider them
	# part of the blog. (This is debateable, but I think it makes
	# more sense this way.)
	if context.page.is_util():
		return ''
	dirp = context.page.curdir()
	(pv, vdir) = context.pref_view_and_dir(dirp)
	if pv != "blog":
		return ''
	else:
		dirp = vdir

	ts = time.localtime(context.page.timestamp)
	r = []
	for i in (("%d/%02d/%02d" % (ts.tm_year, ts.tm_mon, ts.tm_mday),
		   "%02d" % ts.tm_mday),
		  ("%d/%02d" % (ts.tm_year, ts.tm_mon),
		   months[ts.tm_mon-1]),
		  ("%d" % ts.tm_year, "%d" % ts.tm_year)):
		page = context.model.get_virtual_page(dirp, i[0])
		r.append(htmlrends.makelink(i[1], context.url(page)))
	return ' '.join(r)
示例#8
0
文件: htmlauth.py 项目: samveen/dwiki
def postlink(context):
	"""Generate a link to the origin page for a POST request
	in a POST form context."""
	if not ":post:page" in context:
		return ''
	pp = context.model.get_page(context[":post:page"])
	return htmlrends.makelink(pp.path, context.nurl(pp))
示例#9
0
文件: blogdir.py 项目: xakon/dwiki
def month_cutoff(context):
    """With blog::blog, generate a 'see more' set of links for the
	month and the year of the next entry if the display of pages has
	been truncated."""
    if ":blog:clippedrange" not in context:
        return ''
    rv = context[":blog:clippedrange"]
    t = time.localtime(rv[0])
    l1 = pageranges.gen_monthlink(context, t.tm_year, t.tm_mon)
    pg = context.model.get_virtual_page(context.page.me(), "%d" % t.tm_year)
    l2 = htmlrends.makelink("%d" % t.tm_year, context.url(pg))
    return "%s %s" % (l1, l2)
示例#10
0
def month_cutoff(context):
	"""With blog::blog, generate a 'see more' set of links for the
	month and the year of the next entry if the display of pages has
	been truncated."""
	if ":blog:clippedrange" not in context:
		return ''
	rv = context[":blog:clippedrange"]
	t = time.localtime(rv[0])
	l1 = pageranges.gen_monthlink(context, t.tm_year, t.tm_mon)
	pg = context.model.get_virtual_page(context.page.me(), "%d" % t.tm_year)
	l2 = htmlrends.makelink("%d" % t.tm_year, context.url(pg))
	return "%s %s" % (l1, l2)
示例#11
0
def oldest_rel(context):
	# If we don't have the length, we're just dead in the water.
	if not rest_hitstore in context:
		return ('', '')
	curv = context[rest_val]
	tlen = context[rest_hitstore]
	end = tlen - curv
	start = end - curv + 1
	if start <= 1:
		start = 1
	nxt = htmlrends.makelink(next_msg % (end-start+1),
				 gen_range_url(context, start, end),
				 True)
	return (nxt, '')
示例#12
0
def range_rel(context):
	start, end = context[rest_val]
	gap = end - start + 1

	prev = range_prev(context, end+1, end+gap)
	# Next has to clip the range.
	if start > 1:
		end = start - 1
		start = start - gap
		if start <= 0:
			start = 1
		nxt = htmlrends.makelink(next_msg % (end-start+1),
					 gen_range_url(context, start, end),
					 True)
	else:
		nxt = ''
	return (prev, nxt)
示例#13
0
文件: atomgen.py 项目: xakon/dwiki
def atomcommentfeed(context):
    """Generate a link to the Atom comments feed for the current
	page, if comments are turned on."""
    if not context.model.comments_on():
        return ''
    page = context.page.me()
    # Special bonus hack.
    if page.path == context.wiki_root():
        page = page.parent()
    # .comments_on() can return True for pages no one can ever
    # comment on because the access restrictions to them are
    # impossible to pass. However, this is a lesser evil; it
    # just generates useless Atom feeds.
    # By using '!= "dir"' we automatically exclude bad pages
    # and so on from generating that Atom comment link.
    if page.type != "dir" and not page.comments_on(context):
        return ''
    curl = context.url(page, 'atomcomments')
    return htmlrends.makelink("Recent Comments", curl, True, atomCType)
示例#14
0
def atomcommentfeed(context):
	"""Generate a link to the Atom comments feed for the current
	page, if comments are turned on."""
	if not context.model.comments_on():
		return ''
	page = context.page.me()
	# Special bonus hack.
	if page.path == context.wiki_root():
		page = page.parent()
	# .comments_on() can return True for pages no one can ever
	# comment on because the access restrictions to them are
	# impossible to pass. However, this is a lesser evil; it
	# just generates useless Atom feeds.
	# By using '!= "dir"' we automatically exclude bad pages
	# and so on from generating that Atom comment link.
	if page.type != "dir" and not page.comments_on(context):
		return ''
	curl = context.url(page, 'atomcomments')
	return htmlrends.makelink("Recent Comments", curl, True, atomCType)
示例#15
0
def display_results(context):
	"""Display the results of a search."""
	if not can_search(context):
		return ''
	data = context.getviewvar("search")
	if not data:
		return ''
	data = data.strip()
	if not data:
		return ''
	hlist = search_pages(context, [data], find_in)
	if not hlist:
		return ''
	hlist.sort()
	res = []
	res.append("<ul>\n")
	for path in hlist:
		res.append("<li>")
		res.append(htmlrends.makelink(path,
					      context.web.url_from_path(path)))
		res.append("\n")
	res.append("</ul>\n")
	return ''.join(res)
示例#16
0
def link_to_tm(context, tm, plain = None):
	suf = "%d/%02d/%02d" % (tm.tm_year, tm.tm_mon, tm.tm_mday)
	if not plain:
		plain = suf
	page = context.model.get_virtual_page(context.page.me(), suf)
	return htmlrends.makelink(plain, context.url(page))
示例#17
0
def gen_monthlink(context, year, month):
	vp = context.model.get_virtual_page(context.page.me(),
					    "%d/%02d" % (year, month))
	return htmlrends.makelink(months[month-1], context.url(vp))
示例#18
0
def com_optlink(txt, url):
	if not url:
		return httputil.quotehtml(txt)
	return htmlrends.makelink(txt, httputil.quoteurl(url))
示例#19
0
def genlink(context, pg, msg):
	if pg:
		return htmlrends.makelink(msg, context.nurl(pg))
	else:
		return ''
示例#20
0
文件: comments.py 项目: xakon/dwiki
def com_optlink(txt, url):
    if not url:
        return httputil.quotehtml(txt)
    return htmlrends.makelink(txt, httputil.quoteurl(url))
示例#21
0
文件: blogdir.py 项目: xakon/dwiki
def link_to_tm(context, tm, plain=None):
    suf = "%d/%02d/%02d" % (tm.tm_year, tm.tm_mon, tm.tm_mday)
    if not plain:
        plain = suf
    page = context.model.get_virtual_page(context.page.me(), suf)
    return htmlrends.makelink(plain, context.url(page))
示例#22
0
def vp_from_suf(context, suf, msg, nf = False):
	tp = context.model.get_virtual_page(context.page.me(), suf)
	return htmlrends.makelink(msg, context.url(tp), nf)