Beispiel #1
0
def execute(pagename, request):
    _ = request.getText
    actname = __name__.split('.')[-1]
    page = PageEditor(pagename, request)
    pagetext = page.get_raw_body()
    msg = ''

    # be extra paranoid in dangerous actions
    if (actname in config.excluded_actions or not request.user.may.edit(page)
            or not request.user.may.delete(page)):
        msg = _('You are not allowed to rename pages in this wiki!')

    # check whether page exists at all
    elif not page.exists():
        msg = _('This page is already deleted or was never created!')

    # check whether the user clicked the delete button
    elif (request.form.has_key('button')
          and request.form.has_key('newpagename')
          and request.form.has_key('ticket')):
        # check whether this is a valid renaming request (make outside
        # attacks harder by requiring two full HTTP transactions)
        if not _checkTicket(request.form['ticket'][0]):
            msg = _('Please use the interactive user '
                    'interface to rename pages!')
        else:
            renamecomment = request.form.get('comment', [''])[0]
            # strip to ensure naming consistency
            newpagename = request.form.get('newpagename')[0].strip()
            if newpagename == pagename:
                return Page(pagename, request).send_page(
                    msg="You can't rename a page to the name it already has!")
            try:
                newpage = PageEditor(newpagename, request)
            except Page.ExcessiveLength, msg:
                return Page(pagename, request).send_page(msg=msg)

            if len(renamecomment) > wikiaction.MAX_COMMENT_LENGTH:
                msg = _('Comments must be less than %s characters long.' %
                        wikiaction.MAX_COMMENT_LENGTH)
            elif len(newpagename) > MAX_PAGENAME_LENGTH:
                msg = _('Page names must be less than %s characters long.' %
                        MAX_PAGENAME_LENGTH)
            # check whether a page with the new name already exists
            elif (newpage.exists()
                  and not (newpagename.lower() == pagename.lower())):
                msg = _('A page with the name "%s" already exists!') % (
                    newpagename)

            elif not wikiaction.isValidPageName(newpagename):
                msg = _('Invalid pagename: Only the characters A-Z, a-z, 0-9, '
                        '"$", "&", ",", ".", "!", "\'", ":", ";", " ", "/", '
                        '"-", "(", ")" are allowed in page names.')

            # we actually do a rename!
            else:
                if renamecomment: renamecomment = " (" + renamecomment + ")"
                if newpagename.lower() != pagename.lower():
                    page.saveText("#redirect %s" % newpagename,
                                  '0',
                                  comment='Renamed to "%s"' % newpagename,
                                  action='RENAME',
                                  force_save=True)
                    # copy images over
                    copy_files(pagename, newpagename, request)

                newpage.saveText(pagetext,
                                 '0',
                                 comment='Renamed from "%s"%s' %
                                 (pagename, renamecomment),
                                 action="RENAME",
                                 proper_name=newpagename)

                msg = _('Page "%s" was successfully renamed to "%s"!') % (
                    pagename, newpagename)
                if newpagename.lower() != pagename.lower():
                    # check favorites because the redirect will
                    # process before the bookmarks get updated
                    if request.user.valid:
                        request.user.checkFavorites(page)

                    request.http_redirect(
                        '%s/%s?action=show&redirect=%s' %
                        (request.getScriptname(),
                         wikiutil.quoteWikiname(newpagename),
                         urllib.quote_plus(pagename.encode(config.charset),
                                           '')))

                    request.req_cache['pagenames'][(
                        newpagename.lower(),
                        request.config.wiki_name)] = newpagename
                    # we clear so the new page name appears
                    caching.CacheEntry(newpagename.lower(), request).clear()
                    return
                else:
                    request.req_cache['pagenames'][(
                        newpagename.lower(),
                        request.config.wiki_name)] = newpagename
                    # we clear so the new page name appears
                    caching.CacheEntry(newpagename.lower(), request).clear()
                    return newpage.send_page(msg)
