Ejemplo n.º 1
0
    def searchform(self, d):
        """
        assemble HTML code for the search forms
        
        @param d: parameter dictionary
        @rtype: string
        @return: search form html
        """
        _ = self.request.getText
        sitenav_pagename = wikiutil.getSysPage(self.request,
                                               'SiteNavigation').page_name
        dict = {
            'find_page_html': wikiutil.link_tag(
                self.request, d['page_find_page']+'?value='+
                              urllib.quote_plus(d['page_name'], ''),
                _('FindPage')),
            'navi_page_html': wikiutil.link_tag(self.request, sitenav_pagename,
                                                sitenav_pagename),
            'search_html': _("or search titles %(titlesearch)s, "
                             "full text %(textsearch)s or") % d,
        }
        dict.update(d)
        
        html = (
            '<form method="POST" action="%(script_name)s/%(q_page_name)s">\n'
            '<p>\n'
            '<input type="hidden" name="action" value="inlinesearch">\n'
            '%(find_page_html)s %(search_html)s %(navi_page_html)s\n'
            '</p>\n'
            '</form>' % dict)

        return html
Ejemplo n.º 2
0
 def edittext_link(self, d, **keywords):
     """
     Assemble EditText link (or indication that page cannot be edited)
     
     @param d: parameter dictionary
     @rtype: string
     @return: edittext link html
     """
     _ = self.request.getText
     html = []
     html.append('<p>')
     if keywords.get('editable', 1):
         editable = (self.request.user.may.edit(d['page_name']) and
                     d['page'].isWritable())
         if editable:
             html.append("%s %s" % (
                 wikiutil.link_tag(self.request,
                                   d['q_page_name']+'?action=edit',
                                   _('EditText')),
                 _('of this page'),
             ))
         else:
             html.append("%s" % _('Immutable page'))
         html.append(' %(last_edit_info)s' % d)
         html.append('</p>')
     return ''.join(html)
Ejemplo n.º 3
0
 def username(self, d):
     """
     Assemble the username / userprefs link
     
     @param d: parameter dictionary
     @rtype: string
     @return: username html
     """
     html = '<div id="username">%s</div>' % wikiutil.link_tag(
         self.request, wikiutil.quoteWikiname(d['page_user_prefs']),
         wikiutil.escape(d['user_prefs']))
     return html
Ejemplo n.º 4
0
    def make_iconlink(self, which, d, actionButton=False):
        """
        Make a link with an icon

        @param which: icon id (dictionary key)
        @param d: parameter dictionary
        @rtype: string
        @return: html link tag
        """
        page_params, title, icon = config.page_icons_table[which]
        d['title'] = title % d
        d['i18ntitle'] = self.request.getText(d['title'])
        img_src = self.make_icon(icon, d, actionButton)
        return wikiutil.link_tag(self.request, page_params % d, img_src,
                                 attrs='title="%(i18ntitle)s"' % d)
Ejemplo n.º 5
0
 def logo(self, d):
     """
     Assemble the logo
     
     @param d: parameter dictionary
     @rtype: string
     @return: logo html
     """
     if d['logo_string']:
         html = '<div id="logo">%s</div>' % wikiutil.link_tag(
             self.request, wikiutil.quoteWikiname(d['page_front_page']),
             d['logo_string'])
     else:
         html = ''
     return html
Ejemplo n.º 6
0
 def availableactions(self, d):    
     """
     assemble HTML code for the available actions
     
     @param d: parameter dictionary
     @rtype: string
     @return: available actions html
     """
     _ = self.request.getText
     html = []
     html.append('<p>')
     first = 1
     for action in d['available_actions']:
         html.append("%s %s" % (
             (',', _('Or try one of these actions:'))[first],
             wikiutil.link_tag(self.request,
                               '%s?action=%s' % (d['q_page_name'], action),
                               action),
             ))
         first = 0
     html.append('</p>')
     return ''.join(html)
