1c1
< #!/usr/bin/python
---
> #!/local/www/bin/python
7a8,9
>
> Git integration and some other hacks by Kirill Miazine
13a16,20
> reload(sys) # HACK
> sys.setdefaultencoding('utf-8') # MORE HACK!
> os.environ['TZ'] = 'Europe/Oslo'
> time.tzset()
>
15c22,23
< configvars = ('default', 'sname', 'lname', 'pedit', 'owner', 'logdir')
---
> configvars = ('default', 'sname', 'lname', 'pedit', 'owner', 'logdir',
> 'usegit', 'imgzz', 'usecrypto')
32a41,44
> usegit = config.get('usegit', False)
> imgzz = config.get('imgzz', False)
> usecrypto = config.get('usecrypto', False)
>
34,35c46,47
< profile = 'http://infomesh.net/pwyky/profile#'
< s_name = os.environ.get('SCRIPT_NAME', '/notes/index.cgi')
---
> profile = 'http://km.krot.org/wiki/profile#'
> s_name = os.environ.get('SCRIPT_NAME', '/wiki/index.cgi')
62a75,99
> # support for git
> def rungit(*args):
> os.chdir('@raw')
> os.spawnlp(os.P_WAIT, 'git', 'git', *args)
> os.chdir('..')
> if usegit and not os.path.exists('@raw'):
> os.mkdir('@raw')
> if usegit and not os.path.exists('@raw/.git/HEAD'):
> rungit('init', '-q')
> os.chdir('@raw')
> old = glob.glob('*')
> os.chdir('..')
> if old:
> rungit('add', *old)
> rungit('commit', '-q', '-m', 'initial import of existing files', *old)
>
> # extract #id from string
> def getid(s):
> if s[0] == '#':
> if s.find(' ') > 0: (id, s) = s[1:].split(' ', 1)
> else: id = s[1:]
> cid = ' id="%s"' % id
> else: cid = ''
> return (cid, s)
>
126,131d162
< def makeID(s, current):
< s = (''.join(r_alpha.findall(s)) or 'id') + str(len(s))
< while s in current:
< s += 'n'
< return s
<
155c186
< self.ids = []
---
> self.imgloc = 'left'
228,232c259,261
< newid = makeID(content, self.ids)
< self.ids.append(newid)
<
< self.write('
' % newid)
< self.write(content)
---
> x = getid(content)
> self.write('' % x[0])
> self.write(x[1])
334,335c363,364
< elif s == '$timenow':
< result = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
---
> elif s == '$datetimenow':
> result = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
337c366,368
< result = time.strftime('%Y-%m-%d', time.gmtime())
---
> result = time.strftime('%Y-%m-%d', time.localtime())
> elif s == '$timenow':
> result = time.strftime('%H:%M:%S', time.localtime())
341c372,380
< result = '%s' % s[2:]
---
> x = getid(s[2:])
> result = '%s' % x
> elif s.startswith('/ '):
> x = getid(s[2:])
> result = '%s' % x
> elif s.startswith('= '):
> result = '%s' % s[2:]
> elif s.startswith('- '):
> result = '%s' % s[2:]
345a385,398
> elif s.startswith('! '):
> s = s[2:].strip()
> i = s.find(' ')
> if i > 0:
> src, alt= s[:i], s[i+1:]
> else:
> src, alt = s, ''
> if imgzz:
> imgstyle = 'style="float:%s"' % self.imgloc
> if self.imgloc == 'left': self.imgloc = 'right'
> else: self.imgloc = 'left'
> else:
> imgstyle = ''
> result = '
' % (imgstyle, src, alt)
383a437
> self.image = False
405a460,461
> id = attrs.get('id', '')
> if tag != 'h1' and id: self.write('#' + id + ' ')
412a469,478
> id = attrs.get('id', '')
> if id: self.write('#' + id + ' ')
> elif tag == 'em':
> self.write('{/ ')
> id = attrs.get('id', '')
> if id: self.write('#' + id + ' ')
> elif tag == 'tt':
> self.write('{= ')
> elif tag == 'strike':
> self.write('{- ')
415a482,483
> elif tag == 'img':
> self.image = attrs
450c518,523
< elif tag == 'strong':
---
> elif tag == 'img':
> attrs = self.image
> uri, title = attrs.get('src', ''), attrs.get('alt', '')
> self.write('{! %s %s}' % (uri, title))
> self.image = False
> elif tag in ['strong', 'em', 'tt', 'strike']:
504c577,578
< s = '\n\n'
---
> s = ' s += ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'
506a581
> s += '\n'
523,525c598,600
< s = '\n\n' % wn
---
> s = '\n\n' % wn
538,539c613
< s += '%s. This is a pwyky site.'
---
> s += '%s' % owner
542c616
< s += 'Edit this document.'
---
> s += '@edit'
584a659,684
> if usegit: logfield = '@log: '
> else: logfield = ''
> if usecrypto: cryptobtn = '''
>
>
>
>
> '''
> else: cryptobtn = ''
588c688
<
---
>
%s
590c690
<
---
> %s
592c692
< ''' % (wn, cgi.escape(s)))
---
> ''' % (wn, cgi.escape(s), logfield, cryptobtn))
612c712
< lastmod = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(t))
---
> lastmod = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t))
617c717
< plastmod = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(pt))
---
> plastmod = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(pt))
692c792
< lastmod = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(t))
---
> lastmod = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t))
701c801
< today = time.strftime('%Y-%m-%d', time.gmtime())
---
> today = time.strftime('%Y-%m-%d', time.localtime())
889a990,992
> # for git
> logm = form.get('log', '')
> rawp = '@raw/%s' % wn
894a998,1007
> # record changes in git
> if not logm: logm = 'edit %s' % wn
> if os.path.exists(rawp): old = open(rawp).read()
> else: old = ''
> if usegit and s.strip() != old.strip():
> open(rawp, 'w').write(s.strip());
> rungit('add', wn)
> logm = "* %s: %s" % (os.environ.get('REMOTE_USER', 'www') , logm)
> rungit('commit', '-q', '-m', logm, wn)
> rungit('gc', '--quiet')
914a1028,1037
> if os.path.exists('@raw/%s' % wn):
> os.remove('@raw/%s' % wn)
> # remove from git
> if usegit and os.path.exists(rawp):
> if not logm: logm = 'delete %s' % wn
> rungit('rm', wn)
> os.remove(rawp)
> logm = "* %s: %s" % (os.environ.get('REMOTE_USER', 'www') , logm)
> rungit('commit', '-q', '-m', logm, rawp)
> rungit('gc', '--quiet')
941c1064
< t = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
---
> t = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.localtime())