Back to index

moin  1.9.0~rc2
Functions | Variables
MoinMoin.macro.RecentChanges Namespace Reference

Functions

def format_comment
def format_page_edits
def cmp_lines
def print_abandoned
def macro_RecentChanges

Variables

list _DAYS_SELECTION = [1, 2, 3, 7, 14, 30, 60, 90]
int _MAX_DAYS = 7
int _MAX_PAGENAME_LENGTH = 15
int _MAX_COMMENT_LENGTH = 20
list Dependencies = ["time"]
 RecentChanges Macro.

Function Documentation

def MoinMoin.macro.RecentChanges.cmp_lines (   first,
  second 
)

Definition at line 141 of file RecentChanges.py.

00141 
00142 def cmp_lines(first, second):
00143     return cmp(first[0], second[0])

def MoinMoin.macro.RecentChanges.format_comment (   request,
  line 
)

Definition at line 27 of file RecentChanges.py.

00027 
00028 def format_comment(request, line):
00029     comment = line.comment
00030     action = line.action
00031     _ = request.getText
00032     if action.startswith('ATT'):
00033         filename = wikiutil.url_unquote(line.extra)
00034         if action == 'ATTNEW':
00035             comment = _("Upload of attachment '%(filename)s'.") % {
00036                 'filename': filename}
00037         elif action == 'ATTDEL':
00038             comment = _("Attachment '%(filename)s' deleted.") % {
00039                 'filename': filename}
00040         elif action == 'ATTDRW':
00041             comment = _("Drawing '%(filename)s' saved.") % {
00042                 'filename': filename}
00043     elif '/REVERT' in action:
00044         rev = int(line.extra)
00045         comment = (_("Revert to revision %(rev)d.") % {'rev': rev}) + " " + comment
00046     elif '/RENAME' in action:
00047         comment = (_("Renamed from '%(oldpagename)s'.") % {'oldpagename': line.extra}) + " " + comment
00048 
00049     return wikiutil.make_breakable(comment, _MAX_COMMENT_LENGTH)

Here is the caller graph for this function:

def MoinMoin.macro.RecentChanges.format_page_edits (   macro,
  lines,
  bookmark_usecs 
)

Definition at line 50 of file RecentChanges.py.

