diff -r 9336f3e4c328 MoinMoin/action/AttachFile.py --- a/MoinMoin/action/AttachFile.py Fri Jan 11 00:19:55 2008 +0100 +++ b/MoinMoin/action/AttachFile.py Sat Jan 12 12:48:50 2008 +0100 @@ -45,6 +45,51 @@ def htdocs_access(request): class AttachmentAlreadyExists(Exception): pass + +def do_notify(pagename, request, msg): + if request.cfg.mail_enabled: + _ = request.getText + from MoinMoin.PageEditor import PageEditor + from MoinMoin import user + from MoinMoin.mail import sendmail + + page = PageEditor(request, pagename) + trivial = 0 + pagelink = request.getQualifiedURL(page.url(request)) + pagelink += "?action=AttachFile\n\n%s" % msg + + subscribers = page.getSubscribers(request, return_users=1, trivial=trivial) + if subscribers: + mailBody = _("Dear Wiki user,\n\n" + 'You have subscribed to a wiki page or wiki category on "%(sitename)s" for change notification.\n\n' + "The following page has been changed by %(editor)s:\n" + "%(pagelink)s\n\n", formatted=False) % { + 'editor': user.getUserIdentification(request), + 'pagelink': pagelink, + 'sitename': request.cfg.sitename or request.getBaseURL(), + } + # send email to all subscribers + results = [_('Status of sending notification mails:')] + for lang in subscribers.keys(): + emails = map(lambda u: u.email, subscribers[lang]) + names = map(lambda u: u.name, subscribers[lang]) + + mailok, status = sendmail.sendmail(request, emails, + _('[%(sitename)s] Update of "%(pagename)s" by %(username)s ', formatted=False) % { + 'sitename': request.cfg.sitename or "Wiki", + 'pagename': pagename, + 'username': user.getUserIdentification(request), + }, mailBody, mail_from=request.cfg.mail_from) + recipients = ", ".join(names) + results.append(_('[%(lang)s] %(recipients)s: %(status)s') % { + 'lang': lang, 'recipients': recipients, 'status': status}) + + return '

\n%s\n

' % '
'.join(results) + + else: + return "" + else: + return "" def getBasePath(request): """ Get base path where page dirs for attachments are stored. @@ -708,6 +753,7 @@ def do_upload(pagename, request, overwri msg = _("Attachment '%(target)s' (remote name '%(filename)s')" " with %(bytes)d bytes saved.", formatted=False) % { 'target': target, 'filename': filename, 'bytes': bytes} + msg += do_notify(pagename, request, msg) except AttachmentAlreadyExists: msg = _("Attachment '%(target)s' (remote name '%(filename)s') already exists.", formatted=False) % { 'target': target, 'filename': filename} @@ -768,8 +814,12 @@ def del_file(pagename, request): index = Index(request) if index.exists: index.remove_item(pagename, filename) - - upload_form(pagename, request, msg=_("Attachment '%(filename)s' deleted.", formatted=False) % {'filename': filename}) + + msg=_("Attachment '%(filename)s' deleted.", formatted=False) % {'filename': filename} + result = do_notify(pagename, request, msg) + msg = msg + result + + upload_form(pagename, request, msg=msg) def move_file(request, pagename, new_pagename, attachment, new_attachment): _ = request.getText @@ -791,9 +841,19 @@ def move_file(request, pagename, new_pag filesys.rename(attachment_path, new_attachment_path) _addLogEntry(request, 'ATTDEL', pagename, attachment) _addLogEntry(request, 'ATTNEW', new_pagename, new_attachment) - upload_form(pagename, request, msg=_("Attachment '%(filename)s' moved to %(page)s.", formatted=False) % { - 'filename': new_attachment, - 'page': new_pagename}) + + #upload_form(pagename, request, msg=_("Attachment '%(filename)s' moved to %(page)s.", formatted=False) % { + # 'filename': new_attachment, + # 'page': new_pagename}) + msg = _("Attachment '%(old_filename)s' moved from %(old_page)s to %(new_page)s as '%(new_filename)s'.") % { + 'old_filename': attachment, + 'new_filename': new_attachment, + 'old_page': pagename, + 'new_page': new_pagename} + + result = do_notify(pagename, request, msg) + msg = msg + result + upload_form(pagename, request, msg=msg) else: upload_form(pagename, request, msg=_("Nothing changed", formatted=False)) else: