1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SESP; |
4
|
|
|
|
5
|
|
|
use DatabaseLogEntry; |
6
|
|
|
use MWTimestamp; |
7
|
|
|
use User; |
8
|
|
|
|
9
|
|
|
class LogReader { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Get the person who made the last for this page |
13
|
|
|
* |
14
|
|
|
* @return User |
15
|
|
|
*/ |
16
|
|
|
public function getUser() { |
17
|
|
|
return User::newFromID( $this->getLog()->current()->user_id ); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Get the date of the last entry in the log for this page |
22
|
|
|
* |
23
|
|
|
* @return Timestamp |
24
|
|
|
*/ |
25
|
|
|
public function getDate() { |
26
|
|
|
return new MWTimestamp( $this->getLog()->current()->log_timestamp ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get the status of the last entry in the log for this page |
31
|
|
|
* |
32
|
|
|
* @return Timestamp |
33
|
|
|
*/ |
34
|
|
|
public function getStatus() { |
35
|
|
|
return $this->getLog()->current()->log_action; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Fetch the results using our conditions |
40
|
|
|
* |
41
|
|
|
* @return IResultWrapper |
42
|
|
|
* @throws DBError |
43
|
|
|
*/ |
44
|
|
|
protected function getLog() { |
45
|
|
|
if ( !$this->log ) { |
46
|
|
|
// @codingStandardsIgnoreLine DB_SLAVE needs to be kept for now |
47
|
|
|
$dbr = wfGetDB( DB_SLAVE ); |
48
|
|
|
$this->log = $dbr->select( |
49
|
|
|
$query['tables'], $query['fields'], $query['conds'], |
|
|
|
|
50
|
|
|
__METHOD__, $query['options'], $query['join_conds'] |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
return $this->log; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Fetch the query for later calls |
58
|
|
|
* |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
public function getQuery() { |
62
|
|
|
return $this->query; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
// The parameters for our query. |
66
|
|
|
protected $query; |
67
|
|
|
|
68
|
|
|
// The current log |
69
|
|
|
protected $log; |
70
|
|
|
|
71
|
|
|
// Don't run multiple queries if we don't have to |
72
|
|
|
protected static $titleCache = []; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Constructor for reading the log. |
76
|
|
|
* |
77
|
|
|
* @param Title $title page |
78
|
|
|
* @param string $type of log (default: approval) |
79
|
|
|
*/ |
80
|
|
|
public function __construct( Title $title, $type = 'approval' ) { |
81
|
|
|
if ( !isset( self::$titleCache[ $title->getDBKey() ] ) ) { |
82
|
|
|
$this->query = DatabaseLogEntry::getSelectQueryData(); |
83
|
|
|
|
84
|
|
|
$this->query['conds'] = [ |
85
|
|
|
'log_type' => $type, |
86
|
|
|
'log_title' => $title->getDBKey() |
87
|
|
|
]; |
88
|
|
|
$this->query['options'] = [ 'ORDER BY' => 'log_timestamp desc' ]; |
89
|
|
|
} else { |
90
|
|
|
$cache = self::$titleCache[ $title->getDBKey() ]; |
91
|
|
|
$this->query = $cache->getQuery(); |
92
|
|
|
$this->log = $cache->getLog(); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.