diff -aur moin-1.1/MoinMoin/action/AttachFile.py moin-1.1-new/MoinMoin/action/AttachFile.py
--- moin-1.1/MoinMoin/action/AttachFile.py 2003-02-27 21:21:15.000000000 +0000
+++ moin-1.1-new/MoinMoin/action/AttachFile.py 2003-07-09 11:26:36.000000000 +0100
@@ -63,6 +63,22 @@
return attach_dir
+def getModeratedDir(pagename, create=0):
+ """ Get directory where attachments for page `pagename` are stored.
+ """
+ if htdocs_access:
+ # direct file access via webserver, from public htdocs area
+ pagename = wikiutil.quoteFilename(pagename)
+ attach_dir = os.path.join(config.attachments['dir'], pagename, "pending")
+ else:
+ # send file via CGI, from page storage area
+ attach_dir = wikiutil.getPagePath(pagename, "pending")
+
+ if create and not os.path.isdir(attach_dir):
+ filesys.makeDirs(attach_dir)
+
+ return attach_dir
+
def getAttachUrl(pagename, filename, addts=0):
""" Get URL that points to attachment `filename` of page `pagename`.
@@ -164,11 +180,15 @@
return (None, None)
-def _get_filelist(request, pagename):
+def _get_filelist(request, pagename, moderated=0):
_ = request.getText
# access directory
- attach_dir = getAttachDir(pagename)
+ if moderated:
+ attach_dir = getModeratedDir(pagename)
+ else:
+ attach_dir = getAttachDir(pagename)
+
files = []
if os.path.isdir(attach_dir):
files = os.listdir(attach_dir)
@@ -176,12 +196,17 @@
str = ""
if files:
- str = str + _("
"
- "To refer to attachments on a page, use attachment:filename, \n"
- "as shown below in the list of files. \n"
- "Do NOT use the URL of the [get] link, \n"
- "since this is subject to change and can break easily.
"
- )
+ if moderated:
+ str = str + _(""
+ "The following attachments have been added to this page but are not available until they have been approved by the wiki administrator. You can still refer to them using the attachment:filename syntax, but they will not be displayed or linked to until approved.
"
+ )
+ else:
+ str = str + _(""
+ "To refer to attachments on a page, use attachment:filename, \n"
+ "as shown below in the list of files. \n"
+ "Do NOT use the URL of the [get] link, \n"
+ "since this is subject to change and can break easily.
"
+ )
str = str + ""
label_del = _("del")
@@ -209,12 +234,18 @@
else:
viewlink = '%(label_view)s' % locals()
- str = str + ('- [%(del_link)s'
- '%(label_get)s | %(viewlink)s]'
- ' (%(fsize)g KB) attachment:%(file)s
') % locals()
+ if moderated:
+ str = str + ('- attachment:%(file)s (%(fsize)g KB)
') % locals()
+ else:
+ str = str + ('- [%(del_link)s'
+ '%(label_get)s | %(viewlink)s]'
+ ' attachment:%(file)s (%(fsize)g KB)
') % locals()
str = str + "
"
else:
- str = '%s%s
' % (str, _("No attachments stored for %(pagename)s") % locals())
+ if moderated:
+ str = '%s%s
' % (str, _("No pending attachments stored for %(pagename)s") % locals())
+ else:
+ str = '%s%s
' % (str, _("No attachments stored for %(pagename)s") % locals())
return str
@@ -276,6 +307,9 @@
"""
_ = request.getText
+ print _("Pending Files
")
+ print _get_filelist(request, pagename, 1)
+
print _("Attached Files
")
print _get_filelist(request, pagename)
@@ -368,8 +402,12 @@
def do_upload(pagename, request):
+ from MoinMoin.util import mail
_ = request.getText
+ # quota check
+ # quota -u marcus 2>/dev/null | grep /dev | awk '{print $1}'
+
# check file & mimetype
fileitem = request.form['file']
if not fileitem.file:
@@ -378,6 +416,7 @@
return
# get directory, and possibly create it
+ mod_dir = getModeratedDir(pagename, create=1)
attach_dir = getAttachDir(pagename, create=1)
# make filename
@@ -410,23 +449,31 @@
target = target + ext
# save file
+ mfpath = os.path.join(mod_dir, target)
fpath = os.path.join(attach_dir, target)
- if os.path.exists(fpath):
+ if os.path.exists(fpath) or os.path.exists(mfpath):
msg = _("Attachment '%(target)s' (remote name '%(filename)s') already exists.") % locals()
else:
content = fileitem.file.read()
- stream = open(fpath, 'wb')
+ stream = open(mfpath, 'wb')
try:
stream.write(content)
finally:
stream.close()
- os.chmod(fpath, 0666 & config.umask)
+ os.chmod(mfpath, 0666 & config.umask)
bytes = len(content)
msg = _("Attachment '%(target)s' (remote name '%(filename)s')"
" with %(bytes)d bytes saved.") % locals()
_addLogEntry(request, 'ATTNEW', pagename, target)
+ text = msg + _("\n\nSaved to page %(pagename)s.") % locals()
+
+ msg = msg + _("\n\nThe administrator has been notified a pending file exists.")
+
+ # send a mail to the moderator
+ emsg = mail.sendmail(request, [config.mail_administrator], 'Pending attachment on %s' % pagename, text, mail_from=config.mail_from)
+
# return attachment list
upload_form(pagename, request, msg)
diff -aur moin-1.1/MoinMoin/parser/wiki.py moin-1.1-new/MoinMoin/parser/wiki.py
--- moin-1.1/MoinMoin/parser/wiki.py 2003-04-22 20:58:13.000000000 +0100
+++ moin-1.1-new/MoinMoin/parser/wiki.py 2003-07-08 21:00:28.000000000 +0100
@@ -217,9 +217,10 @@
fname = fname + ".gif"
url = url + ".gif"
fpath = os.path.join(AttachFile.getAttachDir(pagename), fname)
+ mpath = os.path.join(AttachFile.getModeratedDir(pagename), fname)
# check whether attachment exists, possibly point to upload form
- if not os.path.exists(fpath):
+ if not os.path.exists(fpath) and not os.path.exists(mpath):
if drawing:
linktext = self._('Create new drawing "%(filename)s"')
else:
@@ -231,6 +232,16 @@
drawing and ('&drawing=%s' % urllib.quote(drawing)) or ''),
linktext % {'filename': fname})
+ if os.path.exists(mpath):
+ linktext = self._('Attachment "%(filename)s" on hold pending approval')
+ return wikiutil.link_tag(
+ '%s?action=AttachFile&moderated=%s%s' % (
+ wikiutil.quoteWikiname(pagename),
+ urllib.quote_plus(fname),
+ drawing and ('&drawing=%s' % urllib.quote(drawing)) or ''),
+ linktext % {'filename': fname})
+
+
# check for image URL, and possibly return IMG tag
# (images are always inlined, just like for other URLs)
if not kw.get('pretty_url', 0) and wikiutil.isPicture(url):