Ejemplo n.º 7
0
def execute(macro, args, formatter=None):
    if not formatter:
        formatter = macro.formatter
    _ = macro.request.getText

    # prevent recursive calls
    global _guard
    if _guard:
        return ""

    # flush the request output because orphaned may take time to generate
    macro.request.flush()

    # delete all linked pages from a dict of all pages
    _guard = 1
    cursor = macro.request.cursor
    cursor.execute(
        """
        SELECT curPages.propercased_name
        FROM curPages LEFT JOIN links on
            (links.destination_pagename=curPages.name and
             links.wiki_id=%(wiki_id)s and curPages.wiki_id=%(wiki_id)s
            )
        WHERE curPages.wiki_id=%(wiki_id)s and
              links.destination_pagename is NULL""",
        {"wiki_id": macro.request.config.wiki_id},
    )

    orphanednames_result = cursor.fetchall()
    _guard = 0

    # check for the extreme case
    if not orphanednames_result:
        return "<p>%s</p>" % _("No orphaned pages in this wiki.")

    # return a list of page links
    from Sycamore.Page import Page

    redirects = []
    pages = []
    show_users = showUsers(macro.request)
    for entry in orphanednames_result:
        name = entry[0]
        if name.startswith(config.user_page_prefix) and not show_users:
            continue
        page = Page(name, macro.request)
        is_redirect = False
        # if not macro.request.user.may.read(name): continue
        if page.isRedirect():
            redirects.append(page)
        else:
            pages.append(page)

    # usually 'Orphaned Pages' or something such
    pagename = macro.request.getPathinfo()[1:]
    if not show_users:
        macro.request.write(
            '<div style="float: right;">'
            '<div class="actionBoxes"><span>'
            "%s"
            "</span></div></div>" % wikiutil.link_tag(macro.request, pagename + "?show_users=true", "show users")
        )
    else:
        macro.request.write(
            '<div style="float: right;">'
            '<div class="actionBoxes"><span>'
            "%s"
            "</span></div></div>" % wikiutil.link_tag(macro.request, pagename, "hide users")
        )

    macro.request.write(macro.formatter.heading(2, "Orphans"))
    macro.request.write(macro.formatter.bullet_list(1))
    for page in pages:
        macro.request.write(macro.formatter.listitem(1))
        macro.request.write(page.link_to(know_status=True, know_status_exists=True))
        macro.request.write(macro.formatter.listitem(0))
    macro.request.write(macro.formatter.bullet_list(0))

    macro.request.write(macro.formatter.heading(2, "Orphaned Redirects"))
    macro.request.write(macro.formatter.bullet_list(1))
    for page in redirects:
        macro.request.write(macro.formatter.listitem(1))
        macro.request.write(page.link_to(know_status=True, know_status_exists=True))
        macro.request.write(macro.formatter.listitem(0))
    macro.request.write(macro.formatter.bullet_list(0))

    return ""  # macros must return strings
Ejemplo n.º 8
0
    def edittext_link(self, d, **keywords):
        """
        Assemble EditText link (or indication that page cannot be edited)
        
        @param d: parameter dictionary
        @rtype: string
        @return: edittext link html
        """
        _ = self.request.getText
        html = []
        actions_in_footer = False
        if keywords.get('editable', 1):
            editable = self.request.user.may.edit(d['page'])
            if editable:
                d['last_edit_info'] = d['page'].last_modified_str()
            else:
                d['last_edit_info'] = ''

            html.append(
                '<script language="JavaScript" type="text/javascript">\n'
                'var donate2=new Image();donate2.src="%s";'
                'var donate=new Image();donate.src="%s";'
                '</script>'
                '<div id="footer">'
                '<table width="100%%" border="0" cellspacing="0" '
                       'cellpadding="0"><tr>' %
                (self.img_url('donate2.png'), self.img_url('donate.png')))
            # noedit is a keyword that tells us if we are in an area where an
            # edit link just logically makes no sense, such as the info tab.
            leftwidth = '10'
            if not keywords.get('noedit'):
                if editable:
                    if d['last_edit_info']:
                        leftwidth = '50'
                    else:
                        leftwidth = '24'
                else:
                    if not self.request.user.isFavoritedTo(d['page']):
                        leftwidth = '20'
                    else:
                        leftwidth = '10'
            html.append('<td align="left" width="%s%%">' % leftwidth)

            if not keywords.get('noedit'):
                if editable:
                    actions_in_footer = True
                    html.append(wikiutil.link_tag(
                        self.request, d['q_page_name']+'?action=edit',
                        _('Edit')))

                if not self.request.user.anonymous:
                    if not self.request.user.isFavoritedTo(d['page']):
                        actions_in_footer = True
                        if editable:
                            html.append(" or %s" % wikiutil.link_tag(
                                self.request,
                                d['q_page_name']+'?action=favorite',
                                _('Bookmark')))
                        else: 
                            html.append(wikiutil.link_tag(self.request,
                                d['q_page_name']+'?action=favorite',
                                _('Bookmark')))
                                
                if actions_in_footer:
                    html.append(' this page')

                if d['last_edit_info']:
                    html.append(' %(last_edit_info)s' % d)
        
            cc_button = (
                '<a href="http://creativecommons.org/licenses/by/2.0/">'
                '<img alt="Creative Commons License" border="0" src="%s"/>'
                '</a>' % self.img_url('cc.png'))
            if self.request.config.license_text:
                html.append('<td align="center" valign="middle">'
                            '<div class="license">%s</div></td>' %
                            self.request.config.license_text)
                if self.request.config.footer_buttons:
                  html.append('<td align="right" valign="middle" '
                                  'width="%spx" style="padding-right: 5px;">'
                              '%s</td></tr></table></div>' %
                              (len(self.request.config.footer_buttons)*100,
                               ' '.join(self.request.config.footer_buttons)))
                else:
                    if not actions_in_footer:
                        html.append('<td align="right" valign="middle" '
                                        'width="%s%%" '
                                        'style="padding-right: 5px;"> '
                                    '</td></tr></table></div>' % leftwidth)
                    else:
                        html.append('<td align="right" valign="middle" '
                                        'width="20px" '
                                        'style="padding-right: 5px;"> '
                                    '</td></tr></table></div>')
            else:
                if self.request.config.footer_buttons:
                    html.append(
                        '<td align="right" valign="middle" width="%spx" '
                            'style="padding-right: 5px;">'
                        '%s</td></tr></table></div>' %
                        (len(self.request.config.footer_buttons)*100,
                         ' '.join(self.request.config.footer_buttons)))
                else:
                    html.append('</tr></table></div>')

        return ''.join(html)
