Esempio n. 1
0
 def testTemplatePage(self):
     """wikiutil: good template names accepted, bad rejected"""
     for name in self.good:
         self.assert_(wikiutil.isTemplatePage(self.request, name),
             '"%(name)s" is a valid template name' % locals())
     for name in self.bad:
         self.failIf(wikiutil.isTemplatePage(self.request, name),
             '"%(name)s" is NOT a valid template name' % locals())
Esempio n. 2
0
    def parse_page(self, page):
        text = page.getPageText()
        header = page.getPageHeader()

        title = page.page_name
        summary = ''
        logo = ''

        title_end_idx = None
        summary_end_idx = None
        match = re.search('<<Logo\\(attachment=([^)]+)\\)>>', text)
        if match != None:
            logo = match.group(1)
        match = re.search('= (.*) =', text)
        if match != None:
            title = match.group(1)
            title_end_idx = match.end(0)
            summary_end_idx1 = text.find('== ')
            summary_end_idx2 = text.find('{{')
            summary_end_idx = summary_end_idx1
            if summary_end_idx2 != -1 and summary_end_idx2 < summary_end_idx1:
                summary_end_idx = summary_end_idx2
            summary = text[title_end_idx:summary_end_idx]
            summary = summary.strip()

        categories = []
        locations = []

        if not wikiutil.isTemplatePage(self.request, page.page_name):
            match = re.search(u'## 关键字:([^\r\n]*)\r?\n?', header)
            if match != None:
                categories = match.group(1).split()
            match = re.search(u'## 地域标签:([^\r\n]*)\r?\n?', header)
            if match != None:
                locations = match.group(1).split()

        return {
            'title': title,
            'summary': summary,
            'logo': logo,
            'categories': categories,
            'locations': locations,
            'lastmodified': page.mtime_usecs()
        }
Esempio n. 3
0
 def testTemplatePage(self):
     """wikiutil: good template names accepted, bad rejected"""
     for name in self.good:
         assert  wikiutil.isTemplatePage(self.request, name)
     for name in self.bad:
         assert not wikiutil.isTemplatePage(self.request, name)
Esempio n. 4
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