Skip to content

Commit ad0beda

Browse files
committed
Merge branch 'dev'
# Conflicts: # README.md
2 parents 86cc819 + 0db2315 commit ad0beda

8 files changed

+248
-229
lines changed

Antispam/Antispam.hooks.php

+55-50
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,30 @@
33
class CTHooks {
44

55
/**
6-
* Upload spam test
6+
* Upload spam test
77
* UploadBase $upload
88
* string $mime
99
* bool|array $error
1010
* @return none
1111
*/
1212
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+
1516
# Skip spam check if error exists already
1617
if ($error !== TRUE) {
1718
return;
1819
}
19-
20+
2021
$allowUpload = true;
2122

2223
// Skip antispam test if user is member of special group
23-
if ( $wgUser->isAllowed('cleantalk-bypass') ) {
24+
if ( $user->isAllowed('cleantalk-bypass') ) {
2425
return;
2526
}
2627

2728
// Skip antispam test for user with getEditCount() more than setted value
28-
$edit_count = $wgUser->getEditCount();
29+
$edit_count = $user->getEditCount();
2930
if ( isset($edit_count) && $edit_count > $wgCTMinEditCount ) {
3031
return;
3132
}
@@ -34,8 +35,8 @@ public static function onUploadFilter ( $upload, $mime, &$error ) {
3435
$ctResult = CTBody::onSpamCheck(
3536
'check_message', array(
3637
'message' => $wgRequest->getVal('wpUploadDescription'),
37-
'sender_email' => $wgUser->mEmail,
38-
'sender_nickname' => $wgUser->mName,
38+
'sender_email' => $user->mEmail,
39+
'sender_nickname' => $user->mName,
3940
)
4041
);
4142
if ( $ctResult->errno != 0 ) {
@@ -52,43 +53,44 @@ public static function onUploadFilter ( $upload, $mime, &$error ) {
5253
}
5354
}
5455

55-
// Disallow edit with CleanTalk comment
56+
// Disallow edit with CleanTalk comment
5657
if (!$allowUpload || $ctResult->allow == 0) {
5758
// Converting links to wikitext format
5859
$errorText = preg_replace("(<a\shref=\"([^\s]+)\".+>([a-f0-9]+)</a>)", "[$1 $2]", $ctResult->comment);
5960

6061
// Fill $error parameter as array with error text
6162
$error = array($errorText);
6263
}
63-
64+
6465
if ($ctResult->inactive === 1) {
6566
CTBody::SendAdminEmail( $wgCTExtName, $ctResult->comment );
6667
}
6768

6869
return;
6970
}
70-
71+
7172
/**
72-
* Edit spam test
73+
* Edit spam test
7374
* @return bool
7475
*/
7576
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+
7880
$allowEdit = true;
7981

8082
// Skip antispam test if editor member of special group
8183
if ( $editor->getArticle()->getContext()->getUser()->isAllowed('cleantalk-bypass') ) {
8284
return $allowEdit;
8385
}
84-
86+
8587
// Skip antispam test of not new edit if flag is set
8688
if ( $wgCTNewEditsOnly && !$editor->isNew) {
8789
return $allowEdit;
8890
}
8991

9092
// Skip antispam test if user is member of special group
91-
if ( $wgUser->isAllowed('cleantalk-bypass') ) {
93+
if ( $user->isAllowed('cleantalk-bypass') ) {
9294
return $allowEdit;
9395
}
9496

@@ -111,7 +113,7 @@ public static function onEditFilter ( $editor, $text, $section, &$error, $summa
111113
/*if ( $ctResult->errno != 0 ) {
112114
return $allowEdit;
113115
}*/
114-
if ( $ctResult->errno != 0 )
116+
if ( $ctResult->errno != 0 )
115117
{
116118
if(CTBody::JSTest()!=1)
117119
{
@@ -126,33 +128,33 @@ public static function onEditFilter ( $editor, $text, $section, &$error, $summa
126128
}
127129
}
128130

129-
// Disallow edit with CleanTalk comment
131+
// Disallow edit with CleanTalk comment
130132
if (!$allowEdit || $ctResult->allow == 0) {
131133
$error = $ctResult->comment;
132-
134+
133135
// Converting links to wikitext format
134136
$error = preg_replace("(<a\shref=\"([^\s]+)\".+>([a-f0-9]+)</a>)", "[$1 $2]", $error);
135-
137+
136138
$error = Html::openElement( 'div', array( 'class' => 'errorbox' ) ) .
137-
$error .
139+
$error .
138140
Html::closeElement( 'div' ) . "\n" .
139141
Html::element( 'br', array( 'clear' => 'all' ) ) . "\n";
140142
}
141-
143+
142144
if ($ctResult->inactive === 1) {
143145
CTBody::SendAdminEmail( $wgCTExtName, $ctResult->comment );
144146
}
145147

146148
return $allowEdit;
147149
}
148-
150+
149151
/**
150-
* Account spam test
152+
* Account spam test
151153
* @return bool
152154
*/
153155
public static function onAbortNewAccount ( $user, &$message ) {
154156
global $wgCTExtName;
155-
157+
156158
$allowAccount = true;
157159

158160
// Check
@@ -163,7 +165,7 @@ public static function onAbortNewAccount ( $user, &$message ) {
163165
)
164166
);
165167
// Allow account if we have any API errors
166-
if ( $ctResult->errno != 0 )
168+
if ( $ctResult->errno != 0 )
167169
{
168170
if(CTBody::JSTest()!=1)
169171
{
@@ -176,12 +178,12 @@ public static function onAbortNewAccount ( $user, &$message ) {
176178
}
177179
}
178180

179-
// Disallow account with CleanTalk comment
181+
// Disallow account with CleanTalk comment
180182
if ($ctResult->allow == 0) {
181183
$allowAccount = false;
182184
$message = $ctResult->comment;
183185
}
184-
186+
185187
if ($ctResult->inactive === 1) {
186188
CTBody::SendAdminEmail( $wgCTExtName, $ctResult->comment );
187189
}
@@ -190,19 +192,19 @@ public static function onAbortNewAccount ( $user, &$message ) {
190192
}
191193
public static function onTitleMove( Title $title, Title $newtitle, User $user )
192194
{
193-
global $wgUser, $wgCTExtName;
195+
global $wgCTExtName;
194196

195197
// Skip antispam test if user is member of special group
196-
if ( $wgUser->isAllowed('cleantalk-bypass') ) {
198+
if ( $user->isAllowed('cleantalk-bypass') ) {
197199
return;
198200
}
199201
$errors = [];
200202
// Check
201203
$ctResult = CTBody::onSpamCheck(
202204
'check_message', array(
203205
'message' => $newtitle->mUrlform ,
204-
'sender_email' => $wgUser->mEmail,
205-
'sender_nickname' => $wgUser->mName,
206+
'sender_email' => $user->mEmail,
207+
'sender_nickname' => $user->mName,
206208
)
207209
);
208210
if ( $ctResult->errno != 0 ) {
@@ -217,28 +219,31 @@ public static function onTitleMove( Title $title, Title $newtitle, User $user )
217219
}
218220
}
219221

220-
// Disallow edit with CleanTalk comment
222+
// Disallow edit with CleanTalk comment
221223
if ($ctResult->allow == 0) {
222224
$errors[] = $ctResult->comment;
223225
}
224-
226+
225227
if ($ctResult->inactive === 1) {
226228
CTBody::SendAdminEmail( $wgCTExtName, $ctResult->comment );
227-
}
229+
}
228230

229231
if (count($errors))
230232
throw new PermissionsError( 'move', $errors );
231-
}
233+
}
232234
public static function onSkinAfterBottomScripts( $skin, &$text )
233235
{
234236
global $wgCTShowLink, $wgCTSFW, $wgCTAccessKey;
235237

236238
$text .= CTBody::AddJSCode();
237-
CTBody::ctSetCookie();
239+
CTBody::ctSetCookie();
240+
241+
$dbr = wfGetDB(DB_MASTER);
242+
238243

239244
/* SFW starts */
240-
241-
if($wgCTSFW)
245+
246+
if($wgCTSFW && !$dbr->isReadOnly())
242247
{
243248
CTBody::createSFWTables();
244249

@@ -252,14 +257,14 @@ public static function onSkinAfterBottomScripts( $skin, &$text )
252257
$settings_changed = false;
253258

254259
if(!isset($settings['lastSFWUpdate']) || ($settings['lastSFWUpdate'] && (time()-$settings['lastSFWUpdate'] > 86400)))
255-
{
260+
{
256261
$sfw->sfw_update($wgCTAccessKey);
257262
$settings['lastSFWUpdate'] = time();
258263
$settings_changed = true;
259264
}
260265
if (!isset($settings['lastSFWSendLogs']) || $settings['lastSFWSendLogs'] && (time() - $settings['lastSFWSendLogs'] > 3600))
261266
{
262-
$sfw->send_logs($wgCTAccessKey);
267+
$sfw->send_logs($wgCTAccessKey);
263268
$settings['lastSFWSendLogs'] = time();
264269
$settings_changed = true;
265270
}
@@ -269,9 +274,9 @@ public static function onSkinAfterBottomScripts( $skin, &$text )
269274
}
270275

271276
/* Check IP here */
272-
277+
273278
$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);
275280

276281
foreach($sfw->ip_array as $key => $value)
277282
{
@@ -284,7 +289,7 @@ public static function onSkinAfterBottomScripts( $skin, &$text )
284289
$sfw->sfw_update_logs($value, 'passed');
285290
}
286291
}
287-
} unset($key, $value);
292+
} unset($key, $value);
288293

289294
if($is_sfw_check)
290295
{
@@ -294,17 +299,17 @@ public static function onSkinAfterBottomScripts( $skin, &$text )
294299
$sfw->sfw_update_logs($sfw->blocked_ip, 'blocked');
295300
$sfw->sfw_die($wgCTAccessKey);
296301
}
297-
}
302+
}
298303
/* Finish checking IP */
299304
}
300305
}
301-
306+
302307
/* SFW ends */
303-
304-
if($wgCTShowLink)
308+
309+
if($wgCTShowLink && strpos($text, 'blocked by CleanTalk') === false)
305310
{
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>";
307312
}
308313
return true;
309314
}
310-
}
315+
}

