Example #1
0
def main(cat=None):
  if cat:
    wiki = u'Wikipédia'
    c = conn(wiki)
    c.execute(u"""SELECT
 redir,
 COUNT(tl_from) marca,
 redireciona_para
 FROM (SELECT
   CONCAT(IF(r.page_namespace = 4, 'Wikipédia', 'Predefinição'), ':', r.page_title) redir,
   r.page_namespace ns,
   r.page_title title,
   CONCAT(IF(m.page_namespace = 4, 'Wikipédia', 'Predefinição'), ':', m.page_title) redireciona_para
   FROM categorylinks
   INNER JOIN page m ON cl_from = m.page_id
   INNER JOIN redirect ON (rd_namespace, rd_title) = (m.page_namespace, m.page_title)
   INNER JOIN page r ON rd_from = r.page_id
   WHERE cl_to = ? AND m.page_namespace IN (4, 10)
 ) marcas
 LEFT JOIN templatelinks ON (tl_namespace, tl_title) = (ns, title)
 GROUP BY redir
 ORDER BY marca""", (cat,))
    r = c.fetchall()
    r = [(redir.decode('utf-8'), int(num), predef.decode('utf-8')) for redir, num, predef  in r]
    if r:
        resp = {'wiki': wiki, 'link': link(wiki), 'lista': r}
    else:
        resp = {'aviso': u'A consulta não retornou resultados'}
    return render_template_string(page, title=u'Transclusões de redirecionamentos para  predefinições da categoria ' + cat.replace(u'_', u' '), **resp)
  else:
    return render_template_string(page, title=u'Transclusões de redirecionametos para predefinições de uma categoria')
Example #2
0
def main(cat=None):
  if cat:
    wiki = u'Wikipédia'
    c = conn(wiki)
    c.execute(u"""SELECT
 CONCAT(IF(page_namespace = 4, 'Wikipédia', 'Predefinição'), ':', page_title) p,
 COUNT(tl_title) t
 FROM (SELECT
   page_namespace,
   page_title
   FROM categorylinks
   INNER JOIN page ON cl_from = page_id
   WHERE cl_to = ? AND page_namespace IN (4, 10)
 ) predefs
 LEFT JOIN templatelinks ON (page_namespace, page_title) = (tl_namespace, tl_title)
 GROUP BY p
 ORDER BY t""", (cat,))
    r = c.fetchall()
    r = [(u.decode('utf-8'), int(n)) for u, n in r]
    if r:
        resp = {'wiki': wiki, 'link': link(wiki), 'lista': r}
    else:
        resp = {'aviso': u'A consulta não retornou resultados'}
    return render_template_string(page, title=u'Transclusões de predefinições da categoria ' + cat.replace(u'_', u' '), **resp)
  else:
    return render_template_string(page, title=u'Transclusões de predefinições de uma categoria')
Example #3
0
def main(wiki=None):
    if not wiki:
        wiki = u'Wikipédia'
    c = conn(wiki)
    if c:
        c.execute('''SELECT
 SUBSTR(rc_timestamp, 1, 10) AS HORA,
 SUM(rc_user = 0),
 SUM(rc_user = 0 AND rc_patrolled),
 SUM(rc_comment LIKE ? OR rc_comment LIKE ? OR rc_comment LIKE ?)
 FROM recentchanges
 WHERE rc_namespace = 0 AND rc_type != 5
 GROUP BY HORA
 ORDER BY rc_id DESC
 LIMIT 168''', ('Foram [[WP:REV|%', u'Reversão de uma ou mais edições de%', u'bot: revertidas edições de%'))
        r1 = c.fetchall()
        c.execute('''SELECT
 SUBSTR(rc_timestamp, 1, 8) AS DIA,
 SUM(rc_user = 0),
 SUM(rc_user = 0 AND rc_patrolled),
 SUM(rc_comment LIKE ? OR rc_comment LIKE ? OR rc_comment LIKE ?)
 FROM recentchanges
 WHERE rc_namespace = 0 AND rc_type != 5
 GROUP BY DIA
 ORDER BY rc_id DESC
 LIMIT 30''', ('Foram [[WP:REV|%', u'Reversão de uma ou mais edições de%', u'bot: revertidas edições de%'))
        r2 = c.fetchall()
        r = {'wiki': wiki, 'link': link(wiki)}
	r['iphquery'] = ','.join([(x in r1[6::6] and '\n[{},{},{},{}]' or '[{},{},{},{}]').format(*x) for x in r1])
	r['ipdquery'] = ','.join([(x in r2[6::6] and '\n[{},{},{},{}]' or '[{},{},{},{}]').format(*x) for x in r2][1:-1])
    else:
        r = {}
    return render_template_string(page, title=u'Patrulhamento de IPs' + (wiki and u': ' + wiki or u''), **r)
