Add new attachment

Only authorized users are allowed to upload new attachments.

This page (revision-5) was last changed on 24-Dec-2006 07:20 by MurrayAltheim  

This page was created on 25-May-2005 01:37 by DuncanMcGregor

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Difference between version and

At line 1 added one line
Fed up with the occasional spam attacks, I've written a Python script to undo changes from a given name or IP address, when using the VersioningFileProvider.
At line 3 added 137 lines
Its a bit convoluted, I've no time to make it better, but it may be of interest. You really should back up your pages directory, save the script as and then run as\\
python /pathto/pages.dir \\
python /pathto/pages.dir BadPersonName
You'll have to restart to clear the CachingProvider cache if you're using it.
import sys
import os
import os.path
import re
import shutil
class PropertiesLine:
def __init__(self, line):
match = re.match(r'^(\d*).(.*)=(.*)', line)
if match != None:
self.version, self.tag, self.value = match.groups()
self.version = int(self.version)
self.tag = self.version = self.value = None
def __repr__(self):
return '%s.%s=%s' % (self.version, self.tag, self.value)
def parseLine(line):
return PropertiesLine(line)
def moveFile(src, dest):
print 'moving %s to %s' % (src, dest)
shutil.copy2(src, dest)
def deleteFile(src):
print 'deleting %s' % src
class PropertiesFile:
def __init__(self, filename):
self.filename = filename
file = open(self.filename)
self.lines = file.readlines()
def latestEdit(self):
latestVersion = -1
result = None
for line in self.lines:
pLine = parseLine(line)
if pLine.version > latestVersion:
latestVersion = pLine.version
result = pLine
return result
def removeVersion(self, version):
self.lines = filter(lambda x: parseLine(x).version != version, self.lines)
def save(self):
file = open(self.filename, 'w')
class Page:
def __init__(self, filename):
self.filename = filename
self.dir, self.file = os.path.split(filename) = os.path.splitext(self.file)[0]
propertiesFilename = os.path.join(self.historyDir(), '')
if os.path.exists(propertiesFilename):
self.propertiesFile = PropertiesFile(propertiesFilename)
self.propertiesFile = None
def versionFilename(self, version):
return os.path.join(self.historyDir(), str(version) + '.txt')
def historyDir(self):
return os.path.join(self.dir, 'OLD',
def isLastEditBy(self, name):
if self.propertiesFile == None:
return 0
latestEdit = self.propertiesFile.latestEdit()
return latestEdit.value == name
def latestVersion(self):
if self.propertiesFile == None:
return -1
return self.propertiesFile.latestEdit().version
def undoLastEdit(self):
if self.propertiesFile == None:
latestVersion = self.latestVersion()
versionToRestore = latestVersion - 1
backupFile = os.path.join(self.historyDir(), 'spam-deleted-' + str(latestVersion)) + '.txt'
moveFile(self.filename, backupFile)
if versionToRestore >= 1:
moveFile(self.versionFilename(versionToRestore), self.filename)
def __repr__(self):
return 'Page %s' % (
class Site:
def __init__(self, dir):
self.dir = dir
self.pages = []
for filename in os.listdir(dir):
root, ext = os.path.splitext(filename)
if ext == '.txt':
self.pages.append(Page(os.path.join(dir, filename)))
def undoEditsBy(self, name):
for page in self.pagesWithLastEditBy(name):
def pagesWithLastEditBy(self, name):
for page in self.pages:
if page.isLastEditBy(name):
yield page
if __name__ == "__main__":
if len(sys.argv) == 2:
dir = '.'
name = sys.argv[1]
dir = sys.argv[1]
name = sys.argv[2]
Version Date Modified Size Author Changes ... Change note
5 24-Dec-2006 07:20 4.145 kB MurrayAltheim to previous restored to previous sensible version
4 24-Dec-2006 06:29 0.002 kB to previous | to last
3 24-Dec-2006 06:28 1.037 kB to previous | to last
2 24-Dec-2006 06:27 0.002 kB to previous | to last
1 25-May-2005 01:37 4.145 kB DuncanMcGregor to last
« This page (revision-5) was last changed on 24-Dec-2006 07:20 by MurrayAltheim