|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file contains only the ArticleInfoRepository class. |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Xtools; |
|
7
|
|
|
|
|
8
|
|
|
use GuzzleHttp; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* ArticleInfoRepository is responsible for retrieving data about a single |
|
12
|
|
|
* article on a given wiki. |
|
13
|
|
|
*/ |
|
14
|
|
|
class ArticleInfoRepository extends Repository |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Get the number of edits made to the page by bots or former bots. |
|
18
|
|
|
* @param Page $page |
|
19
|
|
|
* @param false|int $start |
|
20
|
|
|
* @param false|int $end |
|
21
|
|
|
* @return \Doctrine\DBAL\Driver\Statement resolving with keys 'count', 'username' and 'current'. |
|
22
|
|
|
*/ |
|
23
|
|
|
public function getBotData(Page $page, $start, $end) |
|
24
|
|
|
{ |
|
25
|
|
|
$project = $page->getProject(); |
|
26
|
|
|
$userGroupsTable = $project->getTableName('user_groups'); |
|
27
|
|
|
$userFormerGroupsTable = $project->getTableName('user_former_groups'); |
|
28
|
|
|
|
|
29
|
|
|
$datesConditions = $this->createDatesConditions($start, $end); |
|
30
|
|
|
|
|
31
|
|
|
$sql = "SELECT COUNT(rev_user_text) AS count, rev_user_text AS username, ug_group AS current |
|
32
|
|
|
FROM " . $project->getTableName('revision') . " |
|
33
|
|
|
LEFT JOIN $userGroupsTable ON rev_user = ug_user |
|
34
|
|
|
LEFT JOIN $userFormerGroupsTable ON rev_user = ufg_user |
|
35
|
|
|
WHERE rev_page = :pageId AND (ug_group = 'bot' OR ufg_group = 'bot') $datesConditions |
|
36
|
|
|
GROUP BY rev_user_text"; |
|
37
|
|
|
$pageId = $page->getId(); |
|
38
|
|
|
$resultQuery = $this->getProjectsConnection()->prepare($sql); |
|
39
|
|
|
$resultQuery->bindParam('pageId', $pageId); |
|
40
|
|
|
$resultQuery->execute(); |
|
41
|
|
|
return $resultQuery; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get prior deletions, page moves, and protections to the page. |
|
46
|
|
|
* @param Page $page |
|
47
|
|
|
* @param false|int $start |
|
48
|
|
|
* @param false|int $end |
|
49
|
|
|
* @return string[] each entry with keys 'log_action', 'log_type' and 'timestamp'. |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getLogEvents(Page $page, $start, $end) |
|
52
|
|
|
{ |
|
53
|
|
|
$loggingTable = $page->getProject()->getTableName('logging', 'logindex'); |
|
54
|
|
|
|
|
55
|
|
|
$datesConditions = $this->createDatesConditions($start, $end, '', 'log_timestamp'); |
|
56
|
|
|
|
|
57
|
|
|
$sql = "SELECT log_action, log_type, log_timestamp AS 'timestamp' |
|
58
|
|
|
FROM $loggingTable |
|
59
|
|
|
WHERE log_namespace = '" . $page->getNamespace() . "' |
|
60
|
|
|
AND log_title = :title AND log_timestamp > 1 $datesConditions |
|
61
|
|
|
AND log_type IN ('delete', 'move', 'protect', 'stable')"; |
|
62
|
|
|
$title = str_replace(' ', '_', $page->getTitle()); |
|
63
|
|
|
$resultQuery = $this->getProjectsConnection()->prepare($sql); |
|
64
|
|
|
$resultQuery->bindParam(':title', $title); |
|
65
|
|
|
$resultQuery->execute(); |
|
66
|
|
|
return $resultQuery->fetchAll(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Query the WikiWho service to get authorship percentages. |
|
71
|
|
|
* @see https://api.wikiwho.net/ |
|
72
|
|
|
* @param Page $page |
|
73
|
|
|
* @return array[] Response from WikiWho. |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getTextshares(Page $page) |
|
76
|
|
|
{ |
|
77
|
|
|
$title = rawurlencode(str_replace(' ', '_', $page->getTitle())); |
|
78
|
|
|
$client = new GuzzleHttp\Client(); |
|
79
|
|
|
|
|
80
|
|
|
$projectLang = $page->getProject()->getLang(); |
|
81
|
|
|
|
|
82
|
|
|
$url = "https://api.wikiwho.net/$projectLang/api/v1.0.0-beta/rev_content/" . |
|
83
|
|
|
"$title/?o_rev_id=false&editor=true&token_id=false&out=false&in=false"; |
|
84
|
|
|
|
|
85
|
|
|
$res = $client->request('GET', $url); |
|
86
|
|
|
return json_decode($res->getBody()->getContents(), true); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get a map of user IDs/usernames given the user IDs. |
|
91
|
|
|
* @param Project $project |
|
92
|
|
|
* @param int[] $userIds |
|
93
|
|
|
* @return array |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getUsernamesFromIds(Project $project, $userIds) |
|
96
|
|
|
{ |
|
97
|
|
|
$userTable = $project->getTableName('user'); |
|
98
|
|
|
$userIds = implode(',', $userIds); |
|
99
|
|
|
$sql = "SELECT user_id, user_name |
|
100
|
|
|
FROM $userTable |
|
101
|
|
|
WHERE user_id IN ($userIds)"; |
|
102
|
|
|
$resultQuery = $this->getProjectsConnection()->prepare($sql); |
|
103
|
|
|
$resultQuery->execute(); |
|
104
|
|
|
return $resultQuery->fetchAll(); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|