Permalink
Browse files

Changed protection-related scripts to use API for logging info; the S…

…QL queries kept hanging.
  • Loading branch information...
MZMcBride
MZMcBride committed Jul 14, 2009
1 parent 81fd524 commit b18d1fdef07ea53d86f736d2be7b12d46705e1bd
Showing with 188 additions and 221 deletions.
  1. +34 −39 excessivefullarticles.py
  2. +33 −38 excessivesemiarticles.py
  3. +34 −39 indeffullarticles.py
  4. +27 −33 indeffulltalks.py
  5. +34 −39 indefsemiarticles.py
  6. +26 −33 indefsemitalks.py
@@ -41,68 +41,63 @@
wiki = wikitools.Wiki(settings.apiurl)
wiki.login(settings.username, settings.password)
def lastLogEntry(page):
params = {
'action': 'query',
'list': 'logevents',
'lelimit': '1',
'letitle': page,
'format': 'json',
'ledir': 'older',
'letype': 'protect',
'leprop': 'user|timestamp|comment'
}
request = wikitools.APIRequest(wiki, params)
response = request.query(querycontinue=False)
lastlog = response['query']['logevents']
timestamp = datetime.datetime.strptime(lastlog[0]['timestamp'], '%Y-%m-%dT%H:%M:%SZ').strftime('%Y%m%d%H%M%S')
user = lastlog[0]['user']
comment = lastlog[0]['comment']
return { 'timestamp': timestamp, 'user': user, 'comment': comment }
conn = MySQLdb.connect(host=settings.host, db=settings.dbname, read_default_file='~/.my.cnf')
cursor = conn.cursor()
cursor.execute('''
/* excessivefullarticles.py SLOW_OK */
SELECT
page_is_redirect,
page_title,
user_name,
logs.log_timestamp,
pr_expiry,
logs.log_comment
FROM page
JOIN page_restrictions ON page_id = pr_page
AND page_namespace = 0
pr_expiry
FROM page_restrictions
JOIN page
ON page_id = pr_page
WHERE page_namespace = 0
AND pr_type = 'edit'
AND pr_level = 'sysop'
AND pr_expiry > DATE_FORMAT(DATE_ADD(NOW(),INTERVAL 1 YEAR),'%Y%m%d%H%i%s')
AND pr_expiry != 'infinity'
LEFT JOIN logging AS logs ON logs.log_title = page_title
AND logs.log_namespace = 0
AND logs.log_type = 'protect'
LEFT JOIN user ON logs.log_user = user_id
WHERE CASE WHEN (NOT ISNULL(log_timestamp))
THEN log_timestamp = (SELECT MAX(last.log_timestamp)
FROM logging AS last
WHERE log_title = page_title
AND log_namespace = 0
AND log_type = 'protect')
ELSE 1 END;
AND pr_expiry != 'infinity';
''')
i = 1
output = []
for row in cursor.fetchall():
page = wikitools.Page(wiki, u'%s' % (unicode(row[1], 'utf-8')), followRedir=False)
redirect = row[0]
if redirect == 1:
title = u'<i>[[%s]]</i>' % unicode(row[1], 'utf-8')
else:
title = u'[[%s]]' % unicode(row[1], 'utf-8')
user = row[2]
if user:
user = u'[[User talk:%s|]]' % unicode(user, 'utf-8')
else:
user = ''
timestamp = row[3]
if timestamp:
timestamp = u'%s' % unicode(timestamp, 'utf-8')
else:
timestamp = ''
expiry = u'%s' % unicode(row[4], 'utf-8')
comment = row[5]
if comment:
comment = u'<nowiki>%s</nowiki>' % unicode(comment, 'utf-8')
page_title = u'<i>[[%s]]</i>' % unicode(row[1], 'utf-8')
else:
comment = ''
page_title = u'[[%s]]' % unicode(row[1], 'utf-8')
user = u'[[User talk:%s|]]' % lastLogEntry(page.title)['user']
timestamp = lastLogEntry(page.title)['timestamp']
pr_expiry = row[2]
comment = u'<nowiki>%s</nowiki>' % lastLogEntry(page.title)['comment']
table_row = u'''| %d
| %s
| %s
| %s
| %s
| %s
|-''' % (i, title, user, timestamp, expiry, comment)
|-''' % (i, page_title, user, timestamp, pr_expiry, comment)
output.append(table_row)
i += 1
@@ -116,4 +111,4 @@
report.edit(report_text, summary=settings.editsumm, bot=1)
cursor.close()
conn.close()
conn.close()
@@ -41,68 +41,63 @@
wiki = wikitools.Wiki(settings.apiurl)
wiki.login(settings.username, settings.password)
def lastLogEntry(page):
params = {
'action': 'query',
'list': 'logevents',
'lelimit': '1',
'letitle': page,
'format': 'json',
'ledir': 'older',
'letype': 'protect',
'leprop': 'user|timestamp|comment'
}
request = wikitools.APIRequest(wiki, params)
response = request.query(querycontinue=False)
lastlog = response['query']['logevents']
timestamp = datetime.datetime.strptime(lastlog[0]['timestamp'], '%Y-%m-%dT%H:%M:%SZ').strftime('%Y%m%d%H%M%S')
user = lastlog[0]['user']
comment = lastlog[0]['comment']
return { 'timestamp': timestamp, 'user': user, 'comment': comment }
conn = MySQLdb.connect(host=settings.host, db=settings.dbname, read_default_file='~/.my.cnf')
cursor = conn.cursor()
cursor.execute('''
/* excessivesemiarticles.py SLOW_OK */
SELECT
page_is_redirect,
page_title,
user_name,
logs.log_timestamp,
pr_expiry,
logs.log_comment
FROM page
JOIN page_restrictions ON page_id = pr_page
AND page_namespace = 0
pr_expiry
FROM page_restrictions
JOIN page
ON page_id = pr_page
WHERE page_namespace = 0
AND pr_type = 'edit'
AND pr_level = 'autoconfirmed'
AND pr_expiry > DATE_FORMAT(DATE_ADD(NOW(),INTERVAL 1 YEAR),'%Y%m%d%H%i%s')
AND pr_expiry != 'infinity'
LEFT JOIN logging AS logs ON logs.log_title = page_title
AND logs.log_namespace = 0
AND logs.log_type = 'protect'
LEFT JOIN user ON logs.log_user = user_id
WHERE CASE WHEN (NOT ISNULL(log_timestamp))
THEN log_timestamp = (SELECT MAX(last.log_timestamp)
FROM logging AS last
WHERE log_title = page_title
AND log_namespace = 0
AND log_type = 'protect')
ELSE 1 END;
AND pr_expiry != 'infinity';
''')
i = 1
output = []
for row in cursor.fetchall():
page = wikitools.Page(wiki, u'%s' % (unicode(row[1], 'utf-8')), followRedir=False)
redirect = row[0]
if redirect == 1:
title = u'<i>[[%s]]</i>' % unicode(row[1], 'utf-8')
else:
title = u'[[%s]]' % unicode(row[1], 'utf-8')
user = row[2]
if user:
user = u'[[User talk:%s|]]' % unicode(user, 'utf-8')
else:
user = ''
timestamp = row[3]
if timestamp:
timestamp = u'%s' % unicode(timestamp, 'utf-8')
else:
timestamp = ''
expiry = u'%s' % unicode(row[4], 'utf-8')
comment = row[5]
if comment:
comment = u'<nowiki>%s</nowiki>' % unicode(comment, 'utf-8')
page_title = u'<i>[[%s]]</i>' % unicode(row[1], 'utf-8')
else:
comment = ''
page_title = u'[[%s]]' % unicode(row[1], 'utf-8')
user = u'[[User talk:%s|]]' % lastLogEntry(page.title)['user']
timestamp = lastLogEntry(page.title)['timestamp']
pr_expiry = row[2]
comment = u'<nowiki>%s</nowiki>' % lastLogEntry(page.title)['comment']
table_row = u'''| %d
| %s
| %s
| %s
| %s
| %s
|-''' % (i, title, user, timestamp, expiry, comment)
|-''' % (i, page_title, user, timestamp, pr_expiry, comment)
output.append(table_row)
i += 1
@@ -50,74 +50,69 @@
|}
'''
wiki = wikitools.Wiki(settings.apiurl)
wiki = wikitools.Wiki(settings.apiurl); wiki.setMaxlag(-1)
wiki.login(settings.username, settings.password)
def lastLogEntry(page):
params = {
'action': 'query',
'list': 'logevents',
'lelimit': '1',
'letitle': page,
'format': 'json',
'ledir': 'older',
'letype': 'protect',
'leprop': 'user|timestamp|comment'
}
request = wikitools.APIRequest(wiki, params)
response = request.query(querycontinue=False)
lastlog = response['query']['logevents']
timestamp = datetime.datetime.strptime(lastlog[0]['timestamp'], '%Y-%m-%dT%H:%M:%SZ').strftime('%Y%m%d%H%M%S')
user = lastlog[0]['user']
comment = lastlog[0]['comment']
return { 'timestamp': timestamp, 'user': user, 'comment': comment }
conn = MySQLdb.connect(host=settings.host, db=settings.dbname, read_default_file='~/.my.cnf')
cursor = conn.cursor()
cursor.execute('''
/* indeffullarticles.py SLOW_OK */
SELECT
page_is_redirect,
page_title,
user_name,
logs.log_timestamp,
logs.log_comment
FROM page
JOIN page_restrictions ON page_id = pr_page
page_title
FROM page_restrictions
JOIN page
ON page_id = pr_page
AND page_namespace = 0
AND pr_type = 'edit'
AND pr_level = 'sysop'
AND pr_expiry = 'infinity'
LEFT JOIN logging AS logs ON logs.log_title = page_title
AND logs.log_namespace = 0
AND logs.log_type = 'protect'
LEFT JOIN user ON logs.log_user = user_id
WHERE CASE WHEN (NOT ISNULL(log_timestamp))
THEN log_timestamp = (SELECT MAX(last.log_timestamp)
FROM logging AS last
WHERE log_title = page_title
AND log_namespace = 0
AND log_type = 'protect')
ELSE 1 END;
AND pr_expiry = 'infinity';
''')
i = 1
h = 1
output1 = []
output2 = []
for row in cursor.fetchall():
page = wikitools.Page(wiki, u'%s' % (unicode(row[1], 'utf-8')), followRedir=False)
redirect = row[0]
title = row[1]
user = row[2]
if user:
user = u'[[User talk:%s|]]' % unicode(user, 'utf-8')
else:
user = ''
timestamp = row[3]
if timestamp:
timestamp = u'%s' % unicode(timestamp, 'utf-8')
else:
timestamp = ''
comment = row[4]
if comment:
comment = u'<nowiki>%s</nowiki>' % unicode(comment, 'utf-8')
else:
comment = ''
page_title = row[1]
if redirect == 0:
title = u'{{plth|1=%s}}' % unicode(title, 'utf-8')
page_title = u'{{plth|1=%s}}' % unicode(page_title, 'utf-8')
num = i
i += 1
else:
title = u'{{plthnr|1=%s}}' % unicode(title, 'utf-8')
page_title = u'{{plthnr|1=%s}}' % unicode(page_title, 'utf-8')
num = h
h += 1
user = u'[[User talk:%s|]]' % lastLogEntry(page.title)['user']
timestamp = lastLogEntry(page.title)['timestamp']
comment = u'<nowiki>%s</nowiki>' % lastLogEntry(page.title)['comment']
table_row = u'''| %d
| %s
| %s
| %s
| %s
|-''' % (num, title, user, timestamp, comment)
|-''' % (num, page_title, user, timestamp, comment)
if redirect == 0:
output1.append(table_row)
else:
@@ -133,4 +128,4 @@
report.edit(report_text, summary=settings.editsumm, bot=1)
cursor.close()
conn.close()
conn.close()
Oops, something went wrong.

0 comments on commit b18d1fd

Please sign in to comment.