Skip to content

Commit

Permalink
Fix. General. Added compatibility with php8.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
svfcode committed Sep 18, 2024
1 parent d367000 commit 426b5d7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
5 changes: 4 additions & 1 deletion Antispam/Antispam.body.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use MediaWiki\MediaWikiServices;

class CTBody {
/**
* Builds MD5 secret hash for JavaScript test (self::JSTest)
Expand Down Expand Up @@ -78,7 +80,8 @@ public static function ctTestCookie()
}
public static function createSFWTables()
{
$dbr = wfGetDB(DB_MASTER);
$services = MediaWikiServices::getInstance();
$dbr = $services->getConnectionProvider()->getPrimaryDatabase();

$dbr->query("CREATE TABLE IF NOT EXISTS `cleantalk_sfw` (
`network` int(11) unsigned NOT NULL,
Expand Down
5 changes: 4 additions & 1 deletion Antispam/Antispam.hooks.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use MediaWiki\MediaWikiServices;

class CTHooks {

/**
Expand Down Expand Up @@ -238,7 +240,8 @@ public static function onSkinAfterBottomScripts( $skin, &$text )
$text .= CTBody::AddJSCode();
CTBody::ctSetCookie();

$dbr = wfGetDB(DB_MASTER);
$services = MediaWikiServices::getInstance();
$dbr = $services->getConnectionProvider()->getPrimaryDatabase();


/* SFW starts */
Expand Down
4 changes: 2 additions & 2 deletions Antispam/Cleantalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private function createMsg($method, CleantalkRequest $request) {
// Removing non UTF8 characters from request, because non UTF8 or malformed characters break json_encode().
//
foreach ($request as $param => $value) {
if (!preg_match('//u', $value))
if (!is_null($value) && !preg_match('//u', $value))
$request->{$param} = 'Nulled. Not UTF8 encoded or malformed.';
}

Expand Down Expand Up @@ -547,7 +547,7 @@ public function get_servers_ip($host)

// -1 server is down, skips not reachable server
if ($ping != -1) {
$r_temp[$ping + $i] = $server;
$r_temp[(int)$ping + $i] = $server;
}
$i++;

Expand Down
30 changes: 30 additions & 0 deletions Antispam/CleantalkHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,34 @@ static function apache_request_headers(){
}
return $headers;
}

/**
* Function convert from UTF8
*
* @param array|object|string $obj
* @param string $data_codepage
*
* @return mixed (array|object|string)
*/
public static function stringFromUTF8($obj, $data_codepage = null)
{
// Array || object
if (is_array($obj) || is_object($obj)) {
foreach ($obj as $_key => &$val) {
$val = self::stringFromUTF8($val, $data_codepage);
}
unset($val);
//String
} else {
if ($data_codepage !== null && preg_match('//u', $obj)) {
if ( function_exists('mb_convert_encoding') ) {
$obj = mb_convert_encoding($obj, $data_codepage, 'UTF-8');
} elseif (version_compare(phpversion(), '8.3', '<')) {
$obj = @utf8_decode($obj);
}
}
}

return $obj;
}
}
8 changes: 5 additions & 3 deletions Antispam/CleantalkResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ function __construct($response = null, $obj = null) {
$this->errstr = $obj->errstr;
$this->curl_err = !empty($obj->curl_err) ? $obj->curl_err : false;

$this->errstr = preg_replace("/.+(\*\*\*.+\*\*\*).+/", "$1", $this->errstr);
if (!is_null($this->errstr)) {
$this->errstr = preg_replace("/.+(\*\*\*.+\*\*\*).+/", "$1", $this->errstr);
}

$this->stop_words = isset($obj->stop_words) ? utf8_decode($obj->stop_words) : null;
$this->comment = isset($obj->comment) ? utf8_decode($obj->comment) : null;
$this->stop_words = isset($obj->stop_words) ? CleantalkHelper::stringFromUTF8($obj->stop_words, 'ISO-8859-1') : null;
$this->comment = isset($obj->comment) ? CleantalkHelper::stringFromUTF8($obj->comment, 'ISO-8859-1') : null;
$this->blacklisted = (isset($obj->blacklisted)) ? $obj->blacklisted : null;
$this->allow = (isset($obj->allow)) ? $obj->allow : 0;
$this->id = (isset($obj->id)) ? $obj->id : null;
Expand Down
6 changes: 5 additions & 1 deletion Antispam/CleantalkSFW.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use MediaWiki\MediaWikiServices;

require_once('CleantalkHelper.php' );
/*
* CleanTalk SpamFireWall base class
Expand Down Expand Up @@ -30,7 +33,8 @@ class CleantalkSFW extends CleantalkHelper
public function __construct()
{
$this->table_prefix = "";
$this->db = wfGetDB(DB_MASTER);
$services = MediaWikiServices::getInstance();
$this->db = $services->getConnectionProvider()->getPrimaryDatabase();
}

public function unversal_query($query, $straight_query = false)
Expand Down

0 comments on commit 426b5d7

Please sign in to comment.