-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMajorChangesLogPager.php
118 lines (98 loc) · 2.75 KB
/
MajorChangesLogPager.php
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
<?php
/**
* @ingroup SpecialPage Pager
*/
class MajorChangesLogPager extends LogPager {
private $status;
private $mode;
private $startDate;
private $endDate;
protected $mConds;
/**
* @param IContextSource $context
* @param FormOptions $opts
*/
function __construct( LogEventsList $logEventsList, FormOptions $opts ) {
// Override TagLogFormatter. We don't want to override it system-wide, just here
global $wgLogActionsHandlers;
$wgLogActionsHandlers['tag/update'] = 'MajorChangesTagLogFormatter';
$this->status = $opts->getValue( 'status' );
$this->startDate = $opts->getValue( 'start' );
$this->endDate = $opts->getValue( 'end' );
$this->mode = $opts->getValue( 'mode' );
parent::__construct(
$logEventsList,
[ 'tag' ],
$opts->getValue( 'user' ),
$opts->getValue( 'page' ),
'',
[],
false,
false,
null
);
}
public function getQueryInfo() {
$db = $this->getDatabase();
$this->limitToRelevantTags();
$this->limitByDates();
$info = parent::getQueryInfo();
switch ( $this->status ) {
case 'queue':
$cond = [ 'ct_tag IS NULL OR ct_tag != ' . $db->addQuotes( 'שינוי מהותי טופל' ) ];
break;
case 'done':
$cond = [ 'ct_tag' => 'שינוי מהותי טופל' ];
break;
}
if ( isset( $cond ) ) {
$info[ 'tables' ][] = 'change_tag';
$info[ 'join_conds' ][ 'change_tag' ] = [ 'LEFT OUTER JOIN', 'ct_log_id=log_id' ];
$info[ 'conds' ] = array_merge( $info[ 'conds' ], $cond );
}
return $info;
}
static public function getAllowedModes() {
return [ 'onlymajor', 'onlyminor', 'all' ];
}
protected function limitToRelevantTags() {
$mainTag = MarkMajorChanges::getMainTagName();
$secondTag = MarkMajorChanges::getSecondaryTagName();
switch ( $this->mode ) {
case 'onlymajor':
$tagList = [ $mainTag ];
break;
case 'onlyminor':
$tagList = [ $secondTag ];
break;
default:
$tagList = [ $mainTag, $secondTag ];
}
$this->mConds[ 'ls_field' ] = 'Tag';
$this->mConds[] = 'ls_value IN (' . $this->getDatabase()->makeList( $tagList ) . ')';
}
protected function limitByDates() {
$dbr = wfGetDB( DB_REPLICA );
if ( $this->startDate ) {
$this->mConds[] = 'log_timestamp >= ' .
$dbr->addQuotes( $dbr->timestamp( new DateTime( $this->startDate ) ) );
}
if ( $this->endDate ) {
// Add 1 day, so we check for "any date before tomorrow"
$this->mConds[] = 'log_timestamp < ' .
$dbr->addQuotes( $dbr->timestamp( new DateTime( $this->endDate . ' +1 day' ) ) );
}
}
public function getTotalNumRows() {
$db = $this->getDatabase();
$info = $this->getQueryInfo();
return $db->selectRowCount(
$info['tables'],
'*',
$info['conds'],
__METHOD__,
[],
$info['join_conds']
);
}
}