Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
32 / 32 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
ContributionInfoRetriever | |
100.00% |
32 / 32 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
retrieveFromIP | |
100.00% |
30 / 30 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\IPInfo\InfoRetriever; |
4 | |
5 | use MediaWiki\IPInfo\Info\ContributionInfo; |
6 | use Wikimedia\IPUtils; |
7 | use Wikimedia\Rdbms\IConnectionProvider; |
8 | |
9 | class ContributionInfoRetriever implements InfoRetriever { |
10 | private IConnectionProvider $dbProvider; |
11 | |
12 | public function __construct( IConnectionProvider $dbProvider ) { |
13 | $this->dbProvider = $dbProvider; |
14 | } |
15 | |
16 | /** @inheritDoc */ |
17 | public function getName(): string { |
18 | return 'ipinfo-source-contributions'; |
19 | } |
20 | |
21 | /** @inheritDoc */ |
22 | public function retrieveFromIP( string $ip ): ContributionInfo { |
23 | $hexIP = IPUtils::toHex( $ip ); |
24 | |
25 | $dbr = $this->dbProvider->getReplicaDatabase(); |
26 | $numLocalEdits = $dbr->newSelectQueryBuilder() |
27 | ->from( 'ip_changes' ) |
28 | ->where( [ |
29 | 'ipc_hex' => $hexIP, |
30 | ] |
31 | ) |
32 | ->caller( __METHOD__ ) |
33 | ->fetchRowCount(); |
34 | |
35 | $oneDayTS = (int)wfTimestamp( TS_UNIX ) - ( 24 * 60 * 60 ); |
36 | $numRecentEdits = $dbr->newSelectQueryBuilder() |
37 | ->from( 'ip_changes' ) |
38 | ->where( [ |
39 | 'ipc_hex' => $hexIP, |
40 | $dbr->expr( 'ipc_rev_timestamp', '>', $dbr->timestamp( $oneDayTS ) ), |
41 | ] |
42 | ) |
43 | ->caller( __METHOD__ ) |
44 | ->fetchRowCount(); |
45 | |
46 | $numDeletedEdits = $dbr->newSelectQueryBuilder() |
47 | ->from( 'archive' ) |
48 | ->join( 'actor', null, 'actor_id=ar_actor' ) |
49 | ->where( [ |
50 | 'actor_name' => $ip, |
51 | ] |
52 | ) |
53 | ->caller( __METHOD__ ) |
54 | ->fetchRowCount(); |
55 | |
56 | return new ContributionInfo( $numLocalEdits, $numRecentEdits, $numDeletedEdits ); |
57 | } |
58 | } |