00050 
00051 def format_page_edits(macro, lines, bookmark_usecs):
00052     request = macro.request
00053     _ = request.getText
00054     d = {} # dict for passing stuff to theme
00055     line = lines[0]
00056     pagename = line.pagename
00057     rev = int(line.rev)
00058     tnow = time.time()
00059     is_new = lines[-1].action == 'SAVENEW'
00060     is_renamed = lines[-1].action == 'SAVE/RENAME'
00061     # check whether this page is newer than the user's bookmark
00062     hilite = line.ed_time_usecs > (bookmark_usecs or line.ed_time_usecs)
00063     page = Page(request, pagename)
00064 
00065     html_link = ''
00066     if not page.exists():
00067         img = request.theme.make_icon('deleted')
00068         revbefore = rev - 1
00069         if revbefore and page.exists(rev=revbefore, domain='standard'):
00070             # indicate page was deleted and show diff to last existing revision of it
00071             html_link = page.link_to_raw(request, img, querystr={'action': 'diff'}, rel='nofollow')
00072         else:
00073             # just indicate page was deleted
00074             html_link = img
00075     elif page.isConflict():
00076         img = request.theme.make_icon('conflict')
00077         html_link = page.link_to_raw(request, img, querystr={'action': 'edit'}, rel='nofollow')
00078     elif hilite:
00079         # show special icons if change was after the user's bookmark
00080         if is_new:
00081             img = 'new'
00082         elif is_renamed:
00083             img = 'renamed'
00084         else:
00085             img = 'updated'
00086         img = request.theme.make_icon(img)
00087         html_link = page.link_to_raw(request, img, querystr={'action': 'diff', 'date': '%d' % bookmark_usecs}, rel='nofollow')
00088     else:
00089         # show "DIFF" icon else
00090         img = request.theme.make_icon('diffrc')
00091         html_link = page.link_to_raw(request, img, querystr={'action': 'diff'}, rel='nofollow')
00092 
00093     # print name of page, with a link to it
00094     force_split = len(page.page_name) > _MAX_PAGENAME_LENGTH
00095 
00096     d['icon_html'] = html_link
00097     d['pagelink_html'] = page.link_to(request, text=page.split_title(force=force_split))
00098 
00099     # print time of change
00100     d['time_html'] = None
00101     if request.cfg.changed_time_fmt:
00102         tdiff = long(tnow - wikiutil.version2timestamp(long(line.ed_time_usecs))) / 60 # has to be long for py 2.2.x
00103         if tdiff < 100:
00104             d['time_html'] = _("%(mins)dm ago") % {
00105                 'mins': tdiff}
00106         else:
00107             d['time_html'] = time.strftime(request.cfg.changed_time_fmt, line.time_tuple)
00108 
00109     # print editor name or IP
00110     d['editors'] = None
00111     if request.cfg.show_names:
00112         if len(lines) > 1:
00113             counters = {}
00114             for idx in range(len(lines)):
00115                 name = lines[idx].getEditor(request)
00116                 if not name in counters:
00117                     counters[name] = []
00118                 counters[name].append(idx+1)
00119             poslist = [(v, k) for k, v in counters.items()]
00120             poslist.sort()
00121             d['editors'] = []
00122             for positions, name in poslist:
00123                 d['editors'].append("%s&nbsp;[%s]" % (
00124                     name, util.rangelist(positions)))
00125         else:
00126             d['editors'] = [line.getEditor(request)]
00127 
00128     comments = []
00129     for idx in range(len(lines)):
00130         comment = format_comment(request, lines[idx])
00131         if comment:
00132             comments.append((idx+1, wikiutil.escape(comment)))
00133 
00134     d['changecount'] = len(lines)
00135     d['comments'] = comments
00136 
00137     img = request.theme.make_icon('info')
00138     d['info_html'] = page.link_to_raw(request, img, querystr={'action': 'info'}, rel='nofollow')
00139 
00140     return request.theme.recentchanges_entry(d)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.macro.RecentChanges.macro_RecentChanges (   macro,
  abandoned = False 
)

Definition at line 232 of file RecentChanges.py.

