def testRangeList(self):
        """ util.rangelist: test correct function for misc. input values """
        result = util.rangelist([])
        expected = ''
        assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()

        result = util.rangelist([42])
        expected = '42'
        assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()

        result = util.rangelist([42, 23])
        expected = '23,42'
        assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()

        result = util.rangelist([1, 2, 3, 4, 5])
        expected = '1-5'
        assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()

        result = util.rangelist([2, 5, 3])
        expected = '2-3,5'
        assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()

        result = util.rangelist([2, 3, 5, 6])
        expected = '2-3,5-6'
        assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()

        result = util.rangelist([2, 3, 5, 6, 23, 100, 101, 102, 104])
        expected = '2-3,5-6,23,100-102,104'
        assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()
Ejemplo n.º 2
0
    def testRangeList(self):
        """ util.rangelist: test correct function for misc. input values """
        result = util.rangelist([])
        expected = ''
        assert result == expected, 'Expected "%(expected)s" but got "%(result)s"' % locals()

        result = util.rangelist([42])
        expected = '42'
        assert result == expected, 'Expected "%(expected)s" but got "%(result)s"' % locals()

        result = util.rangelist([42, 23])
        expected = '23,42'
        assert result == expected, 'Expected "%(expected)s" but got "%(result)s"' % locals()

        result = util.rangelist([1, 2, 3, 4, 5])
        expected = '1-5'
        assert result == expected, 'Expected "%(expected)s" but got "%(result)s"' % locals()

        result = util.rangelist([2, 5, 3])
        expected = '2-3,5'
        assert result == expected, 'Expected "%(expected)s" but got "%(result)s"' % locals()

        result = util.rangelist([2, 3, 5, 6])
        expected = '2-3,5-6'
        assert result == expected, 'Expected "%(expected)s" but got "%(result)s"' % locals()

        result = util.rangelist([2, 3, 5, 6, 23, 100, 101, 102, 104])
        expected = '2-3,5-6,23,100-102,104'
        assert result == expected, 'Expected "%(expected)s" but got "%(result)s"' % locals()
Ejemplo n.º 3
0
def format_page_edits(macro, lines, bookmark_usecs):
    request = macro.request
    _ = request.getText
    d = {}  # dict for passing stuff to theme
    line = lines[0]
    pagename = line.pagename
    rev = int(line.rev)
    tnow = time.time()
    is_new = lines[-1].action == "SAVENEW"
    is_renamed = lines[-1].action == "SAVE/RENAME"
    # check whether this page is newer than the user's bookmark
    hilite = line.ed_time_usecs > (bookmark_usecs or line.ed_time_usecs)
    page = Page(request, pagename)

    html_link = ""
    if not page.exists():
        img = request.theme.make_icon("deleted")
        revbefore = rev - 1
        if revbefore and page.exists(rev=revbefore, domain="standard"):
            # indicate page was deleted and show diff to last existing revision of it
            html_link = page.link_to_raw(request, img, querystr={"action": "diff"}, rel="nofollow")
        else:
            # just indicate page was deleted
            html_link = img
    elif page.isConflict():
        img = request.theme.make_icon("conflict")
        html_link = page.link_to_raw(request, img, querystr={"action": "edit"}, rel="nofollow")
    elif hilite:
        # show special icons if change was after the user's bookmark
        if is_new:
            img = "new"
        elif is_renamed:
            img = "renamed"
        else:
            img = "updated"
        img = request.theme.make_icon(img)
        html_link = page.link_to_raw(
            request, img, querystr={"action": "diff", "date": "%d" % bookmark_usecs}, rel="nofollow"
        )
    else:
        # show "DIFF" icon else
        img = request.theme.make_icon("diffrc")
        html_link = page.link_to_raw(request, img, querystr={"action": "diff"}, rel="nofollow")

    # print name of page, with a link to it
    force_split = len(page.page_name) > _MAX_PAGENAME_LENGTH

    d["icon_html"] = html_link
    d["pagelink_html"] = page.link_to(request, text=page.split_title(force=force_split))

    # print time of change
    d["time_html"] = None
    if request.cfg.changed_time_fmt:
        tdiff = long(tnow - wikiutil.version2timestamp(long(line.ed_time_usecs))) / 60  # has to be long for py 2.2.x
        if tdiff < 100:
            d["time_html"] = _("%(mins)dm ago") % {"mins": tdiff}
        else:
            d["time_html"] = time.strftime(request.cfg.changed_time_fmt, line.time_tuple)

    # print editor name or IP
    d["editors"] = None
    if request.cfg.show_names:
        if len(lines) > 1:
            counters = {}
            editorcache = {}
            for idx in range(len(lines)):
                editorkey = lines[idx].addr, lines[idx].hostname, lines[idx].userid
                if editorkey not in editorcache:
                    editorcache[editorkey] = lines[idx].getEditor(request)
                name = editorcache[editorkey]
                if not name in counters:
                    counters[name] = []
                counters[name].append(idx + 1)
            poslist = [(v, k) for k, v in counters.items()]
            poslist.sort()
            d["editors"] = []
            for positions, name in poslist:
                d["editors"].append("%s&nbsp;[%s]" % (name, util.rangelist(positions)))
        else:
            d["editors"] = [line.getEditor(request)]

    comments = []
    for idx in range(len(lines)):
        comment = format_comment(request, lines[idx])
        if comment:
            comments.append((idx + 1, wikiutil.escape(comment)))

    d["changecount"] = len(lines)
    d["comments"] = comments

    img = request.theme.make_icon("info")
    d["info_html"] = page.link_to_raw(request, img, querystr={"action": "info"}, rel="nofollow")

    return request.theme.recentchanges_entry(d)
