1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SESP; |
4
|
|
|
|
5
|
|
|
use DatabaseLogEntry; |
6
|
|
|
use DatabaseBase; |
7
|
|
|
use MWTimestamp; |
8
|
|
|
use Title; |
9
|
|
|
use User; |
10
|
|
|
|
11
|
|
|
class DatabaseLogReader { |
12
|
|
|
|
13
|
|
|
// The parameters for our query. |
14
|
|
|
private $query; |
15
|
|
|
|
16
|
|
|
// The current log |
17
|
|
|
private $log; |
18
|
|
|
|
19
|
|
|
// Don't run multiple queries if we don't have to |
20
|
|
|
private static $titleCache = []; |
21
|
|
|
|
22
|
|
|
// The db connection |
23
|
|
|
private $db; |
24
|
|
|
|
25
|
|
|
// The title key |
26
|
|
|
private $titlekey; |
27
|
|
|
|
28
|
|
|
// The type of query being performed |
29
|
|
|
private $type; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Constructor for reading the log. |
33
|
|
|
* |
34
|
|
|
* @param AppFactory $appFactory injected AppFactory |
|
|
|
|
35
|
|
|
* @param Title $title page |
36
|
|
|
* @param string $type of log (default: approval) |
37
|
|
|
*/ |
38
|
|
|
public function __construct( DatabaseBase $db, Title $title, $type = 'approval' ) { |
39
|
|
|
$this->db = $db; |
40
|
|
|
$this->titlekey = $title->getDBKey(); |
41
|
|
|
$this->type = $type; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Take care of loading from the cache or filling the query. |
46
|
|
|
*/ |
47
|
|
|
private function init() { |
48
|
|
|
if ( !$this->query ) { |
49
|
|
|
if ( !isset( self::$titleCache[ $this->titlekey ] ) ) { |
50
|
|
|
$this->query = DatabaseLogEntry::getSelectQueryData(); |
51
|
|
|
|
52
|
|
|
$this->query['conds'] = [ |
53
|
|
|
'log_type' => $this->type, |
54
|
|
|
'log_title' => $this->titlekey |
55
|
|
|
]; |
56
|
|
|
$this->query['options'] = [ 'ORDER BY' => 'log_timestamp desc' ]; |
57
|
|
|
self::$titleCache[ $this->titlekey ] = $this; |
58
|
|
|
} elseif ( $this->query ) { |
59
|
|
|
$cache = self::$titleCache[ $this->titlekey ]; |
60
|
|
|
$this->query = $cache->getQuery(); |
61
|
|
|
$this->log = $cache->getLog(); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Fetch the results using our conditions |
68
|
|
|
* |
69
|
|
|
* @return IResultWrapper |
70
|
|
|
* @throws DBError |
71
|
|
|
*/ |
72
|
|
|
private function getLog() { |
73
|
|
|
if ( !$this->log ) { |
74
|
|
|
$this->log = $this->db->select( |
75
|
|
|
$this->query['tables'], $this->query['fields'], $this->query['conds'], |
76
|
|
|
__METHOD__, $this->query['options'], $this->query['join_conds'] |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
return $this->log; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Fetch the query for later calls |
84
|
|
|
* |
85
|
|
|
* @return array |
86
|
|
|
*/ |
87
|
|
|
public function getQuery() { |
88
|
|
|
return $this->query; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get the person who made the last for this page |
93
|
|
|
* |
94
|
|
|
* @return User |
95
|
|
|
*/ |
96
|
|
|
public function getUser() { |
97
|
|
|
$this->init(); |
98
|
|
|
$logLine = $this->getLog()->current(); |
99
|
|
|
if ( $logLine ) { |
100
|
|
|
return User::newFromID( $logLine->user_id ); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Get the date of the last entry in the log for this page |
106
|
|
|
* |
107
|
|
|
* @return Timestamp |
108
|
|
|
*/ |
109
|
|
|
public function getDate() { |
110
|
|
|
$this->init(); |
111
|
|
|
$logLine = $this->getLog()->current(); |
112
|
|
|
if ( $logLine ) { |
113
|
|
|
return new MWTimestamp( $logLine->log_timestamp ); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Get the status of the last entry in the log for this page |
119
|
|
|
* |
120
|
|
|
* @return Timestamp |
121
|
|
|
*/ |
122
|
|
|
public function getStatus() { |
123
|
|
|
$this->init(); |
124
|
|
|
$logLine = $this->getLog()->current(); |
125
|
|
|
if ( $logLine ) { |
126
|
|
|
return $logLine->log_action; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.