예제 #1
0
파일: PageActions.py 프로젝트: happytk/moin
def availableactions(request):
    page = request.page
    _ = request.getText
    html = ''
    links = []
    try:
        available = request.getAvailableActions(page) # Moin 1.8
    except AttributeError:
        from MoinMoin.action import get_available_actions
        available = get_available_actions(request.cfg, page, request.user) # Moin 1.9

    for action in available:
        links.append(actionlink(request, action, action))
    if page.isWritable() and request.user.may.write(page.page_name):
        links.append(actionlink(request, 'edit', 'EditText'))
    if request.user.valid and request.user.email:
        action = ("Subscribe", "Unsubscribe")[request.user.isSubscribedTo([page.page_name])]
        links.append(actionlink(request, 'subscribe', action))
    if request.user.valid:
        links.append(actionlink(request, 'userform&logout=logout', 'Logout'))
    links.append(actionlink(request, 'print', 'PrintView'))
    links.append(actionlink(request, 'raw', 'ViewRawText'))
    links.append(actionlink(request, 'refresh', 'DeleteCache'))
    html = u'<ul>%s</ul>' % u''.join(links)
    return html
예제 #2
0
def availableactions(request):
    page = request.page
    _ = request.getText
    links = []
    try:
        available = request.getAvailableActions(page) # Moin 1.8
    except AttributeError:
        from MoinMoin.action import get_available_actions
        available = get_available_actions(request.cfg, page, request.user) # Moin 1.9

    def split_and_translate(title):
        title = Page(request, title).split_title(request)
        return _(title, formatted=False)

    available = [(split_and_translate(action), action) for action in available]

    if page.isWritable() and request.user.may.write(page.page_name):
        available.append((_('Edit Text'), 'edit'))

    if request.user.valid and request.user.email:
        subscribed = request.user.isSubscribedTo([page.page_name])
        title = (_('Subscribe'), _('Unsubscribe'))[subscribed]
        action = ('subscribe', 'unsubscribe')[subscribed]
        available.append((title, action))

    available.append((_('Print View'), 'print'))
    available.append((_('View Raw Text'), 'raw'))
    available.append((_('Delete Cache'), 'refresh'))

    available.sort()
    for title, action in available:
        links.append(actionlink(request, action, title))

    return u'<ul>%s</ul>' % u''.join(links)
 def memodumpIsAvailableAction(self, page, action):
     """
     Return if action is available or not.
     If action starts with lowercase, return True without actually check if action exists.
     """
     request = self.request
     excluded = request.cfg.actions_excluded
     available = get_available_actions(request.cfg, page, request.user)
     return not (action in excluded or (action[0].isupper() and not action in available))
예제 #4
0
파일: wsgiapp.py 프로젝트: happytk/moin
def handle_action(context, pagename, action_name='show'):
    """ Actual dispatcher function for non-XMLRPC actions.

    Also sets up the Page object for this request, normalizes and
    redirects to canonical pagenames and checks for non-allowed
    actions.
    """
    _ = context.getText
    cfg = context.cfg

    # pagename could be empty after normalization e.g. '///' -> ''
    # Use localized FrontPage if pagename is empty
    if not pagename:
        context.page = wikiutil.getFrontPage(context)
    else:
        context.page = Page(context, pagename)
        if '_' in pagename and not context.page.exists():
            pagename = pagename.replace('_', ' ')
            page = Page(context, pagename)
            if page.exists():
                url = page.url(context)
                return context.http_redirect(url)

    msg = None
    # Complain about unknown actions
    if not action_name in get_names(cfg):
        msg = _("Unknown action %(action_name)s.") % {
                'action_name': wikiutil.escape(action_name), }

    # Disallow non available actions
    elif action_name[0].isupper() and not action_name in \
            get_available_actions(cfg, context.page, context.user):
        msg = _("You are not allowed to do %(action_name)s on this page.") % {
                'action_name': wikiutil.escape(action_name), }
        if not context.user.valid:
            # Suggest non valid user to login
            msg += " " + _("Login and try again.")

    if msg:
        context.theme.add_msg(msg, "error")
        context.page.send_page()
    # Try action
    else:
        from MoinMoin import action
        handler = action.getHandler(context, action_name)
        if handler is None:
            msg = _("You are not allowed to do %(action_name)s on this page.") % {
                    'action_name': wikiutil.escape(action_name), }
            if not context.user.valid:
                # Suggest non valid user to login
                msg += " " + _("Login and try again.")
            context.theme.add_msg(msg, "error")
            context.page.send_page()
        else:
            handler(context.page.page_name, context)

    return context
