#!/usr/bin/python # -*- coding: utf-8 -*- #For debugging purposes only #import cgitb #cgitb.enable() import cgi, MySQLdb, sys #Needs to send these headers print "Content-Type: text/html; charset=UTF-8" #Default data Quser = "" patr = False nu = False ns={-2: 'Media:', -1: 'Special:', 0: '', 1: 'Talk:', 2: 'User:', 3: 'User talk:', 4: 'Project:', 5: 'Project talk:', 6: 'Image:', 7: 'Image talk:', 8: 'MediaWiki:', 9: 'MediaWiki talk:', 10: 'Template:', 11: 'Template talk:', 12: 'Help:', 13: 'Help talk:', 14: 'Category:', 15: 'Category talk:', 100: 'Portal:', 101: 'Portal talk:'} #Handle args f = cgi.FieldStorage() if f.has_key('user'): Quser = f['user'].value if f.has_key('patrol'): if f['patrol'].value.lower()=="false": patr=True if f.has_key('newusers'): if f['newusers'].value.lower()=="false": nu=True if Quser!="": Quser = Quser[0].upper() + Quser[1:] #DBdata file=open('/data/project/rightstool/replica.my.cnf', 'r') lista=[l.strip("\n") for l in file.readlines()[1:]] file.close() SQLuser=lista[0].split("=")[1].strip("'") SQLpasswd=lista[1].split("=")[1].strip("'") #Generate some html if patr: checked1=" checked " else: checked1="" if nu: checked2=" checked " else: checked2="" print """ Recent logs
Username:
""" % (sys.argv[0].replace("/data/project/rightstool/public_html//cgi-bin/", "").replace("py", ""), Quser, checked1, checked2) #Do only if the user has been specified if Quser!="": totalcount = 0 print """

Recent log actions for %s

""" % Quser #Getting the wiki list db = MySQLdb.connect(db='meta_p', host="metawiki.labsdb", user=SQLuser, passwd=SQLpasswd) cursor = db.cursor() cursor.execute("SELECT dbname, slice, url FROM wiki WHERE url IS NOT NULL ORDER BY dbname") wikis = cursor.fetchall() dbhost = ""; #Getting the data from MySQL for wiki in wikis: try: if wiki[1] != dbhost: db.close() dbhost = wiki[1] db = MySQLdb.connect(host=dbhost, user=SQLuser, passwd=SQLpasswd) cursor = db.cursor() cursor.execute("USE %s_p;" % wiki[0]) if patr: hidepatrol = "log_type != 'patrol' and " else: hidepatrol = "" if nu: hidenu = "log_type != 'newusers' and " else: hidenu = "" sql = "select log_type, log_namespace, log_title, log_comment, log_timestamp from logging, user where %s%slog_user=user_id and user_name='%s' and log_type != 'suppress' order by log_timestamp desc limit 10;" % (hidepatrol, hidenu, Quser) sqlc = "select count(*) from logging, user where log_user=user_id and user_name='%s';" % Quser cursor.execute(sql) result = cursor.fetchall() results=result cursor.execute(sqlc) result = cursor.fetchall() count = result[0][0] results=() except: results=() if results!=(): print """

%s

Total of %s log action(s)

""" % (wiki[2].replace("http://", "https://"), Quser, wiki[0], count) totalcount += count for i in results: if int(i[1]) not in ns: namespace="Namespace_%s:" % i[1] else: namespace=ns[int(i[1])] if i[3]=='': comment=" " else: comment=i[3].replace("<", "<").replace(">", ">") t=i[4] time="%s/%s/%s %s:%s:%s" % (t[:4], t[4:6], t[6:8], t[8:10], t[10:12], t[12:]) print """""" % (i[0], time, namespace, i[2], comment) print """
Log typeTimeTitleComment
%s%s%s%s%s
""" print """

Total number of log actions: %s.

""" % totalcount db.close() print """

AltStyle によって変換されたページ (->オリジナル) /

"""