Пример #1
0
    def setup_basics(self):
        if self.config.active:
            self.wiki_exists = True
        else:
            self.wiki_exists = False

        if not self.wiki_exists:
            theme_name = config.theme_default
            try:
                self.theme = wikiutil.importPlugin('theme', theme_name)(self)
            except TypeError:
                theme_name = self.config.theme_default
                self.theme = wikiutil.importPlugin('theme', theme_name)(self)
            return
        else:
            self.relative_dir = getRelativeDir(self)
            self.user = user.User(self, is_login=True)

            self.lang = i18n.requestLanguage(self) 
            self.getText = (lambda text, i18n=self.i18n, request=self,
                lang=self.lang: i18n.getText(text, request, lang))

            # set memcache to act locally to this wiki (prefix)
            if config.memcache:
                self.mc.setPrefix(self.config.wiki_id)

            theme_name = self.config.theme_default
            try:
                self.theme = wikiutil.importPlugin('theme', theme_name)(self)
            except TypeError:
                theme_name = self.config.theme_default
                self.theme = wikiutil.importPlugin('theme', theme_name)(self)
Пример #2
0
 def get_dependencies(self, macro_name):
     if self.Dependencies.has_key(macro_name):
         return self.Dependencies[macro_name]
     result = wikiutil.importPlugin('macro', macro_name, 'Dependencies')
     if result != None:
         return result
     else:
         return ["time"]
Пример #3
0
 def processor(self, processor_name, lines):
     """
     processor_name MUST be valid!
     writes out the result instead of returning it!
     """
     processor = wikiutil.importPlugin("processor",
                                       processor_name, "process")
     processor(self.request, self, lines)
     return ''
Пример #4
0
 def processor(self, processor_name, lines):
     """
     processor_name MUST be valid!
     prints out the result insted of returning it!
     """
     Dependencies = wikiutil.importPlugin("processor",
                                          processor_name, "Dependencies")
     if Dependencies == None:
         Dependencies = ["time"]
     if self.__is_static(Dependencies):
         return self.formatter.processor(processor_name, lines)
     else:
         return self.__insert_code('%s%s.processor(%r, %r)' %
                                   (self.__adjust_formatter_state(),
                                    self.__formatter,
                                    processor_name, lines))
Пример #5
0
    def execute(self, macro_name, args, formatter=None):
        self.name = macro_name
        macro = wikiutil.importPlugin('macro', macro_name)
        if macro:
            return macro(self, args, formatter=formatter)

        builtins = vars(self.__class__)
        # builtin macro
        if builtins.has_key('_macro_' + macro_name):
            return builtins['_macro_' + macro_name](self, args,
                                                    formatter=formatter)

        # language pseudo macro
        if i18n.languages.has_key(macro_name):
            return self._m_lang(macro_name, args)

        raise ImportError("Cannot load macro %s" % macro_name)
