comparison MoinMoin/macro/MonthCalendar.py @ 3011:5913913a4dc0

MonthCalendar: avoid even bad behaved bots reading more than current year +/- 1 in the calendar, rel=nofollow for links to nonexisting day pages (port from 1.6)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 06 Jan 2008 19:18:19 +0100
parents 388204baf00f
children a739558ca3dc
comparison
equal deleted inserted replaced
3010:b4f97b0939ba 3011:5913913a4dc0
246 parmoffset2 = cparmoffset2 246 parmoffset2 = cparmoffset2
247 parmtemplate = cparmtemplate 247 parmtemplate = cparmtemplate
248 else: 248 else:
249 year, month = yearmonthplusoffset(parmyear, parmmonth, parmoffset) 249 year, month = yearmonthplusoffset(parmyear, parmmonth, parmoffset)
250 250
251 if request.isSpiderAgent and abs(currentyear - year) > 1:
252 return '' # this is a bot and it didn't follow the rules (see below)
253 if currentyear == year:
254 attrs = {}
255 else:
256 attrs = {'rel': 'nofollow' } # otherwise even well-behaved bots will index forever
257
251 # get the calendar 258 # get the calendar
252 monthcal = calendar.monthcalendar(year, month) 259 monthcal = calendar.monthcalendar(year, month)
253 260
254 # european / US differences 261 # european / US differences
255 months = ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December') 262 months = ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')
268 querystr = "calparms=%%s,%d,%d,%d,%%d,%%s" % (parmyear, parmmonth, parmoffset) 275 querystr = "calparms=%%s,%d,%d,%d,%%d,%%s" % (parmyear, parmmonth, parmoffset)
269 prevlink = p.url(request, querystr % (qpagenames, parmoffset2 - 1, qtemplate), relative=False) 276 prevlink = p.url(request, querystr % (qpagenames, parmoffset2 - 1, qtemplate), relative=False)
270 nextlink = p.url(request, querystr % (qpagenames, parmoffset2 + 1, qtemplate), relative=False) 277 nextlink = p.url(request, querystr % (qpagenames, parmoffset2 + 1, qtemplate), relative=False)
271 prevylink = p.url(request, querystr % (qpagenames, parmoffset2 - 12, qtemplate), relative=False) 278 prevylink = p.url(request, querystr % (qpagenames, parmoffset2 - 12, qtemplate), relative=False)
272 nextylink = p.url(request, querystr % (qpagenames, parmoffset2 + 12, qtemplate), relative=False) 279 nextylink = p.url(request, querystr % (qpagenames, parmoffset2 + 12, qtemplate), relative=False)
273 prevmonth = formatter.url(1, prevlink, 'cal-link') + '&lt;' + formatter.url(0) 280
274 nextmonth = formatter.url(1, nextlink, 'cal-link') + '&gt;' + formatter.url(0) 281 prevmonth = formatter.url(1, prevlink, 'cal-link', **attrs) + '&lt;' + formatter.url(0)
275 prevyear = formatter.url(1, prevylink, 'cal-link') + '&lt;&lt;' + formatter.url(0) 282 nextmonth = formatter.url(1, nextlink, 'cal-link', **attrs) + '&gt;' + formatter.url(0)
276 nextyear = formatter.url(1, nextylink, 'cal-link') + '&gt;&gt;' + formatter.url(0) 283 prevyear = formatter.url(1, prevylink, 'cal-link', **attrs) + '&lt;&lt;' + formatter.url(0)
284 nextyear = formatter.url(1, nextylink, 'cal-link', **attrs) + '&gt;&gt;' + formatter.url(0)
277 285
278 if parmpagename != [thispage]: 286 if parmpagename != [thispage]:
279 pagelinks = '' 287 pagelinks = ''
280 r, g, b = (255, 0, 0) 288 r, g, b = (255, 0, 0)
281 l = len(parmpagename[0]) 289 l = len(parmpagename[0])
287 st = 0 295 st = 0
288 while st < l: 296 while st < l:
289 ch = parmpagename[0][st:st+chstep] 297 ch = parmpagename[0][st:st+chstep]
290 r, g, b = cliprgb(r, g, b) 298 r, g, b = cliprgb(r, g, b)
291 link = Page(request, parmpagename[0]).link_to(request, ch, 299 link = Page(request, parmpagename[0]).link_to(request, ch,
300 rel='nofollow',
292 style='background-color:#%02x%02x%02x;color:#000000;text-decoration:none' % (r, g, b)) 301 style='background-color:#%02x%02x%02x;color:#000000;text-decoration:none' % (r, g, b))
293 pagelinks = pagelinks + link 302 pagelinks = pagelinks + link
294 r, g, b = (r, g+colorstep, b) 303 r, g, b = (r, g+colorstep, b)
295 st = st + chstep 304 st = st + chstep
296 r, g, b = (255-colorstep, 255, 255-colorstep) 305 r, g, b = (255-colorstep, 255, 255-colorstep)
297 for page in parmpagename[1:]: 306 for page in parmpagename[1:]:
298 link = Page(request, page).link_to(request, page, 307 link = Page(request, page).link_to(request, page,
308 rel='nofollow',
299 style='background-color:#%02x%02x%02x;color:#000000;text-decoration:none' % (r, g, b)) 309 style='background-color:#%02x%02x%02x;color:#000000;text-decoration:none' % (r, g, b))
300 pagelinks = pagelinks + '*' + link 310 pagelinks = pagelinks + '*' + link
301 showpagename = ' %s<BR>\n' % pagelinks 311 showpagename = ' %s<BR>\n' % pagelinks
302 else: 312 else:
303 showpagename = '' 313 showpagename = ''
357 titletext.append(title) 367 titletext.append(title)
358 tipname = link 368 tipname = link
359 tiptitle = link 369 tiptitle = link
360 tiptext = '<br>'.join(titletext) 370 tiptext = '<br>'.join(titletext)
361 maketip_js.append("maketip('%s','%s','%s');" % (tipname, tiptitle, tiptext)) 371 maketip_js.append("maketip('%s','%s','%s');" % (tipname, tiptitle, tiptext))
362 onmouse = {'onMouseOver': "tip('%s')" % tipname, 372 attrs = {'onMouseOver': "tip('%s')" % tipname,
363 'onMouseOut': "untip()"} 373 'onMouseOut': "untip()"}
364 else: 374 else:
365 csslink = "cal-emptyday" 375 csslink = "cal-emptyday"
366 if parmtemplate: 376 if parmtemplate:
367 query = {'action': 'edit', 'template': parmtemplate} 377 query = {'action': 'edit', 'template': parmtemplate}
368 else: 378 else:
369 query = {} 379 query = {}
370 r, g, b, u = (255, 255, 255, 0) 380 r, g, b, u = (255, 255, 255, 0)
371 if wkday in wkend: 381 if wkday in wkend:
372 csslink = "cal-weekend" 382 csslink = "cal-weekend"
373 onmouse = {} 383 attrs = {'rel': 'nofollow'}
374 for otherpage in parmpagename[1:]: 384 for otherpage in parmpagename[1:]:
375 otherlink = "%s/%4d-%02d-%02d" % (otherpage, year, month, day) 385 otherlink = "%s/%4d-%02d-%02d" % (otherpage, year, month, day)
376 otherdaypage = Page(request, otherlink) 386 otherdaypage = Page(request, otherlink)
377 if otherdaypage.exists(): 387 if otherdaypage.exists():
378 csslink = "cal-usedday" 388 csslink = "cal-usedday"
380 r, g, b = (r-colorstep, g, b-colorstep) 390 r, g, b = (r-colorstep, g, b-colorstep)
381 else: 391 else:
382 r, g, b = (r, g+colorstep, b) 392 r, g, b = (r, g+colorstep, b)
383 r, g, b = cliprgb(r, g, b) 393 r, g, b = cliprgb(r, g, b)
384 style = 'background-color:#%02x%02x%02x' % (r, g, b) 394 style = 'background-color:#%02x%02x%02x' % (r, g, b)
385 fmtlink = formatter.url(1, daypage.url(request, query, relative=False), csslink, **onmouse) + str(day) + formatter.url(0) 395 fmtlink = formatter.url(1, daypage.url(request, query, relative=False), csslink, **attrs) + str(day) + formatter.url(0)
386 if day == currentday and month == currentmonth and year == currentyear: 396 if day == currentday and month == currentmonth and year == currentyear:
387 cssday = "cal-today" 397 cssday = "cal-today"
388 fmtlink = "<b>%s</b>" % fmtlink # for browser with CSS probs 398 fmtlink = "<b>%s</b>" % fmtlink # for browser with CSS probs
389 else: 399 else:
390 cssday = "cal-nottoday" 400 cssday = "cal-nottoday"