Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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> &nbsp; %s%s<b>' %
                              (edit_icon, page.link_to(absolute=True),
                               wiki_link))
              line_of_text = (
                  line_of_text + " &nbsp;" +
                  '<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;">&nbsp;&nbsp;'
                  '[<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 &nbsp; %s%s &nbsp;<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;">&nbsp;&nbsp;'
                  '[<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 &nbsp; %s%s &nbsp;'
                              '<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;">&nbsp;&nbsp;'
                  '[<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