|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file contains only the AutoEdits class. |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Xtools; |
|
7
|
|
|
|
|
8
|
|
|
use DateTime; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* AutoEdits returns statistics about automated edits made by a user. |
|
12
|
|
|
*/ |
|
13
|
|
|
class AutoEdits extends Model |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var Project The project. */ |
|
16
|
|
|
protected $project; |
|
17
|
|
|
|
|
18
|
|
|
/** @var User The user. */ |
|
19
|
|
|
protected $user; |
|
20
|
|
|
|
|
21
|
|
|
/** @var int Which namespace we are querying for. */ |
|
22
|
|
|
protected $namespace; |
|
23
|
|
|
|
|
24
|
|
|
/** @var DateTime Start date. */ |
|
25
|
|
|
protected $start; |
|
26
|
|
|
|
|
27
|
|
|
/** @var DateTime End date. */ |
|
28
|
|
|
protected $end; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Constructor for the AutoEdit class. |
|
32
|
|
|
* @param Project $project |
|
33
|
|
|
* @param User $user |
|
34
|
|
|
* @param string $namespace Namespace ID or 'all' |
|
35
|
|
|
* @param string $start Start date in a format accepted by strtotime() |
|
36
|
|
|
* @param string $end End date in a format accepted by strtotime() |
|
37
|
|
|
*/ |
|
38
|
2 |
|
public function __construct(Project $project, User $user, $namespace = 'all', $start = '', $end = '') |
|
39
|
|
|
{ |
|
40
|
2 |
|
$this->project = $project; |
|
41
|
2 |
|
$this->user = $user; |
|
42
|
2 |
|
$this->namespace = $namespace; |
|
|
|
|
|
|
43
|
2 |
|
$this->start = $start; |
|
|
|
|
|
|
44
|
2 |
|
$this->end = $end; |
|
|
|
|
|
|
45
|
2 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Get the number of edits this user made using semi-automated tools. |
|
49
|
|
|
* @return int Result of query, see below. |
|
50
|
|
|
*/ |
|
51
|
1 |
|
public function countAutomatedEdits() |
|
52
|
|
|
{ |
|
53
|
1 |
|
return (int) $this->getRepository()->countAutomatedEdits( |
|
|
|
|
|
|
54
|
1 |
|
$this->project, |
|
55
|
1 |
|
$this->user, |
|
56
|
1 |
|
$this->namespace, |
|
57
|
1 |
|
$this->start, |
|
58
|
1 |
|
$this->end |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get non-automated contributions for this user. |
|
64
|
|
|
* @param int $offset Used for pagination, offset results by N edits. |
|
65
|
|
|
* @return array[] Result of query, with columns (string) 'full_page_title' including namespace, |
|
66
|
|
|
* (string) 'page_title', (int) 'page_namespace', (int) 'rev_id', (DateTime) 'timestamp', |
|
67
|
|
|
* (bool) 'minor', (int) 'length', (int) 'length_change', (string) 'comment' |
|
68
|
|
|
*/ |
|
69
|
1 |
|
public function getNonAutomatedEdits($offset = 0) |
|
70
|
|
|
{ |
|
71
|
1 |
|
$revs = $this->getRepository()->getNonAutomatedEdits( |
|
|
|
|
|
|
72
|
1 |
|
$this->project, |
|
73
|
1 |
|
$this->user, |
|
74
|
1 |
|
$this->namespace, |
|
75
|
1 |
|
$this->start, |
|
76
|
1 |
|
$this->end, |
|
77
|
1 |
|
$offset |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
1 |
|
$namespaces = $this->project->getNamespaces(); |
|
81
|
|
|
|
|
82
|
1 |
|
return array_map(function ($rev) use ($namespaces) { |
|
83
|
1 |
|
$pageTitle = $rev['page_title']; |
|
84
|
1 |
|
$fullPageTitle = ''; |
|
85
|
|
|
|
|
86
|
1 |
|
if ($rev['page_namespace'] !== '0') { |
|
87
|
1 |
|
$fullPageTitle = $namespaces[$rev['page_namespace']] . ":$pageTitle"; |
|
88
|
|
|
} else { |
|
89
|
|
|
$fullPageTitle = $pageTitle; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return [ |
|
93
|
1 |
|
'full_page_title' => $fullPageTitle, |
|
94
|
1 |
|
'page_title' => $pageTitle, |
|
95
|
1 |
|
'page_namespace' => (int) $rev['page_namespace'], |
|
96
|
1 |
|
'rev_id' => (int) $rev['rev_id'], |
|
97
|
1 |
|
'timestamp' => DateTime::createFromFormat('YmdHis', $rev['timestamp']), |
|
98
|
1 |
|
'minor' => (bool) $rev['minor'], |
|
99
|
1 |
|
'length' => (int) $rev['length'], |
|
100
|
1 |
|
'length_change' => (int) $rev['length_change'], |
|
101
|
1 |
|
'comment' => $rev['comment'], |
|
102
|
|
|
]; |
|
103
|
1 |
|
}, $revs); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Get counts of known automated tools used by the given user. |
|
108
|
|
|
* @return string[] Each tool that they used along with the count and link: |
|
109
|
|
|
* [ |
|
110
|
|
|
* 'Twinkle' => [ |
|
111
|
|
|
* 'count' => 50, |
|
112
|
|
|
* 'link' => 'Wikipedia:Twinkle', |
|
113
|
|
|
* ], |
|
114
|
|
|
* ] |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getAutomatedCounts() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->getRepository()->getAutomatedCounts( |
|
|
|
|
|
|
119
|
|
|
$this->project, |
|
120
|
|
|
$this->user, |
|
121
|
|
|
$this->namespace, |
|
122
|
|
|
$this->start, |
|
123
|
|
|
$this->end |
|
124
|
|
|
); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.