* looking for arch@arch.thinkmo.de--2003-archives/moin--main--1.5--patch-374 to compare with
* comparing to arch@arch.thinkmo.de--2003-archives/moin--main--1.5--patch-374
M  MoinMoin/Page.py
M  wiki/config/wikiconfig.py
A  MoinMoin/logfile/logmysql.py
A  MoinMoin/logfile/eventmysqllog.py

* modified files

--- orig/MoinMoin/Page.py
+++ mod/MoinMoin/Page.py
@@ -9,7 +9,7 @@
 import StringIO, os, re, random, codecs
 
 from MoinMoin import config, caching, user, util, wikiutil
-from MoinMoin.logfile import eventlog
+from MoinMoin.logfile import eventlog, eventmysqllog
 from MoinMoin.util import filesys
 from MoinMoin.util.datetime import formathttpdate
 
@@ -980,6 +980,7 @@
         # count hit?
         if keywords.get('count_hit', 0):
             eventlog.EventLog(request).add(request, 'VIEWPAGE', {'pagename': self.page_name})
+            eventmysqllog.EventLog(request).add(request, 'VIEWPAGE', {'pagename': self.page_name})
 
         # load the text
         body = self.get_raw_body()


--- orig/wiki/config/wikiconfig.py
+++ mod/wiki/config/wikiconfig.py
@@ -157,3 +157,9 @@
     # Enable graphical charts, requires gdchart.
     #chart_options = {'width': 600, 'height': 300}
 
+    # For MySQL log.
+    mysqlhost = 'localhost'
+    mysqluser = 'root'
+    mysqlpasswd = ''
+    mysqldb = 'moin'
+



--- orig/MoinMoin/logfile/logmysql.py
+++ mod/MoinMoin/logfile/logmysql.py
@@ -0,0 +1,35 @@
+"""
+    MoinMoin log class for mysql
+
+    @license: GNU GPL, see COPYING for details.
+"""
+
+import MySQLdb
+
+class LogMySQL:
+    
+    def __init__(self, request):
+        self.request = request
+        self.mysqlhost = request.cfg.mysqlhost
+        self.mysqluser = request.cfg.mysqluser
+        self.mysqlpasswd = request.cfg.mysqlpasswd
+        self.mysqldb = request.cfg.mysqldb
+
+    def connect(self):
+        # If cann't connect to mysql, just return None.
+        try:
+            self.mysqlconnect_db = MySQLdb.connect(
+                     host=self.mysqlhost,
+                     user=self.mysqluser,
+                     passwd=self.mysqlpasswd,
+                     db=self.mysqldb )
+        except: return 0
+        self.mysql_cursor = self.mysqlconnect_db.cursor()
+        return 1
+
+    def close(self):
+        # close the connect.
+        self.mysqlconnect_db.close()
+
+    def add(self, sqlquery):
+        self.mysql_cursor.execute(sqlquery)



--- orig/MoinMoin/logfile/eventmysqllog.py
+++ mod/MoinMoin/logfile/eventmysqllog.py
@@ -0,0 +1,54 @@
+"""
+    MoinMoin event log class for mysql
+
+    @license: GNU GPL, see COPYING for details.
+
+    Will log to a table name is moinmoinlog,
+    And the table schema is like this:
+    CREATE TABLE `moinmoinlog` (
+      `id` int(20) NOT NULL auto_increment,
+      `logtime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
+      `username` text,
+      `httpagent` text,
+      `eventtype` text,
+      `pagename` text,
+      `httpreferer` text,
+      `site` text,
+      `action` text,
+      `remoteip` text,
+      PRIMARY KEY  (`id`)
+    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+"""
+
+import MySQLdb
+from logmysql import LogMySQL
+
+class EventLog(LogMySQL):
+    
+    def __init__(self, request, **kw):
+        LogMySQL.__init__(self, request)
+
+    def add(self, request, eventtype, values=None):
+        if values is None:
+            values = {}
+        valuesdict = values
+        if self.connect():
+            # All these are ascii
+            remote_addr = getattr(request, 'remote_addr', '')
+            http_user_agent = getattr(request, 'http_user_agent', '')
+            http_referer = getattr(request, 'http_referer', '')
+            username = request.user.valid and request.user.name or ''
+            site = request.cfg.sitename
+            if request.form.has_key('action'):
+                action = request.form['action'][0]
+            else: action = ''
+            if not valuesdict.has_key('pagename'): valuesdict['pagename'] = ""
+	    pagename = valuesdict['pagename']
+            sqlquery = u"""
+INSERT INTO moinmoinlog ( username, httpagent, eventtype, pagename, httpreferer, site, action, remoteip
+) VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');
+""" %(username, http_user_agent, eventtype, pagename, http_referer, site, action, remote_addr)
+            self.mysql_cursor.execute(sqlquery.encode("utf-8"))
+            self.close()
+            return 1
+        return 0