Ejemplo n.º 4
0
def format_page_edits(macro, lines, bookmark_usecs):
    request = macro.request
    _ = request.getText
    d = {} # dict for passing stuff to theme
    line = lines[0]
    pagename = line.pagename
    rev = int(line.rev)
    tnow = time.time()
    is_new = lines[-1].action == 'SAVENEW'
    is_renamed = lines[-1].action == 'SAVE/RENAME'
    # check whether this page is newer than the user's bookmark
    hilite = line.ed_time_usecs > (bookmark_usecs or line.ed_time_usecs)
    page = Page(request, pagename)

    html_link = ''
    if not page.exists():
        img = request.theme.make_icon('deleted')
        revbefore = rev - 1
        if revbefore and page.exists(rev=revbefore, domain='standard'):
            # indicate page was deleted and show diff to last existing revision of it
            html_link = page.link_to_raw(request, img, querystr={'action': 'diff'}, rel='nofollow')
        else:
            # just indicate page was deleted
            html_link = img
    elif page.isConflict():
        img = request.theme.make_icon('conflict')
        html_link = page.link_to_raw(request, img, querystr={'action': 'edit'}, rel='nofollow')
    elif hilite:
        # show special icons if change was after the user's bookmark
        if is_new:
            img = 'new'
        elif is_renamed:
            img = 'renamed'
        else:
            img = 'updated'
        img = request.theme.make_icon(img)
        html_link = page.link_to_raw(request, img, querystr={'action': 'diff', 'date': '%d' % bookmark_usecs}, rel='nofollow')
    else:
        # show "DIFF" icon else
        img = request.theme.make_icon('diffrc')
        html_link = page.link_to_raw(request, img, querystr={'action': 'diff'}, rel='nofollow')

    # print name of page, with a link to it
    force_split = len(page.page_name) > _MAX_PAGENAME_LENGTH

    d['icon_html'] = html_link
    d['pagelink_html'] = page.link_to(request, text=page.split_title(force=force_split))

    # print time of change
    d['time_html'] = None
    if request.cfg.changed_time_fmt:
        tdiff = long(tnow - wikiutil.version2timestamp(long(line.ed_time_usecs))) / 60 # has to be long for py 2.2.x
        if tdiff < 100:
            d['time_html'] = _("%(mins)dm ago") % {
                'mins': tdiff}
        else:
            d['time_html'] = time.strftime(request.cfg.changed_time_fmt, line.time_tuple)

    # print editor name or IP
    d['editors'] = None
    if request.cfg.show_names:
        if len(lines) > 1:
            counters = {}
            for idx in range(len(lines)):
                name = lines[idx].getEditor(request)
                if not name in counters:
                    counters[name] = []
                counters[name].append(idx+1)
            poslist = [(v, k) for k, v in counters.items()]
            poslist.sort()
            d['editors'] = []
            for positions, name in poslist:
                d['editors'].append("%s&nbsp;[%s]" % (
                    name, util.rangelist(positions)))
        else:
            d['editors'] = [line.getEditor(request)]

    comments = []
    for idx in range(len(lines)):
        comment = format_comment(request, lines[idx])
        if comment:
            comments.append((idx+1, wikiutil.escape(comment)))

    d['changecount'] = len(lines)
    d['comments'] = comments

    img = request.theme.make_icon('info')
    d['info_html'] = page.link_to_raw(request, img, querystr={'action': 'info'}, rel='nofollow')

    return request.theme.recentchanges_entry(d)
