1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Peachy MediaWiki Bot API |
5
|
|
|
* |
6
|
|
|
* Peachy is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU General Public License as published by |
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU General Public License for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU General Public License |
17
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
class FlaggedRevs { |
21
|
|
|
|
22
|
|
|
private $wiki; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param Wiki $wikiClass |
26
|
|
|
* @throws DependencyError |
27
|
|
|
*/ |
28
|
|
|
function __construct( Wiki &$wikiClass ) { |
|
|
|
|
29
|
|
|
|
30
|
|
|
if( !array_key_exists( 'FlaggedRevs', $wikiClass->get_extensions() ) ) { |
31
|
|
|
throw new DependencyError( "FlaggedRevs", "http://www.mediawiki.org/wiki/Extension:FlaggedRevs" ); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$this->wiki = $wikiClass; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param $revid |
39
|
|
|
* @param null $reason |
40
|
|
|
* @param int $status |
41
|
|
|
* @return bool |
42
|
|
|
* @throws AssertFailure |
43
|
|
|
* @throws BadEntryError |
44
|
|
|
* @throws HookError |
45
|
|
|
* @throws LoggedOut |
46
|
|
|
* @throws MWAPIError |
47
|
|
|
*/ |
48
|
|
|
public function review( $revid, $reason = null, $status = 1 ) { |
49
|
|
|
|
50
|
|
|
if( !in_array( 'review', $this->wiki->get_userrights() ) ) { |
51
|
|
|
pecho( "User is not allowed to review revisions", PECHO_FATAL ); |
52
|
|
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$tokens = $this->wiki->get_tokens(); |
56
|
|
|
|
57
|
|
|
if( $tokens['edit'] == '+\\' ) { |
58
|
|
|
pecho( "User has logged out.\n\n", PECHO_FATAL ); |
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if( mb_strlen( $reason, '8bit' ) > 255 ) { |
|
|
|
|
63
|
|
|
pecho( "Comment is over 255 bytes, the maximum allowed.\n\n", PECHO_FATAL ); |
64
|
|
|
return false; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
pecho( "Reviewing $revid...\n\n", PECHO_NOTICE ); |
68
|
|
|
|
69
|
|
|
$editarray = array( |
70
|
|
|
'flag_accuracy' => $status, |
71
|
|
|
'action' => 'review', |
72
|
|
|
'token' => $tokens['edit'], |
73
|
|
|
'revid' => $revid |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
if( !empty( $reason ) ) $editArray['comment'] = $reason; |
|
|
|
|
77
|
|
|
|
78
|
|
|
if( $this->wiki->get_maxlag() ) { |
79
|
|
|
$editarray['maxlag'] = $this->wiki->get_maxlag(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
Hooks::runHook( 'StartReview', array( &$editarray ) ); |
83
|
|
|
|
84
|
|
|
$result = $this->wiki->apiQuery( $editarray, true ); |
85
|
|
|
|
86
|
|
|
if( isset( $result['review'] ) ) { |
87
|
|
|
if( isset( $result['review']['revid'] ) ) { |
88
|
|
|
return true; |
89
|
|
|
} else { |
90
|
|
|
pecho( "Review error...\n\n" . print_r( $result['review'], true ) . "\n\n", PECHO_FATAL ); |
91
|
|
|
return false; |
92
|
|
|
} |
93
|
|
|
} else { |
94
|
|
|
pecho( "Review error...\n\n" . print_r( $result, true ), PECHO_FATAL ); |
95
|
|
|
return false; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param $title |
101
|
|
|
* @param string $level |
102
|
|
|
* @param null $reason |
103
|
|
|
* @param bool|false $autoreview |
104
|
|
|
* @param bool|false $watch |
105
|
|
|
* @return bool |
106
|
|
|
* @throws AssertFailure |
107
|
|
|
* @throws BadEntryError |
108
|
|
|
* @throws HookError |
109
|
|
|
* @throws LoggedOut |
110
|
|
|
* @throws MWAPIError |
111
|
|
|
*/ |
112
|
|
|
public function stabilize( $title, $level = 'none', $reason = null, $autoreview = false, $watch = false ) { |
|
|
|
|
113
|
|
|
|
114
|
|
|
if( !in_array( 'stablesettings', $this->wiki->get_userrights() ) ) { |
115
|
|
|
pecho( "User is not allowed to change the stabilization settings", PECHO_FATAL ); |
116
|
|
|
return false; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$tokens = $this->wiki->get_tokens(); |
120
|
|
|
|
121
|
|
|
if( $tokens['edit'] == '+\\' ) { |
122
|
|
|
pecho( "User has logged out.\n\n", PECHO_FATAL ); |
123
|
|
|
return false; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
if( mb_strlen( $reason, '8bit' ) > 255 ) { |
|
|
|
|
127
|
|
|
pecho( "Comment is over 255 bytes, the maximum allowed.\n\n", PECHO_FATAL ); |
128
|
|
|
return false; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
pecho( "Stabilizing title...\n\n", PECHO_NOTICE ); |
132
|
|
|
|
133
|
|
|
$editarray = array( |
134
|
|
|
'action' => 'review', |
135
|
|
|
'title' => $title, |
136
|
|
|
'token' => $tokens['edit'], |
137
|
|
|
'protectlevel' => $level |
138
|
|
|
); |
139
|
|
|
|
140
|
|
|
if( $watch ) $editArray['watch'] = 'yes'; |
|
|
|
|
141
|
|
|
if( !empty( $reason ) ) $editArray['reason'] = $reason; |
|
|
|
|
142
|
|
|
|
143
|
|
|
if( $this->wiki->get_maxlag() ) { |
144
|
|
|
$editarray['maxlag'] = $this->wiki->get_maxlag(); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
Hooks::runHook( 'StartStabilize', array( &$editarray ) ); |
148
|
|
|
|
149
|
|
|
$result = $this->wiki->apiQuery( $editarray, true ); |
150
|
|
|
|
151
|
|
|
if( isset( $result['stabilize'] ) ) { |
152
|
|
|
if( isset( $result['stabilize']['title'] ) ) { |
153
|
|
|
return true; |
154
|
|
|
} else { |
155
|
|
|
pecho( "Stabilization error...\n\n" . print_r( $result['stabilize'], true ) . "\n\n", PECHO_FATAL ); |
156
|
|
|
return false; |
157
|
|
|
} |
158
|
|
|
} else { |
159
|
|
|
pecho( "Stabilization error...\n\n" . print_r( $result, true ), PECHO_FATAL ); |
160
|
|
|
return false; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function flagconfig() { } |
166
|
|
|
|
167
|
|
|
public function reviewedpages() { } |
168
|
|
|
|
169
|
|
|
public function unreviewedpages() { } |
170
|
|
|
|
171
|
|
|
public function oldreviewedpages() { } |
172
|
|
|
|
173
|
|
|
} |
174
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.