Beispiel #2
0
    def handleData(self):
        _ = self._
        form = self.request.form
        msg = ''
    
        settings_pagename = "%s/%s" % (config.wiki_settings_page,
                                       config.wiki_settings_page_general)
        if self.request.user.may.admin(Page(settings_pagename, self.request)):
            # try to get the wiki name, if empty return an errror message
            if (form.has_key('wikiname') and
                form['wikiname'][0].replace('\t', '').strip()):
                sitename = form['wikiname'][0]
                if len(sitename) > 32:
                    return _("Your sitename must be less than 32 characters "
                             "long!")
                self.request.config.sitename = sitename
            else:
                return _("Please enter a name for your wiki!")

            if (form.has_key('catchphrase') and
                form['catchphrase'][0].replace('\t', '').strip()):
                catchphrase = form['catchphrase'][0]
                if len(catchphrase) > 100:
                    return _("Please enter a catchphrase for your wiki!")
                self.request.config.catchphrase = catchphrase
            if (form.has_key('edit_agreement_text') and
                form['edit_agreement_text'][0].replace('\t', '').strip()):
                edit_agreement_text = form['edit_agreement_text'][0] 
                if len(edit_agreement_text) > SANE_TEXT_UPPER_LIMIT:
                    return _("Too much edit agreement text...enter less!")
                self.request.config.edit_agreement_text = \
                    wikiutil.sanitize_html(edit_agreement_text)
            if (form.has_key('license_text') and
                form['license_text'][0].replace('\t', '').strip()):
                license_text = form['license_text'][0]
                if len(license_text) > SANE_TEXT_UPPER_LIMIT:
                    return _("Too much license text...enter less!")
                self.request.config.license_text = \
                    wikiutil.sanitize_html(license_text)
            if (form.has_key('tabs_nonuser') and
                form['tabs_nonuser'][0].replace('\t', '').strip()):
                tabs_nonuser_text = form['tabs_nonuser'][0]
                if len(tabs_nonuser_text) > SANE_TEXT_UPPER_LIMIT:
                    return _("Too much text in the tabs area...enter less!")
                tabs_nonuser = tabs_nonuser_text.strip().split('\n')
                fixed_tabs_nonuser = []
                for pagename in tabs_nonuser:
                  if not isValidPageName(pagename):
                    return _('"%s" is not a valid page name.  '
                             'You may only set tabs to page names..sorry!' % (
                                wikituil.escape(pagename)))
                  fixed_tabs_nonuser.append(pagename.strip())
                self.request.config.tabs_nonuser = fixed_tabs_nonuser
            if (form.has_key('tabs_user') and
                form['tabs_user'][0].replace('\t', '').strip()):
                tabs_user_text = form['tabs_user'][0]
                if len(tabs_user_text) > SANE_TEXT_UPPER_LIMIT:
                    return _("Too much text in the tabs area...enter less!")
                tabs_user = tabs_user_text.strip().split('\n')
                fixed_tabs_user = []
                for pagename in tabs_user:
                  if not isValidPageName(pagename):
                    return _('"%s" is not a valid page name.  '
                             'You may only set tabs to page names..sorry!' % (
                                pagename))
                  fixed_tabs_user.append(pagename.strip())
                self.request.config.tabs_user = fixed_tabs_user
            
            footer_buttons = []
            for num in range(1,4):
                formkey = 'footer_button_%i' % num
                if (form.has_key(formkey) and
                    form[formkey][0].replace('\t', '').strip()):
                    butttext = form[formkey][0]
                    if len(butttext) > SANE_TEXT_UPPER_LIMIT:
                        return _("Too much text in your footer button %i" % num,
                                 "..enter less!")
                    if form.has_key('footer_sanitize_%i' % num):
                        footer_buttons.append(wikiutil.sanitize_html(butttext))
                    else:
                        footer_buttons.append('<!-- NOSANITIZE -->' + butttext)

            self.request.config.footer_buttons = footer_buttons
            if form.has_key('tz'):
                tz = form['tz'][0]
                if tz  in pytz.common_timezones:
                    self.request.config.tz = tz
            if form.has_key('address_locale'):
                address_locale = form['address_locale'][0]
                if len(address_locale) > 40:
                    return _("Too much text in your address locale"
                             "..enter less!")
                address_locale = address_locale
                self.request.config.address_locale = address_locale
            else:
                self.request.config.address_locale = ''

            checkbox_fields = config.local_config_checkbox_fields
            for key, description in checkbox_fields:
                if form.has_key(key):
                    self.request.config.__dict__[key] = True
                    if key == 'is_disabled':
                        msg = ("<p>You have <strong>marked this wiki as "
                               "deleted</strong>.  The wiki will be deleted "
                               "permanently in 30 days.  If you made a "
                               "mistake, uncheck the \"delete this wiki\" "
                               "checkbox.</p>"
                               "<p>Until this wiki is permanently purged, "
                               "it will be be visible only to the admins of "
                               "this wiki.</p>")
                else:
                    self.request.config.__dict__[key] = False

            # sets the config -- becomes active as soon as this line is
            # executed!
            self.request.config.set_config(self.request.config.wiki_name,
                                           self.request.config.get_dict(),
                                           self.request)
            return _("General settings updated!") + msg