Antispam/Antispam.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
require_once('CleantalkSFW.php' );
1212

1313
/**
14-
* cleantalk.org is a cloud antispam service
14+
* cleantalk.org is a cloud antispam service
1515
*
1616
* @see http://stopforumspam.com/faq
1717
* @author Denis Shagimuratov <[email protected]>
@@ -32,22 +32,22 @@
3232
$wgCTCheckNoConnect = true;
3333

3434
/**
35-
* Cloud URL
35+
* Cloud URL
3636
*/
3737
$wgCTServerURL = 'http://moderate.cleantalk.org/api2.0';
3838

3939
/**
40-
* Extension agent name and version
40+
* Extension agent name and version
4141
*/
42-
$wgCTAgent = 'mediawiki-23';
42+
$wgCTAgent = 'mediawiki-24';
4343

4444
/**
45-
* Extension name
45+
* Extension name
4646
*/
4747
$wgCTExtName = 'Antispam by CleanTalk';
4848

4949
/**
50-
* Admin notificaction account ID
50+
* Admin notificaction account ID
5151
*/
5252
$wgCTAdminAccountId = 1;
5353

@@ -91,11 +91,11 @@
9191

9292
$wgExtensionCredits['antispam'][] = array(
9393
'path' => __FILE__,
94-
'name' => $wgCTExtName,
94+
'name' => $wgCTExtName,
9595
'author' => 'Denis Shagimuratov',
9696
'url' => 'https://www.mediawiki.org/wiki/Extension:Antispam',
9797
'descriptionmsg' => 'cleantalk-desc',
98-
'version' => '2.3',
98+
'version' => '2.4',
9999
);
100100

101101
$wgAutoloadClasses['CTBody'] = __DIR__ . '/Antispam.body.php';

0 commit comments

Comments
 (0)