00232 
00233 def macro_RecentChanges(macro, abandoned=False):
00234     # handle abandoned keyword
00235     if abandoned:
00236         return print_abandoned(macro)
00237 
00238     request = macro.request
00239     _ = request.getText
00240     output = []
00241     user = request.user
00242     page = macro.formatter.page
00243     pagename = page.page_name
00244 
00245     d = {}
00246     d['page'] = page
00247     d['q_page_name'] = wikiutil.quoteWikinameURL(pagename)
00248 
00249     log = editlog.EditLog(request)
00250 
00251     tnow = time.time()
00252     msg = ""
00253 
00254     # get bookmark from valid user
00255     bookmark_usecs = request.user.getBookmark() or 0
00256 
00257     # add bookmark link if valid user
00258     d['rc_curr_bookmark'] = None
00259     d['rc_update_bookmark'] = None
00260     if request.user.valid:
00261         d['rc_curr_bookmark'] = _('(no bookmark set)')
00262         if bookmark_usecs:
00263             currentBookmark = wikiutil.version2timestamp(bookmark_usecs)
00264             currentBookmark = user.getFormattedDateTime(currentBookmark)
00265             currentBookmark = _('(currently set to %s)') % currentBookmark
00266             deleteBookmark = page.link_to(request, _("Delete bookmark"), querystr={'action': 'bookmark', 'time': 'del'}, rel='nofollow')
00267             d['rc_curr_bookmark'] = currentBookmark + ' ' + deleteBookmark
00268 
00269         version = wikiutil.timestamp2version(tnow)
00270         d['rc_update_bookmark'] = page.link_to(request, _("Set bookmark"), querystr={'action': 'bookmark', 'time': '%d' % version}, rel='nofollow')
00271 
00272     # set max size in days
00273     max_days = min(int(request.values.get('max_days', 0)), _DAYS_SELECTION[-1])
00274     # default to _MAX_DAYS for useres without bookmark
00275     if not max_days and not bookmark_usecs:
00276         max_days = _MAX_DAYS
00277     d['rc_max_days'] = max_days
00278 
00279     # give known user the option to extend the normal display
00280     if request.user.valid:
00281         d['rc_days'] = _DAYS_SELECTION
00282     else:
00283         d['rc_days'] = []
00284 
00285     output.append(request.theme.recentchanges_header(d))
00286 
00287     pages = {}
00288     ignore_pages = {}
00289 
00290     today = request.user.getTime(tnow)[0:3]
00291     this_day = today
00292     day_count = 0
00293 
00294     for line in log.reverse():
00295 
00296         if not request.user.may.read(line.pagename):
00297             continue
00298 
00299         line.time_tuple = request.user.getTime(wikiutil.version2timestamp(line.ed_time_usecs))
00300         day = line.time_tuple[0:3]
00301         hilite = line.ed_time_usecs > (bookmark_usecs or line.ed_time_usecs)
00302 
00303         if ((this_day != day or (not hilite and not max_days))) and len(pages) > 0:
00304             # new day or bookmark reached: print out stuff
00305             this_day = day
00306             for p in pages:
00307                 ignore_pages[p] = None
00308             pages = pages.values()
00309             pages.sort(cmp_lines)
00310             pages.reverse()
00311 
00312             if request.user.valid:
00313                 bmtime = pages[0][0].ed_time_usecs
00314                 d['bookmark_link_html'] = page.link_to(request, _("Set bookmark"), querystr={'action': 'bookmark', 'time': '%d' % bmtime}, rel='nofollow')
00315             else:
00316                 d['bookmark_link_html'] = None
00317             d['date'] = request.user.getFormattedDate(wikiutil.version2timestamp(pages[0][0].ed_time_usecs))
00318             output.append(request.theme.recentchanges_daybreak(d))
00319 
00320             for p in pages:
00321                 output.append(format_page_edits(macro, p, bookmark_usecs))
00322             pages = {}
00323             day_count += 1
00324             if max_days and (day_count >= max_days):
00325                 break
00326 
00327         elif this_day != day:
00328             # new day but no changes
00329             this_day = day
00330 
00331         if line.pagename in ignore_pages:
00332             continue
00333 
00334         # end listing by default if user has a bookmark and we reached it
00335         if not max_days and not hilite:
00336             msg = _('[Bookmark reached]')
00337             break
00338 
00339         if line.pagename in pages:
00340             pages[line.pagename].append(line)
00341         else:
00342             pages[line.pagename] = [line]
00343     else:
00344         if len(pages) > 0:
00345             # end of loop reached: print out stuff
00346             # XXX duplicated code from above
00347             # but above does not trigger if we have the first day in wiki history
00348             for p in pages:
00349                 ignore_pages[p] = None
00350             pages = pages.values()
00351             pages.sort(cmp_lines)
00352             pages.reverse()
00353 
00354             if request.user.valid:
00355                 bmtime = pages[0][0].ed_time_usecs
00356                 d['bookmark_link_html'] = page.link_to(request, _("Set bookmark"), querystr={'action': 'bookmark', 'time': '%d' % bmtime}, rel='nofollow')
00357             else:
00358                 d['bookmark_link_html'] = None
00359             d['date'] = request.user.getFormattedDate(wikiutil.version2timestamp(pages[0][0].ed_time_usecs))
00360             output.append(request.theme.recentchanges_daybreak(d))
00361 
00362             for p in pages:
00363                 output.append(format_page_edits(macro, p, bookmark_usecs))
00364 
00365 
00366     d['rc_msg'] = msg
00367     output.append(request.theme.recentchanges_footer(d))
00368 
00369     return ''.join(output)
00370 
00371 