예제 #5
0
파일: wsgiapp.py 프로젝트: Opngate/moinmoin
def handle_action(context, pagename, action_name='show'):
    """ Actual dispatcher function for non-XMLRPC actions.

    Also sets up the Page object for this request, normalizes and
    redirects to canonical pagenames and checks for non-allowed
    actions.
    """
    _ = context.getText
    cfg = context.cfg

    # pagename could be empty after normalization e.g. '///' -> ''
    # Use localized FrontPage if pagename is empty
    if not pagename:
        context.page = wikiutil.getFrontPage(context)
    else:
        context.page = Page(context, pagename)
        if '_' in pagename and not context.page.exists():
            pagename = pagename.replace('_', ' ')
            page = Page(context, pagename)
            if page.exists():
                url = page.url(context)
                return context.http_redirect(url)

    msg = None
    # Complain about unknown actions
    if not action_name in get_names(cfg):
        msg = _("Unknown action %(action_name)s.") % {
                'action_name': wikiutil.escape(action_name), }

    # Disallow non available actions
    elif action_name[0].isupper() and not action_name in \
            get_available_actions(cfg, context.page, context.user):
        msg = _("You are not allowed to do %(action_name)s on this page.") % {
                'action_name': wikiutil.escape(action_name), }
        if not context.user.valid:
            # Suggest non valid user to login
            msg += " " + _("Login and try again.")

    if msg:
        context.theme.add_msg(msg, "error")
        context.page.send_page()
    # Try action
    else:
        from MoinMoin import action
        handler = action.getHandler(context, action_name)
        if handler is None:
            msg = _("You are not allowed to do %(action_name)s on this page.") % {
                    'action_name': wikiutil.escape(action_name), }
            if not context.user.valid:
                # Suggest non valid user to login
                msg += " " + _("Login and try again.")
            context.theme.add_msg(msg, "error")
            context.page.send_page()
        else:
            handler(context.page.page_name, context)

    return context
예제 #6
0
파일: blank.py 프로젝트: happytk/moin
    def availableactions(self, d):
        """
        assemble HTML code for the available actions

        @param d: parameter dictionary
        @rtype: string
        @return: available actions html
        """
        request = self.request
        _ = request.getText
        rev = d['rev']
        html = []
        page = d['page']
        available = get_available_actions(request.cfg, page, request.user)
        if available:
            available = list(available)
            available.sort()
            for action in available:
                # Always add spaces: AttachFile -> Attach File
                # XXX do not make a page object just for split_title
                #title = Page(request, action).split_title(force=1)
                title = action
                # Use translated version if available
                title = _(title)
                querystr = {'action': action}
                if rev:
                    querystr['rev'] = str(rev)
                link = page.link_to(request, text=title, querystr=querystr, rel='nofollow')
                html.append('<li>%s</li>' % link)

        title = _("DeleteCache")
        link = page.link_to(request, text=title, querystr={'action': 'refresh'}, rel='nofollow')

        cache = caching.CacheEntry(request, page, page.getFormatterName(), scope='item')
        date = request.user.getFormattedDateTime(cache.mtime())
        # deletecache = u'<p>%s %s</p>' % (link, _('(cached %s)') % date)

        html.append('<li>%s</li>' % link)
        # html = deletecache + u'<p>%s %s</p>\n' % (_('Or try one of these actions:'),
                                       # u', '.join(html))
        return '\n'.join(html)
예제 #7
0
    def availableactions(self, d):
        """
        assemble HTML code for the available actions

        @param d: parameter dictionary
        @rtype: string
        @return: available actions html
        """
        request = self.request
        _ = request.getText
        rev = d['rev']
        html = []
        page = d['page']
        available = get_available_actions(request.cfg, page, request.user)
        if available:
            available = list(available)
            available.sort()
            for action in available:
                # Always add spaces: AttachFile -> Attach File
                # XXX do not make a page object just for split_title
                #title = Page(request, action).split_title(force=1)
                title = action
                # Use translated version if available
                title = _(title)
                querystr = {'action': action}
                if rev:
                    querystr['rev'] = str(rev)
                link = page.link_to(request, text=title, querystr=querystr, rel='nofollow')
                html.append(link)

        title = _("DeleteCache")
        link = page.link_to(request, text=title, querystr={'action': 'refresh'}, rel='nofollow')

        cache = caching.CacheEntry(request, page, page.getFormatterName(), scope='item')
        date = request.user.getFormattedDateTime(cache.mtime())
        deletecache = u'<p>%s %s</p>' % (link, _('(cached %s)') % date)

        html = deletecache + u'<p>%s %s</p>\n' % (_('Or try one of these actions:'),
                                       u', '.join(html))
        return html
예제 #8
0
    def actionsMenu(self, page):
        """ Create actions menu list and items data dict

        The menu will contain the same items always, but items that are
        not available will be disabled (some broken browsers will let
        you select disabled options though).

        The menu should give best user experience for javascript
        enabled browsers, and acceptable behavior for those who prefer
        not to use Javascript.

        TODO: Move actionsMenuInit() into body onload - requires that the theme will render body,
              it is currently done in wikiutil/page.

        @param page: current page, Page object
        @rtype: unicode
        @return: actions menu html fragment
        """
        request = self.request
        _ = request.getText
        rev = request.rev

        menu = [
            'raw',
            'print',
            'RenderAsDocbook',
            'refresh',
            '__separator__',
            'SpellCheck',
            'LikePages',
            'LocalSiteMap',
            '__separator__',
            'RenamePage',
            'CopyPage',
            'DeletePage',
            '__separator__',
            'MyPages',
            'SubscribeUser',
            '__separator__',
            'Despam',
            'revert',
            'PackagePages',
            'SyncPages',
            ]

        titles = {
            # action: menu title
            '__title__': _("More Actions:"),
            # Translation may need longer or shorter separator
            '__separator__': _('------------------------'),
            'raw': _('Raw Text'),
            'print': _('Print View'),
            'refresh': _('Delete Cache'),
            'SpellCheck': _('Check Spelling'), # rename action!
            'RenamePage': _('Rename Page'),
            'CopyPage': _('Copy Page'),
            'DeletePage': _('Delete Page'),
            'LikePages': _('Like Pages'),
            'LocalSiteMap': _('Local Site Map'),
            'MyPages': _('My Pages'),
            'SubscribeUser': _('Subscribe User'),
            'Despam': _('Remove Spam'),
            'revert': _('Revert to this revision'),
            'PackagePages': _('Package Pages'),
            'RenderAsDocbook': _('Render as Docbook'),
            'SyncPages': _('Sync Pages'),
            }

        options = []
        option = '<option value="%(action)s"%(disabled)s>%(title)s</option>'

        # class="disabled" is a workaround for browsers that ignore
        # "disabled", e.g IE, Safari
        # for XHTML: data['disabled'] = ' disabled="disabled"'
        disabled = ' disabled class="disabled"'

        # Format standard actions
        available = get_available_actions(request.cfg, page, request.user)
        for action in menu:
            data = {'action': action, 'disabled': '', 'title': titles[action]}
            # removes excluded actions from the more actions menu
            if action in request.cfg.actions_excluded:
                continue

            # Enable delete cache only if page can use caching
            if action == 'refresh':
                if not page.canUseCache():
                    data['action'] = 'show'
                    data['disabled'] = disabled

            # revert action enabled only if user can revert
            if action == 'revert' and not request.user.may.revert(page.page_name):
                data['action'] = 'show'
                data['disabled'] = disabled

            # SubscribeUser action enabled only if user has admin rights
            if action == 'SubscribeUser' and not request.user.may.admin(page.page_name):
                data['action'] = 'show'
                data['disabled'] = disabled

            # Despam action enabled only for superusers
            if action == 'Despam' and not request.user.isSuperUser():
                data['action'] = 'show'
                data['disabled'] = disabled

            # Special menu items. Without javascript, executing will
            # just return to the page.
            if action.startswith('__'):
                data['action'] = 'show'

            # Actions which are not available for this wiki, user or page
            if (action == '__separator__' or
                (action[0].isupper() and not action in available)):
                data['disabled'] = disabled

            options.append(self.get_actions_menu_link(page, data))

        # Add custom actions not in the standard menu, except for
        # some actions like AttachFile (we have them on top level)
        more = [item for item in available if not item in titles and not item in ('AttachFile', )]
        more.sort()
        if more:
            # Add separator
            separator = u'<li class="divider"></li>'
            options.append(separator)
            # Add more actions (all enabled)
            for action in more:
                data = {'action': action, 'disabled': ''}
                # Always add spaces: AttachFile -> Attach File
                # XXX do not create page just for using split_title -
                # creating pages for non-existent does 2 storage lookups
                #title = Page(request, action).split_title(force=1)
                title = action
                # Use translated version if available
                data['title'] = _(title)
                options.append(self.get_actions_menu_link(page, data))

        data = {
            'label': titles['__title__'],
            'options': '\n'.join(options),
            'rev_field': rev and '<input type="hidden" name="rev" value="%d">' % rev or '',
            'do_button': _("Do"),
            'url': self.request.href(page.page_name)
            }

        html = '''
<li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown">
        More Actions
        <b class="caret"></b>
    </a>
    <ul class="dropdown-menu">
        %s
    </ul>
</li>
''' % '\n'.join(options)

        return html
예제 #9
0
    def actionsMenu(self, page):
        """ Create actions menu list and items data dict

        The menu will contain the same items always, but items that are
        not available will be disabled (some broken browsers will let
        you select disabled options though).

        The menu should give best user experience for javascript
        enabled browsers, and acceptable behavior for those who prefer
        not to use Javascript.

        TODO: Move actionsMenuInit() into body onload - requires that the theme will render body,
              it is currently done in wikiutil/page.


        @param page: current page, Page object
        @rtype: unicode
        @return: actions menu html fragment
        """
        request = self.request
        _ = request.getText
        rev = request.rev
        # rev was a hidden input within the more actions form
        # alternative will be to append it to anchor urls
        if rev: 
            revision = '&amp;rev=%s' % rev
        else:
            revision = ''

        menu = [
            'raw',
            'print',
            'RenderAsDocbook',
            'refresh',
            #'__separator__',
            'SpellCheck',
            'LikePages',
            'LocalSiteMap',
            #'__separator__',
            'RenamePage',
            'CopyPage',
            'DeletePage',
            #'__separator__',
            'MyPages',
            'SubscribeUser',
            #'__separator__',
            'Despam',
            'revert',
            'PackagePages',
            'SyncPages',
            'GuardarHoja',
            'SubirHoja'
            ]

        titles = {
            # action: menu title
            '__title__': _("More Actions:"),
            # Rick: Set separator to blank, as that looks better in our drop down menu:
            '__separator__': _(''),
            'raw': _('Raw Text'),
            'print': _('Print View'),
            'refresh': _('Delete Cache'),
            'SpellCheck': _('Check Spelling'), # rename action!
            'RenamePage': _('Rename Page'),
            'CopyPage': _('Copy Page'),
            'DeletePage': _('Delete Page'),
            'LikePages': _('Like Pages'),
            'LocalSiteMap': _('Local Site Map'),
            'MyPages': _('My Pages'),
            'SubscribeUser': _('Subscribe User'),
            'Despam': _('Remove Spam'),
            'revert': _('volver a versi&oacute;n anterior'),
            'PackagePages': _('Package Pages'),
            'RenderAsDocbook': _('Render as Docbook'),
            'SyncPages': _('Sync Pages'),
            'GuardarHoja': 'Guardar como .rst',
            'SubirHoja': 'Agregar contenido .sws'
            }

        options = []
        #original:  option = '<option value="%(action)s"%(disabled)s>%(title)s</option>'
        
        option = '<li><a href="%(baseurl)s?action=%(action)s%(revision)s">%(title)s</a></li>'
        disabledOption = '<li class="disabled">%(title)s</li>'
     
        # class="disabled" is a workaround for browsers that ignore
        # "disabled", e.g IE, Safari
        # for XHTML: data['disabled'] = ' disabled="disabled"'
        disabled = ' disabled class="disabled"'
        # @@@ is this best way to form link to current page?  Had trouble with subpages replicating parent page name in url
        #  baseurl is full url as used here
        baseurl = self.request.getScriptname() + '/' + wikiutil.quoteWikinameURL(page.page_name) 


        # Format standard actions
        available = get_available_actions(request.cfg, page, request.user)
        for action in menu:
            data = {'action': action, 'disabled': '', 'title': titles[action], 'baseurl': baseurl, 'revision': revision,}
            # removes excluded actions from the more actions menu
            if action in request.cfg.actions_excluded:
                continue

            # Enable delete cache only if page can use caching
            if action == 'refresh':
                if not page.canUseCache():
                    data['action'] = 'show'
                    data['disabled'] = disabled

            # revert action enabled only if user can revert
            if action == 'revert' and not request.user.may.revert(page.page_name):
                data['action'] = 'show'
                data['disabled'] = disabled

            # SubscribeUser action enabled only if user has admin rights
            if action == 'SubscribeUser' and not request.user.may.admin(page.page_name):
                data['action'] = 'show'
                data['disabled'] = disabled

            # PackagePages action only if user has write rights
            if action == 'PackagePages' and not request.user.may.write(page.page_name):
                data['action'] = 'show'
                data['disabled'] = disabled

            # Despam action enabled only for superusers
            if action == 'Despam' and not request.user.isSuperUser():
                data['action'] = 'show'
                data['disabled'] = disabled

            # Special menu items. Without javascript, executing will
            # just return to the page.
            if action.startswith('__'):
                data['action'] = 'show'

            # Actions which are not available for this wiki, user or page
            if (action == '__separator__' or
                (action[0].isupper() and not action in available)):
                data['disabled'] = disabled


            #~ options.append(option % data) # @@@
            if data['disabled']:
                options.append(disabledOption % data)
            else:
                options.append(option % data)

        # Add custom actions not in the standard menu, except for
        # some actions like AttachFile (we have them on top level)
        more = [item for item in available if not item in titles and not item in ('AttachFile', )]
        more.sort()
        if more:
            # Add separator
            #~ separator = option % {'action': 'show', 'disabled': disabled,  # @@@
                                  #~ 'title': titles['__separator__'], 'baseurl': baseurl,} # @@@ deleted by last fix
                                  #~ 'title': titles['__separator__'], 'baseurl': baseurl, 'revision': revision,} # @@@
            separator = disabledOption % {'action': 'show', 'disabled': disabled,
                                  'title': titles['__separator__'], 'baseurl': baseurl,} 

            options.append(separator)
            # Add more actions (all enabled)
            for action in more:
                data = {'action': action, 'disabled': '', 'baseurl': baseurl, 'revision': revision,}
                # Always add spaces: AttachFile -> Attach File
                # XXX do not create page just for using split_title -
                # creating pages for non-existent does 2 storage lookups
                #title = Page(request, action).split_title(force=1)
                title = action
                # Use translated version if available
                data['title'] = _(title)
                options.append(option % data)

        data = {
            'label': titles['__title__'],
            'options': '\n'.join(options),
            'rev_field': rev and '<input type="hidden" name="rev" value="%d">' % rev or '',
            'do_button': _("Do"),
            'baseurl': self.request.getScriptname(),
            'pagename_quoted': wikiutil.quoteWikinameURL(page.page_name),
            }
        html = '''
<div class="togglelink" id="togglelink" onclick="toggleMenu('menu1')">[ m&aacute;s opciones ]</div>
<div id="menu1">
<ul>
%(options)s
</ul>
</div>
''' % data

        return html
예제 #10
0
    def actionsMenu(self, page):
        """ Create actions menu list and items data dict

        The menu will contain the same items always, but items that are
        not available will be disabled (some broken browsers will let
        you select disabled options though).

        The menu should give best user experience for javascript
        enabled browsers, and acceptable behavior for those who prefer
        not to use Javascript.

        TODO: Move actionsMenuInit() into body onload - requires that the theme will render body,
              it is currently done in wikiutil/page.

        @param page: current page, Page object
        @rtype: unicode
        @return: actions menu html fragment
        """
        request = self.request
        _ = request.getText
        rev = request.rev

        menu = [
            'raw',
            'print',
            'RenderAsDocbook',
            'refresh',
            '__separator__',
            'SpellCheck',
            'LikePages',
            'LocalSiteMap',
            '__separator__',
            'RenamePage',
            'CopyPage',
            'DeletePage',
            '__separator__',
            'MyPages',
            'SubscribeUser',
            '__separator__',
            'Despam',
            'revert',
            'PackagePages',
            'SyncPages',
        ]

        titles = {
            # action: menu title
            '__title__': _("More Actions:"),
            # Translation may need longer or shorter separator
            '__separator__': _('------------------------'),
            'raw': _('Raw Text'),
            'print': _('Print View'),
            'refresh': _('Delete Cache'),
            'SpellCheck': _('Check Spelling'),  # rename action!
            'RenamePage': _('Rename Page'),
            'CopyPage': _('Copy Page'),
            'DeletePage': _('Delete Page'),
            'LikePages': _('Like Pages'),
            'LocalSiteMap': _('Local Site Map'),
            'MyPages': _('My Pages'),
            'SubscribeUser': _('Subscribe User'),
            'Despam': _('Remove Spam'),
            'revert': _('Revert to this revision'),
            'PackagePages': _('Package Pages'),
            'RenderAsDocbook': _('Render as Docbook'),
            'SyncPages': _('Sync Pages'),
        }

        options = []
        option = '<option value="%(action)s"%(disabled)s>%(title)s</option>'

        # class="disabled" is a workaround for browsers that ignore
        # "disabled", e.g IE, Safari
        # for XHTML: data['disabled'] = ' disabled="disabled"'
        disabled = ' disabled class="disabled"'

        # Format standard actions
        available = get_available_actions(request.cfg, page, request.user)
        for action in menu:
            data = {'action': action, 'disabled': '', 'title': titles[action]}
            # removes excluded actions from the more actions menu
            if action in request.cfg.actions_excluded:
                continue

            # Enable delete cache only if page can use caching
            if action == 'refresh':
                if not page.canUseCache():
                    data['action'] = 'show'
                    data['disabled'] = disabled

            # revert action enabled only if user can revert
            if action == 'revert' and not request.user.may.revert(
                    page.page_name):
                data['action'] = 'show'
                data['disabled'] = disabled

            # SubscribeUser action enabled only if user has admin rights
            if action == 'SubscribeUser' and not request.user.may.admin(
                    page.page_name):
                data['action'] = 'show'
                data['disabled'] = disabled

            # Despam action enabled only for superusers
            if action == 'Despam' and not request.user.isSuperUser():
                data['action'] = 'show'
                data['disabled'] = disabled

            # Special menu items. Without javascript, executing will
            # just return to the page.
            if action.startswith('__'):
                data['action'] = 'show'

            # Actions which are not available for this wiki, user or page
            if (action == '__separator__'
                    or (action[0].isupper() and not action in available)):
                data['disabled'] = disabled

            options.append(self.get_actions_menu_link(page, data))

        # Add custom actions not in the standard menu, except for
        # some actions like AttachFile (we have them on top level)
        more = [
            item for item in available
            if not item in titles and not item in ('AttachFile', )
        ]
        more.sort()
        if more:
            # Add separator
            separator = u'<li class="divider"></li>'
            options.append(separator)
            # Add more actions (all enabled)
            for action in more:
                data = {'action': action, 'disabled': ''}
                # Always add spaces: AttachFile -> Attach File
                # XXX do not create page just for using split_title -
                # creating pages for non-existent does 2 storage lookups
                #title = Page(request, action).split_title(force=1)
                title = action
                # Use translated version if available
                data['title'] = _(title)
                options.append(self.get_actions_menu_link(page, data))

        data = {
            'label':
            titles['__title__'],
            'options':
            '\n'.join(options),
            'rev_field':
            rev and '<input type="hidden" name="rev" value="%d">' % rev or '',
            'do_button':
            _("Do"),
            'url':
            self.request.href(page.page_name)
        }

        html = '''
<li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown">
        More Actions
        <b class="caret"></b>
    </a>
    <ul class="dropdown-menu">
        %s
    </ul>
</li>
''' % '\n'.join(options)

        return html
예제 #11
0
파일: moniker19.py 프로젝트: apzr/wiki
    def actionsMenu(self, page):
        """ Create actions menu list and items data dict

        The menu will contain the same items always, but items that are
        not available will be disabled (some broken browsers will let
        you select disabled options though).

        The menu should give best user experience for javascript
        enabled browsers, and acceptable behavior for those who prefer
        not to use Javascript.

        TODO: Move actionsMenuInit() into body onload - requires that the theme will render body,
              it is currently done in wikiutil/page.


        @param page: current page, Page object
        @rtype: unicode
        @return: actions menu html fragment
        """
        request = self.request
        _ = request.getText
        rev = request.rev
        # rev was a hidden input within the more actions form
        # alternative will be to append it to anchor urls
        if rev:
            revision = '&amp;rev=%s' % rev
        else:
            revision = ''

        menu = [
            'raw',
            'print',
            'RenderAsDocbook',
            'refresh',
            #'__separator__',
            'SpellCheck',
            'LikePages',
            'LocalSiteMap',
            #'__separator__',
            'RenamePage',
            'CopyPage',
            'DeletePage',
            #'__separator__',
            'MyPages',
            'SubscribeUser',
            #'__separator__',
            'Despam',
            'revert',
            'PackagePages',
            'SyncPages',
        ]

        titles = {
            # action: menu title
            '__title__': _("More Actions:"),
            # Rick: Set separator to blank, as that looks better in our drop down menu:
            '__separator__': _(''),
            'raw': _('Raw Text'),
            'print': _('Print View'),
            'refresh': _('Delete Cache'),
            'SpellCheck': _('Check Spelling'),  # rename action!
            'RenamePage': _('Rename Page'),
            'CopyPage': _('Copy Page'),
            'DeletePage': _('Delete Page'),
            'LikePages': _('Like Pages'),
            'LocalSiteMap': _('Local Site Map'),
            'MyPages': _('My Pages'),
            'SubscribeUser': _('Subscribe User'),
            'Despam': _('Remove Spam'),
            'revert': _('revert to this revision'),
            'PackagePages': _('Package Pages'),
            'RenderAsDocbook': _('Render as Docbook'),
            'SyncPages': _('Sync Pages'),
        }

        options = []
        #original:  option = '<option value="%(action)s"%(disabled)s>%(title)s</option>'

        option = '<li><a href="%(baseurl)s?action=%(action)s%(revision)s">%(title)s</a></li>'
        disabledOption = '<li class="disabled">%(title)s</li>'

        # class="disabled" is a workaround for browsers that ignore
        # "disabled", e.g IE, Safari
        # for XHTML: data['disabled'] = ' disabled="disabled"'
        disabled = ' disabled class="disabled"'
        # @@@ is this best way to form link to current page?  Had trouble with subpages replicating parent page name in url
        #  baseurl is full url as used here
        baseurl = self.request.getScriptname(
        ) + '/' + wikiutil.quoteWikinameURL(page.page_name)

        # Format standard actions
        available = get_available_actions(request.cfg, page, request.user)
        for action in menu:
            data = {
                'action': action,
                'disabled': '',
                'title': titles[action],
                'baseurl': baseurl,
                'revision': revision,
            }
            # removes excluded actions from the more actions menu
            if action in request.cfg.actions_excluded:
                continue

            # Enable delete cache only if page can use caching
            if action == 'refresh':
                if not page.canUseCache():
                    data['action'] = 'show'
                    data['disabled'] = disabled

            # revert action enabled only if user can revert
            if action == 'revert' and not request.user.may.revert(
                    page.page_name):
                data['action'] = 'show'
                data['disabled'] = disabled

            # SubscribeUser action enabled only if user has admin rights
            if action == 'SubscribeUser' and not request.user.may.admin(
                    page.page_name):
                data['action'] = 'show'
                data['disabled'] = disabled

            # PackagePages action only if user has write rights
            if action == 'PackagePages' and not request.user.may.write(
                    page.page_name):
                data['action'] = 'show'
                data['disabled'] = disabled

            # Despam action enabled only for superusers
            if action == 'Despam' and not request.user.isSuperUser():
                data['action'] = 'show'
                data['disabled'] = disabled

            # Special menu items. Without javascript, executing will
            # just return to the page.
            if action.startswith('__'):
                data['action'] = 'show'

            # Actions which are not available for this wiki, user or page
            if (action == '__separator__'
                    or (action[0].isupper() and not action in available)):
                data['disabled'] = disabled

            #~ options.append(option % data) # @@@
            if data['disabled']:
                options.append(disabledOption % data)
            else:
                options.append(option % data)

        # Add custom actions not in the standard menu, except for
        # some actions like AttachFile (we have them on top level)
        more = [
            item for item in available
            if not item in titles and not item in ('AttachFile', )
        ]
        more.sort()
        if more:
            # Add separator
            #~ separator = option % {'action': 'show', 'disabled': disabled,  # @@@
            #~ 'title': titles['__separator__'], 'baseurl': baseurl,} # @@@ deleted by last fix
            #~ 'title': titles['__separator__'], 'baseurl': baseurl, 'revision': revision,} # @@@
            separator = disabledOption % {
                'action': 'show',
                'disabled': disabled,
                'title': titles['__separator__'],
                'baseurl': baseurl,
            }

            options.append(separator)
            # Add more actions (all enabled)
            for action in more:
                data = {
                    'action': action,
                    'disabled': '',
                    'baseurl': baseurl,
                    'revision': revision,
                }
                # Always add spaces: AttachFile -> Attach File
                # XXX do not create page just for using split_title -
                # creating pages for non-existent does 2 storage lookups
                #title = Page(request, action).split_title(force=1)
                title = action
                # Use translated version if available
                data['title'] = _(title)
                options.append(option % data)

        data = {
            'label':
            titles['__title__'],
            'options':
            '\n'.join(options),
            'rev_field':
            rev and '<input type="hidden" name="rev" value="%d">' % rev or '',
            'do_button':
            _("Do"),
            'baseurl':
            self.request.getScriptname(),
            'pagename_quoted':
            wikiutil.quoteWikinameURL(page.page_name),
        }
        html = '''
<div class="togglelink" id="togglelink" onclick="toggleMenu('menu1')">[ more options ]</div>
<div id="menu1">
<ul>
%(options)s
</ul>
</div>
''' % data

        return html
