mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 08:17:58 -05:00
wiki: Remove globals.
This commit is contained in:
@@ -215,8 +215,6 @@ class VWikiPage(Validator):
|
||||
except AbortWikiError:
|
||||
return
|
||||
|
||||
c.wiki_may_revise = this_may_revise(wp)
|
||||
|
||||
return wp
|
||||
|
||||
def validpage(self, page):
|
||||
|
||||
@@ -38,7 +38,8 @@ from r2.controllers.validator import VMarkdown, VModhash, nop
|
||||
|
||||
from r2.controllers.validator.wiki import (VWikiPage, VWikiPageAndVersion,
|
||||
VWikiModerator, VWikiPageRevise,
|
||||
this_may_view, wiki_validate)
|
||||
this_may_revise, this_may_view,
|
||||
wiki_validate)
|
||||
from r2.controllers.api_docs import api_doc, api_section
|
||||
from r2.lib.pages.wiki import (WikiPageView, WikiNotFound, WikiRevisions,
|
||||
WikiEdit, WikiSettings, WikiRecent,
|
||||
@@ -74,13 +75,14 @@ class WikiController(RedditController):
|
||||
allow_stylesheets = True
|
||||
|
||||
@wiki_validate(pv=VWikiPageAndVersion(('page', 'v', 'v2'), required=False,
|
||||
restricted=False))
|
||||
def GET_wiki_page(self, pv):
|
||||
restricted=False),
|
||||
page_name=nop('page'))
|
||||
def GET_wiki_page(self, pv, page_name):
|
||||
page, version, version2 = pv
|
||||
message = None
|
||||
|
||||
if not page:
|
||||
return self.redirect(join_urls(c.wiki_base_url, '/notfound/', c.wiki_page))
|
||||
return self.redirect(join_urls(c.wiki_base_url, '/notfound/', page_name))
|
||||
|
||||
if version:
|
||||
edit_by = version.author_name()
|
||||
@@ -110,7 +112,8 @@ class WikiController(RedditController):
|
||||
content = version.content
|
||||
|
||||
return WikiPageView(content, alert=message, v=version, diff=diffcontent,
|
||||
edit_by=edit_by, edit_date=edit_date).render()
|
||||
may_revise=this_may_revise(page), edit_by=edit_by,
|
||||
edit_date=edit_date, page=page.name).render()
|
||||
|
||||
@paginated_listing(max_page_size=100, backend='cassandra')
|
||||
@wiki_validate(page=VWikiPage(('page'), restricted=False))
|
||||
@@ -118,7 +121,7 @@ class WikiController(RedditController):
|
||||
revisions = page.get_revisions()
|
||||
builder = WikiRevisionBuilder(revisions, num=num, reverse=reverse, count=count, after=after, skip=not c.is_wiki_mod, wrap=default_thing_wrapper())
|
||||
listing = WikiRevisionListing(builder).listing()
|
||||
return WikiRevisions(listing).render()
|
||||
return WikiRevisions(listing, page=page.name, may_revise=this_may_revise(page)).render()
|
||||
|
||||
@wiki_validate(wp=VWikiPageRevise('page'),
|
||||
page=nop('page'))
|
||||
@@ -141,7 +144,7 @@ class WikiController(RedditController):
|
||||
error = _('a max of %d separators "/" are allowed in a wiki page name.') % c.error['MAX_SEPARATORS']
|
||||
return BoringPage(_("Wiki error"), infotext=error).render()
|
||||
else:
|
||||
return WikiNotFound(page=page).render()
|
||||
return WikiNotFound(page=page, may_revise=True).render()
|
||||
|
||||
@wiki_validate(wp=VWikiPageRevise('page', restricted=True))
|
||||
def GET_wiki_revise(self, wp, page, message=None, **kw):
|
||||
@@ -152,7 +155,8 @@ class WikiController(RedditController):
|
||||
content = kw.get('content', wp.content)
|
||||
if not message and wp.name in page_descriptions:
|
||||
message = page_descriptions[wp.name]
|
||||
return WikiEdit(content, previous, alert=message).render()
|
||||
return WikiEdit(content, previous, alert=message, page=wp.name,
|
||||
may_revise=True).render()
|
||||
|
||||
@paginated_listing(max_page_size=100, backend='cassandra')
|
||||
def GET_wiki_recent(self, num, after, reverse, count):
|
||||
@@ -182,13 +186,15 @@ class WikiController(RedditController):
|
||||
num = num, after = after, reverse = reverse,
|
||||
count = count, skip = False)
|
||||
listing = LinkListing(builder).listing()
|
||||
return WikiDiscussions(listing).render()
|
||||
return WikiDiscussions(listing, page=page.name,
|
||||
may_revise=this_may_revise(page)).render()
|
||||
|
||||
@wiki_validate(page=VWikiPage('page', restricted=True, modonly=True))
|
||||
def GET_wiki_settings(self, page):
|
||||
settings = {'permlevel': page._get('permlevel', 0)}
|
||||
mayedit = page.get_editors()
|
||||
return WikiSettings(settings, mayedit, show_settings=not page.special).render()
|
||||
return WikiSettings(settings, mayedit, show_settings=not page.special,
|
||||
page=page.name, may_revise=True).render()
|
||||
|
||||
@wiki_validate(VModhash(),
|
||||
page=VWikiPage('page', restricted=True, modonly=True),
|
||||
@@ -216,7 +222,6 @@ class WikiController(RedditController):
|
||||
c.wiki_base_url = join_urls(c.site.path, 'wiki')
|
||||
c.wiki_api_url = join_urls(c.site.path, '/api/wiki')
|
||||
c.wiki_id = g.default_sr if frontpage else c.site.name
|
||||
c.wiki_page = None
|
||||
c.show_wiki_actions = True
|
||||
self.editconflict = False
|
||||
c.is_wiki_mod = (c.user_is_admin or c.site.is_moderator(c.user)) if c.user_is_loggedin else False
|
||||
|
||||
@@ -6,51 +6,59 @@ from r2.controllers.validator.wiki import this_may_revise
|
||||
from pylons.i18n import _
|
||||
|
||||
class WikiView(Templated):
|
||||
def __init__(self, content, edit_by, edit_date, diff=None):
|
||||
def __init__(self, content, edit_by, edit_date, may_revise=False, page=None, diff=None):
|
||||
self.page_content_md = content
|
||||
self.page = page
|
||||
self.diff = diff
|
||||
self.edit_by = edit_by
|
||||
self.may_revise = c.wiki_may_revise
|
||||
self.may_revise = may_revise
|
||||
self.edit_date = edit_date
|
||||
self.base_url = c.wiki_base_url
|
||||
Templated.__init__(self)
|
||||
|
||||
class WikiPageListing(Templated):
|
||||
def __init__(self, pages, linear_pages):
|
||||
def __init__(self, pages, linear_pages, page=None):
|
||||
self.pages = pages
|
||||
self.page = page
|
||||
self.linear_pages = linear_pages
|
||||
self.base_url = c.wiki_base_url
|
||||
Templated.__init__(self)
|
||||
|
||||
class WikiEditPage(Templated):
|
||||
def __init__(self, page_content='', previous='', show_reason_field=True):
|
||||
def __init__(self, page_content='', previous='', page=None, show_reason_field=True):
|
||||
self.page_content = page_content
|
||||
self.page = page
|
||||
self.previous = previous
|
||||
self.base_url = c.wiki_base_url
|
||||
self.show_reason_field = show_reason_field
|
||||
Templated.__init__(self)
|
||||
|
||||
class WikiPageSettings(Templated):
|
||||
def __init__(self, settings, mayedit, show_settings=True, **context):
|
||||
def __init__(self, settings, mayedit, show_settings=True, page=None, **context):
|
||||
self.permlevel = settings['permlevel']
|
||||
self.show_settings = show_settings
|
||||
self.page = page
|
||||
self.base_url = c.wiki_base_url
|
||||
self.mayedit = mayedit
|
||||
Templated.__init__(self)
|
||||
|
||||
class WikiPageRevisions(Templated):
|
||||
def __init__(self, revisions):
|
||||
def __init__(self, revisions, page=None):
|
||||
self.listing = revisions
|
||||
self.page = page
|
||||
Templated.__init__(self)
|
||||
|
||||
class WikiPageDiscussions(Templated):
|
||||
def __init__(self, listing):
|
||||
def __init__(self, listing, page=None):
|
||||
self.listing = listing
|
||||
self.page = page
|
||||
Templated.__init__(self)
|
||||
|
||||
class WikiBasePage(Templated):
|
||||
def __init__(self, content, action, pageactions, showtitle=False, description=None, **context):
|
||||
def __init__(self, content, action, pageactions, page=None, showtitle=False,
|
||||
description=None, **context):
|
||||
self.pageactions = pageactions
|
||||
self.page = page
|
||||
self.base_url = c.wiki_base_url
|
||||
self.action = action
|
||||
self.description = description
|
||||
@@ -64,61 +72,63 @@ class WikiBasePage(Templated):
|
||||
class WikiBase(Reddit):
|
||||
extra_page_classes = ['wiki-page']
|
||||
|
||||
def __init__(self, content, actionless=False, alert=None, **context):
|
||||
def __init__(self, content, page=None, may_revise=False, actionless=False, alert=None, **context):
|
||||
pageactions = []
|
||||
title = c.site.name
|
||||
if not actionless and c.wiki_page:
|
||||
title = '%s - %s' % (title, c.wiki_page)
|
||||
pageactions += [(c.wiki_page, _("view"), False)]
|
||||
if c.wiki_may_revise:
|
||||
if not actionless and page:
|
||||
title = '%s - %s' % (title, page)
|
||||
pageactions += [(page, _("view"), False)]
|
||||
if may_revise:
|
||||
pageactions += [('edit', _("edit"), True)]
|
||||
pageactions += [('revisions/%s' % c.wiki_page, _("history"), False)]
|
||||
pageactions += [('revisions/%s' % page, _("history"), False)]
|
||||
pageactions += [('discussions', _("talk"), True)]
|
||||
if c.is_wiki_mod:
|
||||
pageactions += [('settings', _("settings"), True)]
|
||||
|
||||
action = context.get('wikiaction', (c.wiki_page, 'wiki'))
|
||||
action = context.get('wikiaction', (page, 'wiki'))
|
||||
context['title'] = title
|
||||
|
||||
if alert:
|
||||
context['infotext'] = alert
|
||||
elif c.wikidisabled:
|
||||
context['infotext'] = _("this wiki is currently disabled, only mods may interact with this wiki")
|
||||
context['content'] = WikiBasePage(content, action, pageactions, **context)
|
||||
context['content'] = WikiBasePage(content, action, pageactions, page=page, **context)
|
||||
Reddit.__init__(self, **context)
|
||||
|
||||
class WikiPageView(WikiBase):
|
||||
def __init__(self, content, diff=None, **context):
|
||||
def __init__(self, content, page, diff=None, **context):
|
||||
may_revise = context.get('may_revise')
|
||||
if not content and not context.get('alert'):
|
||||
if c.wiki_may_revise:
|
||||
if may_revise:
|
||||
context['alert'] = _("this page is empty, edit it to add some content.")
|
||||
content = WikiView(content, context.get('edit_by'), context.get('edit_date'), diff=diff)
|
||||
WikiBase.__init__(self, content, **context)
|
||||
content = WikiView(content, context.get('edit_by'), context.get('edit_date'),
|
||||
may_revise=may_revise, page=page, diff=diff)
|
||||
WikiBase.__init__(self, content, page=page, **context)
|
||||
|
||||
class WikiNotFound(WikiBase):
|
||||
def __init__(self, page, **context):
|
||||
context['alert'] = _("page %s does not exist in this subreddit") % page
|
||||
context['actionless'] = True
|
||||
content = WikiEditPage(show_reason_field=False)
|
||||
WikiBase.__init__(self, content, **context)
|
||||
content = WikiEditPage(show_reason_field=False, page=page)
|
||||
WikiBase.__init__(self, content, page, **context)
|
||||
|
||||
class WikiEdit(WikiBase):
|
||||
def __init__(self, content, previous, **context):
|
||||
content = WikiEditPage(content, previous)
|
||||
def __init__(self, content, previous, page, **context):
|
||||
content = WikiEditPage(content, previous, page)
|
||||
context['wikiaction'] = ('edit', _("editing"))
|
||||
WikiBase.__init__(self, content, **context)
|
||||
WikiBase.__init__(self, content, page=page, **context)
|
||||
|
||||
class WikiSettings(WikiBase):
|
||||
def __init__(self, settings, mayedit, **context):
|
||||
content = WikiPageSettings(settings, mayedit, **context)
|
||||
def __init__(self, settings, mayedit, page, **context):
|
||||
content = WikiPageSettings(settings, mayedit, page=page, **context)
|
||||
context['wikiaction'] = ('settings', _("settings"))
|
||||
WikiBase.__init__(self, content, **context)
|
||||
WikiBase.__init__(self, content, page=page, **context)
|
||||
|
||||
class WikiRevisions(WikiBase):
|
||||
def __init__(self, revisions, **context):
|
||||
content = WikiPageRevisions(revisions)
|
||||
context['wikiaction'] = ('revisions/%s' % c.wiki_page, _("revisions"))
|
||||
WikiBase.__init__(self, content, **context)
|
||||
def __init__(self, revisions, page, **context):
|
||||
content = WikiPageRevisions(revisions, page)
|
||||
context['wikiaction'] = ('revisions/%s' % page, _("revisions"))
|
||||
WikiBase.__init__(self, content, page=page, **context)
|
||||
|
||||
class WikiRecent(WikiBase):
|
||||
def __init__(self, revisions, **context):
|
||||
@@ -134,10 +144,10 @@ class WikiListing(WikiBase):
|
||||
WikiBase.__init__(self, content, description=description, showtitle=True, **context)
|
||||
|
||||
class WikiDiscussions(WikiBase):
|
||||
def __init__(self, listing, **context):
|
||||
content = WikiPageDiscussions(listing)
|
||||
def __init__(self, listing, page, **context):
|
||||
content = WikiPageDiscussions(listing, page)
|
||||
context['wikiaction'] = ('discussions', _("discussions"))
|
||||
description = [_("Discussions are site-wide links to this wiki page."),
|
||||
_("Submit a link to this wiki page or see other discussions about this wiki page.")]
|
||||
WikiBase.__init__(self, content, description=description, **context)
|
||||
WikiBase.__init__(self, content, page=page, description=description, **context)
|
||||
|
||||
|
||||
@@ -538,11 +538,14 @@ class SearchBuilder(IDBuilder):
|
||||
return True
|
||||
|
||||
class WikiRevisionBuilder(QueryBuilder):
|
||||
show_extended = True
|
||||
|
||||
def wrap_items(self, items):
|
||||
types = {}
|
||||
wrapped = []
|
||||
for item in items:
|
||||
w = self.wrap(item)
|
||||
w.show_extended = self.show_extended
|
||||
types.setdefault(w.render_class, []).append(w)
|
||||
wrapped.append(w)
|
||||
|
||||
@@ -556,6 +559,8 @@ class WikiRevisionBuilder(QueryBuilder):
|
||||
return not item.is_hidden
|
||||
|
||||
class WikiRecentRevisionBuilder(WikiRevisionBuilder):
|
||||
show_extended = False
|
||||
|
||||
def must_skip(self, item):
|
||||
return (datetime.datetime.now(g.tz) - item.date).days >= WIKI_RECENT_DAYS
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
%endif
|
||||
"
|
||||
%if action[2]:
|
||||
href="${thing.base_url}/${action[0]}/${c.wiki_page}"
|
||||
href="${thing.base_url}/${action[0]}/${thing.page}"
|
||||
%else:
|
||||
href="${thing.base_url}/${action[0]}"
|
||||
%endif
|
||||
@@ -41,8 +41,8 @@
|
||||
%if thing.title:
|
||||
${thing.title}
|
||||
%endif
|
||||
%if c.wiki_page:
|
||||
<strong>${c.wiki_page}</strong>
|
||||
%if thing.page:
|
||||
<strong>${thing.page}</strong>
|
||||
%endif
|
||||
</h1>
|
||||
|
||||
|
||||
@@ -47,5 +47,5 @@
|
||||
%endif
|
||||
<input type="hidden" id="previous" name="previous" value="${thing.previous}" />
|
||||
<br/><br/><input type="submit" value="${_('save page')}" />
|
||||
<input type="button" value="${_('cancel edit')}" onclick="location.href='${thing.base_url}/${c.wiki_page}'" />
|
||||
<input type="button" value="${_('cancel edit')}" onclick="location.href='${thing.base_url}/${thing.page}'" />
|
||||
</form>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
${thing.listing}
|
||||
|
||||
<div class="morelink discussionlink">
|
||||
<a href="/submit?url=http://${get_domain()}/wiki/${c.wiki_page}&resubmit=true&no_self=true&title=Check+out+this+wiki+page">${_("submit a discussion")}
|
||||
<a href="/submit?url=http://${get_domain()}/wiki/${thing.page}&resubmit=true&no_self=true&title=Check+out+this+wiki+page">${_("submit a discussion")}
|
||||
<div class="nub"></div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
###############################################################################
|
||||
|
||||
${thing.listing}
|
||||
%if c.wiki_page and thing.listing.things:
|
||||
%if thing.page and thing.listing.things:
|
||||
<button onclick="r.wiki.goCompare()">${_("compare selected")}</button>
|
||||
%endif
|
||||
<br/>
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
<li>
|
||||
${user}
|
||||
—
|
||||
${ynbutton(_("delete"), _("done"), quote("..%s/alloweditor/del" % (c.wiki_api_url)), hidden_data=dict(username=user, page=c.wiki_page), post_callback="$.refresh")}
|
||||
${ynbutton(_("delete"), _("done"), quote("..%s/alloweditor/del" % (c.wiki_api_url)), hidden_data=dict(username=user, page=thing.page), post_callback="$.refresh")}
|
||||
</li>
|
||||
%endfor
|
||||
</ul>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
%endif
|
||||
">
|
||||
|
||||
%if c.wiki_page:
|
||||
%if thing.show_extended:
|
||||
<td style="white-space: nowrap;">
|
||||
<input type="radio" name="v1" value="${thing._id}" checked="yes">
|
||||
<input type="radio" name="v2" value="${thing._id}" checked="yes">
|
||||
@@ -44,7 +44,7 @@
|
||||
${timestamp(thing.date)} ago
|
||||
</td>
|
||||
|
||||
%if not c.wiki_page:
|
||||
%if not thing.show_extended:
|
||||
<td>
|
||||
<a href="${c.wiki_base_url}/${thing.page}">${thing.page}</a>
|
||||
</td>
|
||||
@@ -62,7 +62,7 @@
|
||||
${thing._get('reason')}
|
||||
</td>
|
||||
|
||||
%if c.wiki_page and c.is_wiki_mod:
|
||||
%if thing.show_extended and c.is_wiki_mod:
|
||||
<td>
|
||||
<a href="#" class="revision_hide" data-revision="${thing._id}">hide</a>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user