Esempio n. 1
0
 def testFormPage(self):
     """wikiutil: good form names accepted, bad rejected"""
     for name in self.good:
         self.assert_(wikiutil.isFormPage(self.request, name),
             '"%(name)s" is a valid form name' % locals())
     for name in self.bad:
         self.failIf(wikiutil.isFormPage(self.request, name),
             '"%(name)s" is NOT a valid form name' % locals())
Esempio n. 2
0
def execute(macro, args):
    _ = macro.request.getText
    pagename = args

    if not wikiutil.isFormPage(macro.request, pagename):
        return (macro.formatter.sysmsg(1) +
                macro.formatter.text('Not a form page: %s' % args) +
                macro.formatter.sysmsg(0))

    formpage = Page(macro.request, pagename)
    body = formpage.get_raw_body()

    pi_formtext = []
    pi_formfields = []

    while body and body[0] == '#':
        # extract first line
        try:
            line, body = body.split('\n', 1)
        except ValueError:
            line = body
            body = ''

        # skip comments (lines with two hash marks)
        if line[1] == '#': continue

        # parse the PI
        verb, args = (line[1:]+' ').split(' ', 1)
        verb = verb.lower()
        args = args.strip()

        if verb != 'form': continue

        # collect form definitions
        if not pi_formtext:
            pi_formtext.append('<table border="1" cellspacing="1" cellpadding="3">\n'
                '<form method="POST" action="%s">\n'
                '<input type="hidden" name="action" value="formtest">\n' % 'action')
        pi_formtext.append(wikiform.parseDefinition(macro.request, args, pi_formfields))

    # user-defined form preview?
    if pi_formtext:
        pi_formtext.append('<input type="hidden" name="fieldlist" value="%s">\n' %
            "|".join(pi_formfields))
        pi_formtext.append('</form></table>\n')

    return macro.formatter.rawHTML(''.join(pi_formtext))
Esempio n. 3
0
    def saveText(self, newtext, rev, **kw):
        """ Save new text for a page.

        @param newtext: text to save for this page
        @param rev: revision of the page
        @keyword trivial: trivial edit (default: 0)
        @keyword extra: extra info field (e.g. for SAVE/REVERT with revno)
        @keyword comment: comment field (when preview is true)
        @keyword action: action for editlog (default: SAVE)
        @rtype: unicode
        @return: error msg
        """
        _ = self._
        backup_url = self._make_backup(newtext, **kw)
        action = kw.get('action', 'SAVE')

        #!!! need to check if we still retain the lock here
        #!!! rev check is not enough since internal operations use "0"

        # expand variables, unless it's a template or form page
        if not (wikiutil.isTemplatePage(self.request, self.page_name) or
                wikiutil.isFormPage(self.request, self.page_name)):
            newtext = self._expand_variables(newtext)

        msg = ""
        if not self.request.user.may.save(self, newtext, rev, **kw):
            msg = _('You are not allowed to edit this page!')
            raise self.AccessDenied, msg
        elif not self.isWritable():
            msg = _('Page is immutable!')
            raise self.Immutable, msg
        elif not newtext:
            msg = _('You cannot save empty pages.')
            raise self.EmptyPage, msg
        elif rev != 0 and rev != self.current_rev():
            msg = _("""Sorry, someone else saved the page while you edited it.

Please do the following: Use the back button of your browser, and cut&paste
your changes from there. Then go forward to here, and click EditText again.
Now re-add your changes to the current page contents.

''Do not just replace
the content editbox with your version of the page, because that would
delete the changes of the other person, which is excessively rude!''
""")

            if backup_url:
                msg += "<p>%s</p>" % _(
                    'A backup of your changes is [%(backup_url)s here].') % {'backup_url': backup_url}
            raise self.EditConflict, msg
        elif newtext == self.get_raw_body():
            msg = _('You did not change the page content, not saved!')
            raise self.Unchanged, msg
        elif self.cfg.acl_enabled:
            from wikiacl import parseACL
            # Get current ACL and compare to new ACL from newtext. If
            # they are not the sames, the user must have admin
            # rights. This is a good place to update acl cache - instead
            # of wating for next request.
            acl = self.getACL(self.request)
            if (not self.request.user.may.admin(self.page_name) and
                parseACL(self.request, newtext) != acl and
                action != "SAVE/REVERT"):
                msg = _("You can't change ACLs on this page since you have no admin rights on it!")
                raise self.NoAdmin, msg
            
        # save only if no error occurred (msg is empty)
        if not msg:
            # set success msg
            msg = _("Thank you for your changes. Your attention to detail is appreciated.")
            
            # determine action for edit log 
            if action == 'SAVE' and not self.exists():
                action = 'SAVENEW'
            comment = kw.get('comment', u'')
            extra = kw.get('extra', u'')
            trivial = kw.get('trivial', 0)
            
            # write the page file
            mtime_usecs, rev = self._write_file(newtext, action, comment, extra)
            self.clean_acl_cache()
  
            # send notification mails
            if self.request.cfg.mail_smarthost:
                msg = msg + self._notifySubscribers(comment, trivial)
          
        # remove lock (forcibly if we were allowed to break it by the UI)
        # !!! this is a little fishy, since the lock owner might not notice
        # we broke his lock ==> but revision checking during preview will
        self.lock.release(force=not msg) # XXX does "not msg" make any sense?
  
        return msg