summaryrefslogtreecommitdiff
path: root/includes/SpecialBlockme.php
blob: 6c9dea06f14c33620b70c26a3837ed47b58a4746 (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
<?php
/**
 *
 * @addtogroup SpecialPage
 */

/**
 *
 */
function wfSpecialBlockme() {
	global $wgRequest, $wgBlockOpenProxies, $wgOut, $wgProxyKey;

	$ip = wfGetIP();
	
	if( !$wgBlockOpenProxies || $wgRequest->getText( 'ip' ) != md5( $ip . $wgProxyKey ) ) {
		$wgOut->addWikiMsg( 'proxyblocker-disabled' );
		return;
	}

	$blockerName = wfMsg( "proxyblocker" );
	$reason = wfMsg( "proxyblockreason" );

	$u = User::newFromName( $blockerName );
	$id = $u->idForName();
	if ( !$id ) {
		$u = User::newFromName( $blockerName );
		$u->addToDatabase();
		$u->setPassword( bin2hex( mt_rand(0, 0x7fffffff ) ) );
		$u->saveSettings();
		$id = $u->getID();
	}

	$block = new Block( $ip, 0, $id, $reason, wfTimestampNow() );
	$block->insert();

	$wgOut->addWikiMsg( "proxyblocksuccess" );
}