[/usr/scripts/wiki-lenny] rangement
darcs-hash:20081207164436-bd074-9cf3f0f44fb60382857d76652ba52009ecdef954.gz
This commit is contained in:
parent
5a39b58bd8
commit
f5fb69b833
4 changed files with 0 additions and 382 deletions
|
@ -1,187 +0,0 @@
|
||||||
# -*- coding: iso-8859-1 -*-
|
|
||||||
"""
|
|
||||||
MoinMoin - edit a page
|
|
||||||
|
|
||||||
This either calls the text or the GUI page editor.
|
|
||||||
|
|
||||||
@copyright: 2000-2004 Juergen Hermann <jh@web.de>,
|
|
||||||
2006 MoinMoin:ThomasWaldmann
|
|
||||||
@license: GNU GPL, see COPYING for details.
|
|
||||||
"""
|
|
||||||
from MoinMoin import wikiutil
|
|
||||||
from MoinMoin.Page import Page
|
|
||||||
|
|
||||||
def execute(pagename, request):
|
|
||||||
""" edit a page """
|
|
||||||
_ = request.getText
|
|
||||||
|
|
||||||
if 'button_preview' in request.form and 'button_spellcheck' in request.form:
|
|
||||||
# multiple buttons pressed at once? must be some spammer/bot
|
|
||||||
request.makeForbidden403()
|
|
||||||
request.surge_protect(kick_him=True) # get rid of him
|
|
||||||
return
|
|
||||||
|
|
||||||
if not request.user.may.write(pagename):
|
|
||||||
request.theme.add_msg(_('You are not allowed to edit this page.'), "error")
|
|
||||||
Page(request, pagename).send_page()
|
|
||||||
return
|
|
||||||
|
|
||||||
valideditors = ['text', 'gui', ]
|
|
||||||
editor = ''
|
|
||||||
if request.user.valid:
|
|
||||||
editor = request.user.editor_default
|
|
||||||
if editor not in valideditors:
|
|
||||||
editor = request.cfg.editor_default
|
|
||||||
|
|
||||||
editorparam = request.form.get('editor', [editor])[0]
|
|
||||||
if editorparam == "guipossible":
|
|
||||||
lasteditor = editor
|
|
||||||
elif editorparam == "textonly":
|
|
||||||
editor = lasteditor = 'text'
|
|
||||||
else:
|
|
||||||
editor = lasteditor = editorparam
|
|
||||||
|
|
||||||
if request.cfg.editor_force:
|
|
||||||
editor = request.cfg.editor_default
|
|
||||||
|
|
||||||
# if it is still nothing valid, we just use the text editor
|
|
||||||
if editor not in valideditors:
|
|
||||||
editor = 'text'
|
|
||||||
|
|
||||||
rev = request.rev or 0
|
|
||||||
savetext = request.form.get('savetext', [None])[0]
|
|
||||||
comment = request.form.get('comment', [u''])[0]
|
|
||||||
category = request.form.get('category', [None])[0]
|
|
||||||
rstrip = int(request.form.get('rstrip', ['0'])[0])
|
|
||||||
trivial = int(request.form.get('trivial', ['0'])[0])
|
|
||||||
|
|
||||||
if 'button_switch' in request.form:
|
|
||||||
if editor == 'text':
|
|
||||||
editor = 'gui'
|
|
||||||
else: # 'gui'
|
|
||||||
editor = 'text'
|
|
||||||
|
|
||||||
# load right editor class
|
|
||||||
if editor == 'gui':
|
|
||||||
from MoinMoin.PageGraphicalEditor import PageGraphicalEditor
|
|
||||||
pg = PageGraphicalEditor(request, pagename)
|
|
||||||
else: # 'text'
|
|
||||||
from MoinMoin.PageEditor import PageEditor
|
|
||||||
pg = PageEditor(request, pagename)
|
|
||||||
|
|
||||||
# is invoked without savetext start editing
|
|
||||||
if savetext is None or 'button_load_draft' in request.form:
|
|
||||||
pg.sendEditor()
|
|
||||||
return
|
|
||||||
|
|
||||||
# did user hit cancel button?
|
|
||||||
cancelled = 'button_cancel' in request.form
|
|
||||||
|
|
||||||
if request.cfg.edit_ticketing:
|
|
||||||
ticket = request.form.get('ticket', [''])[0]
|
|
||||||
if not wikiutil.checkTicket(request, ticket):
|
|
||||||
request.theme.add_msg(_('Please use the interactive user interface to use action %(actionname)s!') % {'actionname': 'edit' }, "error")
|
|
||||||
pg.send_page()
|
|
||||||
return
|
|
||||||
|
|
||||||
from MoinMoin.error import ConvertError
|
|
||||||
try:
|
|
||||||
if lasteditor == 'gui':
|
|
||||||
# convert input from Graphical editor
|
|
||||||
format = request.form.get('format', ['wiki'])[0]
|
|
||||||
if format == 'wiki':
|
|
||||||
converter_name = 'text_html_text_moin_wiki'
|
|
||||||
else:
|
|
||||||
converter_name = 'undefined' # XXX we don't have other converters yet
|
|
||||||
convert = wikiutil.importPlugin(request.cfg, "converter", converter_name, 'convert')
|
|
||||||
savetext = convert(request, pagename, savetext)
|
|
||||||
|
|
||||||
# IMPORTANT: normalize text from the form. This should be done in
|
|
||||||
# one place before we manipulate the text.
|
|
||||||
savetext = pg.normalizeText(savetext, stripspaces=rstrip)
|
|
||||||
except ConvertError:
|
|
||||||
# we don't want to throw an exception if user cancelled anyway
|
|
||||||
if not cancelled:
|
|
||||||
raise
|
|
||||||
|
|
||||||
if cancelled:
|
|
||||||
pg.sendCancel(savetext or "", rev)
|
|
||||||
pagedir = pg.getPagePath(check_create=0)
|
|
||||||
import os
|
|
||||||
if not os.listdir(pagedir):
|
|
||||||
os.removedirs(pagedir)
|
|
||||||
return
|
|
||||||
|
|
||||||
comment = wikiutil.clean_input(comment)
|
|
||||||
|
|
||||||
# Add category
|
|
||||||
|
|
||||||
# TODO: this code does not work with extended links, and is doing
|
|
||||||
# things behind your back, and in general not needed. Either we have
|
|
||||||
# a full interface for categories (add, delete) or just add them by
|
|
||||||
# markup.
|
|
||||||
|
|
||||||
if category and category != _('<No addition>'): # opera 8.5 needs this
|
|
||||||
# strip trailing whitespace
|
|
||||||
savetext = savetext.rstrip()
|
|
||||||
|
|
||||||
# Add category separator if last non-empty line contains
|
|
||||||
# non-categories.
|
|
||||||
lines = [line for line in savetext.splitlines() if line]
|
|
||||||
if lines:
|
|
||||||
|
|
||||||
#TODO: this code is broken, will not work for extended links
|
|
||||||
#categories, e.g ["category hebrew"]
|
|
||||||
categories = lines[-1].split()
|
|
||||||
|
|
||||||
if categories:
|
|
||||||
confirmed = wikiutil.filterCategoryPages(request, categories)
|
|
||||||
if len(confirmed) < len(categories):
|
|
||||||
# This was not a categories line, add separator
|
|
||||||
savetext += u'\n----\n'
|
|
||||||
|
|
||||||
# Add new category
|
|
||||||
if savetext and savetext[-1] != u'\n':
|
|
||||||
savetext += ' '
|
|
||||||
savetext += category + u'\n' # Should end with newline!
|
|
||||||
|
|
||||||
# Preview, spellcheck or spellcheck add new words
|
|
||||||
if ('button_preview' in request.form or
|
|
||||||
'button_spellcheck' in request.form or
|
|
||||||
'button_newwords' in request.form):
|
|
||||||
pg.sendEditor(preview=savetext, comment=comment)
|
|
||||||
|
|
||||||
# Preview with mode switch
|
|
||||||
elif 'button_switch' in request.form:
|
|
||||||
pg.sendEditor(preview=savetext, comment=comment, staytop=1)
|
|
||||||
|
|
||||||
# Save new text
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
from MoinMoin.security.textcha import TextCha
|
|
||||||
if not TextCha(request).check_answer_from_form():
|
|
||||||
raise pg.SaveError(_('TextCha: Wrong answer! Go back and try again...'))
|
|
||||||
savemsg = pg.saveText(savetext, rev, trivial=trivial, comment=comment)
|
|
||||||
except pg.EditConflict, e:
|
|
||||||
msg = e.message
|
|
||||||
|
|
||||||
# Handle conflict and send editor
|
|
||||||
pg.set_raw_body(savetext, modified=1)
|
|
||||||
|
|
||||||
pg.mergeEditConflict(rev)
|
|
||||||
# We don't send preview when we do merge conflict
|
|
||||||
pg.sendEditor(msg=msg, comment=comment)
|
|
||||||
return
|
|
||||||
|
|
||||||
except pg.SaveError, msg:
|
|
||||||
# msg contains a unicode string
|
|
||||||
savemsg = unicode(msg)
|
|
||||||
|
|
||||||
# Send new page after save or after unsuccessful conflict merge.
|
|
||||||
request.reset()
|
|
||||||
pg = Page(request, pagename)
|
|
||||||
|
|
||||||
# sets revision number to default for further actions
|
|
||||||
request.rev = 0
|
|
||||||
request.theme.add_msg(savemsg, "info")
|
|
||||||
pg.send_page()
|
|
|
@ -1,195 +0,0 @@
|
||||||
# -*- coding: iso-8859-1 -*-
|
|
||||||
"""
|
|
||||||
MoinMoin - create account action
|
|
||||||
|
|
||||||
@copyright: 2007 MoinMoin:JohannesBerg
|
|
||||||
@license: GNU GPL, see COPYING for details.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from MoinMoin import user, wikiutil, util
|
|
||||||
from MoinMoin.Page import Page
|
|
||||||
from MoinMoin.widget import html
|
|
||||||
from MoinMoin.security.textcha import TextCha
|
|
||||||
from MoinMoin.auth import MoinAuth
|
|
||||||
|
|
||||||
|
|
||||||
_debug = False
|
|
||||||
|
|
||||||
def _create_user(request):
|
|
||||||
_ = request.getText
|
|
||||||
form = request.form
|
|
||||||
|
|
||||||
if request.request_method != 'POST':
|
|
||||||
return
|
|
||||||
|
|
||||||
if not TextCha(request).check_answer_from_form():
|
|
||||||
return _('TextCha: Wrong answer! Go back and try again...')
|
|
||||||
|
|
||||||
# Create user profile
|
|
||||||
theuser = user.User(request, auth_method="new-user")
|
|
||||||
|
|
||||||
# Require non-empty name
|
|
||||||
try:
|
|
||||||
theuser.name = form['name'][0]
|
|
||||||
except KeyError:
|
|
||||||
return _("Empty user name. Please enter a user name.")
|
|
||||||
|
|
||||||
# Don't allow creating users with invalid names
|
|
||||||
if not user.isValidName(request, theuser.name):
|
|
||||||
return _("""Invalid user name {{{'%s'}}}.
|
|
||||||
Name may contain any Unicode alpha numeric character, with optional one
|
|
||||||
space between words. Group page name is not allowed.""", wiki=True) % wikiutil.escape(theuser.name)
|
|
||||||
|
|
||||||
# Name required to be unique. Check if name belong to another user.
|
|
||||||
if user.getUserId(request, theuser.name):
|
|
||||||
return _("This user name already belongs to somebody else.")
|
|
||||||
|
|
||||||
# try to get the password and pw repeat
|
|
||||||
password = form.get('password1', [''])[0]
|
|
||||||
password2 = form.get('password2', [''])[0]
|
|
||||||
|
|
||||||
# Check if password is given and matches with password repeat
|
|
||||||
if password != password2:
|
|
||||||
return _("Passwords don't match!")
|
|
||||||
if not password:
|
|
||||||
return _("Please specify a password!")
|
|
||||||
|
|
||||||
pw_checker = request.cfg.password_checker
|
|
||||||
if pw_checker:
|
|
||||||
pw_error = pw_checker(theuser.name, password)
|
|
||||||
if pw_error:
|
|
||||||
return _("Password not acceptable: %s") % pw_error
|
|
||||||
|
|
||||||
# Encode password
|
|
||||||
if password and not password.startswith('{SHA}'):
|
|
||||||
try:
|
|
||||||
theuser.enc_password = user.encodePassword(password)
|
|
||||||
except UnicodeError, err:
|
|
||||||
# Should never happen
|
|
||||||
return "Can't encode password: %s" % str(err)
|
|
||||||
|
|
||||||
# try to get the email, for new users it is required
|
|
||||||
email = wikiutil.clean_input(form.get('email', [''])[0])
|
|
||||||
theuser.email = email.strip()
|
|
||||||
if not theuser.email and 'email' not in request.cfg.user_form_remove:
|
|
||||||
return _("Please provide your email address. If you lose your"
|
|
||||||
" login information, you can get it by email.")
|
|
||||||
|
|
||||||
# Email should be unique - see also MoinMoin/script/accounts/moin_usercheck.py
|
|
||||||
if theuser.email and request.cfg.user_email_unique:
|
|
||||||
if user.get_by_email_address(request, theuser.email):
|
|
||||||
return _("This email already belongs to somebody else.")
|
|
||||||
|
|
||||||
# save data
|
|
||||||
theuser.save()
|
|
||||||
|
|
||||||
if form.has_key('create_and_mail'):
|
|
||||||
theuser.mailAccountData()
|
|
||||||
|
|
||||||
result = _("User account created! You can use this account to login now...")
|
|
||||||
if _debug:
|
|
||||||
result = result + util.dumpFormData(form)
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def _create_form(request):
|
|
||||||
_ = request.getText
|
|
||||||
url = request.page.url(request)
|
|
||||||
ret = html.FORM(action=url)
|
|
||||||
ret.append(html.INPUT(type='hidden', name='action', value='newaccount'))
|
|
||||||
lang_attr = request.theme.ui_lang_attr()
|
|
||||||
ret.append(html.Raw('<div class="userpref"%s>' % lang_attr))
|
|
||||||
tbl = html.TABLE(border="0")
|
|
||||||
ret.append(tbl)
|
|
||||||
ret.append(html.Raw('</div>'))
|
|
||||||
|
|
||||||
row = html.TR()
|
|
||||||
tbl.append(row)
|
|
||||||
row.append(html.TD().append(html.STRONG().append(
|
|
||||||
html.Text(_("Name")))))
|
|
||||||
cell = html.TD()
|
|
||||||
row.append(cell)
|
|
||||||
cell.append(html.INPUT(type="text", size="36", name="name"))
|
|
||||||
cell.append(html.Text(' ' + _("(Use FirstnameLastname)")))
|
|
||||||
|
|
||||||
row = html.TR()
|
|
||||||
tbl.append(row)
|
|
||||||
row.append(html.TD().append(html.STRONG().append(
|
|
||||||
html.Text(_("Password")))))
|
|
||||||
row.append(html.TD().append(html.INPUT(type="password", size="36",
|
|
||||||
name="password1")))
|
|
||||||
|
|
||||||
row = html.TR()
|
|
||||||
tbl.append(row)
|
|
||||||
row.append(html.TD().append(html.STRONG().append(
|
|
||||||
html.Text(_("Password repeat")))))
|
|
||||||
row.append(html.TD().append(html.INPUT(type="password", size="36",
|
|
||||||
name="password2")))
|
|
||||||
|
|
||||||
row = html.TR()
|
|
||||||
tbl.append(row)
|
|
||||||
row.append(html.TD().append(html.STRONG().append(html.Text(_("Email")))))
|
|
||||||
row.append(html.TD().append(html.INPUT(type="text", size="36",
|
|
||||||
name="email")))
|
|
||||||
|
|
||||||
textcha = TextCha(request)
|
|
||||||
if textcha.is_enabled():
|
|
||||||
row = html.TR()
|
|
||||||
tbl.append(row)
|
|
||||||
row.append(html.TD().append(html.STRONG().append(
|
|
||||||
html.Text(_('TextCha (required)')))))
|
|
||||||
td = html.TD()
|
|
||||||
if textcha:
|
|
||||||
td.append(textcha.render())
|
|
||||||
row.append(td)
|
|
||||||
|
|
||||||
row = html.TR()
|
|
||||||
tbl.append(row)
|
|
||||||
row.append(html.TD())
|
|
||||||
td = html.TD()
|
|
||||||
row.append(td)
|
|
||||||
td.append(html.INPUT(type="submit", name="create_only",
|
|
||||||
value=_('Create Profile')))
|
|
||||||
if request.cfg.mail_enabled:
|
|
||||||
td.append(html.Text(' '))
|
|
||||||
td.append(html.INPUT(type="submit", name="create_and_mail",
|
|
||||||
value="%s + %s" % (_('Create Profile'),
|
|
||||||
_('Email'))))
|
|
||||||
|
|
||||||
return unicode(ret)
|
|
||||||
|
|
||||||
def execute(pagename, request):
|
|
||||||
found = False
|
|
||||||
for auth in request.cfg.auth:
|
|
||||||
if isinstance(auth, MoinAuth):
|
|
||||||
found = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if not found:
|
|
||||||
# we will not have linked, so forbid access
|
|
||||||
request.makeForbidden403()
|
|
||||||
return
|
|
||||||
|
|
||||||
page = Page(request, pagename)
|
|
||||||
_ = request.getText
|
|
||||||
form = request.form
|
|
||||||
|
|
||||||
submitted = form.has_key('create_only') or form.has_key('create_and_mail')
|
|
||||||
|
|
||||||
if submitted: # user pressed create button
|
|
||||||
request.theme.add_msg(_create_user(request), "dialog")
|
|
||||||
return page.send_page()
|
|
||||||
else: # show create form
|
|
||||||
request.emit_http_headers()
|
|
||||||
request.theme.send_title(_("Create Account"), pagename=pagename)
|
|
||||||
|
|
||||||
request.write(request.formatter.startContent("content"))
|
|
||||||
|
|
||||||
# THIS IS A BIG HACK. IT NEEDS TO BE CLEANED UP
|
|
||||||
request.write(_create_form(request))
|
|
||||||
|
|
||||||
request.write(request.formatter.endContent())
|
|
||||||
|
|
||||||
request.theme.send_footer(pagename)
|
|
||||||
request.theme.send_closing_html()
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue