Ejemplo n.º 1
0
def getNames(cfg):
    if not hasattr(cfg.cache, 'macro_names'):
        lnames = names[:]
        lnames.extend(i18n.wikiLanguages().keys())
        lnames.extend(wikiutil.getPlugins('macro', cfg))
        cfg.cache.macro_names = lnames  # remember it
    return cfg.cache.macro_names
Ejemplo n.º 2
0
def getNames(cfg):
    if hasattr(cfg, 'macro_names'):
        return cfg.macro_names
    else:
        lnames = names[:]
        lnames.extend(wikiutil.getPlugins('macro', cfg))
        return lnames
Ejemplo n.º 3
0
def getNames(cfg):
    if not hasattr(cfg.cache, "macro_names"):
        lnames = names[:]
        lnames.extend(i18n.wikiLanguages().keys())
        lnames.extend(wikiutil.getPlugins("macro", cfg))
        cfg.cache.macro_names = lnames  # remember it
    return cfg.cache.macro_names
Ejemplo n.º 4
0
    def _theme_select(self):
        """ Create theme selection. """
        cur_theme = self.request.user.valid and self.request.user.theme_name or self.cfg.theme_default
        options = [("<default>", "<%s>" % self._("Default"))]
        for theme in wikiutil.getPlugins('theme', self.request.cfg):
            options.append((theme, theme))

        return util.web.makeSelection('theme_name', options, cur_theme)
Ejemplo n.º 5
0
    def _theme_select(self):
        """ Create theme selection. """
        cur_theme = self.request.user.valid and self.request.user.theme_name or self.cfg.theme_default
        options = [("<default>", "<%s>" % self._("Default"))]
        for theme in wikiutil.getPlugins('theme', self.request.cfg):
            options.append((theme, theme))

        return util.web.makeSelection('theme_name', options, cur_theme)
Ejemplo n.º 6
0
def get_names(config):
    """ Get a list of known actions.

    @param config: a config object
    @rtype: set
    @return: set of known actions
    """
    if not hasattr(config.cache, 'action_names'):
        actions = names[:]
        actions.extend(wikiutil.getPlugins('action', config))
        actions = set([action for action in actions
                      if not action in config.actions_excluded])
        config.cache.action_names = actions # remember it
    return config.cache.action_names
Ejemplo n.º 7
0
    def testSyntaxReferenceOthers(self):
        formatters = wikiutil.getPlugins("formatter", self.request.cfg)

        # we have separate tests for those:
        formatters.remove('text_docbook')
        formatters.remove('dom_xml')

        for f_name in formatters:
            try:
                formatter = wikiutil.importPlugin(self.request.cfg, "formatter", f_name, "Formatter")
            except wikiutil.PluginAttributeError:
                pass
            else:
                print "Formatting using %r" % formatter
                self.formatPage("HelpOnMoinWikiSyntax", formatter)
                print "Done."
Ejemplo n.º 8
0
def get_names(config):
    """ Get a list of known actions.

    @param config: a config object
    @rtype: set
    @return: set of known actions
    """
    if not hasattr(config.cache, 'action_names'):
        actions = names[:]
        actions.extend(wikiutil.getPlugins('action', config))
        actions = set([
            action for action in actions
            if not action in config.actions_excluded
        ])
        config.cache.action_names = actions  # remember it
    return config.cache.action_names
Ejemplo n.º 9
0
    def test_sanitize_to_id_idempotent(self):
        def _verify(formatter, id):
            origid = formatter.sanitize_to_id(id)
            id = origid
            for i in xrange(3):
                id = formatter.sanitize_to_id(id)
                assert id == origid

        formatters = wikiutil.getPlugins("formatter", self.request.cfg)
        try:
            from xml.dom import getDOMImplementation
            dom = getDOMImplementation("4DOM")
        except ImportError:
            # if we don't have 4suite installed, the docbook formatter would just raise an exception
            formatters.remove('text_docbook')

        testids = [
            r"tho/zeequeen&angu\za",
            r"quuirahz\iphohsaij,i",
            r"ashuifa+it[ohchieque",
            r"ohyie-lakoo`duaghaib",
            r"eixaepumuqu[ie\ba|eh",
            r"theegieque;zahmeitie",
            r"pahcooje&rahkeiz$oez",
            r"ohjeeng*iequao%fai?p",
            r"ahfoodahmepooquepee;",
            r"ubed_aex;ohwebeixah%",
            r"eitiekicaejuelae=g^u",
            r"",
            r'  ',
            r'--123',
            r'__$$',
            r'@@',
            u'\xf6\xf6llasdf\xe4',
        ]

        for f_name in formatters:
            try:
                formatter = wikiutil.importPlugin(self.request.cfg,
                                                  "formatter", f_name,
                                                  "Formatter")
                f = formatter(self.request)
                for id in testids:
                    yield _verify, f, id
            except wikiutil.PluginAttributeError:
                pass
Ejemplo n.º 10
0
    def test_sanitize_to_id_idempotent(self):
        def _verify(formatter, id):
            origid = formatter.sanitize_to_id(id)
            id = origid
            for i in xrange(3):
                id = formatter.sanitize_to_id(id)
                assert id == origid

        formatters = wikiutil.getPlugins("formatter", self.request.cfg)
        try:
            from xml.dom import getDOMImplementation
            dom = getDOMImplementation("4DOM")
        except ImportError:
            # if we don't have 4suite installed, the docbook formatter would just raise an exception
            formatters.remove('text_docbook')

        testids = [
            r"tho/zeequeen&angu\za",
            r"quuirahz\iphohsaij,i",
            r"ashuifa+it[ohchieque",
            r"ohyie-lakoo`duaghaib",
            r"eixaepumuqu[ie\ba|eh",
            r"theegieque;zahmeitie",
            r"pahcooje&rahkeiz$oez",
            r"ohjeeng*iequao%fai?p",
            r"ahfoodahmepooquepee;",
            r"ubed_aex;ohwebeixah%",
            r"eitiekicaejuelae=g^u",
            r"",
            r'  ',
            r'--123',
            r'__$$',
            r'@@',
            u'\xf6\xf6llasdf\xe4',
        ]

        for f_name in formatters:
            try:
                formatter = wikiutil.importPlugin(self.request.cfg, "formatter",
                                                  f_name, "Formatter")
                f = formatter(self.request)
                for id in testids:
                    yield _verify, f, id
            except wikiutil.PluginAttributeError:
                pass
Ejemplo n.º 11
0
    def testSyntaxReferenceOthers(self):
        formatters = wikiutil.getPlugins("formatter", self.request.cfg)

        # we have separate tests for those:
        formatters.remove('text_docbook')
        formatters.remove('dom_xml')

        for f_name in formatters:
            try:
                formatter = wikiutil.importPlugin(self.request.cfg,
                                                  "formatter", f_name,
                                                  "Formatter")
            except wikiutil.PluginAttributeError:
                pass
            else:
                print "Formatting using %r" % formatter
                self.formatPage("HelpOnMoinWikiSyntax", formatter)
                print "Done."
Ejemplo n.º 12
0
def _create_prefs_page(request, sel=None):
    _ = request.getText
    plugins = wikiutil.getPlugins('userprefs', request.cfg)
    ret = html.P()
    ret.append(html.Text(_("Please choose:")))
    ret.append(html.BR())
    items = html.UL()
    ret.append(items)
    for sub in plugins:
        if sub in request.cfg.userprefs_disabled:
            continue
        cls = wikiutil.importPlugin(request.cfg, 'userprefs', sub, 'Settings')
        obj = cls(request)
        if not obj.allowed():
            continue
        url = request.page.url(request, {'action': 'userprefs', 'sub': sub})
        lnk = html.LI().append(html.A(href=url).append(html.Text(obj.title)))
        items.append(lnk)
    return unicode(ret)
Ejemplo n.º 13
0
def _create_prefs_page(request, sel=None):
    _ = request.getText
    plugins = wikiutil.getPlugins('userprefs', request.cfg)
    ret = html.P()
    ret.append(html.Text(_("Please choose:")))
    ret.append(html.BR())
    items = html.UL()
    ret.append(items)
    for sub in plugins:
        if sub in request.cfg.userprefs_disabled:
            continue
        cls = wikiutil.importPlugin(request.cfg, 'userprefs', sub, 'Settings')
        obj = cls(request)
        if not obj.allowed():
            continue
        url = request.page.url(request, {'action': 'userprefs', 'sub': sub})
        lnk = html.LI().append(html.A(href=url).append(html.Text(obj.title)))
        items.append(lnk)
    return unicode(ret)
Ejemplo n.º 14
0
def get_handlers(cfg):
    """Create a list of available event handlers.

    Each handler is a handle() function defined in a plugin,
    pretty much like in case of actions.

    TODO: maybe make it less dumb? ;-)
    """
    event_handlers = []
    names = wikiutil.getPlugins("events", cfg)

    for name in names:
        try:
            handler = wikiutil.importPlugin(cfg, "events", name, "handle")
        except PluginAttributeError:
            handler = None

        if handler is not None:
            event_handlers.append(handler)

    return event_handlers
Ejemplo n.º 15
0
def get_handlers(cfg):
    """Create a list of available event handlers.

    Each handler is a handle() function defined in a plugin,
    pretty much like in case of actions.

    TODO: maybe make it less dumb? ;-)
    """
    event_handlers = []
    names = wikiutil.getPlugins("events", cfg)

    for name in names:
        try:
            handler = wikiutil.importPlugin(cfg, "events", name, "handle")
        except PluginAttributeError:
            handler = None

        if handler is not None:
            event_handlers.append(handler)

    return event_handlers
Ejemplo n.º 16
0
    def username(self, d):
        request = self.request
        _ = request.getText

        urls = []

        # Add username/homepage link for registered users. We don't care
        # if it exists, the user can create it.
        if request.user.valid and request.user.name:
            interwiki = wikiutil.getInterwikiHomePage(request)
            linkpage = '#'
            if interwiki[0] == 'Self':
                wikitail = wikiutil.url_unquote(interwiki[1])
                linkpage = request.script_root + '/' + wikitail

            name = wikiutil.escape(request.user.name)
            urls.append('<li class="nav-header"><a href="%s">%s</a></li>'
                    % (linkpage, name))

            plugins = wikiutil.getPlugins('userprefs', request.cfg)
            for sub in plugins:
                if sub in request.cfg.userprefs_disabled:
                    continue
                cls = wikiutil.importPlugin(request.cfg, 'userprefs',
                                            sub, 'Settings')
                obj = cls(request)
                if not obj.allowed():
                    continue
                url = request.page.url(request, {'action': 'userprefs',
                                                 'sub': sub})
                urls.append('<li><a href="%s">%s</a></li>' % (url, obj.title))

        if request.user.valid:
            if request.user.auth_method in request.cfg.auth_can_logout:
                query = {'action': 'logout', 'logout': 'logout'}
                url = request.page.url(request, query)
                urls.append('<li><a href="%s">%s</a></li>' % (url, _('Logout')))
        elif request.cfg.auth_have_login:
            query = {'action': 'login'}
            # special direct-login link if the auth methods want no input
            if request.cfg.auth_login_inputs == ['special_no_input']:
                query['login'] = '******'
            url = request.page.url(request, query)
            urls.append('<li><a href="%s">%s</a></li>' % (url, _('Login')))

        formadd = getattr(request.cfg, 'user_form_add', ())
        # Please note that you need to have a function of the form
        # lambda self, req: ... to the config as the function is
        # defined within a class.
        formcond = getattr(request.cfg, 'user_form_addcondition',
                           lambda req: True)
        if formcond(request):
            for url, text in formadd:
                urls.append('<li><a href="%s">%s</a></li>' % (url, _(text)))

        out = ""

        if urls:
            out = u"""
        <ul class="nav navbar-nav navbar-right">
            <li>
            <a class="dropdown-toggle" data-toggle="dropdown" title="%s">
              <i class="glyphicon glyphicon-user"></i>
            </a>
            <ul class="dropdown-menu navbar-right">
                %s
            </ul>
            </li>
        </ul>""" % (_('User Preferences'), ("\n" + " " * 16).join(urls))

        return out
Ejemplo n.º 17
0
def getNames(cfg):
    if not hasattr(cfg.cache, 'action_names'):
        lnames = names[:]
        lnames.extend(wikiutil.getPlugins('action', cfg))
        cfg.cache.action_names = lnames # remember it
    return cfg.cache.action_names
Ejemplo n.º 18
0
 def execute(self):
     if self.args:
         return self.formatRawMarkup() 
     from MoinMoin import wikiutil
     themes = wikiutil.getPlugins('theme', self.request.cfg)
     return self.format(themes)