-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathWatchesQuery.php
More file actions
135 lines (109 loc) · 3.1 KB
/
Copy pathWatchesQuery.php
File metadata and controls
135 lines (109 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
class WatchesQuery {
public $sqlMaxPendingMins = 'MAX( TIMESTAMPDIFF(MINUTE, w.wl_notificationtimestamp, UTC_TIMESTAMP()) ) AS max_pending_minutes';
public $sqlAvgPendingMins = 'AVG( TIMESTAMPDIFF(MINUTE, w.wl_notificationtimestamp, UTC_TIMESTAMP()) ) AS avg_pending_minutes';
public $tables;
public $fields;
public $join_conds;
public $conds;
public $options;
/**
* @var int $limit: maximum number of database rows to return
* @todo FIXME: who/what sets this?
* @example 20
*/
public $limit;
/**
* @var int $offset: used with $limit for pagination
* @todo FIXME: who/what sets this?
* @example 100
*/
public $offset;
/**
* @var array $fieldNames: property declared in child classes to bind a MW
* message with a SQL database column
* @todo FIXME: where is this used?
* @example array( 'dbkey' => 'message-name', 'page_ns_and_title' => 'watchanalytics-special-header-page-title' )
*/
protected $fieldNames;
/**
* @var string|bool $userGroupFilter: defines which user group to be used to
* filter for page-watches
* @example 'sysop'
*/
protected $userGroupFilter = false;
/**
* @var string|bool $categoryFilter: defines which category to be used to
* filter for page-watches
* @example 'Articles_with_unsourced_statements'
*/
protected $categoryFilter = false;
public function __construct() {
}
public function createTimeStringFromMinutes( $totalMinutes ) {
$remainder = $totalMinutes;
$minutesInDay = 60 * 24;
$minutesInHour = 60;
$days = floor( $remainder / $minutesInDay );
$remainder = $remainder % $minutesInDay;
$hours = floor( $remainder / $minutesInHour );
$remainder = $remainder % $minutesInHour;
$minutes = $remainder;
$time = [];
if ( $days ) {
$time[] = $days . ' day' . ( ( $days > 1 ) ? 's' : '' );
}
if ( $hours ) {
$time[] = $hours . ' hour' . ( ( $hours > 1 ) ? 's' : '' );
}
if ( $minutes ) {
$time[] = $minutes . ' minute' . ( ( $minutes > 1 ) ? 's' : '' );
}
// return implode(', ', $time);
if ( count( $time ) > 0 ) {
return $time[0];
} else {
return '';
}
}
public function getFieldNames() {
$output = [];
foreach ( $this->fieldNames as $dbKey => $msg ) {
$output[$dbKey] = wfMessage( $msg )->text();
}
return $output;
}
public function getQueryInfo() {
$this->conds = $this->conds ? $this->conds : [];
if ( isset( $this->limit ) ) {
$this->options['LIMIT'] = $this->limit;
}
if ( isset( $this->offset ) ) {
$this->options['OFFSET'] = $this->offset;
}
$return = [
'tables' => $this->tables,
'fields' => $this->fields,
'join_conds' => $this->join_conds,
'conds' => $this->conds,
'options' => $this->options,
];
return $return;
}
public function setUserGroupFilter( $ugf ) {
if ( $ugf ) {
$this->userGroupFilter = $ugf;
}
}
public function setCategoryFilter( $cf ) {
if ( $cf ) {
$this->categoryFilter = $cf;
}
}
public function setCategoryFilterQueryInfo() {
$this->tables['cat'] = 'categorylinks';
$this->join_conds['cat'] = [
'RIGHT JOIN', 'cat.cl_from = p.page_id AND cat.cl_to = "' . $this->categoryFilter . '"'
];
}
}