Example #4
0
def main(wiki=None):
    if not wiki:
        wiki = u'Wikipédia'
    r = query(u"""SELECT
 page_title,
 page_len,
 rev_timestamp,
 rev_user_text,
 cl_to
 FROM (
  SELECT
   page_id,
   page_latest,
   page_title,
   page_len
   FROM page
   WHERE page_namespace = 0 AND page_is_redirect = 0 AND page_id NOT IN (
    SELECT
     cl_from
     FROM categorylinks
     WHERE cl_to = 'Desambiguação'
   )
   AND page_len < 800
   ORDER BY page_len
   LIMIT 500
 ) p
 LEFT JOIN revision ON page_latest = rev_id
 LEFT JOIN categorylinks ON page_id = cl_from AND cl_to NOT LIKE '!%'
 GROUP BY page_title
 ORDER BY page_len""", wiki)
    if r:
        resp = {'wiki': wiki, 'link': link(wiki), 'lista': r}
    else:
        resp = {}
    return render_template_string(page, title=u'Artigos curtos', **resp)
Example #5
0
def main(wiki=None):
    if not wiki:
        wiki = u'Wikipédia'
    c = conn(wiki)
    if c:
        c.execute(
            '''SELECT
 SUBSTR(rc_timestamp, 1, 10) AS HORA,
 SUM(rc_user = 0),
 SUM(rc_user = 0 AND rc_patrolled),
 SUM(rc_comment LIKE ? OR rc_comment LIKE ? OR rc_comment LIKE ?)
 FROM recentchanges
 WHERE rc_namespace = 0 AND rc_type != 5
 GROUP BY HORA
 ORDER BY rc_id DESC
 LIMIT 168''', ('Foram [[WP:REV|%', u'Reversão de uma ou mais edições de%',
                u'bot: revertidas edições de%'))
        r1 = c.fetchall()
        c.execute(
            '''SELECT
 SUBSTR(rc_timestamp, 1, 8) AS DIA,
 SUM(rc_user = 0),
 SUM(rc_user = 0 AND rc_patrolled),
 SUM(rc_comment LIKE ? OR rc_comment LIKE ? OR rc_comment LIKE ?)
 FROM recentchanges
 WHERE rc_namespace = 0 AND rc_type != 5
 GROUP BY DIA
 ORDER BY rc_id DESC
 LIMIT 30''', ('Foram [[WP:REV|%', u'Reversão de uma ou mais edições de%',
               u'bot: revertidas edições de%'))
        r2 = c.fetchall()
        r = {'wiki': wiki, 'link': link(wiki)}
        r['iphquery'] = ','.join([(x in r1[6::6] and '\n[{},{},{},{}]'
                                   or '[{},{},{},{}]').format(*x) for x in r1])
        r['ipdquery'] = ','.join([(x in r2[6::6] and '\n[{},{},{},{}]'
                                   or '[{},{},{},{}]').format(*x)
                                  for x in r2][1:-1])
    else:
        r = {}
    return render_template_string(page,
                                  title=u'Patrulhamento de IPs' +
                                  (wiki and u': ' + wiki or u''),
                                  **r)
