forked from albertoleoncio/wikipedia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
badnames.php
104 lines (73 loc) · 4 KB
/
badnames.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
include './bin/globals.php';
//Login
include './bin/api.php';
loginAPI($usernameBQ, $passwordBQ);
//Coleta categoria de usuários notificados
$list = json_decode(file_get_contents("https://pt.wikipedia.org/w/api.php?action=query&format=json&list=categorymembers&cmtitle=Category%3A!Usu%C3%A1rios%20com%20nomes%20impr%C3%B3prios%20notificados&cmprop=title%7Ctimestamp&cmsort=timestamp&cmlimit=500"), true)["query"]["categorymembers"];
//Loop para cada usuário da categoria
foreach ($list as $item) {
//Coleta nome da página de discussão do usuário
$usertalk = $item["title"];
//Coleta informações do usuário
$info = json_decode(file_get_contents("https://pt.wikipedia.org/w/api.php?action=query&format=json&list=blocks&bkusers=".urlencode(preg_replace('/.*?:/', '', $usertalk))), true)['query']['blocks'];
//Verifica se usuário está bloqueado
if (!isset($info[0])) {
//Verifica se prazo de 5 dias foi decorrido. Caso sim, interrompe loop e segue para o próximo usuário
if ((date("U", strtotime($item["timestamp"])) + 432000) > time()) continue;
//Define página de discussão do usuário e recupera codigo-fonte da página
$page = $usertalk;
$html = getAPI($page);
//Gravar código
editAPI($html, NULL, TRUE, "", $page, $usernameBQ);
} else {
//Define variável
$blockinfo = $info[0];
//Caso bloqueio seja menor que 24 horas, interrompe loop e segue para o próximo usuário
if ($blockinfo['expiry'] != "infinity") continue;
//Define página de discussão do usuário e recupera codigo-fonte da página
$page = $usertalk;
$html = getAPI($page);
//Remove categorização
$html = preg_replace('/{{#ifeq:[^\|]*\|{{PAGENAME}}.*\]\]}}}}(?=\n)/', '', $html);
//Gravar código
editAPI($html, NULL, TRUE, "bot: Removendo categoria de nome impróprio", $page, $usernameBQ);
//Limpa variável para próximo loop
unset($page);
}
}
echo("<hr>");
//Coleta categoria de usuários notificados
$list2 = json_decode(file_get_contents("https://pt.wikipedia.org/w/api.php?action=query&format=json&list=categorymembers&cmtitle=Categoria%3A!Usu%C3%A1rios%20com%20nomes%20impr%C3%B3prios%20pass%C3%ADveis%20de%20bloqueio&cmprop=title&cmsort=timestamp&cmlimit=500"), true)["query"]["categorymembers"];
//Loop para cada usuário da categoria
foreach ($list2 as $item2) {
//Coleta nome da página de discussão do usuário
$usertalk = $item2["title"];
//Coleta informações do usuário
$info2 = json_decode(file_get_contents("https://pt.wikipedia.org/w/api.php?action=query&format=json&list=blocks&bkusers=".urlencode(preg_replace('/.*?:/', '', $usertalk))), true)['query']['blocks'];
//Verifica se usuário está bloqueado
if (isset($info2[0])) {
//Define página de discussão do usuário e recupera codigo-fonte da página
$page = $usertalk;
$html = getAPI($page);
//Remove categorização
$html = preg_replace('/{{#ifeq:[^\|]*\|{{PAGENAME}}.*\]\]}}}}(?=\n)/', '', $html);
//Gravar código e passa para o próximo usuário
editAPI($html, NULL, TRUE, "bot: Removendo categoria de nome impróprio", $page, $usernameBQ);
continue;
}
//Coleta afluentes da página de usuário
$afluentes = end(json_decode(file_get_contents('https://pt.wikipedia.org/w/api.php?action=query&format=json&prop=linkshere&titles='.urlencode($item2["title"])), true)["query"]["pages"]);
//Verifica se já há pedido de revisão ou renomeação para a conta
if (isset($afluentes["linkshere"])) {
if (array_search("6286011", array_column($afluentes["linkshere"], 'pageid')) !== FALSE) continue;
if (array_search("2077627", array_column($afluentes["linkshere"], 'pageid')) !== FALSE) continue;
}
//Define página de pedidos e recupera codigo-fonte da página
$page = "Wikipédia:Pedidos/Revisão de nomes de usuário";
$html = getAPI($page);
//Insere pedido no código
$html = $html."\n{{subst:Nome de usuário impróprio/BloqBot|".preg_replace('/.*?:/', '', $item2["title"])."}}\n";
//Gravar código
editAPI($html, NULL, FALSE, "bot: Inserindo pedido de usuário notificado há 5 dias", $page, $usernameBQ);
}