Beispiel #3
0
def execute(pagename, request):
    _ = request.getText
    actname = __name__.split('.')[-1]
    page = PageEditor(pagename, request)
    pagetext = page.get_raw_body()
    msg = ''

    # be extra paranoid in dangerous actions
    if (actname in config.excluded_actions or not
        request.user.may.edit(page) or not request.user.may.delete(page)):
            msg = _('You are not allowed to rename pages in this wiki!')

    # check whether page exists at all
    elif not page.exists():
        msg = _('This page is already deleted or was never created!')

    # check whether the user clicked the delete button
    elif (request.form.has_key('button') and
          request.form.has_key('newpagename') and
          request.form.has_key('ticket')):
        # check whether this is a valid renaming request (make outside
        # attacks harder by requiring two full HTTP transactions)
        if not _checkTicket(request.form['ticket'][0]):
            msg = _('Please use the interactive user '
                    'interface to rename pages!')
        else:
            renamecomment = request.form.get('comment', [''])[0]
            # strip to ensure naming consistency
            newpagename = request.form.get('newpagename')[0].strip() 
            if newpagename == pagename:
                return Page(pagename, request).send_page(
                    msg="You can't rename a page to the name it already has!")
            try:
                newpage = PageEditor(newpagename, request)
            except Page.ExcessiveLength, msg:
                return Page(pagename, request).send_page(msg=msg)

            if len(renamecomment) > wikiaction.MAX_COMMENT_LENGTH:
                msg = _('Comments must be less than %s characters long.' %
                         wikiaction.MAX_COMMENT_LENGTH)
            elif len(newpagename) > MAX_PAGENAME_LENGTH:
               msg = _('Page names must be less than %s characters long.' %
                         MAX_PAGENAME_LENGTH)
            # check whether a page with the new name already exists
            elif (newpage.exists() and not
                  (newpagename.lower() == pagename.lower())):
                msg = _('A page with the name "%s" already exists!') % (
                        newpagename)

            elif not wikiaction.isValidPageName(newpagename):
                msg = _('Invalid pagename: Only the characters A-Z, a-z, 0-9, '
                        '"$", "&", ",", ".", "!", "\'", ":", ";", " ", "/", '
                        '"-", "(", ")" are allowed in page names.')
                
            # we actually do a rename!
            else:
                if renamecomment: renamecomment = " (" + renamecomment + ")"
                if newpagename.lower() != pagename.lower(): 
                    page.saveText("#redirect %s" % newpagename, '0',
                                  comment='Renamed to "%s"' % newpagename,
                                  action='RENAME', force_save=True)
                    # copy images over
                    copy_files(pagename, newpagename, request)

                newpage.saveText(pagetext, '0',
                                 comment='Renamed from "%s"%s' %
                                    (pagename, renamecomment),
                                 action="RENAME", proper_name=newpagename)

                msg = _('Page "%s" was successfully renamed to "%s"!') % (
                        pagename,newpagename)
                if newpagename.lower() != pagename.lower():
                    # check favorites because the redirect will
                    # process before the bookmarks get updated
                    if request.user.valid:
                        request.user.checkFavorites(page)

                    request.http_redirect('%s/%s?action=show&redirect=%s' % (
                        request.getScriptname(),
                        wikiutil.quoteWikiname(newpagename),
                        urllib.quote_plus(pagename.encode(config.charset), '')))

                    request.req_cache['pagenames'][
                        (newpagename.lower(),
                         request.config.wiki_name)] = newpagename
                    # we clear so the new page name appears
                    caching.CacheEntry(newpagename.lower(), request).clear()
                    return
                else:
                  request.req_cache['pagenames'][
                    (newpagename.lower(),
                     request.config.wiki_name)] = newpagename
                  # we clear so the new page name appears
                  caching.CacheEntry(newpagename.lower(), request).clear() 
                  return newpage.send_page(msg)