예제 #12
0
    def bs_actions(self, page):
        """ Create actions menu list and items data dict
        @param page: current page, Page object
        @rtype: unicode
        @return: actions menu html fragment
        """
        html = []
        request = self.request
        _ = request.getText
        rev = request.rev

        menu = [
            'raw',
            'print',
            'RenderAsDocbook',
            'refresh',
            '__separator__',
            'SpellCheck',
            'LikePages',
            'LocalSiteMap',
            '__separator__',
            'RenamePage',
            'CopyPage',
            'DeletePage',
            '__separator__',
            'MyPages',
            'SubscribeUser',
            '__separator__',
            'Despam',
            'revert',
            'PackagePages',
            'SyncPages',
            ]

        # TODO use glyph-icons
        titles = {
            # action: menu title
            '__separator__': '',
            'raw':   _('Raw Text'),
            'print': _('Print View'),
            'refresh': _('Delete Cache'),
            'SpellCheck': _('Check Spelling'), # rename action!
            'RenamePage': _('Rename Page'),
            'CopyPage': _('Copy Page'),
            'DeletePage': _('Delete Page'),
            'LikePages': _('Like Pages'),
            'LocalSiteMap': _('Local Site Map'),
            'MyPages': _('My Pages'),
            'SubscribeUser': _('Subscribe User'),
            'Despam': _('Remove Spam'),
            'revert': _('Revert to this revision'),
            'PackagePages': _('Package Pages'),
            'RenderAsDocbook': _('Render as Docbook'),
            'SyncPages': _('Sync Pages'),
            }

        html.append(u'<div class="btn-group">')
        html.append(u'<a class="btn btn-mini dropdown-toggle" data-toggle="dropdown">')
        html.append(_('More Actions'))
        html.append(u'<span class="caret"></span>')
        html.append(u'</a>')
        html.append(u'<ul class="dropdown-menu">')

        option = '<li%(state)s><a href="'
        option += self.request.href(page.page_name)
        option += u'?action=%(action)s'
        if rev:
            option += u'&rev=%s' % rev
        option += u'">%(title)s</a><li>'

        disabled = u' class="disabled"'

        separator = u'<li class="divider"></li>'

        # Format standard actions
        available = get_available_actions(request.cfg, page, request.user)
        for action in menu:
            data = {'action': action,
                    'state' : u'',
                    'title' : titles[action]}
            # removes excluded actions from the more actions menu
            if action in request.cfg.actions_excluded:
                continue

            # Enable delete cache only if page can use caching
            if action == 'refresh':
                if not page.canUseCache():
                    data['action'] = 'show'
                    data['state'] = disabled

            # revert action enabled only if user can revert
            if action == 'revert' and not request.user.may.revert(page.page_name):
                data['action'] = 'show'
                data['state'] = disabled

            # SubscribeUser action enabled only if user has admin rights
            if action == 'SubscribeUser' and not request.user.may.admin(page.page_name):
                data['action'] = 'show'
                data['state'] = disabled

            # Despam action enabled only for superusers
            if action == 'Despam' and not request.user.isSuperUser():
                data['action'] = 'show'
                data['state'] = disabled

            # Special menu items. Without javascript, executing will
            # just return to the page.
            if action.startswith('__'):
                data['action'] = 'show'

            # Actions which are not available for this wiki, user or page
            if (action == '__separator__'):
                html.append(separator)
                continue

            if (action[0].isupper() and not action in available):
                data['state'] = disabled

            html.append(option % data)

        # Add custom actions not in the standard menu, except for
        # some actions like AttachFile (we have them on top level)
        more = [item for item in available if not item in titles and not item in ('AttachFile', )]
        more.sort()
        if more:
            # Add separator
            html.append(separator)
            # Add more actions (all enabled)
            for action in more:
                data = {'action': action, 'state': ''}
                # Always add spaces: AttachFile -> Attach File
                # XXX do not create page just for using split_title -
                # creating pages for non-existent does 2 storage lookups
                #title = Page(request, action).split_title(force=1)
                title = action
                # Use translated version if available
                data['title'] = _(title)
                html.append(option % data)

        html.append(u'</ul></div>')

        return u'\n'.join(html)