Attachment 'macro_MyWikiPages.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - MyPages Macro
   4 
   5     @copyright: 2006-2006 by Keith Schwols (renegade_gourmet@yahoo.com)
   6     @license: GNU GPL, see COPYING for details.
   7 """
   8 
   9 import re, time
  10 from MoinMoin import util, wikiutil, config
  11 from MoinMoin.Page import Page
  12 from MoinMoin.logfile import editlog
  13 from MoinMoin.user import getUserId, getUserIdentification 
  14 
  15 _MAX_DAYS=999 
  16 _MAX_PAGENAME_LENGTH=35
  17 #############################################################################
  18 ### MyPages Macro
  19 #############################################################################
  20 
  21 def _mypages_header(self):
  22     """
  23     Completely stolen from the theme/__init.py__, however we don't want
  24     all the bells and whistles (RSS link, preample etc.)
  25     But, we do like the 'theme' controled table vision
  26     """
  27     html = '<div class="recentchanges"%s>\n' % self.ui_lang_attr()
  28     html += '<div>\n'
  29     html += '<p>'
  30     html += '</p>\n</div>\n'
  31     html += '<table>\n'
  32     return html
  33 
  34 def _mypages_footer():
  35     """
  36     Complete the RecentChanges like table
  37     """
  38     html = ''
  39     html += '</table>\n'
  40     html += '</div>\n'
  41     return html
  42 
  43 def execute(macro, args):
  44     """
  45     Define args accepted here
  46     @max_days - limit log to last 'n' days
  47     @user - if not current user
  48     @hide_deleted = 1 if you wish to skip non-existent pages (created and subsequently deleted)
  49     @list_only =1 if you wish a single <OL> list
  50     """
  51     request = macro.request
  52     formatter = macro.formatter
  53     user = request.user
  54 
  55     ## KCS TBD: should find a standard MoinMoin args parser - is there one?
  56     if args:
  57         args = args.split(',')
  58         args = [arg.strip() for arg in args]
  59     else:
  60         args = []
  61 
  62     kw = {} # create a dictionary for the formatter.image call
  63     for arg in args :
  64         if '=' in arg:
  65             key, value = arg.split('=', 1)
  66             kw[str(key)] = wikiutil.escape(value, quote=1)
  67 
  68     if kw.has_key('user'):
  69       user.name = kw['user']
  70       user.id = getUserId(request,user.name)
  71 
  72     max_days = int(kw.get('max_days',_MAX_DAYS))
  73     msg = ""
  74     if not max_days == _MAX_DAYS:
  75         msg = "within the last %s days" % max_days
  76     tnow = time.time()
  77     tthen = tnow - max_days * 24 * 60 * 60;
  78 
  79     page = formatter.page
  80     pagename = page.page_name
  81     
  82     log = editlog.EditLog(request)
  83 
  84     pages = {}
  85     pagelist = [];
  86     # Process the global logfile and save all the matching page create messages in the pagelist 
  87     for line in log.reverse():
  88         if not request.user.may.read(line.pagename):
  89             continue
  90     
  91         if (line.ed_time_usecs/1000000) < tthen:
  92             continue
  93 
  94 	pages[line.pagename] = [line]
  95 	if kw.get('hide_deleted',0):
  96 	   page = Page(request, line.pagename)
  97 	   if not page.exists():
  98 	      continue
  99 	if line.action == "SAVENEW"  and line.userid == user.id:
 100             pagelist.append(line.pagename)
 101 
 102     # Sort ignoring case
 103     tmp = [(name.upper(), name) for name in pagelist]
 104     tmp.sort()
 105     pagelist = [item[1] for item in tmp]
 106 
 107     request.write("<h2>%d %s %s %s\n<br></h2>" % (len(pagelist),' Pages created by ',user.name, msg))
 108 
 109     # Use the Table is we have more than 2 entries, otherwise simple list (or message of 0 pages)
 110     if not kw.get('list_only',1) or len(pagelist) > 2:
 111 	d = {} # data dictionary to theme
 112         index_letters = []
 113 	info_img = request.theme.make_icon('info')
 114         diff_img = request.theme.make_icon('diffrc')
 115         del_img =  request.theme.make_icon('deleted')
 116         new_img =  request.theme.make_icon('new')
 117         current_letter = None
 118 	request.write(_mypages_header(request.theme))
 119         for name in pagelist:
 120             page = Page(request,name)
 121             (file, rev, exists) = page.get_rev()
 122             letter = wikiutil.getUnicodeIndexGroup(name)
 123             if letter not in index_letters:
 124                 index_letters.append(letter)
 125             if letter != current_letter:
 126                 current_letter = letter
 127 		d['date'] = letter
 128                 d['bookmark_link_html'] = None
 129                 request.write(request.theme.recentchanges_daybreak(d))
 130             d['icon_html'] = ''
 131             if exists:
 132               if rev == 1:
 133 		d['icon_html'] = wikiutil.link_tag(request,
 134 						   wikiutil.quoteWikinameURL(name),
 135                                                    new_img, formatter=macro.formatter)
 136               else:
 137 		d['icon_html'] = wikiutil.link_tag(request,
 138 						   wikiutil.quoteWikinameURL(name) + "?action=diff",
 139 						   diff_img, formatter=macro.formatter)
 140             else:
 141 		d['icon_html'] = del_img
 142  
 143 	    dispname = name 
 144 	    if len(name) > _MAX_PAGENAME_LENGTH:
 145 		dispname = name.replace('/','/ ')
 146 
 147 	    d['pagelink_html'] = page.link_to(request, attachment_indicator=1, text=dispname)
 148                                               
 149             line=pages[name][0]
 150             line.time_tuple = request.user.getTime(wikiutil.version2timestamp(line.ed_time_usecs))
 151 	    d['time_html'] = 'Created: ' + time.strftime(request.cfg.date_fmt, line.time_tuple)
 152             d['info_html'] = wikiutil.link_tag(request,
 153 					       wikiutil.quoteWikinameURL(name) + "?action=info",
 154 					       info_img, formatter=macro.formatter)
 155             # Don't know what to put in the 'editors' column - afraid of information overload 
 156             # User's have the 'action-info' to get the details.
 157 	    d['editors'] = ''
 158             d['comments'] = ''
 159             if exists and rev > 1:
 160 	      comments=[[0,u'%d revisions' % rev]]
 161 	      d['changecount'] = 1
 162 	      d['comments'] = comments
 163             request.write(request.theme.recentchanges_entry(d))
 164         d['rc_msg'] = ''
 165 	request.write(_mypages_footer())
 166 
 167     elif len(pagelist) > 0:
 168       request.write('<ol>')
 169       for pagename in pagelist:
 170 	 page = Page(request, pagename)
 171 	 page_link = page.link_to(request, text=pagename)
 172 	 request.write('<li>')
 173 	 request.write(page_link)
 174 	 request.write('</li>')
 175       request.write('</ol>')
 176     else:
 177       request.write("<emphasis>You have not created any pages on this Wiki!</emphasis>")
 178 
 179     return ''

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-06-22 01:00:23, 1.8 KB) [[attachment:action_MyWikiPages.py]]
  • [get | view] (2006-06-22 01:00:55, 5.9 KB) [[attachment:macro_MyWikiPages.py]]
  • [get | view] (2006-07-13 21:24:38, 146.0 KB) [[attachment:screenshot.png]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.