Ejemplo n.º 9
0
def execute(macro, args, formatter=None):
    if not formatter:
        formatter = macro.formatter
    _ = macro.request.getText

    # prevent recursive calls
    global _guard
    if _guard:
        return ''
    html = []

    # flush request output because this may take a second to generate
    macro.request.flush()

    # build a list of wanted pages tuples.
    # (pagename, k) where k is the number of links to pagename
    wanted_results = raw_wanted_results(macro)

    if not wanted_results:
        macro.request.write("<p>%s</p>" % _("No wanted pages in this wiki."))
        return ''

    # we have wanted pages, so let's generate a list of
    # where the wanted pages are wanted from
    wanted = where_wanted_from(wanted_results, macro)

    # find the 'most wanted' pages
    wanted.sort(comparey)
    most_wanted = wanted[0:60]
    #alphabetize these
    most_wanted.sort(comparey_alpha)

    # usually 'Wanted Page' or something such
    pagename = macro.request.getPathinfo()[1:] 

    if not showUsers(macro.request):
        html.append('<div style="float: right;">'
                    '<div class="actionBoxes"><span>%s</span></div></div>' %
                    wikiutil.link_tag(macro.request,
                                      pagename + "?show_users=true",
                                      "show users"))
    else:
      html.append('<div style="float: right;">'
                  '<div class="actionBoxes"><span>%s</span></div></div>' %
                  wikiutil.link_tag(macro.request, pagename, "hide users"))
    html.append(
        '<p>The "most" wanted pages based upon the number of links made from '
        'other pages (bigger means more wanted):</p>\n'
        '<div style="margin-top: 0px; margin-left: auto; margin-right: auto; '
                    'width: 760px; text-align: left; vertical-align: top; '
                    'padding-left: 7px; padding-right: 7px;">\n'
        '<p style="padding: 15px;  line-height: 1.45; margin-top: 0; '
                  'padding-left: 7px; padding-right: 7px; width: 760px; '
                  'solid 1px #eee; background: #f5f5f5; '
                  'border: 1px solid rgb(170, 170, 170); ">\n')

    # find the max number of links
    number_list = []
    for name, number, source_name in most_wanted:
        number_list.append(number)
    if number_list:
        max_links = max(number_list)
    else:
        max_links = 0

    for name, number, source_pagenames in most_wanted:
        print_number = ((number*1.0)/max_links) * 30
        if print_number < 12:
            print_number = 12
        html.append('<a class="nonexistent" style="font-size: %spx;  '
                                                  'margin-top: 10px; '
                                                  'margin-bottom: 10px; '
                                                  'margin-right: 5px; " '
                       'href="%s/%s">%s</a> &nbsp;' %
                    (print_number, macro.request.getBaseURL(),
                     wikiutil.quoteWikiname(name), name))

    html.append('</p></div>')
    macro.request.write(''.join(html))
    macro.request.write('<p>What follows is a list of all "wanted" pages.  '
                        'Each wanted page includes a list, following it, of '
                        'all the pages where it is referred to:</p>\n')

    macro.request.write('<ol>\n')
    output_complete_wanted_list(wanted, macro)
    macro.request.write("</ol>")

    return ''