def mainloop(self): # we don't expect non-option arguments self.init_request() request = self.request # Checks for a template page and sets homepage_default_text if self.options.template_page and Page( self.request, self.options.template_page).exists(): homepage_default_text = Page( self.request, self.options.template_page).get_raw_body() # replace is needed because substitution is done for request.user # see option --user homepage_default_text = homepage_default_text.replace( '@ME@', "%(username)s") homepage_default_text = homepage_default_text.replace( '@EMAIL@', "<<MailTo(%(obfuscated_mail)s)>>") else: homepage_default_text = '''#acl %(username)s:read,write,delete,revert Default == %(username)s == Email: <<MailTo(%(obfuscated_mail)s)>> ## You can even more obfuscate your email address by adding more uppercase letters followed by a leading and trailing blank. ---- CategoryHomepage ''' # Check for user if self.options.homepage_creator: uid = user.getUserId(request, self.options.homepage_creator) request.user = user.User(request, uid) # Check for Group definition members = [] if self.options.user_homepage: members = [ self.options.user_homepage, ] elif self.options.name_of_group_page: members = request.groups.get(self.options.name_of_group_page, []) elif self.options.all_users: uids = user.getUserList(request) members = [user.User(request, uid).name for uid in uids] if not members: print "No user selected!" return # loop through members for creating homepages for name in members: uid = user.getUserId(request, name) account = user.User(request, uid) homepage_text = homepage_default_text % { "username": account.name, "obfuscated_mail": encodeSpamSafeEmail(account.email) } self.write_homepage(account, homepage_text)
def mainloop(self): # we don't expect non-option arguments self.init_request() request = self.request # Checks for a template page and sets homepage_default_text if self.options.template_page and Page(self.request, self.options.template_page).exists(): homepage_default_text = Page(self.request, self.options.template_page).get_raw_body() # replace is needed because substitution is done for request.user # see option --user homepage_default_text = homepage_default_text.replace('@ME@', "%(username)s") homepage_default_text = homepage_default_text.replace('@EMAIL@', "<<MailTo(%(obfuscated_mail)s)>>") else: homepage_default_text = '''#acl %(username)s:read,write,delete,revert Default #format wiki == %(username)s == Email: <<MailTo(%(obfuscated_mail)s)>> ## You can even more obfuscate your email address by adding more uppercase letters followed by a leading and trailing blank. ---- CategoryHomepage ''' # Check for user if self.options.homepage_creator: uid = user.getUserId(request, self.options.homepage_creator) request.user = user.User(request, uid) # Check for Group definition members = [] if self.options.user_homepage: members = [self.options.user_homepage, ] elif self.options.name_of_group_page: members = request.groups.get(self.options.name_of_group_page, []) elif self.options.all_users: uids = user.getUserList(request) members = [user.User(request, uid).name for uid in uids] if not members: print "No user selected!" return # loop through members for creating homepages for name in members: uid = user.getUserId(request, name) account = user.User(request, uid) homepage_text = homepage_default_text % { "username": account.name, "obfuscated_mail": encodeSpamSafeEmail(account.email) } self.write_homepage(account, homepage_text)
def execute(macro, text): request = macro.request formatter = macro.formatter _ = request.getText # return immediately if getting links for the current page if request.mode_getpagelinks: return '' currentyear, currentmonth, currentday, h, m, s, wd, yd, ds = request.user.getTime( time.time()) thispage = formatter.page.page_name # does the url have calendar params (= somebody has clicked on prev/next links in calendar) ? if 'calparms' in macro.request.args: has_calparms = 1 # yes! text2 = macro.request.args['calparms'] cparmpagename, cparmyear, cparmmonth, cparmoffset, cparmoffset2, cparmheight6, cparmanniversary, cparmtemplate = \ parseargs(request, text2, thispage, currentyear, currentmonth, 0, 0, False, False, u'') # Note: cparmheight6 and cparmanniversary are not used, they are just there # to have a consistent parameter string in calparms and macro args else: has_calparms = 0 if text is None: # macro call without parameters text = u'' # parse and check arguments parmpagename, parmyear, parmmonth, parmoffset, parmoffset2, parmheight6, anniversary, parmtemplate = \ parseargs(request, text, thispage, currentyear, currentmonth, 0, 0, False, False, u'') # does url have calendar params and is THIS the right calendar to modify (we can have multiple # calendars on the same page)? #if has_calparms and (cparmpagename,cparmyear,cparmmonth,cparmoffset) == (parmpagename,parmyear,parmmonth,parmoffset): # move all calendars when using the navigation: if has_calparms and cparmpagename == parmpagename: year, month = yearmonthplusoffset(parmyear, parmmonth, parmoffset + cparmoffset2) parmoffset2 = cparmoffset2 parmtemplate = cparmtemplate else: year, month = yearmonthplusoffset(parmyear, parmmonth, parmoffset) if request.isSpiderAgent and abs(currentyear - year) > 1: return '' # this is a bot and it didn't follow the rules (see below) if currentyear == year: attrs = {} else: attrs = { 'rel': 'nofollow' } # otherwise even well-behaved bots will index forever # get the calendar monthcal = calendar.monthcalendar(year, month) # european / US differences months = ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December') # Set things up for Monday or Sunday as the first day of the week if calendar.firstweekday() == calendar.MONDAY: wkend = (5, 6) wkdays = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun') if calendar.firstweekday() == calendar.SUNDAY: wkend = (0, 6) wkdays = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat') colorstep = 85 p = Page(request, thispage) qpagenames = '*'.join( [wikiutil.quoteWikinameURL(pn) for pn in parmpagename]) qtemplate = wikiutil.quoteWikinameURL(parmtemplate) querystr = "calparms=%%s,%d,%d,%d,%%d,,,%%s" % (parmyear, parmmonth, parmoffset) prevlink = p.url(request, querystr % (qpagenames, parmoffset2 - 1, qtemplate)) nextlink = p.url(request, querystr % (qpagenames, parmoffset2 + 1, qtemplate)) prevylink = p.url(request, querystr % (qpagenames, parmoffset2 - 12, qtemplate)) nextylink = p.url(request, querystr % (qpagenames, parmoffset2 + 12, qtemplate)) prevmonth = formatter.url(1, prevlink, 'cal-link', ** attrs) + '<' + formatter.url(0) nextmonth = formatter.url(1, nextlink, 'cal-link', ** attrs) + '>' + formatter.url(0) prevyear = formatter.url(1, prevylink, 'cal-link', ** attrs) + '<<' + formatter.url(0) nextyear = formatter.url(1, nextylink, 'cal-link', ** attrs) + '>>' + formatter.url(0) if parmpagename != [thispage]: pagelinks = '' r, g, b = (255, 0, 0) l = len(parmpagename[0]) steps = len(parmpagename) maxsteps = (255 / colorstep) if steps > maxsteps: steps = maxsteps chstep = int(l / steps) st = 0 while st < l: ch = parmpagename[0][st:st + chstep] r, g, b = cliprgb(r, g, b) link = Page(request, parmpagename[0]).link_to( request, ch, rel='nofollow', style= 'background-color:#%02x%02x%02x;color:#000000;text-decoration:none' % (r, g, b)) pagelinks = pagelinks + link r, g, b = (r, g + colorstep, b) st = st + chstep r, g, b = (255 - colorstep, 255, 255 - colorstep) for page in parmpagename[1:]: link = Page(request, page).link_to( request, page, rel='nofollow', style= 'background-color:#%02x%02x%02x;color:#000000;text-decoration:none' % (r, g, b)) pagelinks = pagelinks + '*' + link showpagename = ' %s<BR>\n' % pagelinks else: showpagename = '' if calendar.firstweekday() == calendar.SUNDAY: resth1 = ' <th colspan="7" class="cal-header">\n' \ '%s' \ ' %s %s <b> %s %s</b> %s\n %s\n' \ ' </th>\n' % (showpagename, prevyear, prevmonth, months[month-1], str(year), nextmonth, nextyear) if calendar.firstweekday() == calendar.MONDAY: resth1 = ' <th colspan="7" class="cal-header">\n' \ '%s' \ ' %s %s <b> %s / %s</b> %s\n %s\n' \ ' </th>\n' % (showpagename, prevyear, prevmonth, str(year), month, nextmonth, nextyear) restr1 = ' <tr>\n%s </tr>\n' % resth1 r7 = range(7) restd2 = [] for wkday in r7: wday = _(wkdays[wkday]) if wkday in wkend: cssday = "cal-weekend" else: cssday = "cal-workday" restd2.append(' <td class="%s">%s</td>\n' % (cssday, wday)) restr2 = ' <tr>\n%s </tr>\n' % "".join(restd2) if parmheight6: while len(monthcal) < 6: monthcal = monthcal + [[0, 0, 0, 0, 0, 0, 0]] maketip_js = [] restrn = [] for week in monthcal: restdn = [] for wkday in r7: day = week[wkday] if not day: restdn.append(' <td class="cal-invalidday"> </td>\n') else: page = parmpagename[0] if anniversary: link = "%s/%02d-%02d" % (page, month, day) else: link = "%s/%4d-%02d-%02d" % (page, year, month, day) daypage = Page(request, link) if daypage.exists() and request.user.may.read(link): csslink = "cal-usedday" query = {} r, g, b, u = (255, 0, 0, 1) daycontent = daypage.get_raw_body() header1_re = re.compile(r'^\s*=\s(.*)\s=$', re.MULTILINE) # re.UNICODE titletext = [] for match in header1_re.finditer(daycontent): if match: title = match.group(1) title = wikiutil.escape(title).replace("'", "\\'") titletext.append(title) tipname_unescaped = link.replace("'", "\\'") link = wikiutil.escape(link).replace("'", "\\'") tipname = link tiptitle = link tiptext = '<br>'.join(titletext) maketip_js.append("maketip('%s','%s','%s');" % (tipname, tiptitle, tiptext)) attrs = { 'onMouseOver': "tip('%s')" % tipname_unescaped, 'onMouseOut': "untip()" } else: csslink = "cal-emptyday" if parmtemplate: query = {'action': 'edit', 'template': parmtemplate} else: query = {} r, g, b, u = (255, 255, 255, 0) if wkday in wkend: csslink = "cal-weekend" attrs = {'rel': 'nofollow'} for otherpage in parmpagename[1:]: otherlink = "%s/%4d-%02d-%02d" % (otherpage, year, month, day) otherdaypage = Page(request, otherlink) if otherdaypage.exists(): csslink = "cal-usedday" if u == 0: r, g, b = (r - colorstep, g, b - colorstep) else: r, g, b = (r, g + colorstep, b) r, g, b = cliprgb(r, g, b) style = 'background-color:#%02x%02x%02x' % (r, g, b) fmtlink = formatter.url(1, daypage.url(request, query), csslink, ** attrs) + str(day) + formatter.url(0) if day == currentday and month == currentmonth and year == currentyear: cssday = "cal-today" fmtlink = "<b>%s</b>" % fmtlink # for browser with CSS probs else: cssday = "cal-nottoday" restdn.append(' <td style="%s" class="%s">%s</td>\n' % (style, cssday, fmtlink)) restrn.append(' <tr>\n%s </tr>\n' % "".join(restdn)) restable = '<table border="2" cellspacing="2" cellpadding="2">\n<col width="14%%" span="7">%s%s%s</table>\n' restable = restable % (restr1, restr2, "".join(restrn)) if maketip_js: tip_js = '''<script language="JavaScript" type="text/javascript"> <!-- %s // --> </script> ''' % '\n'.join(maketip_js) else: tip_js = '' result = """\ <script type="text/javascript" src="%s/common/js/infobox.js"></script> <div id="%s" style="position:absolute; visibility:hidden; z-index:20; top:-999em; left:0px;"></div> %s%s """ % (request.cfg.url_prefix_static, formatter.make_id_unique('infodiv'), tip_js, restable) return formatter.rawHTML(result)
def execute(macro, text): request = macro.request formatter = macro.formatter _ = request.getText # return immediately if getting links for the current page if request.mode_getpagelinks: return '' currentyear, currentmonth, currentday, h, m, s, wd, yd, ds = request.user.getTime(time.time()) thispage = formatter.page.page_name # does the url have calendar params (= somebody has clicked on prev/next links in calendar) ? if 'calparms' in macro.request.args: has_calparms = 1 # yes! text2 = macro.request.args['calparms'] cparmpagename, cparmyear, cparmmonth, cparmoffset, cparmoffset2, cparmheight6, cparmanniversary, cparmtemplate = \ parseargs(request, text2, thispage, currentyear, currentmonth, 0, 0, False, False, u'') # Note: cparmheight6 and cparmanniversary are not used, they are just there # to have a consistent parameter string in calparms and macro args else: has_calparms = 0 if text is None: # macro call without parameters text = u'' # parse and check arguments parmpagename, parmyear, parmmonth, parmoffset, parmoffset2, parmheight6, anniversary, parmtemplate = \ parseargs(request, text, thispage, currentyear, currentmonth, 0, 0, False, False, u'') # does url have calendar params and is THIS the right calendar to modify (we can have multiple # calendars on the same page)? #if has_calparms and (cparmpagename,cparmyear,cparmmonth,cparmoffset) == (parmpagename,parmyear,parmmonth,parmoffset): # move all calendars when using the navigation: if has_calparms and cparmpagename == parmpagename: year, month = yearmonthplusoffset(parmyear, parmmonth, parmoffset + cparmoffset2) parmoffset2 = cparmoffset2 parmtemplate = cparmtemplate else: year, month = yearmonthplusoffset(parmyear, parmmonth, parmoffset) if request.isSpiderAgent and abs(currentyear - year) > 1: return '' # this is a bot and it didn't follow the rules (see below) if currentyear == year: attrs = {} else: attrs = {'rel': 'nofollow' } # otherwise even well-behaved bots will index forever # get the calendar monthcal = calendar.monthcalendar(year, month) # european / US differences months = ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December') # Set things up for Monday or Sunday as the first day of the week if calendar.firstweekday() == calendar.MONDAY: wkend = (5, 6) wkdays = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun') if calendar.firstweekday() == calendar.SUNDAY: wkend = (0, 6) wkdays = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat') colorstep = 85 p = Page(request, thispage) qpagenames = '*'.join([wikiutil.quoteWikinameURL(pn) for pn in parmpagename]) qtemplate = wikiutil.quoteWikinameURL(parmtemplate) querystr = "calparms=%%s,%d,%d,%d,%%d,,,%%s" % (parmyear, parmmonth, parmoffset) prevlink = p.url(request, querystr % (qpagenames, parmoffset2 - 1, qtemplate)) nextlink = p.url(request, querystr % (qpagenames, parmoffset2 + 1, qtemplate)) prevylink = p.url(request, querystr % (qpagenames, parmoffset2 - 12, qtemplate)) nextylink = p.url(request, querystr % (qpagenames, parmoffset2 + 12, qtemplate)) prevmonth = formatter.url(1, prevlink, 'cal-link', **attrs) + '<' + formatter.url(0) nextmonth = formatter.url(1, nextlink, 'cal-link', **attrs) + '>' + formatter.url(0) prevyear = formatter.url(1, prevylink, 'cal-link', **attrs) + '<<' + formatter.url(0) nextyear = formatter.url(1, nextylink, 'cal-link', **attrs) + '>>' + formatter.url(0) if parmpagename != [thispage]: pagelinks = '' r, g, b = (255, 0, 0) l = len(parmpagename[0]) steps = len(parmpagename) maxsteps = (255 / colorstep) if steps > maxsteps: steps = maxsteps chstep = int(l / steps) st = 0 while st < l: ch = parmpagename[0][st:st+chstep] r, g, b = cliprgb(r, g, b) link = Page(request, parmpagename[0]).link_to(request, ch, rel='nofollow', style='background-color:#%02x%02x%02x;color:#000000;text-decoration:none' % (r, g, b)) pagelinks = pagelinks + link r, g, b = (r, g+colorstep, b) st = st + chstep r, g, b = (255-colorstep, 255, 255-colorstep) for page in parmpagename[1:]: link = Page(request, page).link_to(request, page, rel='nofollow', style='background-color:#%02x%02x%02x;color:#000000;text-decoration:none' % (r, g, b)) pagelinks = pagelinks + '*' + link showpagename = ' %s<BR>\n' % pagelinks else: showpagename = '' if calendar.firstweekday() == calendar.SUNDAY: resth1 = ' <th colspan="7" class="cal-header">\n' \ '%s' \ ' %s %s <b> %s %s</b> %s\n %s\n' \ ' </th>\n' % (showpagename, prevyear, prevmonth, months[month-1], str(year), nextmonth, nextyear) if calendar.firstweekday() == calendar.MONDAY: resth1 = ' <th colspan="7" class="cal-header">\n' \ '%s' \ ' %s %s <b> %s / %s</b> %s\n %s\n' \ ' </th>\n' % (showpagename, prevyear, prevmonth, str(year), month, nextmonth, nextyear) restr1 = ' <tr>\n%s </tr>\n' % resth1 r7 = range(7) restd2 = [] for wkday in r7: wday = _(wkdays[wkday]) if wkday in wkend: cssday = "cal-weekend" else: cssday = "cal-workday" restd2.append(' <td class="%s">%s</td>\n' % (cssday, wday)) restr2 = ' <tr>\n%s </tr>\n' % "".join(restd2) if parmheight6: while len(monthcal) < 6: monthcal = monthcal + [[0, 0, 0, 0, 0, 0, 0]] maketip_js = [] restrn = [] for week in monthcal: restdn = [] for wkday in r7: day = week[wkday] if not day: restdn.append(' <td class="cal-invalidday"> </td>\n') else: page = parmpagename[0] if anniversary: link = "%s/%02d-%02d" % (page, month, day) else: link = "%s/%4d-%02d-%02d" % (page, year, month, day) daypage = Page(request, link) if daypage.exists() and request.user.may.read(link): csslink = "cal-usedday" query = {} r, g, b, u = (255, 0, 0, 1) daycontent = daypage.get_raw_body() header1_re = re.compile(r'^\s*=\s(.*)\s=$', re.MULTILINE) # re.UNICODE titletext = [] for match in header1_re.finditer(daycontent): if match: title = match.group(1) title = wikiutil.escape(title).replace("'", "\\'") titletext.append(title) tipname_unescaped = link.replace("'", "\\'") link = wikiutil.escape(link).replace("'", "\\'") tipname = link tiptitle = link tiptext = '<br>'.join(titletext) maketip_js.append("maketip('%s','%s','%s');" % (tipname, tiptitle, tiptext)) attrs = {'onMouseOver': "tip('%s')" % tipname_unescaped, 'onMouseOut': "untip()"} else: csslink = "cal-emptyday" if parmtemplate: query = {'action': 'edit', 'template': parmtemplate} else: query = {} r, g, b, u = (255, 255, 255, 0) if wkday in wkend: csslink = "cal-weekend" attrs = {'rel': 'nofollow'} for otherpage in parmpagename[1:]: otherlink = "%s/%4d-%02d-%02d" % (otherpage, year, month, day) otherdaypage = Page(request, otherlink) if otherdaypage.exists(): csslink = "cal-usedday" if u == 0: r, g, b = (r-colorstep, g, b-colorstep) else: r, g, b = (r, g+colorstep, b) r, g, b = cliprgb(r, g, b) style = 'background-color:#%02x%02x%02x' % (r, g, b) fmtlink = formatter.url(1, daypage.url(request, query), csslink, **attrs) + str(day) + formatter.url(0) if day == currentday and month == currentmonth and year == currentyear: cssday = "cal-today" fmtlink = "<b>%s</b>" % fmtlink # for browser with CSS probs else: cssday = "cal-nottoday" restdn.append(' <td style="%s" class="%s">%s</td>\n' % (style, cssday, fmtlink)) restrn.append(' <tr>\n%s </tr>\n' % "".join(restdn)) restable = '<table border="2" cellspacing="2" cellpadding="2">\n<col width="14%%" span="7">%s%s%s</table>\n' restable = restable % (restr1, restr2, "".join(restrn)) if maketip_js: tip_js = '''<script language="JavaScript" type="text/javascript"> <!-- %s // --> </script> ''' % '\n'.join(maketip_js) else: tip_js = '' result = """\ <script type="text/javascript" src="%s/common/js/infobox.js"></script> <div id="%s" style="position:absolute; visibility:hidden; z-index:20; top:-999em; left:0px;"></div> %s%s """ % (request.cfg.url_prefix_static, formatter.make_id_unique('infodiv'), tip_js, restable) return formatter.rawHTML(result)