Short description

Sometimes I use a wiki for exercises. I like to add the solution on demand to the question. e.g.:

Include_patch.png

By this patch you got the button Include added at the place where you write

[[Include(Solution,,,on_demand=1)]]

[[IncludeMe(Lösung1, , to="^----$",on_demand=1,button_name=Beispiel)]]

After selecting it include is accomplished. If you have more as one on_demand button in your page only the one you have selected do accomplish include.

What do you think about this additional option? -- ReimarBauer 2005-10-24 21:39:20

For the patch I have used the 1.5.0 alpha Include.py

--- Include.py  2005-10-16 22:55:56.000000000 +0200
+++ Include.py  2005-10-25 22:00:43.652908160 +0200
@@ -10,6 +10,7 @@
     
     @copyright: 2000-2004 by Jürgen Hermann <jh@web.de>
     @copyright: 2000-2001 by Richard Jones <richard@bizarsoftware.com.au>
+    @copyright: 2005-10-25 by Reimar Bauer <R.Bauer@fz-juelich.de> on_demand button action added
     @license: GNU GPL, see COPYING for details.
 """
 
@@ -33,9 +34,12 @@
 _arg_skipitems = r'(,\s*skipitems=(?P<skipitems>\d+))?'
 _arg_titlesonly = r'(,\s*(?P<titlesonly>titlesonly))?'
 _arg_editlink = r'(,\s*(?P<editlink>editlink))?'
-_args_re_pattern = r'^(?P<name>[^,]+)(%s(%s)?%s%s%s%s%s%s%s)?$' % (
+_arg_on_demand = r'(,\s*on_demand=(?P<on_demand>\d+))?'
+_arg_button_name = r'(,\s*button_name=(?P<button_name>(?P<text>.+?)))?$'
+
+_args_re_pattern = r'^(?P<name>[^,]+)(%s(%s)?%s%s%s%s%s%s%s%s%s)?$' % (
     _arg_heading, _arg_level, _arg_from, _arg_to, _arg_sort, _arg_items,
-    _arg_skipitems, _arg_titlesonly, _arg_editlink)
+    _arg_skipitems, _arg_titlesonly, _arg_editlink, _arg_on_demand,_arg_button_name )
 
 _title_re = r"^(?P<heading>\s*(?P<hmarker>=+)\s.*\s(?P=hmarker))$"
 
@@ -53,16 +57,51 @@
 def execute(macro, text, args_re=re.compile(_args_re_pattern), title_re=re.compile(_title_re, re.M), called_by_toc=0):
     request = macro.request
     _ = request.getText
-
     # return immediately if getting links for the current page
     if request.mode_getpagelinks:
         return ''
-
+    
     # parse and check arguments
     args = args_re.match(text)
     if not args:
         return (_sysmsg % ('error', _('Invalid include arguments "%s"!')) % (text,))
 
+    on_demand = args.group('on_demand')
+    button_name = args.group('button_name')
+    if button_name == None :
+        button_name = 'Include'
+      
+    if on_demand :
+     
+        if request.form.has_key('button') and request.form.has_key('ticket'):
+        # check whether this is a valid request
+            if not wikiutil.checkTicket(request.form['ticket'][0]) :
+                  return thispage.send_page(request,
+                      msg = _('Please use the interactive user interface !'))
+            if request.form['name'][0] == args.group('name') :
+               return Include(macro, text, args_re=re.compile(_args_re_pattern), title_re=re.compile(_title_re, re.M), called_by_toc=0)
+        formhtml = '''
+<form method="post" action="">
+<input type="submit" name="button" value="%(button)s">
+<input type="hidden" name="ticket" value="%(ticket)s">
+<input type="hidden" name="name" value="%(text)s">
+<p>
+</form>''' % {
+    'text'   : args.group('name'),
+    'ticket' : wikiutil.createTicket(),
+    'button' : button_name}
+    
+        return formhtml
+    else:
+       return Include(macro, text, args_re=re.compile(_args_re_pattern), title_re=re.compile(_title_re, re.M), called_by_toc=0)
+    
+def Include(macro, text, args_re=re.compile(_args_re_pattern), title_re=re.compile(_title_re, re.M), called_by_toc=0):
+    request = macro.request
+    _ = request.getText
+   
+    # parse and check arguments
+    args = args_re.match(text)
+
     # prepare including page
     result = []
     print_mode = macro.form.has_key('action') and macro.form['action'][0] in ("print", "format")

Discussion

A simpler way would be to render the solution invisible, and toggle the visibility with javascript. Such solution can be easily implemented with SectionParser, using toggle script like in this html: toggle.html

I like the toggle version the best. It is faster for the user. Also it would be nice to have that option in a link instead of a form button. It would be nice if, like external links, an icon was placed infront of the link. The icon could be a downward pointing triangle and if you clicked that instead of the link it would drop the content into the page. This format would be much more subtle than a form button, but would also probably be more difficult to implement. I am interested in using this feature to write tutorials. It is nice when writing a tutorial to link off to other pages for troubleshooting or details involved in each step of a lengthy process. It would be even nicer to have optional information drop down into the page.

(!) Moin 1.6 has inline comments, see HelpOnComments. If the user chooses not to see comments (see UserPreferences) by default, this solves this feature request (thus I tag this as implemented). -- ThomasWaldmann 2007-11-17 16:49:45


CategoryFeatureRequest CategoryMoinMoinPatch CategoryFeatureImplemented

MoinMoin: FeatureRequests/IncludeOnDemand (last edited 2007-11-17 16:49:45 by ThomasWaldmann)