Exemple #1
0
def do_user_browser(request):
    """ Browser for SystemAdmin macro. """
    from Sycamore.util.dataset import TupleDataset, Column
    from Sycamore.Page import Page
    _ = request.getText

    data = TupleDataset()
    data.columns = [
        Column('id', label=('ID'), align='right'),
        Column('name', label=('Username')),
        Column('email', label=('Email')),
        Column('action', label=_('Action')),
    ]

    # Iterate over users
    for uid in user.getUserList(self.request.cursor):
        account = user.User(request, uid)

        userhomepage = Page(account.name, self.request)
        if userhomepage.exists():
            namelink = userhomepage.link_to()
        else:
            namelink = account.name

        data.addRow((
            request.formatter.code(1) + uid + request.formatter.code(0),
            request.formatter.rawHTML(namelink),
            request.formatter.url('mailto:' + account.email, account.email,
                                  'external', pretty_url=1, unescaped=1),
            '',
        ))

    if data:
        from Sycamore.widget.browser import DataBrowserWidget

        browser = DataBrowserWidget(request)
        browser.setData(data)
        return browser.toHTML()

    # No data
    return ''
Exemple #2
0
def display_edits(request, userpage, on_pagename):
    def printNextPrev(request, pagename, last_edit, offset_given):
        """
        prints the next and previous links, if they're needed.
        """
        if last_edit == 1 and not offset_given:
            return 

        html = []
        if last_edit != 1:
            html.append(
                '<div class="actionBoxes" '
                     'style="margin-right:10px !important; '
                            'float: left !important;">'
                '<span>'
                    '<a href="%s/%s?action=userinfo&offset=%s">'
                        '&larr;previous edits'
                    '</a>'
                '</span></div>' %
                (request.getBaseURL(), pagename, offset_given+1))
        if offset_given:
            html.append(
                '<div class="actionBoxes" style="float: left !important;">'
                '<span>'
                '<a href="%s/%s?action=userinfo&offset=%s">'
                    'next edits&rarr;'
                '</a>'
                '</span></div>' %
                (request.getBaseURL(), pagename, offset_given-1))
        html.append('<div style="clear: both;"></div>')

        return [''.join(html)]


    _ = request.getText

    edits = TupleDataset()
    edits.columns = [
        Column('page', label=_('Page')),
        Column('mtime', label=_('Date'), align='right'),
        Column('ip', label=_('From IP')),
        Column('comment', label=_('Comment')),
    ]

    if config.wiki_farm:
        edits.columns.insert(1, Column('wiki', label=_('Wiki')))

    has_edits = False
    totalEdits = editedPages = 0
    editedWiki = 0

    this_edit = 0
    offset_given = int(request.form.get('offset', [0])[0])
    if not offset_given: 
        offset = 0
    else:
        offset = offset_given*100 - offset_given

    userid = getUserId(userpage, request)
    request.cursor.execute("""SELECT count(editTime) from allPages
                              where userEdited=%(userid)s""",
                           {'userid':userid})
    count_result = request.cursor.fetchone()

    if count_result: 
        totalEdits = count_result[0]

    request.cursor.execute("""SELECT count(DISTINCT name) from allPages
                              where userEdited=%(userid)s""",
                           {'userid':userid})
    count_result = request.cursor.fetchone()
    
    if count_result:
        editedPages = count_result[0]

    request.cursor.execute("""SELECT count(DISTINCT wiki_id) from allPages
                              where userEdited=%(userid)s""",
                           {'userid':userid})
    wiki_count_result = request.cursor.fetchone()
    if wiki_count_result:
        editedWikis = wiki_count_result[0]

    request.cursor.execute(
        """SELECT allPages.name, allPages.editTime, allPages.userIP,
                  allPages.editType, allPages.comment, wikis.name
           from allPages, wikis
           where allPages.userEdited=%(userid)s and
                 wikis.id=allPages.wiki_id
           order by editTime desc limit 100 offset %(offset)s""",
       {'userid':userid, 'offset':offset})
    results = request.cursor.fetchall()

    if results:
        has_edits = True
    
    count = 1
    original_wiki = request.config.wiki_name
    for edit in results:
        this_edit = 1 + totalEdits - count - offset

        pagename = edit[0]
        mtime = edit[1]
        userIp = '<a href="http://revip.info/ipinfo/%s" tooltip="%s">%s</a>' % (edit[2], edit[2], edit[2])
        editType = edit[3]
        comment = edit[4]
        wiki_name = edit[5]

        request.switch_wiki(wiki_name)
        page = Page(pagename, request, wiki_name=wiki_name)

        version = page.date_to_version_number(mtime)

        if request.user.may.read(page):
            may_read = True
            show_page = page.link_to(
                querystr='action=diff&amp;version2=%s&amp;version1=%s' %
                    (version, version-1),
                guess_case=True, absolute=True)
            formatted_mtime = request.user.getFormattedDateTime(mtime)
            comment = Comment(request, comment, editType).render()
        else:
            may_read = False
            show_page = """<em>hidden</em>"""
            userIp = '<em>hidden</em>'
            comment = '<em>hidden</em>'
            formatted_mtime = '<em>hidden</em>'
                     

        if config.wiki_farm:
            if may_read:
                farm_link = farm.link_to_wiki(wiki_name, request.formatter)
            else:
                farm_link = '<em>hidden</em>'
        
            edits.addRow((show_page,
                          farm_link,
                          formatted_mtime,
                          userIp,
                          comment))
        else:
            edits.addRow((show_page,
                          formatted_mtime,
                          userIp,
                          comment))
        count += 1

    request.switch_wiki(original_wiki)
    
    if has_edits:
        request.write('<p>This user has made <b>%d</b> edits to <b>%d</b> '
                      'pages' % (totalEdits, editedPages ))
        if config.wiki_farm:
            request.write(' on <b>%s</b> wikis' % editedWikis)
        request.write('.</p>')

        request.write('<div id="useredits">')
        edit_table = DataBrowserWidget(request)
        edit_table.setData(edits)
        edit_table.render(append=printNextPrev(request, on_pagename, this_edit,
                                               offset_given))
        request.write('</div>')
        request.write('<script type="text/javascript" src="/wiki/revipbox.js"></script>')
    else:
        request.write("<p>This user hasn't edited any pages.</p>")