Short description

Sometimes its wanted to get notified if an attachment is uploaded, moved or deleted on a page.

This patch is based on 1.5.8 changeset: 852:ca98a59c5902 AttachFile_notify_patch-1.5.8.txt

Within wikiconfig.py it is configurable by setting mail_attachment_changes = True.

mail_attachment_changes = True

This feature is in 1.7 slightly different implemented.

/!\ The mail enabled check seems duplicate at some place(s).

  • right, only the do_notify method needs it.

patch for 1.6

  • the config var is removed
  • notification for delete too
 1 diff -r 9336f3e4c328 MoinMoin/action/AttachFile.py
 2 --- a/MoinMoin/action/AttachFile.py	Fri Jan 11 00:19:55 2008 +0100
 3 +++ b/MoinMoin/action/AttachFile.py	Sat Jan 12 12:48:50 2008 +0100
 4 @@ -45,6 +45,51 @@ def htdocs_access(request):
 5  
 6  class AttachmentAlreadyExists(Exception):
 7  pass
 8 +
 9 +def do_notify(pagename, request, msg):
 10 + if request.cfg.mail_enabled:
 11 + _ = request.getText
 12 + from MoinMoin.PageEditor import PageEditor
 13 + from MoinMoin import user
 14 + from MoinMoin.mail import sendmail
 15 +
 16 + page = PageEditor(request, pagename)
 17 + trivial = 0
 18 + pagelink = request.getQualifiedURL(page.url(request))
 19 + pagelink += "?action=AttachFile\n\n%s" % msg
 20 +
 21 + subscribers = page.getSubscribers(request, return_users=1, trivial=trivial)
 22 + if subscribers:
 23 + mailBody = _("Dear Wiki user,\n\n"
 24 + 'You have subscribed to a wiki page or wiki category on "%(sitename)s" for change notification.\n\n'
 25 + "The following page has been changed by %(editor)s:\n"
 26 + "%(pagelink)s\n\n", formatted=False) % {
 27 + 'editor': user.getUserIdentification(request),
 28 + 'pagelink': pagelink,
 29 + 'sitename': request.cfg.sitename or request.getBaseURL(),
 30 + }
 31 + # send email to all subscribers
 32 + results = [_('Status of sending notification mails:')]
 33 + for lang in subscribers.keys():
 34 + emails = map(lambda u: u.email, subscribers[lang])
 35 + names = map(lambda u: u.name, subscribers[lang])
 36 +
 37 + mailok, status = sendmail.sendmail(request, emails,
 38 + _('[%(sitename)s] Update of "%(pagename)s" by %(username)s ', formatted=False) % {
 39 + 'sitename': request.cfg.sitename or "Wiki",
 40 + 'pagename': pagename,
 41 + 'username': user.getUserIdentification(request),
 42 + }, mailBody, mail_from=request.cfg.mail_from)
 43 + recipients = ", ".join(names)
 44 + results.append(_('[%(lang)s] %(recipients)s: %(status)s') % {
 45 + 'lang': lang, 'recipients': recipients, 'status': status})
 46 +
 47 + return '<p>\n%s\n</p> ' % '<br>'.join(results)
 48 +
 49 + else:
 50 + return ""
 51 + else:
 52 + return ""
 53  
 54  def getBasePath(request):
 55  """ Get base path where page dirs for attachments are stored.
 56 @@ -708,6 +753,7 @@ def do_upload(pagename, request, overwri
 57  msg = _("Attachment '%(target)s' (remote name '%(filename)s')"
 58  " with %(bytes)d bytes saved.", formatted=False) % {
 59  'target': target, 'filename': filename, 'bytes': bytes}
 60 + msg += do_notify(pagename, request, msg)
 61  except AttachmentAlreadyExists:
 62  msg = _("Attachment '%(target)s' (remote name '%(filename)s') already exists.", formatted=False) % {
 63  'target': target, 'filename': filename}
 64 @@ -768,8 +814,12 @@ def del_file(pagename, request):
 65  index = Index(request)
 66  if index.exists:
 67  index.remove_item(pagename, filename)
 68 -
 69 - upload_form(pagename, request, msg=_("Attachment '%(filename)s' deleted.", formatted=False) % {'filename': filename})
 70 + 
 71 + msg=_("Attachment '%(filename)s' deleted.", formatted=False) % {'filename': filename}
 72 + result = do_notify(pagename, request, msg)
 73 + msg = msg + result
 74 + 
 75 + upload_form(pagename, request, msg=msg)
 76  
 77  def move_file(request, pagename, new_pagename, attachment, new_attachment):
 78  _ = request.getText
 79 @@ -791,9 +841,19 @@ 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.", formatted=False) % {
 84 - 'filename': new_attachment,
 85 - 'page': new_pagename})
 86 +
 87 + #upload_form(pagename, request, msg=_("Attachment '%(filename)s' moved to %(page)s.", formatted=False) % {
 88 + # 'filename': new_attachment,
 89 + # 'page': new_pagename})
 90 + msg = _("Attachment '%(old_filename)s' moved from %(old_page)s to %(new_page)s as '%(new_filename)s'.") % {
 91 + 'old_filename': attachment,
 92 + 'new_filename': new_attachment,
 93 + 'old_page': pagename,
 94 + 'new_page': new_pagename}
 95 +
 96 + result = do_notify(pagename, request, msg)
 97 + msg = msg + result
 98 + upload_form(pagename, request, msg=msg)
 99  else:
 100  upload_form(pagename, request, msg=_("Nothing changed", formatted=False))
 101  else:

AttachFile_notify_patch-1.6.txt


CategoryFeaturePatched CategoryFeatureImplemented

MoinMoin: FeatureRequests/NotifyAttachmentChange (last edited 2008年03月18日 12:50:47 by ThomasWaldmann )

AltStyle によって変換されたページ (->オリジナル) /