# -*- coding: iso-8859-1 -*-
"""  
     MoinMoin - MyWikiPages action  
   
     Copyright (c) 2006 by Keith Schwols <kcs@fc.intel.com>
     All rights reserved, see COPYING for details.  
   
     2006 - kcs
       The MyWikiPages action shows you all the pages in the Wiki that you have created.
       The output is a list similar to the TitleIndex or WordIndex pages.

       This action requires the MyWikiPages macro code to function.
     """  

from MoinMoin import config, util, wikiutil
import re
 
def execute(pagename, request):
    """
    optional parameters:
    @user = UserName you wish a report for.  Current User is not specified
    @max_days = number of days to go back in the log.  Default is beginning of time
    @hide_deleted = 1 if you want skip reporting non-existent pages
    """
    my_pages = wikiutil.importPlugin(request.cfg, 'macro', 'MyWikiPages')
    my_pages.request = request
    my_pages.formatter = request.formatter
    my_pages.formatter.page = request.page

    request.http_headers()
    # This action generate data using the user language
    request.setContentLanguage(request.lang)

    wikiutil.send_title(request, 'MyWikiPages', pagename=pagename)

    request.write(request.formatter.startContent("content"))

    ##ToDo find a standard MoinMoin mechanism to parse args
    args=""
    user = str(request.form.get('user',[''])[0])
    if user != '':
      args = "user=%s" % user
    max_days = int(request.form.get('max_days', [0])[0])
    if max_days != 0:
      args = args + ", max_days=%03d" % max_days
    hide_deleted = int(request.form.get('hide_deleted',[0])[0])
    if hide_deleted == 1:
      args = args + ", hide_deleted=1"
    my_pages(my_pages,args);

    # End content and send footer
    request.write(request.formatter.endContent())
    wikiutil.send_footer(request, pagename)
