Attachment 'AttachFile_notify_patch-1.5.8.txt'

Download

   1 diff -r ca98a59c5902 MoinMoin/action/AttachFile.py
   2 --- a/MoinMoin/action/AttachFile.py	Fri Oct 26 09:15:18 2007 +0200
   3 +++ b/MoinMoin/action/AttachFile.py	Tue Nov 20 18:46:08 2007 +0100
   4 @@ -554,6 +554,48 @@ def upload_form(pagename, request, msg='
   5      request.write('</div>\n') # end content div
   6      wikiutil.send_footer(request, pagename)
   7  
   8 +def do_notify(pagename, request, msg):
   9 +    if request.cfg.mail_enabled and request.cfg.mail_attachment_changes:
  10 +        _ = request.getText
  11 +        from MoinMoin.PageEditor import PageEditor
  12 +
  13 +        page =  PageEditor(request, pagename)   
  14 +        trivial = 0    
  15 +        pagelink = request.getQualifiedURL(page.url(request))
  16 +        pagelink += "?action=AttachFile\n\n%s" % msg 
  17 +
  18 +        subscribers = page.getSubscribers(request, return_users=1, trivial=trivial)
  19 +        if subscribers:
  20 +            mailBody = _("Dear Wiki user,\n\n"
  21 +            'You have subscribed to a wiki page or wiki category on "%(sitename)s" for change notification.\n\n'
  22 +            "The following page has been changed by %(editor)s:\n"
  23 +            "%(pagelink)s\n\n" , formatted=False) % {
  24 +                'editor': user.getUserIdentification(request),
  25 +                'pagelink': pagelink,
  26 +                'sitename': request.cfg.sitename or request.getBaseURL(),
  27 +            }
  28 +            # send email to all subscribers
  29 +            results = [_('Status of sending notification mails:')]
  30 +            for lang in subscribers.keys():
  31 +                emails = map(lambda u: u.email, subscribers[lang])
  32 +                names  = map(lambda u: u.name,  subscribers[lang])
  33 +
  34 +                mailok, status = util.mail.sendmail(request, emails,
  35 +                      _('[%(sitename)s] Update of "%(pagename)s" by %(username)s ', formatted=False) % { 
  36 +                                                                                'sitename': request.cfg.sitename or "Wiki",
  37 +                                                                                'pagename': pagename,
  38 +                                                                                'username': user.getUserIdentification(request),
  39 +                                                                                 }, mailBody, mail_from=request.cfg.mail_from)
  40 +                recipients = ", ".join(names)
  41 +                results.append(_('[%(lang)s] %(recipients)s: %(status)s') % {
  42 +                'lang': lang, 'recipients': recipients, 'status': status})
  43 +
  44 +            return '<p>\n%s\n</p> ' % '<br>'.join(results)
  45 +        
  46 +        else:
  47 +            return ""  
  48 +    else: 
  49 +        return ""
  50  
  51  def do_upload(pagename, request, overwrite):
  52      _ = request.getText
  53 @@ -628,6 +670,12 @@ def do_upload(pagename, request, overwri
  54                  " with %(bytes)d bytes saved.") % {
  55                  'target': target, 'filename': filename, 'bytes': bytes}
  56          _addLogEntry(request, 'ATTNEW', pagename, target)
  57 +        # send notification mails
  58 +        result = ""
  59 +        if request.cfg.mail_enabled:
  60 +            result = do_notify(pagename, request, msg)
  61 +                    
  62 +        msg = msg + result
  63  
  64      # return attachment list
  65      upload_form(pagename, request, msg)
  66 @@ -674,8 +722,10 @@ def del_file(pagename, request):
  67      # delete file
  68      os.remove(fpath)
  69      _addLogEntry(request, 'ATTDEL', pagename, filename)
  70 -
  71 -    upload_form(pagename, request, msg=_("Attachment '%(filename)s' deleted.") % {'filename': filename})
  72 +    msg = _("Attachment '%(filename)s' deleted.") % {'filename': filename}
  73 +    result = do_notify(pagename, request, msg)
  74 +    msg = msg + result
  75 +    upload_form(pagename, request, msg=msg)
  76  
  77  def move_file(request, pagename, new_pagename, attachment, new_attachment):
  78      _ = request.getText
  79 @@ -697,9 +747,15 @@ def move_file(request, pagename, new_pag
  80              filesys.rename(attachment_path, new_attachment_path)
  81              _addLogEntry(request, 'ATTDEL', pagename, attachment)
  82              _addLogEntry(request, 'ATTNEW', new_pagename, new_attachment)
  83 -            upload_form(pagename, request, msg=_("Attachment '%(filename)s' moved to %(page)s.") % {
  84 -                                                 'filename': new_attachment,
  85 -                                                 'page': new_pagename})
  86 +            msg = _("Attachment '%(old_filename)s' moved from  %(old_page)s to %(new_page)s as '%(new_filename)s'.") % {
  87 +                                                 'old_filename': attachment,
  88 +                                                 'new_filename': new_attachment,
  89 +                                                 'old_page': pagename,
  90 +                                                 'new_page': new_pagename}
  91 +
  92 +            result = do_notify(pagename, request, msg)
  93 +            msg = msg + result
  94 +            upload_form(pagename, request, msg=msg)
  95          else:
  96              upload_form(pagename, request, msg=_("Nothing changed"))
  97      else:
  98 diff -r ca98a59c5902 MoinMoin/multiconfig.py
  99 --- a/MoinMoin/multiconfig.py	Fri Oct 26 09:15:18 2007 +0200
 100 +++ b/MoinMoin/multiconfig.py	Tue Nov 20 16:17:43 2007 +0100
 101 @@ -281,6 +281,7 @@ reStructuredText Quick Reference
 102      mail_sendmail = None # "/usr/sbin/sendmail -t -i" to not use SMTP, but sendmail
 103      mail_smarthost = None
 104      mail_from = None # u'Jürgen Wiki <noreply@jhwiki.org>'
 105 +    mail_attachment_changes = False
 106  
 107      # some dangerous mimetypes (we don't use "content-disposition: inline" for them when a user
 108      # downloads such attachments, because the browser might execute e.g. Javascript contained

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] (2007-11-20 17:56:19, 5.5 KB) [[attachment:AttachFile_notify_patch-1.5.8.txt]]
  • [get | view] (2008-01-12 11:58:01, 5.2 KB) [[attachment:AttachFile_notify_patch-1.6.txt]]
 All files | Selected Files: delete move to page copy to page

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