Description
For new wiki users, new page create from templates contains variables like @ME@, @MONDAY@, @WEEK@ may confused them. What if the macros are expanded before saving the page.
8-) not be confused, @MONDAY@, @WEEK@ are variables for my patched wiki.
Solution
When create new page from template, expand some of the variables from the template, and fill into the new page.
Much of the mystery on variables is hidden from end user.
Patch on this
Below is my patch. Use it at your own risk.
1 Expand variables in page edit form when load contents from template.
2
3 diff -r 0865ccb99181 MoinMoin/PageEditor.py
4 --- a/MoinMoin/PageEditor.py Wed Nov 19 10:25:14 2008 +0800
5 +++ b/MoinMoin/PageEditor.py Wed Nov 19 10:25:16 2008 +0800
6 @@ -281,6 +281,9 @@
7 template_page = wikiutil.unquoteWikiname(form['template'][0])
8 if request.user.may.read(template_page):
9 raw_body = Page(request, template_page).get_raw_body()
10 + # OSSXP: expand variables in page edit form when load contents from template.
11 + if not wikiutil.isTemplatePage(request, self.page_name):
12 + raw_body = self._expand_variables(raw_body)
13 if raw_body:
14 request.theme.add_msg(_("[Content of new page loaded from %s]") % (template_page, ), 'info')
15 else:
16 @@ -795,7 +798,7 @@
17
18 return time.strftime("%Y-%m-%dT%H:%M:%S", timefuncs.tmtuple(now)) + zone
19
20 - def _expand_variables(self, text):
21 + def _expand_variables(self, text, preload=False):
22 """ Expand @VARIABLE@ in `text`and return the expanded text.
23
24 @param text: current text of wikipage
25 @@ -830,7 +833,12 @@
26 userDictPage = u.name + "/MyDict"
27 if request.dicts.has_dict(userDictPage):
28 variables.update(request.dicts.dict(userDictPage))
29 -
30 + # OSSXP: expand variables in page edit form when load contents from template.
31 + if preload:
32 + variables['SIG'] = "-- %s @TIME@" % signature
33 + for name in ['TIME','DATE']:
34 + if variables.has_key(name):
35 + del variables[name]
36 for name in variables:
37 text = text.replace('@%s@' % name, variables[name])
38 return text
@SIG@