Example #6
0
def main(predef=None):
  if predef:
    wiki = u'Wikipédia'
    c = conn(wiki)
    c.execute(u"""SELECT
 CONCAT('Predefinição', ':', page_title) p,
 COUNT(tl_title) t
 FROM (SELECT
   page_title
   FROM page
   WHERE page_namespace = 10 AND page_title LIKE ?
 ) predefs
 LEFT JOIN templatelinks ON page_title = tl_title AND tl_namespace = 10
 GROUP BY p
 ORDER BY t, p""", (predef + u'%',))
    r = c.fetchall()
    r = [(u.decode('utf-8'), int(n)) for u, n in r]
    if r:
        resp = {'wiki': wiki, 'link': link(wiki), 'lista': r}
    else:
        resp = {'aviso': u'A consulta não retornou resultados'}
    return render_template_string(page, title=u'Transclusões de predefinições com o prefixo "' + predef.replace(u'_', u' ') + u'..."', **resp)
  else:
    return render_template_string(page, title=u'Transclusões de predefinições com um prefixo')
Example #7
0
def main(args=None):
    if not args:
        return render_template_string(mainpage, title='Abuse Filter Graphs')
    elif args.isdigit():
        wiki, filter = u'ptwiki', args
    else:
        args = args.split(u':')
        wiki, filter = args[0], len(args) > 1 and args[1]
    c = conn(wiki)
    if c and not filter:  # Todos os filtros
        c.execute('''SELECT
 F,
 af_public_comments,
 N,
 A,
 E,
 D,
 B
 FROM (
 SELECT
 afl_filter AS F,
 SUM(afl_actions = '') AS N,
 SUM(afl_actions = 'warn') AS A,
 SUM(afl_actions = 'tag') AS E,
 SUM(afl_actions = 'disallow') AS D,
 SUM(afl_actions = 'block') AS B
 FROM abuse_filter_log
 WHERE afl_timestamp > DATE_FORMAT(SUBDATE(NOW(), INTERVAL 30 DAY), '%Y%m%d%H%i%s')
 GROUP BY afl_filter) AS stats
 LEFT JOIN abuse_filter
 ON F = af_id''')
        r = c.fetchall()
        r = [(f, t and t.decode('utf8')
              or u'', int(n), int(a), int(e), int(d), int(b))
             for f, t, n, a, e, d, b in r]
        r = {
            'wiki': wiki,
            'link': link(wiki),
            'filters': r,
            'max': max(map(max, [f[2:] for f in r]))
        }
        return render_template_string(allfilters,
                                      title=wiki + ' Abuse Filter Graphs',
                                      **r)
    elif c and filter:  # Um ou mais filtros ao longo do tempo
        query = '''SELECT
 SUBSTR(afl_timestamp, 1, 8) dia,
 SUM(afl_actions = '') nada,
 SUM(afl_actions = 'tag') etiq,
 SUM(afl_actions = 'warn') aviso,
 SUM(afl_actions = 'disallow') desaut
 FROM abuse_filter_log
 WHERE afl_filter = ? AND afl_timestamp > DATE_FORMAT(SUBDATE(NOW(), INTERVAL 1 YEAR), '%Y%m%d%H%i%s')
 GROUP BY WEEK(afl_timestamp)
 ORDER BY dia'''
        filter = [f for f in filter.split('&') if f][0:10]
        filters, names = {}, {}
        for f in filter:
            c.execute(query, (f, ))
            r = c.fetchall()
            filters[f] = []
            for l in r:
                if l[0][4:] == '0101' and filters[f] and int(
                        str(filters[f][-1][0])[4:]) > 1225:
                    filters[f][-1] = [filters[f][-1][0]] + [
                        int(l[i]) + filters[f][-1][i] for i in range(1, 5)
                    ]
                else:
                    filters[f].append(map(int, l))
            c.execute(
                'SELECT af_public_comments FROM abuse_filter WHERE af_id = ?',
                (f, ))
            names[f] = 'Filter ' + f + u' – ' + c.fetchone()[0].decode(
                'utf-8').replace(u'"', u'\\"')
        title = len(filter) == 1 and names[filter[0]] or ' + '.join(
            ['Filter ' + f for f in filter])
        r = {
            'wiki': wiki,
            'link': link(wiki),
            'filters': filters,
            'names': names
        }
        return render_template_string(filtergraph, title=title, **r)
    else:
        r = {}
        return render_template_string(allfilters, title=u'Filters', **r)