Here is the call graph for this function:

Definition at line 144 of file RecentChanges.py.

00144 
00145 def print_abandoned(macro):
00146     request = macro.request
00147     _ = request.getText
00148     output = []
00149     d = {}
00150     page = macro.formatter.page
00151     pagename = page.page_name
00152     d['page'] = page
00153     d['q_page_name'] = wikiutil.quoteWikinameURL(pagename)
00154     msg = None
00155 
00156     pages = request.rootpage.getPageList()
00157     last_edits = []
00158     for name in pages:
00159         log = Page(request, name).editlog_entry()
00160         if log:
00161             last_edits.append(log)
00162         #   we don't want all Systempages at the beginning of the abandoned list
00163         #    line = editlog.EditLogLine({})
00164         #    line.pagename = page
00165         #    line.ed_time = 0
00166         #    line.comment = 'not edited'
00167         #    line.action = ''
00168         #    line.userid = ''
00169         #    line.hostname = ''
00170         #    line.addr = ''
00171         #    last_edits.append(line)
00172     del pages
00173     last_edits.sort()
00174 
00175     # set max size in days
00176     max_days = min(int(request.values.get('max_days', 0)), _DAYS_SELECTION[-1])
00177     # default to _MAX_DAYS for users without bookmark
00178     if not max_days:
00179         max_days = _MAX_DAYS
00180     d['rc_max_days'] = max_days
00181 
00182     # give known user the option to extend the normal display
00183     if request.user.valid:
00184         d['rc_days'] = _DAYS_SELECTION
00185     else:
00186         d['rc_days'] = None
00187 
00188     d['rc_update_bookmark'] = None
00189     output.append(request.theme.recentchanges_header(d))
00190 
00191     length = len(last_edits)
00192 
00193     index = 0
00194     last_index = 0
00195     day_count = 0
00196 
00197     if length > 0:
00198         line = last_edits[index]
00199         line.time_tuple = request.user.getTime(wikiutil.version2timestamp(line.ed_time_usecs))
00200         this_day = line.time_tuple[0:3]
00201         day = this_day
00202 
00203     while 1:
00204 
00205         index += 1
00206 
00207         if index > length:
00208             break
00209 
00210         if index < length:
00211             line = last_edits[index]
00212             line.time_tuple = request.user.getTime(wikiutil.version2timestamp(line.ed_time_usecs))
00213             day = line.time_tuple[0:3]
00214 
00215         if (day != this_day) or (index == length):
00216             d['bookmark_link_html'] = None
00217             d['date'] = request.user.getFormattedDate(wikiutil.version2timestamp(last_edits[last_index].ed_time_usecs))
00218             output.append(request.theme.recentchanges_daybreak(d))
00219             this_day = day
00220 
00221             for page in last_edits[last_index:index]:
00222                 output.append(format_page_edits(macro, [page], None))
00223             last_index = index
00224             day_count += 1
00225             if (day_count >= max_days):
00226                 break
00227 
00228     d['rc_msg'] = msg
00229     output.append(request.theme.recentchanges_footer(d))
00230     return ''.join(output)
00231 

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

list MoinMoin.macro.RecentChanges._DAYS_SELECTION = [1, 2, 3, 7, 14, 30, 60, 90]

Definition at line 16 of file RecentChanges.py.

Definition at line 19 of file RecentChanges.py.

Definition at line 17 of file RecentChanges.py.

Definition at line 18 of file RecentChanges.py.

RecentChanges Macro.

Definition at line 25 of file RecentChanges.py.