|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file contains only the ArticleInfoRepository class. |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Xtools; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* ArticleInfoRepository is responsible for retrieving data about a single |
|
10
|
|
|
* article on a given wiki. |
|
11
|
|
|
*/ |
|
12
|
|
|
class ArticleInfoRepository extends Repository |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Get the number of edits made to the page by bots or former bots. |
|
16
|
|
|
* @param Page $page |
|
17
|
|
|
* @return PDOStatement resolving with keys 'count', 'username' and 'current'. |
|
18
|
|
|
*/ |
|
19
|
|
|
public function getBotData(Page $page) |
|
20
|
|
|
{ |
|
21
|
|
|
$project = $page->getProject(); |
|
22
|
|
|
$userGroupsTable = $project->getTableName('user_groups'); |
|
23
|
|
|
$userFromerGroupsTable = $project->getTableName('user_former_groups'); |
|
24
|
|
|
$sql = "SELECT COUNT(rev_user_text) AS count, rev_user_text AS username, ug_group AS current |
|
25
|
|
|
FROM " . $project->getTableName('revision') . " |
|
26
|
|
|
LEFT JOIN $userGroupsTable ON rev_user = ug_user |
|
27
|
|
|
LEFT JOIN $userFromerGroupsTable ON rev_user = ufg_user |
|
28
|
|
|
WHERE rev_page = :pageId AND (ug_group = 'bot' OR ufg_group = 'bot') |
|
29
|
|
|
GROUP BY rev_user_text"; |
|
30
|
|
|
$pageId = $page->getId(); |
|
31
|
|
|
$resultQuery = $this->getProjectsConnection()->prepare($sql); |
|
32
|
|
|
$resultQuery->bindParam('pageId', $pageId); |
|
33
|
|
|
$resultQuery->execute(); |
|
34
|
|
|
return $resultQuery; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Get prior deletions, page moves, and protections to the page. |
|
39
|
|
|
* @param Page page |
|
40
|
|
|
* @return string[] each entry with keys 'log_action', 'log_type' and 'timestamp'. |
|
41
|
|
|
*/ |
|
42
|
|
View Code Duplication |
public function getLogEvents(Page $page) |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
$loggingTable = $page->getProject()->getTableName('logging', 'logindex'); |
|
45
|
|
|
$sql = "SELECT log_action, log_type, log_timestamp AS 'timestamp' |
|
46
|
|
|
FROM $loggingTable |
|
47
|
|
|
WHERE log_namespace = '" . $page->getNamespace() . "' |
|
48
|
|
|
AND log_title = :title AND log_timestamp > 1 |
|
49
|
|
|
AND log_type IN ('delete', 'move', 'protect', 'stable')"; |
|
50
|
|
|
$title = str_replace(' ', '_', $page->getTitle()); |
|
51
|
|
|
$resultQuery = $this->getProjectsConnection()->prepare($sql); |
|
52
|
|
|
$resultQuery->bindParam(':title', $title); |
|
53
|
|
|
$resultQuery->execute(); |
|
54
|
|
|
return $resultQuery->fetchAll(); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.