Revert r55842 "Can now pass in element attributes other than just id to buildTable...
[lhc/web/wiklou.git] / includes / specials / SpecialRemoveRestrictions.php
1 <?php
2
3 function wfSpecialRemoveRestrictions() {
4 global $wgOut, $wgRequest, $wgUser, $wgLang;
5 $sk = $wgUser->getSkin();
6 $title = SpecialPage::getTitleFor( 'RemoveRestrictions' );
7 $id = $wgRequest->getVal( 'id' );
8 if( !is_numeric( $id ) ) {
9 $wgOut->addWikiMsg( 'removerestrictions-noid' );
10 return;
11 }
12
13 UserRestriction::purgeExpired();
14 $r = UserRestriction::newFromId( $id, true );
15 if( !$r ) {
16 $wgOut->addWikiMsg( 'removerestrictions-wrongid' );
17 return;
18 }
19
20 $form = array();
21 $form['removerestrictions-user'] = $sk->userLink( $r->getSubjectId(), $r->getSubjectText() ) .
22 $sk->userToolLinks( $r->getSubjectId(), $r->getSubjectText() );
23 $form['removerestrictions-type'] = UserRestriction::formatType( $r->getType() );
24 if( $r->isPage() )
25 $form['removerestrictions-page'] = $sk->link( $r->getPage() );
26 if( $r->isNamespace() )
27 $form['removerestrictions-namespace'] = $wgLang->getDisplayNsText( $r->getNamespace() );
28 $form['removerestrictions-reason'] = Xml::input( 'reason' );
29
30 $result = null;
31 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'edittoken' ) ) )
32 $result = wfSpecialRemoveRestrictionsProcess( $r );
33
34 $wgOut->addWikiMsg( 'removerestrictions-intro' );
35 $wgOut->addHTML( Xml::fieldset( wfMsgHtml( 'removerestrictions-legend' ) ) );
36 if( $result )
37 $wgOut->addHTML( '<strong class="success">' . wfMsgExt( 'removerestrictions-success',
38 'parseinline', $r->getSubjectText() ) . '</strong>' );
39 $wgOut->addHTML( Xml::openElement( 'form', array( 'action' => $title->getLocalUrl( array( 'id' => $id ) ),
40 'method' => 'post' ) ) );
41 $wgOut->addHTML( Xml::buildForm( $form, 'removerestrictions-submit' ) );
42 $wgOut->addHTML( Xml::hidden( 'id', $r->getId() ) );
43 $wgOut->addHTML( Xml::hidden( 'title', $title->getPrefixedDbKey() ) );
44 $wgOut->addHTML( Xml::hidden( 'edittoken', $wgUser->editToken() ) );
45 $wgOut->addHTML( "</form></fieldset>" );
46 }
47
48 function wfSpecialRemoveRestrictionsProcess( $r ) {
49 global $wgRequest;
50 $reason = $wgRequest->getVal( 'reason' );
51 $result = $r->delete();
52 $log = new LogPage( 'restrict' );
53 $params = array( $r->getType() );
54 if( $r->isPage() )
55 $params[] = $r->getPage()->getPrefixedDbKey();
56 if( $r->isNamespace() )
57 $params[] = $r->getNamespace();
58 $log->addEntry( 'remove', Title::makeTitle( NS_USER, $r->getSubjectText() ), $reason, $params );
59 return $result;
60 }