summaryrefslogtreecommitdiff
path: root/includes/specials/SpecialRemoveRestrictions.php
blob: ded6cbe3d7e603d6f194da1c0a67ef1857575ecb (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
56
57
58
59
60
<?php

function wfSpecialRemoveRestrictions() {
	global $wgOut, $wgRequest, $wgUser, $wgLang, $wgTitle;
	$sk = $wgUser->getSkin();

	$id = $wgRequest->getVal( 'id' );
	if( !is_numeric( $id ) ) {
		$wgOut->addWikiMsg( 'removerestrictions-noid' );
		return;
	}

	UserRestriction::purgeExpired();
	$r = UserRestriction::newFromId( $id, true );
	if( !$r ) {
		$wgOut->addWikiMsg( 'removerestrictions-wrongid' );
		return;
	}

	$form = array();
	$form['removerestrictions-user'] = $sk->userLink( $r->getSubjectId(), $r->getSubjectText() ) .
		$sk->userToolLinks( $r->getSubjectId(), $r->getSubjectText() );
	$form['removerestrictions-type'] = UserRestriction::formatType( $r->getType() );
	if( $r->isPage() )
		$form['removerestrictions-page'] = $sk->link( $r->getPage() );
	if( $r->isNamespace() )
		$form['removerestrictions-namespace'] = $wgLang->getDisplayNsText( $r->getNamespace() );
	$form['removerestrictions-reason'] = Xml::input( 'reason' );

	$result = null;
	if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'edittoken' ) ) )
		$result = wfSpecialRemoveRestrictionsProcess( $r );

	$wgOut->addWikiMsg( 'removerestrictions-intro' );
	$wgOut->addHTML( Xml::fieldset( wfMsgHtml( 'removerestrictions-legend' ) ) );
	if( $result )
		$wgOut->addHTML( '<strong class="success">' . wfMsgExt( 'removerestrictions-success',
			'parseinline', $r->getSubjectText() ) . '</strong>' );
	$wgOut->addHTML( Xml::openElement( 'form', array( 'action' => $wgTitle->getLocalUrl( array( 'id' => $id ) ),
		'method' => 'post' ) ) );
	$wgOut->addHTML( Xml::buildForm( $form, 'removerestrictions-submit' ) );
	$wgOut->addHTML( Xml::hidden( 'id', $r->getId() ) );
	$wgOut->addHTML( Xml::hidden( 'title', $wgTitle->getPrefixedDbKey() ) );
	$wgOut->addHTML( Xml::hidden( 'edittoken', $wgUser->editToken() ) );
	$wgOut->addHTML( "</form></fieldset>" );
}

function wfSpecialRemoveRestrictionsProcess( $r ) {
	global $wgUser, $wgRequest;
	$reason = $wgRequest->getVal( 'reason' );
	$result = $r->delete();
	$log = new LogPage( 'restrict' );
	$params = array( $r->getType() );
	if( $r->isPage() )
		$params[] = $r->getPage()->getPrefixedDbKey();
	if( $r->isNamespace() )
		$params[] = $r->getNamespace();
	$log->addEntry( 'remove', Title::makeTitle( NS_USER, $r->getSubjectText() ), $reason, $params );
	return $result;
}