Ejemplo n.º 5
0
def format_page_edits(macro, lines, bookmark_usecs):
    request = macro.request
    _ = request.getText
    d = {} # dict for passing stuff to theme
    line = lines[0]
    pagename = line.pagename
    tnow = time.time()
    is_new = lines[-1].action == 'SAVENEW'
    # check whether this page is newer than the user's bookmark
    hilite = line.ed_time_usecs > (bookmark_usecs or line.ed_time_usecs)
    page = Page(request, line.pagename)

    html_link = ''
    if not page.exists():
        # indicate page was deleted
        html_link = request.theme.make_icon('deleted')
    elif is_new:
        # show "NEW" icon if page was created after the user's bookmark
        if hilite:
            img = request.theme.make_icon('new')
            html_link = wikiutil.link_tag(request, wikiutil.quoteWikinameURL(pagename),
                                          img, formatter=macro.formatter)
    elif hilite:
        # show "UPDATED" icon if page was edited after the user's bookmark
        img = request.theme.make_icon('updated')
        html_link = wikiutil.link_tag(request,
                                      wikiutil.quoteWikinameURL(pagename) + "?action=diff&date=%d" % bookmark_usecs,
                                      img, formatter=macro.formatter)
    else:
        # show "DIFF" icon else
        img = request.theme.make_icon('diffrc')
        html_link = wikiutil.link_tag(request,
                                      wikiutil.quoteWikinameURL(line.pagename) + "?action=diff",
                                      img, formatter=macro.formatter)

    # print name of page, with a link to it
    force_split = len(page.page_name) > _MAX_PAGENAME_LENGTH
    
    d['icon_html'] = html_link
    d['pagelink_html'] = page.link_to(request, text=page.split_title(request, force=force_split))
    
    # print time of change
    d['time_html'] = None
    if request.cfg.changed_time_fmt:
        tdiff = long(tnow - wikiutil.version2timestamp(long(line.ed_time_usecs))) / 60 # has to be long for py 2.2.x
        if tdiff < 100:
            d['time_html'] = _("%(mins)dm ago") % {
                'mins': tdiff}
        else:
            d['time_html'] = time.strftime(request.cfg.changed_time_fmt, line.time_tuple)
    
    # print editor name or IP
    d['editors'] = None
    if request.cfg.show_names:
        if len(lines) > 1:
            counters = {}
            for idx in range(len(lines)):
                name = lines[idx].getEditor(request)
                if not name in counters:
                    counters[name] = []
                counters[name].append(idx+1)
            poslist = map(None,  counters.values(), counters.keys())
            poslist.sort()
            ##request.write(repr(counters.items()))
            d['editors'] = []
            for positions, name in poslist:
                d['editors'].append("%s&nbsp;[%s]" % (
                    name, util.rangelist(positions)))
        else:
            d['editors'] = [line.getEditor(request)]

    comments = []
    for idx in range(len(lines)):
        comment = format_comment(request, lines[idx])
        if comment:
            comments.append((idx+1, wikiutil.escape(comment)))
    
    d['changecount'] = len(lines)
    d['comments'] = comments

    img = request.theme.make_icon('info')
    info_html = wikiutil.link_tag(request,
                                  wikiutil.quoteWikinameURL(line.pagename) + "?action=info",
                                  img, formatter=macro.formatter)
    d['info_html'] = info_html
    
    return request.theme.recentchanges_entry(d)