Пример #6
0
def execute(macro, args, formatter=None):
    if not formatter:
        if hasattr(macro.parser, 'formatter'):
            formatter = macro.parser.formatter
        else:
            formatter = macro.formatter
    _ = macro.request.getText

    inline_edit_state = formatter.inline_edit
    formatter.inline_edit = False

    # included page will already have paragraphs. no need to print another.
    macro.parser.inhibit_p = 1 

    if line_has_just_macro(macro, args, formatter):
        macro.parser.inhibit_br = 2

    request = macro.request

    # parse and check arguments
    if not args:
        return (_sysmsg % ('error',
                           _('You did not give a pagename of a page to '
                             'include!')))
    # prepare including page
    result = []
    this_page = formatter.page

    # if we're in a paragraph, let's close it.
    if macro.formatter.in_p:
       result.append(macro.formatter.paragraph(0))

    if not hasattr(this_page, '_macroInclude_pagelist'):
        this_page._macroInclude_pagelist = {}

    re_args = re.match('('
        '('
            '(?P<name1>.+?)(\s*,\s*)((".*")|(left|right)|([0-9]{1,2}%)))|'
        '(?P<name2>.+))', args)
    if not re_args:
        return (_sysmsg % ('error', _('Invalid arguments to Include.')))

    have_more_args = re_args.group('name1')
    page_name = re_args.group('name1') or re_args.group('name2')

    if have_more_args:
        args = args[re_args.end('name1'):]
    else:
        args = ''
    re_args = re.search('"(?P<heading>.*)"', args)
    if re_args:
        heading = re_args.group('heading')
    else:
        heading = None

    if heading:
        before_heading = args[:re_args.start('heading')-1].strip()
        after_heading = args[re_args.end('heading')+1:].strip()
        args = before_heading + after_heading[1:]

    args_elements = args.split(',')
    align = None
    was_given_width = False
    width = '50%'
    for arg in args_elements:
        arg = arg.strip()
        if arg == 'left' or arg == 'right':
            align = arg
        elif arg.endswith('%'):
            try:
                arg = str(int(arg[:-1])) + '%'
            except:
                continue
            width = arg
	    was_given_width = True

    inc_name = wikiutil.AbsPageName(this_page.page_name, page_name)
    inc_page = Page(inc_name, macro.request)
    if not macro.request.user.may.read(inc_page):
        return ''
    if this_page.page_name.lower() == inc_name.lower():
        result.append('<p><strong class="error">'
                      'Recursive include of "%s" forbidden</strong></p>' %
                      inc_name)
	return ''.join(result)

    # check for "from" and "to" arguments (allowing partial includes)
    body = inc_page.get_raw_body(fresh=True) + '\n'
    edit_icon = ''
    
    # do headings
    level = 1
    if heading:
        result.append(formatter.heading(level, heading, action_link="edit",
                                        link_to_heading=True,
                                        pagename=inc_page.proper_name(),
                                        backto=this_page.page_name))

    if this_page._macroInclude_pagelist.has_key(inc_name):
        if (this_page._macroInclude_pagelist[inc_name] >
            caching.MAX_DEPENDENCY_DEPTH):
            return '<em>Maximum include depth exceeded.</em>'
         
    # set or increment include marker
    this_page._macroInclude_pagelist[inc_name] = \
        this_page._macroInclude_pagelist.get(inc_name, 0) + 1

    # format the included page
    pi_format = config.default_markup or "wiki" 
    Parser = wikiutil.importPlugin("parser", pi_format, "Parser")
    raw_text = inc_page.get_raw_body(fresh=True)
    formatter.setPage(inc_page)
    parser = Parser(raw_text, formatter.request)

    parser.print_first_p = 0 # don't print two <p>'s

    # note that our page now depends on the content of the included page
    if formatter.name == 'text_python':
        # this means we're in the caching formatter
        caching.dependency(this_page.page_name, inc_name.lower(), macro.request)
    # output formatted
    buffer = cStringIO.StringIO()
    formatter.request.redirect(buffer)
    parser.format(formatter, inline_edit_default_state=False)

    formatter.setPage(this_page)
    formatter.request.redirect()
    text = buffer.getvalue().decode('utf-8')
    buffer.close()
    result.append(text)
              
    # decrement or remove include marker
    if this_page._macroInclude_pagelist[inc_name] > 1:
        this_page._macroInclude_pagelist[inc_name] -= 1
    else:
        del this_page._macroInclude_pagelist[inc_name]


    attrs = ''
    if align:
    	attrs += (' style="width: %s; float: %s; clear: %s;" ' %
                  (width, align, align))
    elif was_given_width:
        attrs += ' style="width: %s;' % width
    attrs += ' class="includedPage"'
    include_page = '<div%s>%s</div>' % (attrs, ''.join(result))

    ## turn back on inline editing ability
    parser.formatter.inline_edit = inline_edit_state
    formatter.inline_edit = inline_edit_state

    # return include text
    return include_page