summaryrefslogtreecommitdiff
path: root/extensions/FunnyDot.php
blob: 418575e2fcb0a4755aa96892edf7f507bf768e8a (plain)
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
<?php

if ( defined( 'MEDIAWIKI' ) ) {

global $wgHooks;
$wgHooks['ArticleSave'][] = 'checkAntiSpamHash';

$wgExtensionCredits['other'][] = array(
    'name' => 'FunnyDot',
    'description' => 'Schutz vor Spam-Bots',
    'author' => 'Pierre Schmitz',
    'url' => 'http://www.laber-land.de',
);

function hexVal($in)
	{
	$result = preg_replace('/[^0-9a-fA-F]/', '', $in);
	return (empty($result) ? 0 : $result);
	}

function checkAntiSpamHash()
	{
	global $wgAntiSpamHash, $wgAntiSpamTimeout, $wgAntiSpamWait;

	$now = time();

	if (!empty($_COOKIE['AntiSpamTime']) && !empty($_COOKIE['AntiSpamHash']))
		{
		$time = intval($_COOKIE['AntiSpamTime']);
		$hash = hexVal($_COOKIE['AntiSpamHash']);

		if ($hash != sha1($time.$wgAntiSpamHash))
			{
			return false;
			}

		if ($now - $time > $wgAntiSpamTimeout)
			{
			return false;
			}
		elseif ($now - $time < $wgAntiSpamWait)
			{
			return false;
			}
		}
	else
		{
		return false;
		}

	return true;
	}

} # End invocation guard
?>