Description

Editing a page with a template parameter will replace the exiting page text with the content of the template, or with empty string if the template is not readable or missing.

Steps to reproduce

Way 1 - using NewPageMacro:

  1. Enter the name of this page in the text field and click the button...

Way 2 - using a link:

  1. Try this: http://moinmoin.wikiwikiweb.de:80/MoinMoinBugs/NewPageOverwritesExistingPage?action=edit&template=HomepageTemplate

In both ways, the content of this page will be replaced with the content of HomepageTemplate, with no warning.

Way 3 - with non existing template page:

  1. Try this: http://moinmoin.wikiwikiweb.de:80/MoinMoinBugs/NewPageOverwritesExistingPage?action=edit&template=NoSuchTemplate

The content of this page will be replaced with the "Describe this page", with no warning.

The expected behavior is (I think) simply open an editor with the existing page content.

Its not clear what should happen with a deleted page - get automatically the latest revision, or ignore it?

Details

This Wiki.

Workaround

Do a search before adding a new page - what is always recommended ;-)

Discussion

This is huge bug, but easy to fix. The problem is not in the newpage action, but in PageEditor, when trying to edit a page with a template, it should not overwrite existing page text. template=xxx should work only for non existing pages, that have empty text.

This patch fix the problem by ignoring template argument if the page exists:

   1 * looking for arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-665 to compare with
   2 * comparing to arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-665
   3 M  MoinMoin/PageEditor.py
   4 
   5 * modified files
   6 
   7 --- orig/MoinMoin/PageEditor.py
   8 +++ mod/MoinMoin/PageEditor.py
   9 @@ -285,22 +285,35 @@
  10          
  11          self.request.write(self.request.formatter.startContent("content"))
  12          
  13 -        # get the text body for the editor field
  14 -        if form.has_key('template'):
  15 -            # "template" parameter contains the name of the template page
  16 -            template_page = wikiutil.unquoteWikiname(form['template'][0])
  17 +        # Get the text body for the editor field.
  18 +
  19 +        # TODO: what about deleted pages? show the text of the last
  20 +        # revision or use the template?
  21 +
  22 +        raw_body = ''
  23 +        if self.exists():
  24 +            # If the page exists, we get the text from the page.
  25 +
  26 +            # TODO: maybe warn if template argument was ignored becuase
  27 +            # the page exists?
  28 +            
  29 +            raw_body = self.get_raw_body()
  30 +        elif form.has_key('template'):
  31 +            # If the page does not exists, we try to get the content
  32 +            # from the template parameter.
  33 +            template_page = form['template'][0]
  34              if self.request.user.may.read(template_page):
  35                  raw_body = Page(self.request, template_page).get_raw_body()
  36                  if raw_body:
  37 -                    self.request.write(_("[Content of new page loaded from %s]") % (template_page,), '<br>')
  38 +                    self.request.write(_("[Content of new page loaded from %s]") %
  39 +                                       (template_page,), '<br>')
  40                  else:
  41 -                    self.request.write(_("[Template %s not found]") % (template_page,), '<br>')
  42 +                    self.request.write(_("[Template %s not found]") %
  43 +                                       (template_page,), '<br>')
  44              else:
  45 -                raw_body = ''
  46 -                self.request.write(_("[You may not read %s]") % (template_page,), '<br>')
  47 -        else:
  48 -            raw_body = self.get_raw_body()
  49 -
  50 +                self.request.write(_("[You may not read %s]") %
  51 +                                   (template_page,), '<br>')
  52 +        
  53          # send text above text area
  54          template_param = ''
  55          if form.has_key('template'):
template.patch

There are two more problems with the code, but I don't want to add those fixes to this commit:

I don't commit it because I'm not completely sure about this, so check it and comment. -- NirSoffer 2005-03-13 21:20:21

This patch causes another bug in 1.3.5: if you preview a page which is not saved to a file yet, your changes are lost. (i.e., after creating new empty page, you preview, then all changes are lost) . The patch should be as following:

Plan


CategoryMoinMoinBugFixed

MoinMoin: MoinMoinBugs/NewPageOverwritesExistingPage (last edited 2007-10-29 19:06:41 by localhost)