3
3
class CTHooks {
4
4
5
5
/**
6
- * Upload spam test
6
+ * Upload spam test
7
7
* UploadBase $upload
8
8
* string $mime
9
9
* bool|array $error
10
10
* @return none
11
11
*/
12
12
public static function onUploadFilter ( $ upload , $ mime , &$ error ) {
13
- global $ wgRequest , $ wgCTExtName , $ wgCTMinEditCount , $ wgUser ;
14
-
13
+ global $ wgRequest , $ wgCTExtName , $ wgCTMinEditCount ;
14
+ $ user = RequestContext::getMain ()->getUser ();
15
+
15
16
# Skip spam check if error exists already
16
17
if ($ error !== TRUE ) {
17
18
return ;
18
19
}
19
-
20
+
20
21
$ allowUpload = true ;
21
22
22
23
// Skip antispam test if user is member of special group
23
- if ( $ wgUser ->isAllowed ('cleantalk-bypass ' ) ) {
24
+ if ( $ user ->isAllowed ('cleantalk-bypass ' ) ) {
24
25
return ;
25
26
}
26
27
27
28
// Skip antispam test for user with getEditCount() more than setted value
28
- $ edit_count = $ wgUser ->getEditCount ();
29
+ $ edit_count = $ user ->getEditCount ();
29
30
if ( isset ($ edit_count ) && $ edit_count > $ wgCTMinEditCount ) {
30
31
return ;
31
32
}
@@ -34,8 +35,8 @@ public static function onUploadFilter ( $upload, $mime, &$error ) {
34
35
$ ctResult = CTBody::onSpamCheck (
35
36
'check_message ' , array (
36
37
'message ' => $ wgRequest ->getVal ('wpUploadDescription ' ),
37
- 'sender_email ' => $ wgUser ->mEmail ,
38
- 'sender_nickname ' => $ wgUser ->mName ,
38
+ 'sender_email ' => $ user ->mEmail ,
39
+ 'sender_nickname ' => $ user ->mName ,
39
40
)
40
41
);
41
42
if ( $ ctResult ->errno != 0 ) {
@@ -52,43 +53,44 @@ public static function onUploadFilter ( $upload, $mime, &$error ) {
52
53
}
53
54
}
54
55
55
- // Disallow edit with CleanTalk comment
56
+ // Disallow edit with CleanTalk comment
56
57
if (!$ allowUpload || $ ctResult ->allow == 0 ) {
57
58
// Converting links to wikitext format
58
59
$ errorText = preg_replace ("(<a\shref= \"([^\s]+) \".+>([a-f0-9]+)</a>) " , "[$1 $2] " , $ ctResult ->comment );
59
60
60
61
// Fill $error parameter as array with error text
61
62
$ error = array ($ errorText );
62
63
}
63
-
64
+
64
65
if ($ ctResult ->inactive === 1 ) {
65
66
CTBody::SendAdminEmail ( $ wgCTExtName , $ ctResult ->comment );
66
67
}
67
68
68
69
return ;
69
70
}
70
-
71
+
71
72
/**
72
- * Edit spam test
73
+ * Edit spam test
73
74
* @return bool
74
75
*/
75
76
public static function onEditFilter ( $ editor , $ text , $ section , &$ error , $ summary ) {
76
- global $ wgCTExtName , $ wgCTNewEditsOnly , $ wgCTMinEditCount , $ wgUser ;
77
-
77
+ global $ wgCTExtName , $ wgCTNewEditsOnly , $ wgCTMinEditCount ;
78
+ $ user = $ editor ->getArticle ()->getContext ()->getUser ();
79
+
78
80
$ allowEdit = true ;
79
81
80
82
// Skip antispam test if editor member of special group
81
83
if ( $ editor ->getArticle ()->getContext ()->getUser ()->isAllowed ('cleantalk-bypass ' ) ) {
82
84
return $ allowEdit ;
83
85
}
84
-
86
+
85
87
// Skip antispam test of not new edit if flag is set
86
88
if ( $ wgCTNewEditsOnly && !$ editor ->isNew ) {
87
89
return $ allowEdit ;
88
90
}
89
91
90
92
// Skip antispam test if user is member of special group
91
- if ( $ wgUser ->isAllowed ('cleantalk-bypass ' ) ) {
93
+ if ( $ user ->isAllowed ('cleantalk-bypass ' ) ) {
92
94
return $ allowEdit ;
93
95
}
94
96
@@ -111,7 +113,7 @@ public static function onEditFilter ( $editor, $text, $section, &$error, $summa
111
113
/*if ( $ctResult->errno != 0 ) {
112
114
return $allowEdit;
113
115
}*/
114
- if ( $ ctResult ->errno != 0 )
116
+ if ( $ ctResult ->errno != 0 )
115
117
{
116
118
if (CTBody::JSTest ()!=1 )
117
119
{
@@ -126,33 +128,33 @@ public static function onEditFilter ( $editor, $text, $section, &$error, $summa
126
128
}
127
129
}
128
130
129
- // Disallow edit with CleanTalk comment
131
+ // Disallow edit with CleanTalk comment
130
132
if (!$ allowEdit || $ ctResult ->allow == 0 ) {
131
133
$ error = $ ctResult ->comment ;
132
-
134
+
133
135
// Converting links to wikitext format
134
136
$ error = preg_replace ("(<a\shref= \"([^\s]+) \".+>([a-f0-9]+)</a>) " , "[$1 $2] " , $ error );
135
-
137
+
136
138
$ error = Html::openElement ( 'div ' , array ( 'class ' => 'errorbox ' ) ) .
137
- $ error .
139
+ $ error .
138
140
Html::closeElement ( 'div ' ) . "\n" .
139
141
Html::element ( 'br ' , array ( 'clear ' => 'all ' ) ) . "\n" ;
140
142
}
141
-
143
+
142
144
if ($ ctResult ->inactive === 1 ) {
143
145
CTBody::SendAdminEmail ( $ wgCTExtName , $ ctResult ->comment );
144
146
}
145
147
146
148
return $ allowEdit ;
147
149
}
148
-
150
+
149
151
/**
150
- * Account spam test
152
+ * Account spam test
151
153
* @return bool
152
154
*/
153
155
public static function onAbortNewAccount ( $ user , &$ message ) {
154
156
global $ wgCTExtName ;
155
-
157
+
156
158
$ allowAccount = true ;
157
159
158
160
// Check
@@ -163,7 +165,7 @@ public static function onAbortNewAccount ( $user, &$message ) {
163
165
)
164
166
);
165
167
// Allow account if we have any API errors
166
- if ( $ ctResult ->errno != 0 )
168
+ if ( $ ctResult ->errno != 0 )
167
169
{
168
170
if (CTBody::JSTest ()!=1 )
169
171
{
@@ -176,12 +178,12 @@ public static function onAbortNewAccount ( $user, &$message ) {
176
178
}
177
179
}
178
180
179
- // Disallow account with CleanTalk comment
181
+ // Disallow account with CleanTalk comment
180
182
if ($ ctResult ->allow == 0 ) {
181
183
$ allowAccount = false ;
182
184
$ message = $ ctResult ->comment ;
183
185
}
184
-
186
+
185
187
if ($ ctResult ->inactive === 1 ) {
186
188
CTBody::SendAdminEmail ( $ wgCTExtName , $ ctResult ->comment );
187
189
}
@@ -190,19 +192,19 @@ public static function onAbortNewAccount ( $user, &$message ) {
190
192
}
191
193
public static function onTitleMove ( Title $ title , Title $ newtitle , User $ user )
192
194
{
193
- global $ wgUser , $ wgCTExtName ;
195
+ global $ wgCTExtName ;
194
196
195
197
// Skip antispam test if user is member of special group
196
- if ( $ wgUser ->isAllowed ('cleantalk-bypass ' ) ) {
198
+ if ( $ user ->isAllowed ('cleantalk-bypass ' ) ) {
197
199
return ;
198
200
}
199
201
$ errors = [];
200
202
// Check
201
203
$ ctResult = CTBody::onSpamCheck (
202
204
'check_message ' , array (
203
205
'message ' => $ newtitle ->mUrlform ,
204
- 'sender_email ' => $ wgUser ->mEmail ,
205
- 'sender_nickname ' => $ wgUser ->mName ,
206
+ 'sender_email ' => $ user ->mEmail ,
207
+ 'sender_nickname ' => $ user ->mName ,
206
208
)
207
209
);
208
210
if ( $ ctResult ->errno != 0 ) {
@@ -217,28 +219,31 @@ public static function onTitleMove( Title $title, Title $newtitle, User $user )
217
219
}
218
220
}
219
221
220
- // Disallow edit with CleanTalk comment
222
+ // Disallow edit with CleanTalk comment
221
223
if ($ ctResult ->allow == 0 ) {
222
224
$ errors [] = $ ctResult ->comment ;
223
225
}
224
-
226
+
225
227
if ($ ctResult ->inactive === 1 ) {
226
228
CTBody::SendAdminEmail ( $ wgCTExtName , $ ctResult ->comment );
227
- }
229
+ }
228
230
229
231
if (count ($ errors ))
230
232
throw new PermissionsError ( 'move ' , $ errors );
231
- }
233
+ }
232
234
public static function onSkinAfterBottomScripts ( $ skin , &$ text )
233
235
{
234
236
global $ wgCTShowLink , $ wgCTSFW , $ wgCTAccessKey ;
235
237
236
238
$ text .= CTBody::AddJSCode ();
237
- CTBody::ctSetCookie ();
239
+ CTBody::ctSetCookie ();
240
+
241
+ $ dbr = wfGetDB (DB_MASTER );
242
+
238
243
239
244
/* SFW starts */
240
-
241
- if ($ wgCTSFW )
245
+
246
+ if ($ wgCTSFW && ! $ dbr -> isReadOnly () )
242
247
{
243
248
CTBody::createSFWTables ();
244
249
@@ -252,14 +257,14 @@ public static function onSkinAfterBottomScripts( $skin, &$text )
252
257
$ settings_changed = false ;
253
258
254
259
if (!isset ($ settings ['lastSFWUpdate ' ]) || ($ settings ['lastSFWUpdate ' ] && (time ()-$ settings ['lastSFWUpdate ' ] > 86400 )))
255
- {
260
+ {
256
261
$ sfw ->sfw_update ($ wgCTAccessKey );
257
262
$ settings ['lastSFWUpdate ' ] = time ();
258
263
$ settings_changed = true ;
259
264
}
260
265
if (!isset ($ settings ['lastSFWSendLogs ' ]) || $ settings ['lastSFWSendLogs ' ] && (time () - $ settings ['lastSFWSendLogs ' ] > 3600 ))
261
266
{
262
- $ sfw ->send_logs ($ wgCTAccessKey );
267
+ $ sfw ->send_logs ($ wgCTAccessKey );
263
268
$ settings ['lastSFWSendLogs ' ] = time ();
264
269
$ settings_changed = true ;
265
270
}
@@ -269,9 +274,9 @@ public static function onSkinAfterBottomScripts( $skin, &$text )
269
274
}
270
275
271
276
/* Check IP here */
272
-
277
+
273
278
$ is_sfw_check = true ;
274
- $ sfw ->ip_array = (array )CleantalkSFW::ip_get (array ('real ' ), true );
279
+ $ sfw ->ip_array = (array )CleantalkSFW::ip_get (array ('real ' ), true );
275
280
276
281
foreach ($ sfw ->ip_array as $ key => $ value )
277
282
{
@@ -284,7 +289,7 @@ public static function onSkinAfterBottomScripts( $skin, &$text )
284
289
$ sfw ->sfw_update_logs ($ value , 'passed ' );
285
290
}
286
291
}
287
- } unset($ key , $ value );
292
+ } unset($ key , $ value );
288
293
289
294
if ($ is_sfw_check )
290
295
{
@@ -294,17 +299,17 @@ public static function onSkinAfterBottomScripts( $skin, &$text )
294
299
$ sfw ->sfw_update_logs ($ sfw ->blocked_ip , 'blocked ' );
295
300
$ sfw ->sfw_die ($ wgCTAccessKey );
296
301
}
297
- }
302
+ }
298
303
/* Finish checking IP */
299
304
}
300
305
}
301
-
306
+
302
307
/* SFW ends */
303
-
304
- if ($ wgCTShowLink )
308
+
309
+ if ($ wgCTShowLink && strpos ( $ text , ' blocked by CleanTalk ' ) === false )
305
310
{
306
- $ text .="<div style='width:100%;text-align:center;'><a href='https://cleantalk.org'>MediaWiki spam</a> blocked by CleanTalk.</div> " ;
311
+ $ text .="<div style='width:100%;text-align:center;display: flow-root; '><a href='https://cleantalk.org'>MediaWiki spam</a> blocked by CleanTalk.</div> " ;
307
312
}
308
313
return true ;
309
314
}
310
- }
315
+ }
0 commit comments