def _from_wiki_msg(self): """ Print a message that says what wiki we're from and what our base wiki is. """ wiki_name = self.from_wiki base_wiki_sitename = farm.getBaseWikiFullName(self.request) d = {'wiki_name':farm.link_to_wiki(wiki_name, self.request.formatter), 'base_wiki_name':farm.link_to_wiki( farm.getBaseWikiName(), self.request.formatter), 'base_wiki_sitename_link':farm.link_to_wiki( farm.getBaseWikiName(), self.request.formatter, text=base_wiki_sitename, no_icon=True), 'base_wiki_sitename': base_wiki_sitename, } msg = config.wiki_farm_from_wiki_msg % d return msg
def display_watched_wikis(request, userpage): theuser = user.User(request, name=userpage) watched_wikis = theuser.getWatchedWikis().keys() if not watched_wikis: request.write('<p><i>Watching no wikis.</i></p>') return wikis_html = ['<div class="userWatchedWikisList">'] for wiki_name in watched_wikis: wikis_html.append('<span>%s</span>' % farm.link_to_wiki(wiki_name, request.formatter)) wikis_html.append('</div>') request.write(''.join(wikis_html))
def execute(macro, args, formatter=None): if not formatter: formatter = macro.formatter request = macro.request text = [] text.append('<div style="float: left; width: 40%;">') text.append(formatter.heading(2, "Recently created wikis")) text.append(formatter.bullet_list(1)) recent_wikis = get_recent_wikis(request) for wiki_name, editTime in recent_wikis: link = farm.link_to_wiki(wiki_name, formatter) text.append('%s%s%s' % (formatter.listitem(1), link, formatter.listitem(0))) text.append(formatter.bullet_list(0)) text.append('</div>') set_recent_wikis_cache(request, recent_wikis) text.append('<div style="float: right; width: 40%;">') text.append(formatter.heading(2, "Recently edited wikis")) text.append(formatter.bullet_list(1)) recently_edited = get_recently_edited(request) for wiki_name in recently_edited: link = farm.link_to_wiki(wiki_name, formatter) text.append('%s%s%s' % (formatter.listitem(1), link, formatter.listitem(0))) text.append(formatter.bullet_list(0)) text.append('</div>') set_recently_edited_cache(request, recently_edited) text.append('<div style="clear:both;"></div>') output_html = formatter.rawHTML(''.join(text)) return output_html
def display_bookmarks(request, userpage): theuser = user.User(request, name=userpage) bookmarks = theuser.getFavorites() wiki_names = bookmarks.keys() # put current wiki in front of the rest if request.config.wiki_name in bookmarks: wiki_names.remove(request.config.wiki_name) wiki_names.insert(0, request.config.wiki_name) request.write('<div class="userFavoritesList">') for wiki_name in wiki_names: if config.wiki_farm: request.write('<h4>on %s:</h4>' % farm.link_to_wiki(wiki_name, request.formatter)) request.write('<div>') for pagename in bookmarks[wiki_name]: request.write('<span class="userFavoriteItem">%s</span>' % Page(pagename, request, wiki_name=wiki_name).link_to(guess_case=True)) if config.wiki_farm: request.write('</div>') request.write('</div>')
def execute(macro, args, formatter=None, **kw): if not formatter: formatter = macro.formatter request = macro.request _ = request.getText # set up javascript entry grouping -- this happens when the page renders request.write('<script type="text/javascript">' 'onLoadStuff.push(\'groupAllRcChanges();\');' '</script>\n') request.write('<script type="text/javascript" src="/wiki/revipbox.js"></script>\n') pagename = formatter.page.page_name q_pagename = wikiutil.quoteWikiname(pagename) rc_page = Page(pagename, request) d = {} d['q_page_name'] = q_pagename d['page'] = rc_page if args == 'global': wiki_global = True else: wiki_global = False # set max size in days max_days = min(int(request.form.get('max_days', [0])[0]), _DAYS_SELECTION[-1]) # get bookmark from valid user bookmark = request.user.getBookmark(wiki_global=wiki_global) # default to _MAX_DAYS for users without rc bookmark if not max_days: max_days = _MAX_DAYS d['rc_max_days'] = max_days if wiki_global: watched_wikis = request.user.getWatchedWikis() lines = wikidb.getRecentChanges(request, max_days=max_days, changes_since=bookmark, wiki_global=wiki_global, on_wikis=watched_wikis) else: lines = wikidb.getRecentChanges(request, max_days=max_days, changes_since=bookmark, wiki_global=wiki_global) tnow = time.time() msg = "" do_we_show_comments = request.user.getShowComments() setup_show_comments(do_we_show_comments, rc_page, request, d) add_bookmark_link(rc_page, tnow, bookmark, wiki_global, request, d) print_rc_header(request, d) if not lines: if wiki_global: request.write('<p>This page shows you changes on ' '<strong>all</strong> of the wikis you are watching!' '</p>') if not watched_wikis: if request.user.valid: request.write('<p>You are not watching any wikis, though. ' 'To watch a wiki, simply go to the wiki you\'re ' 'interested in and click the "watch this wiki" ' 'link next to your user settings in the upper ' 'right.</p>') else: request.write('<p>You are not logged in. Please login to ' 'view changes on the wikis you are watching.' '</p>') if not wiki_global or watched_wikis: request.write("<p>No recent changes. Quick — change " "something while nobody's looking!</p>") lines_by_day = group_changes_by_day(lines, tnow, max_days, request) for day, lines in lines_by_day: print_day(day, request, d) if wiki_global and request.user.getRcGroupByWiki(): lines_grouped = group_changes_by_wiki(lines, request) wiki_names_sorted = lines_grouped.keys() wiki_names_sorted.sort() for wiki_name in wiki_names_sorted: if lines_grouped[wiki_name]: request.write('<h3 style="padding: .2em;">%s:</h3>' % farm.link_to_wiki(wiki_name, formatter)) print_changes(lines_grouped[wiki_name], bookmark, tnow, max_days, do_we_show_comments, d, wiki_global, macro, request, formatter, grouped=True) else: print_changes(lines, bookmark, tnow, max_days, do_we_show_comments, d, wiki_global, macro, request, formatter) d['rc_msg'] = msg request.write(request.theme.recentchanges_footer(d)) return ''
def format_page_edits(request, lines, showcomments, bookmark, formatter, wiki_global=False, grouped_by_wiki=False): _ = request.getText d = {} # dict for passing stuff to theme line = lines[0] d['show_comments'] = showcomments pagename = line.pagename tnow = time.time() # check whether this page is newer than the user's bookmark hilite = line.ed_time > (bookmark or line.ed_time) if wiki_global: page = Page(line.pagename, request, wiki_name=line.wiki_name) else: page = Page(line.pagename, request) # we can infer 'exists?' from current rc data in some cases getPageStatus(lines, pagename, request) html_link = format_page_edit_icon(request, lines, page, hilite, bookmark, formatter) # print name of page, with a link to it force_split = len(page.page_name) > _MAX_PAGENAME_LENGTH d['rc_tag_html'] = html_link if wiki_global: if not grouped_by_wiki: on_wiki = (' <span class="minorText">(on %s)</span>' % farm.link_to_wiki(line.wiki_name, formatter)) else: on_wiki = '' d['pagelink_html'] = '%s%s' % ( page.link_to(text=pagename, absolute=True), on_wiki) else: d['pagelink_html'] = page.link_to(text=pagename) # print time of change d['time_html'] = None if config.changed_time_fmt: tdiff = int(tnow - line.ed_time) / 60 if tdiff < 1440: numhrs = int(tdiff/60) nummins = tdiff%60 txthrs = "" txttime = "" if numhrs == 1: txthrs = '1 hour' if numhrs > 1: txthrs = '%s hours' % str(numhrs) txttime = txthrs if nummins == 1: txttime = '%s 1 minute' % str(txthrs) if nummins > 1: txttime = '%s %s minutes' % (str(txthrs), str(nummins)) if nummins == 0 and numhrs == 0: numsecs = int(tnow - line.ed_time) % 60 txttime = '%s second' % str(numsecs) if numsecs > 1: txttime = '%ss' % txttime d['time_html'] = '%s ago' % txttime else: d['time_html'] = time.strftime("at %I:%M %p", line.time_tuple) # print editor name or IP d['editors'] = [] if config.show_hosts: for idx in range(len(lines)): name = getEditor(lines[idx], request) ip = lines[idx].host d['editors'].append((name,ip)) comments = [] for idx in range(len(lines)): comment = Comment(request, lines[idx].comment, lines[idx].action, page).render() comments.append(comment) d['changecount'] = len(lines) d['comments'] = comments return request.theme.recentchanges_entry(d)
def asHTML(self, msg='', new_user=False): """ Create the complete HTML form code. """ _ = self._ form_html = [] self.from_wiki = None if self.request.form.has_key('new_user'): if (self.request.form['new_user'][0] and not self.request.user.valid): new_user = True # if they are clicking into the user settings area # from a non-hub wiki then we want to get this wiki's name # and display some message accoridngly if self.request.form.has_key('from_wiki'): self.from_wiki = self.request.form['from_wiki'][0].lower().strip() if not wikiutil.isInFarm(self.from_wiki, self.request): self.from_wiki = None # different form elements depending on login state html_uid = '' html_sendmail = '' if self.request.user.valid: html_uid = '<tr><td>ID</td><td>%s</td></tr>' % self.request.user.id buttons = [ ('save', _('Save')), ('logout', _('Logout')), ] else: if new_user: buttons = [ ("save", _('Create Profile')), ] else: buttons = [ ("login", _('Login')), ] self.make_form() if new_user and self.from_wiki: if self.from_wiki != farm.getBaseWikiName(): self._inner.append(html.Raw(self._from_wiki_msg())) if not self.request.user.valid: if not new_user: user_name_help_text = '' else: user_name_help_text = ' ' + config.user_name_help_text self.make_row(_('Name'), [html.INPUT(type="text", size=32, name="username", value=self.request.user.name) ], option_text=user_name_help_text) if new_user: self.make_row(_('Password'), [ html.INPUT( type="password", size=32, name="password", ) ]) self.make_row(_('Password repeat'), [ html.INPUT( type="password", size=32, name="password2", ), ' ', ]) self.make_row(_('Email'), [ html.INPUT( type="text", size=40, name="email", value=self.request.user.email )]) if new_user: new_user_int = 1 else: new_user_int = 0 self.make_row('', [ html.INPUT( type="hidden", name="new_user", value=new_user_int )]) # Add buttons for new user button_cell = [] for name, label in buttons: button_cell.extend([ html.INPUT(type="submit", name=name, value=label), ' ', ]) self.make_row('', button_cell) form_html.append(str(self._form)) form_html.append(first_time_msg) form_html.append(forgot_password_msg) # show options only if already logged in elif self.request.user.valid: self.make_form() self._inner.append(html.Raw('<h2>General Settings</h2>')) if self.from_wiki: if self.from_wiki != farm.getBaseWikiName(): self._inner.append(html.Raw(self._from_wiki_msg())) self.make_row(_('Email'), [ html.INPUT( type="text", size=40, name="email", value=self.request.user.email )]) self.make_row(_('Time zone'), [ _('My time zone is'), ' ', self._tz_select(), ]) self.make_row('', [ html.INPUT(type="checkbox", name='remember_me', value=1, checked=getattr(self.request.user, 'remember_me', 0)), 'Remember me so I don\'t have to keep logging in', ]) if config.wiki_farm: # FIXME: make the link link somewhere sane based on # current context. # prepare list of possible userpage locations wikis_for_userpage_options = \ copy(self.request.user.getWatchedWikis()) if self.request.user.wiki_for_userpage: wikis_for_userpage_options[ self.request.user.wiki_for_userpage] = None wikis_for_userpage_options[ farm.getBaseWikiName()] = None wikis_for_userpage_options = wikis_for_userpage_options.keys() selection_tuples = [] for name in wikis_for_userpage_options: selection_tuples.append((name, name)) wikis_for_userpage_options = selection_tuples wikis_for_userpage_options.insert(0, ('', 'each wiki (default)')) self.make_row(_('User page'), [ html.Raw('<div><span style="vertical-align: bottom;">' 'My name links to my user page on ' + self.request.theme.make_icon('interwiki', {'wikitag': self.request.user.wiki_for_userpage}, html_class="interwiki_icon") + '</span>'), util.web.makeSelection('wiki_for_userpage', wikis_for_userpage_options, selectedval=self.request.user.wiki_for_userpage), html.Raw('</div>') ], option_text=_('(Choosing from watched wikis.)')) self.make_row(_('Editor size'), [ html.INPUT(type="text", size=3, maxlength=3, name="edit_cols", value=self.request.user.edit_cols), ' x ', html.INPUT(type="text", size=3, maxlength=3, name="edit_rows", value=self.request.user.edit_rows), ]) self.make_row(_('Personal CSS URL'), [ html.INPUT( type="text", size=40, name="css_url", value=self.request.user.css_url ), ' '], option_text=_('(Leave empty to disable user CSS)'), ) # Add buttons button_cell = [] for name, label in buttons: button_cell.extend([ html.INPUT(type="submit", name=name, value=label), ' ', ]) self.make_row('', button_cell) form_html.append(str(self._form)) if config.wiki_farm: form_html.append('<h2>Watched wikis</h2><p>' 'These are wikis you want to see on the ' 'Interwiki Recent Changes page.</p>') watched_wiki_list = self.request.user.getWatchedWikis() if not watched_wiki_list: form_html.append('<p><em>You have no watched wikis. ' 'To add watch a wiki, simply visit a ' 'wiki and click the "watch this wiki" ' 'link in the upper right hand corner of ' 'the screen (under "Welcome %s").' '</em></p>' % ( self.request.user.propercased_name)) else: form_html.append('<ul>') for wiki_name in watched_wiki_list: remove_link = ( '<span style="font-size:x-small; margin-left: ' '1.5em;">[%s]</span>' % ( Page(config.page_user_preferences, self.request).link_to( know_status=True, know_status_exists=True, querystr=('action=watch_wiki&wikiname=%s' '&del=1' % wiki_name), text='remove'))) form_html.append('<li>%s %s</li>' % ( farm.link_to_wiki(wiki_name, self.request.formatter), remove_link)) form_html.append('</ul>') self.make_form() self._inner.append(html.Raw('<h2>Change password</h2>')) buttons = [("save", _("Change password"))] self.make_row(_('Password'), [ html.INPUT( type="password", size=32, name="password", ) ]) self.make_row(_('Password repeat'), [ html.INPUT( type="password", size=32, name="password2", ), ' ', ]) # Add buttons button_cell = [] for name, label in buttons: button_cell.extend([ html.INPUT(type="submit", name=name, value=label), ' ', ]) self.make_row('', button_cell) self._inner.append(html.Raw('<h2>Disable account</h2>')) buttons = [("save", _("Disable account"))] self.make_row('', [ html.INPUT(type="checkbox", name='disabled', value=1, checked=getattr(self.request.user, 'disabled', 0)), 'Disable this account forever', ]) # Add buttons button_cell = [] for name, label in buttons: button_cell.extend([ html.INPUT(type="submit", name=name, value=label), ' ', ]) self.make_row('', button_cell) form_html.append(str(self._form)) else: self.make_form() self._inner.append(html.Raw('<h2>Log in</h2>')) self.make_row(_('User name'), [ html.INPUT( type="text", size=22, name="username", ) ]) self.make_row(_('Password'), [ html.INPUT( type="password", size=22, name="password", ), ' ', ]) # Add buttons for general settings button_cell = [] for name, label in buttons: button_cell.extend([ html.INPUT(type="submit", name=name, value=label), ' ', ]) self.make_row('', button_cell) form_html.append(str(self._form)) form_html.append(forgot_password_msg) return ''.join(form_html)
def handleData(self, new_user=None): from Sycamore.Page import MAX_PAGENAME_LENGTH as MAX_USERNAME_LENGTH _ = self._ form = self.request.form msg = '' isdisabled = False if form.get('disabled', [0])[0] == '1': isdisabled = True self.from_wiki = None if self.request.form.has_key('from_wiki'): self.from_wiki = self.request.form['from_wiki'][0].lower().strip() if not wikiutil.isInFarm(self.from_wiki, self.request): self.from_wiki = None new_user = int(form.get('new_user', [0])[0]) # wiki farm authentication # we want them to be able to sign back in right after they # click the 'logout' GET link, hence this test is_form_logout = (form.has_key('qs') and urllib.unquote(form['qs'][0]) == 'action=userform&logout=Logout') if (self.request.form.has_key('badlogin') and self.request.form['badlogin'][0]): _create_nologin_cookie(self.request) if config.wiki_farm: wiki_base_url = farm.getBaseFarmURL(self.request) else: wiki_base_url = '%s/' % self.request.getScriptname() return_string = ('Unknown username or wrong password.<br/><br/>' 'New user? <a href="%s%s?new_user=1">Click here ' 'to create an account!</a><br/><br/>' 'Forgot your password? We\'ll email it to you.' '<form action="%s" method="POST">' '<input type="hidden" name="action" ' 'value="userform">' 'Email address: <input class="formfields" ' 'type="text" name="email">' ' <input type="submit" class="formbutton" ' 'name="login_sendmail" ' 'value="Mail me my account data">' '</form>' % ( wiki_base_url, wikiutil.quoteWikiname( config.page_user_preferences), wiki_base_url)) return return_string if (form.has_key('login_check') and form['login_check'][0] and form.has_key('backto_wiki') and form.has_key('backto_page')): backto_wiki = form['backto_wiki'][0] backto_page = form['backto_page'][0].encode(config.charset) if form.has_key('qs') and not is_form_logout: q_query_string = form['qs'][0] else: q_query_string = '' if self.request.user.valid: secret, stored_expire_time, session = \ self.request.user.cookie_dough if q_query_string: url = ('%s?action=userform&backto_page=%s&qs=%s' '&secret=%s&expire_time=%s&uid=%s&session=%s' % ( backto_page, urllib.quote(backto_page), urllib.quote(q_query_string), urllib.quote(secret), stored_expire_time, self.request.user.id, urllib.quote(session))) else: url = ('%s?action=userform&backto_page=%s&secret=%s' '&expire_time=%s&uid=%s&session=%s' % ( backto_page, urllib.quote(backto_page), urllib.quote(secret), stored_expire_time, self.request.user.id, urllib.quote(session))) else: if q_query_string: url = ('%s?action=userform&backto_page=%s¬_logged_in=1' '&qs=%s' % (backto_page, urllib.quote(backto_page), urllib.quote(q_query_string))) else: url = ('%s?action=userform&backto_page=%s¬_logged_in=1' % (backto_page, urllib.quote(backto_page))) self.request.http_redirect(url) return # bounce-back wiki farm authentication if form.has_key('not_logged_in') and form.has_key('backto_page'): backto = urllib.unquote(form['backto_page'][0].encode( config.charset)) if form.has_key('qs') and not is_form_logout: query_string = '?%s' % (urllib.unquote(form['qs'][0] ).encode(config.charset)) else: query_string = '' url = '%s%s' % (backto, query_string) _create_nologin_cookie(self.request) self.request.http_redirect(url) return # bounce-back wiki farm authentication elif (form.has_key('uid') and form.has_key('secret') and form.has_key('session') and form.has_key('expire_time')): uid = form['uid'][0] secret = urllib.unquote(form['secret'][0]) session = form['session'][0] expire_time = float(form['expire_time'][0]) if form.has_key('backto_page'): backto_page = form['backto_page'][0] else: backto_page = '/' if form.has_key('qs') and not is_form_logout: query_string = '?%s' % urllib.unquote(form['qs'][0]) else: query_string = '' url = '%s%s' % (backto_page, query_string) self.request.http_redirect(url) self.request.user.sendCookie(self.request, expire=expire_time, sessionid=session, secret=secret, id=uid) self.request.user.clearNologinCookie(self.request) return if form.has_key('logout') or isdisabled: msg = '' if isdisabled: if not self.request.isPOST(): return "Use the interactive interface to change settings!" # disable the account self.request.user.disabled = 1 # save user's profile self.request.user.save() msg = '<p>%s</p>' % _("Your account has been disabled.") # clear the cookie in the browser and locally try: cookie = Cookie.SimpleCookie(self.request.saved_cookie) except Cookie.CookieError: # ignore invalid cookies cookie = None else: if config.wiki_farm: cookie_id = wikiutil.quoteCookiename( config.wiki_base_domain + ',ID') else: cookie_id = wikiutil.quoteCookiename( config.sitename + ',ID') if cookie.has_key(cookie_id): self.removeSession(cookie[cookie_id].value) cookie_dir = config.web_dir if not cookie_dir: cookie_dir = '/' domain = wikiutil.getCookieDomain(self.request) expirestr = time.strftime("%A, %d-%b-%Y %H:%M:%S GMT", time.gmtime(0)) self.request.setHttpHeader(('Set-Cookie', ('%s="%s"; domain=%s; path=%s; ' 'expires=%s' % ( (cookie_id, cookie[cookie_id].value, domain, cookie_dir, expirestr))))) self.request.saved_cookie = '' self.request.auth_username = '' self.request.user = user.User(self.request) return msg + _("Cookie deleted. You are now logged out.") if form.has_key('login_sendmail'): if not self.request.isPOST(): return "Use the interactive interface to change settings!" if not config.mail_smarthost: return _('This wiki is not enabled for mail processing. ' 'Contact the owner of the wiki, who can either enable ' 'email, or remove the "Subscribe" icon.') try: email = form['email'][0] except KeyError: return _("Please provide a valid email address!") text = '' uid = user.getUserIdByEmail(email, self.request) if uid: theuser = user.User(self.request, uid) if theuser.valid: code = self.createCode(theuser.id) sitename = farm.getBaseWikiFullName(self.request) if config.wiki_farm: url = farm.getBaseFarmURL(self.request) else: url = '%s/' % self.request.getBaseURL() text = ("Go here to automatically log into %s: " "%s%s?action=userform&uid=%s&code=%s\n" "Once you're logged in, you should change your " "password in your settings " "(you forgot your password, right?).\n\n" "(The link in this email is good for " "one use only.)" % ( sitename, url, wikiutil.quoteWikiname( config.page_user_preferences), theuser.id, code)) if not text: return _("Found no account matching the given email address " "'%(email)s'!") % {'email': email} mailok, msg = util.mail.sendmail(self.request, [email], 'Your wiki account data', text, mail_from=config.mail_from) return wikiutil.escape(msg) if form.has_key('login') or form.has_key('uid'): uid = None if form.has_key('code') and form.has_key('uid'): given_uid = form['uid'][0].strip() given_code = form['code'][0].strip() given_code if self.isValidCode(given_uid, given_code): uid = given_uid if uid: # we were given account information so let's # create an account -> log them in theuser = user.User(self.request, id=uid) msg = _("You are now logged in! " "Please change your password below!") # send the cookie theuser.sendCookie(self.request) self.request.user = theuser return msg else: # we weren't given information, so let's see # if they gave us a login/password # try to get the user name try: name = form['username'][0].replace('\t', ' ').strip() except KeyError: name = '' # try to get the password password = form.get('password',[''])[0] # load the user data and check for validness if name: theuser = user.User(self.request, name=name, password=password, is_login=True) else: theuser = user.User(self.request, id=uid, name=name, password=password, is_login=True) if config.wiki_farm: wiki_base_url = farm.getBaseFarmURL(self.request) else: wiki_base_url = '%s/' % self.request.getScriptname() if not theuser.valid: if (not self.request.form.has_key('backto_wiki') or not self.request.form['backto_wiki'][0]): return_string = ('Unknown username or wrong password.' '<br/><br/>New user? ' '<a href="%s%s?new_user=1">' 'Click here to create an account!</a>' '<br/><br/>Forgot your password? ' 'We\'ll email it to you.' '<form action="%s" method="POST">' '<input type="hidden" name="action" ' 'value="userform">' 'Email address: ' '<input class="formfields" ' 'type="text" name="email">' ' ' '<input type="submit" ' 'class="formbutton" ' 'name="login_sendmail" ' 'value="Mail me my account ' 'data">' '</form>' % ( wiki_base_url, wikiutil.quoteWikiname( config.page_user_preferences), wiki_base_url)) return return_string else: self.request.http_redirect( urllib.unquote( self.request.form['backto_page'][0].encode( config.charset)) + '?action=userform&badlogin=1') return # send the cookie theuser.sendCookie(self.request) self.request.user = theuser send_back_home(self.request, msg="You are now logged in!") else: if not self.request.isPOST(): return """Use the interactive interface to change settings!""" # save user's profile, first get user instance theuser = user.User(self.request) # try to get the name # if name is empty or missing, return an error msg if (form.has_key('username') and form['username'][0].replace('\t', '').strip()): theuser.propercased_name = \ form['username'][0].replace('\t', ' ').strip() theuser.name = theuser.propercased_name.lower() elif form.has_key('username'): raise BadData, (_("Please enter a user name!"), new_user) if (self.request.user.name and (self.request.user.name != theuser.name)): # they are still logged on and are trying to make a new account raise BadData, (_("Please log out before creating an account."), new_user) if user.getUserId(theuser.name, self.request): if theuser.name != self.request.user.name: raise BadData, (_("User name already exists!"), new_user) else: new_user = False if form.has_key('save') and form['save'][0] == 'Change password': # change password setting # try to get the password and pw repeat password = form.get('password', [''])[0] password2 = form.get('password2',[''])[0] # Check if password is given and matches with password repeat if password != password2: raise BadData, (_("Passwords don't match!"), new_user) if not password and new_user: raise BadData, (_("Please specify a password!"), new_user) if password: theuser.enc_password = user.generate_hash(password) self._clear_all_sessions_except_current() msg = _("Password changed!") else: # process general settings # tr to get the email theuser.email = form.get('email', [''])[0] if theuser.email: email_user_id = user.getUserIdByEmail(theuser.email, self.request) else: email_user_id = None if not theuser.email or not re.match(".+@.+\..{2,}", theuser.email): raise BadData, (_("Please provide your email address - " "without that you could not " "get your login data via email just in " "case you lose it."), new_user) elif email_user_id and email_user_id != theuser.id: raise BadData, (_("Somebody else has already registered " "with the email address \"%s\", please " "pick something else." % theuser.email), new_user) # editor size theuser.edit_rows = util.web.getIntegerInput(self.request, 'edit_rows', theuser.edit_rows, 10, 60) theuser.edit_cols = util.web.getIntegerInput(self.request, 'edit_cols', theuser.edit_cols, 30, 100) # time zone tz = form.get('tz', theuser.tz)[0] if tz not in pytz.common_timezones: tz = theuser.tz theuser.tz = tz wiki_for_userpage = form.get('wiki_for_userpage', [''])[0].lower() if (wiki_for_userpage and not wikiutil.isInFarm(wiki_for_userpage, self.request)): raise BadData, (_('"%s" is not the name of a wiki.' % ( wiki_for_userpage)), new_user) if wiki_for_userpage != theuser.wiki_for_userpage: # they have changed the wiki! time to do # something differently msg = _("<p>User preferences saved!</p>" "<p><strong>Note:</strong> It may take a bit for " "all links to your name to point to the " "new wiki.</p>") theuser.wiki_for_userpage = wiki_for_userpage # User CSS URL theuser.css_url = form.get('css_url', [''])[0] # try to get the (optional) preferred language #theuser.language = form.get('language', [''])[0] # checkbox options keys = [] for key in user_checkbox_fields: value = form.get(key, [0])[0] try: value = int(value) except ValueError: pass setattr(theuser, key, value) if new_user: # strip spaces, we don't allow them anyway theuser.propercased_name = theuser.propercased_name.strip() theuser.name = theuser.propercased_name.lower() if not theuser.name.strip(): raise BadData, (_("Please provide a user name!"), new_user) elif theuser.propercased_name.find(' ') != -1: raise BadData, (_("Invalid username: spaces are not " "allowed in user names"), new_user) elif re.search('[%s]' % re.escape(USER_NOT_ALLOWED_CHARS), theuser.propercased_name): raise BadData, (_("Invalid username: the characters " "%s are not allowed in usernames." % ( wikiutil.escape( USER_NOT_ALLOWED_CHARS))), new_user) # messes up subpages. # '/' isn't allowed, so we just disallow this and we're cool. elif theuser.name == '..' or theuser.name == '.': raise BadData, (_("Invalid username: okay, seriously, " "that's a pretty lame name. " "Pick something better!"), new_user) elif len(theuser.propercased_name) > MAX_USERNAME_LENGTH: raise BadData, (_("Invalid username: a username can be " "at most %s characters long." % ( MAX_USERNAME_LEGNTH)), new_user) elif (not theuser.email or not re.match(".+@.+\..{2,}", theuser.email)): raise BadData, (_("Please provide your email address - " "without that you could not get your " "login data via email just in case you " "lose it."), new_user) name_exists = user.getUserId(theuser.name, self.request) if name_exists: raise BadData, (_("This user name already belongs to " "somebody else."), new_user) email_exists = user.getUserIdByEmail(theuser.email, self.request) if email_exists: raise BadData, (_("This email already belongs to somebody " "else."), new_user) # try to get the password and pw repeat password = form.get('password', [''])[0] password2 = form.get('password2',[''])[0] # Check if password is given and matches with password repeat if password != password2: raise BadData, (_("Passwords don't match!"), new_user) if not password and new_user: raise BadData, (_("Please specify a password!"), new_user) if password: theuser.enc_password = user.generate_hash(password) theuser.anonymous = False # save data and send cookie theuser.save(new_user=new_user) theuser.sendCookie(self.request) self.request.user = theuser from Sycamore.formatter.text_html import Formatter formatter = Formatter(self.request) if not new_user: if not msg: msg = _("User preferences saved!") if self.from_wiki: go_back_to_wiki = farm.link_to_wiki(self.from_wiki, formatter) msg = ('%s<br/><br/>Wanna go ' 'back to %s?' % (msg, go_back_to_wiki)) else: msg = _("Account created! You are now logged in.") self.request.user.valid = 1 if (self.from_wiki and self.from_wiki.lower() != farm.getBaseWikiName()): go_back_to_wiki = farm.link_to_wiki(self.from_wiki, formatter) msg = ('%s<br/><br/>Head back over to %s and your new account ' 'should work there!' % (msg, go_back_to_wiki)) if _debug: msg = msg + util.dumpFormData(form) return msg
def render_favorites(local_favoriteList, request, formatter, macro, wiki_global): seen_list = [] line_of_text = '' for page_line in local_favoriteList: page = Page(page_line.pagename, request, wiki_name=page_line.wiki_name) page_line.comment = Comment(request, page_line.comment, page_line.action, page=page).render() bookmark = request.user.getFavBookmark(page) # in the case of uploads/deletes of images, etc we'd like to show # a useful comment page_line.time_tuple = request.user.getTime(page_line.ed_time) day = page_line.time_tuple[0:3] if not wiki_global: wiki_link = '' else: wiki_link = ('<span class="minorText">(on %s)</span>' % farm.link_to_wiki(page_line.wiki_name, formatter)) if page_line.ed_time > bookmark: # We do bold edit_icon = format_page_edit_icon(request, [page_line], page, True, bookmark, formatter) line_of_text = ('<div class="rcpagelink"><span><b>' '%s</b> %s%s<b>' % (edit_icon, page.link_to(absolute=True), wiki_link)) line_of_text = ( line_of_text + " " + '<span align="right" style="font-size: 12px;">' + 'last modified ') line_of_text = line_of_text + '%s %s' % (find_month[day[1]], day[2]) line_of_text = (line_of_text + time.strftime(" at %I:%M %p</b> by</span>", page_line.time_tuple) + '<span class="faveditor">') if page_line.comment: line_of_text = ( line_of_text + ' %s</span><span class="favcomment"> (%s)</span>' % (getEditor(page_line, request), page_line.comment)) else: line_of_text = (line_of_text + ' %s</span>' % (getEditor(page_line, request))) line_of_text = ( line_of_text + '<span style="font-size:12px;"> ' '[<a href="%s/%s?action=favorite&delete=%s&wiki_name=%s">' 'Remove</a>]</span>' % (request.getScriptname(), wikiutil.quoteWikiname( macro.formatter.page.proper_name()), wikiutil.quoteWikiname(page_line.pagename), page.wiki_name) + '</span></div>') else: edit_icon = format_page_edit_icon(request, [page_line], page, False, bookmark, formatter) # We don't do bold if page_line.ed_time: # page has been created line_of_text = ('<div class="rcpagelink"><span>' '%s %s%s <span class="favtime">' 'last modified ' % (edit_icon, page.link_to(absolute=True), wiki_link)) line_of_text = line_of_text + '%s %s' % (find_month[day[1]], day[2]) line_of_text = ( line_of_text + time.strftime(" at %I:%M %p by</span>", page_line.time_tuple) + '<span class="faveditor">') if page_line.comment: line_of_text = (line_of_text + ' %s</span><span class="favcomment"> (%s)</span>' % (getEditor(page_line, request), page_line.comment)) else: line_of_text = line_of_text + ' %s</span>' % ( getEditor(page_line, request)) line_of_text = ( line_of_text + '<span style="font-size:12px;"> ' '[<a href="%s/%s?action=favorite&delete=%s&wiki_name=%s">' 'Remove</a>]</span>' % (request.getScriptname(), wikiutil.quoteWikiname( macro.formatter.page.proper_name()), wikiutil.quoteWikiname(page_line.pagename), page.wiki_name)) line_of_text = line_of_text + '</span></div>' else: # page has NOT been created line_of_text = ('<div class="rcpagelink"><span>' '%s %s%s ' '<span align="right" class="favtime">' 'page has not been created yet</span>' % (edit_icon, page.link_to(absolute=True), wiki_link)) line_of_text = (line_of_text + '<span style="font-size:12px;"> ' '[<a href="%s/%s?action=favorite&delete=%s&wiki_name=%s">' 'Remove</a>]</span>' % (request.getScriptname(), wikiutil.quoteWikiname( macro.formatter.page.proper_name()), wikiutil.quoteWikiname(page_line.pagename), page.wiki_name)) line_of_text = line_of_text + '</span></div>' seen_list.append((page_line.pagename, line_of_text)) return seen_list
def execute(pagename, request): from Sycamore.PageEditor import PageEditor _ = request.getText actname = __name__.split('.')[-1] page = Page(pagename, request) msg = None form = request.form wikiname = None if not config.wiki_farm or not config.allow_web_based_wiki_creation: return page.send_page(msg='You are not allowed to create new wikis.') if not request.user.valid: return page.send_page(msg='You must be logged in to create new wikis.') if do_email_auth: if request.form.has_key('send_email') and request.form['send_email'][0]: if (not request.form.has_key('wikiname') or not request.form['wikiname'][0]): return page.send_page(msg='Missing wiki name.') wikiname = request.form['wikiname'][0].lower() if not farm.isValidWikiName(wikiname): msg = ('Wiki creation failed because the wiki name "%s" is ' 'invalid. You may only use the numbers 0-9, the ' 'letters a-z, and the dash "-" in a wiki name.' % wikiname) elif wikiutil.isInFarm(wikiname, request): msg = 'Wiki "%s" already exists!' % wikiname else: msg = send_validation_email(wikiname, request) return page.send_page(msg=msg) email_code = has_valid_email_link(request) if not email_code: return page.send_page(msg=("Invalid email link. " "To create a wiki you must follow the link send to your email account.")) if form.has_key('wikiname') and form['wikiname'][0]: can_create_wiki = False wikiname = form['wikiname'][0].lower() if do_email_auth: if not config.captcha_support: can_create_wiki = True elif form.has_key('captcha_id') and form.has_key('captcha_code'): this_captcha = captcha.Captcha(page, id=form['captcha_id'][0]) if this_captcha.check(form['captcha_code'][0]): can_create_wiki = True else: msg = ('Human verification was incorrect. ' 'Please try again!') else: if form.has_key('audio'): type = 'wav' else: type = 'png' captcha.send_captcha(page, wikiname, actname, email_code, type) return else: can_create_wiki = True if can_create_wiki: msg = farm.create_wiki(wikiname, request.user.name, request) if do_email_auth: _clearAuthCode(request, wikiname, email_code) if msg: # there was a problem return page.send_page(msg=msg) farm.add_wiki_to_watch(wikiname, request) formatter = Formatter(request) wiki_location = farm.link_to_wiki(wikiname, formatter) msg = ( 'Wiki "%s" created successfully! ' 'Follow this link to get to your wiki:\n' '<p>\n' '%s\n' '</p>\n' '<p>\n' 'The wiki was added to your list of watched wikis ' '(change in ' '<a href="%sUser_Settings">your account settings</a>).\n' '</p>' % (wikiname, wiki_location, farm.getBaseFarmURL(request))) return page.send_page(msg=msg)
def display_edits(request, userpage, on_pagename): def printNextPrev(request, pagename, last_edit, offset_given): """ prints the next and previous links, if they're needed. """ if last_edit == 1 and not offset_given: return html = [] if last_edit != 1: html.append( '<div class="actionBoxes" ' 'style="margin-right:10px !important; ' 'float: left !important;">' '<span>' '<a href="%s/%s?action=userinfo&offset=%s">' '←previous edits' '</a>' '</span></div>' % (request.getBaseURL(), pagename, offset_given+1)) if offset_given: html.append( '<div class="actionBoxes" style="float: left !important;">' '<span>' '<a href="%s/%s?action=userinfo&offset=%s">' 'next edits→' '</a>' '</span></div>' % (request.getBaseURL(), pagename, offset_given-1)) html.append('<div style="clear: both;"></div>') return [''.join(html)] _ = request.getText edits = TupleDataset() edits.columns = [ Column('page', label=_('Page')), Column('mtime', label=_('Date'), align='right'), Column('ip', label=_('From IP')), Column('comment', label=_('Comment')), ] if config.wiki_farm: edits.columns.insert(1, Column('wiki', label=_('Wiki'))) has_edits = False totalEdits = editedPages = 0 editedWiki = 0 this_edit = 0 offset_given = int(request.form.get('offset', [0])[0]) if not offset_given: offset = 0 else: offset = offset_given*100 - offset_given userid = getUserId(userpage, request) request.cursor.execute("""SELECT count(editTime) from allPages where userEdited=%(userid)s""", {'userid':userid}) count_result = request.cursor.fetchone() if count_result: totalEdits = count_result[0] request.cursor.execute("""SELECT count(DISTINCT name) from allPages where userEdited=%(userid)s""", {'userid':userid}) count_result = request.cursor.fetchone() if count_result: editedPages = count_result[0] request.cursor.execute("""SELECT count(DISTINCT wiki_id) from allPages where userEdited=%(userid)s""", {'userid':userid}) wiki_count_result = request.cursor.fetchone() if wiki_count_result: editedWikis = wiki_count_result[0] request.cursor.execute( """SELECT allPages.name, allPages.editTime, allPages.userIP, allPages.editType, allPages.comment, wikis.name from allPages, wikis where allPages.userEdited=%(userid)s and wikis.id=allPages.wiki_id order by editTime desc limit 100 offset %(offset)s""", {'userid':userid, 'offset':offset}) results = request.cursor.fetchall() if results: has_edits = True count = 1 original_wiki = request.config.wiki_name for edit in results: this_edit = 1 + totalEdits - count - offset pagename = edit[0] mtime = edit[1] userIp = '<a href="http://revip.info/ipinfo/%s" tooltip="%s">%s</a>' % (edit[2], edit[2], edit[2]) editType = edit[3] comment = edit[4] wiki_name = edit[5] request.switch_wiki(wiki_name) page = Page(pagename, request, wiki_name=wiki_name) version = page.date_to_version_number(mtime) if request.user.may.read(page): may_read = True show_page = page.link_to( querystr='action=diff&version2=%s&version1=%s' % (version, version-1), guess_case=True, absolute=True) formatted_mtime = request.user.getFormattedDateTime(mtime) comment = Comment(request, comment, editType).render() else: may_read = False show_page = """<em>hidden</em>""" userIp = '<em>hidden</em>' comment = '<em>hidden</em>' formatted_mtime = '<em>hidden</em>' if config.wiki_farm: if may_read: farm_link = farm.link_to_wiki(wiki_name, request.formatter) else: farm_link = '<em>hidden</em>' edits.addRow((show_page, farm_link, formatted_mtime, userIp, comment)) else: edits.addRow((show_page, formatted_mtime, userIp, comment)) count += 1 request.switch_wiki(original_wiki) if has_edits: request.write('<p>This user has made <b>%d</b> edits to <b>%d</b> ' 'pages' % (totalEdits, editedPages )) if config.wiki_farm: request.write(' on <b>%s</b> wikis' % editedWikis) request.write('.</p>') request.write('<div id="useredits">') edit_table = DataBrowserWidget(request) edit_table.setData(edits) edit_table.render(append=printNextPrev(request, on_pagename, this_edit, offset_given)) request.write('</div>') request.write('<script type="text/javascript" src="/wiki/revipbox.js"></script>') else: request.write("<p>This user hasn't edited any pages.</p>")