SpecialRemoveRestrictions.php 2.3 KB

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