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
|
|
|
private static $titleCache = []; |
14
|
|
|
private $query; |
15
|
|
|
private $log; |
16
|
|
|
private $db; |
17
|
|
|
private $titleKey; |
18
|
|
|
private $type; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param AppFactory $appFactory injected AppFactory |
|
|
|
|
22
|
|
|
* @param string $titleKey from page name |
23
|
|
|
* @param string $type of log (default: approval) |
24
|
|
|
*/ |
25
|
|
|
public function __construct( DatabaseBase $db, $titleKey, $type = 'approval' ) { |
26
|
|
|
$this->db = $db; |
27
|
|
|
$this->titleKey = $titleKey; |
28
|
|
|
$this->type = $type; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Take care of loading from the cache or filling the query. |
33
|
|
|
*/ |
34
|
|
|
private function init() { |
35
|
|
|
if ( !$this->query ) { |
36
|
|
|
if ( !isset( self::$titleCache[ $this->titleKey ] ) ) { |
37
|
|
|
$this->query = DatabaseLogEntry::getSelectQueryData(); |
38
|
|
|
|
39
|
|
|
$this->query['conds'] = [ |
40
|
|
|
'log_type' => $this->type, |
41
|
|
|
'log_title' => $this->titleKey |
42
|
|
|
]; |
43
|
|
|
$this->query['options'] = [ 'ORDER BY' => 'log_timestamp desc' ]; |
44
|
|
|
self::$titleCache[ $this->titleKey ] = $this; |
45
|
|
|
} elseif ( $this->query ) { |
46
|
|
|
$cache = self::$titleCache[ $this->titleKey ]; |
47
|
|
|
$this->query = $cache->getQuery(); |
48
|
|
|
$this->log = $cache->getLog(); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Fetch the results using our conditions |
55
|
|
|
* |
56
|
|
|
* @return IResultWrapper |
57
|
|
|
* @throws DBError |
58
|
|
|
*/ |
59
|
|
|
private function getLog() { |
60
|
|
|
if ( !$this->log ) { |
61
|
|
|
$this->log = $this->db->select( |
62
|
|
|
$this->query['tables'], $this->query['fields'], $this->query['conds'], |
63
|
|
|
__METHOD__, $this->query['options'], $this->query['join_conds'] |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
return $this->log; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Fetch the query parameters for later calls |
71
|
|
|
* |
72
|
|
|
* @return array of parameters for SELECT call |
73
|
|
|
*/ |
74
|
|
|
public function getQuery() { |
75
|
|
|
return $this->query; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return User |
80
|
|
|
*/ |
81
|
|
|
public function getUserForLogEntry() { |
82
|
|
|
$this->init(); |
83
|
|
|
$logLine = $this->getLog()->current(); |
84
|
|
|
if ( $logLine ) { |
85
|
|
|
return User::newFromID( $logLine->user_id ); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return Timestamp |
91
|
|
|
*/ |
92
|
|
|
public function getDateOfLogEntry() { |
93
|
|
|
$this->init(); |
94
|
|
|
$logLine = $this->getLog()->current(); |
95
|
|
|
if ( $logLine ) { |
96
|
|
|
return new MWTimestamp( $logLine->log_timestamp ); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function getStatusOfLogEntry() { |
104
|
|
|
$this->init(); |
105
|
|
|
$logLine = $this->getLog()->current(); |
106
|
|
|
if ( $logLine ) { |
107
|
|
|
return $logLine->log_action; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
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.