Example #8
0
def main(args=None):
    if not args:
        wiki, filter = u'Wikipédia', None
    elif args.replace(u'&', u'').replace(u'_', u'').isdigit():
        wiki, filter = u'Wikipédia', args
    elif args.split(':')[0] not in (u'Wikipédia', u'Wikilivros', u'Wikinotícias', u'Wikicionário', u'Wikiversidade', u'Wikiquote', u'Wikisource', u'Wikivoyage'):
	return redirect('https://tools.wmflabs.org/ptwikis/Filters:' + args)
    else:
        args = args.split(u':')
        wiki, filter = args[0], len(args) > 1 and args[1]
    c = conn(wiki)
    if c and not filter: # Todos os filtros
        c.execute('''SELECT
 F,
 af_public_comments,
 N,
 A,
 E,
 D
 FROM (
 SELECT
 afl_filter AS F,
 SUM(afl_actions = '') AS N,
 SUM(afl_actions = 'warn') AS A,
 SUM(afl_actions = 'tag') AS E,
 SUM(afl_actions = 'disallow') AS D
 FROM abuse_filter_log
 WHERE afl_timestamp > DATE_FORMAT(SUBDATE(NOW(), INTERVAL 30 DAY), '%Y%m%d%H%i%s')
 GROUP BY afl_filter) AS stats
 LEFT JOIN abuse_filter
 ON F = af_id''')
        r = c.fetchall()
        r = [(f, t and t.decode('utf8') or u'', int(n), int(a), int(e), int(d)) for f, t, n, a, e, d in r]
        r = {'wiki': wiki, 'link': link(wiki), 'filters': r, 'max': max(map(max, [f[2:] for f in r]))}
	return render_template_string(allfilters, title='Filtros', **r)
    elif c and filter: # Um ou mais filtros ao longo do tempo
        query = '''SELECT
 SUBSTR(afl_timestamp, 1, 8) dia,
 SUM(afl_actions = '') nada,
 SUM(afl_actions = 'tag') etiq,
 SUM(afl_actions = 'warn') aviso,
 SUM(afl_actions = 'disallow') desaut
 FROM abuse_filter_log
 WHERE afl_filter = ? AND afl_timestamp > DATE_FORMAT(SUBDATE(NOW(), INTERVAL 1 YEAR), '%Y%m%d%H%i%s')
 GROUP BY WEEK(afl_timestamp)
 ORDER BY dia'''
        filter = [f for f in filter.split('&') if f][0:10]
        filters, names = {}, {}
        for f in filter:
            c.execute(query, (f,))
            r = c.fetchall()
            filters[f] = []
            for l in r:
              if l[0][4:] == '0101' and filters[f] and int(str(filters[f][-1][0])[4:]) > 1225:
                filters[f][-1] = [filters[f][-1][0]] + [int(l[i]) + filters[f][-1][i] for i in range(1, 5)]
              else:
                filters[f].append(map(int, l))
	    c.execute('SELECT af_public_comments FROM abuse_filter WHERE af_id = ?', (f,))
	    names[f] = 'Filtro ' + f + u' – ' + c.fetchone()[0].decode('utf-8').replace(u'"', u'\\"')
        title = len(filter) == 1 and names[filter[0]] or ' + '.join(['Filtro ' + f for f in filter])
	r = {'wiki': wiki, 'link': link(wiki), 'filters': filters, 'names': names}
	return render_template_string(filtergraph, title=title, **r)
    else:
        r = {}
        return render_template_string(allfilters, title=u'Filtros', **r)