3 function wfSpecialRestrictUser( $par = null ) {
4 global $wgOut, $wgRequest;
5 $user = $userOrig = null;
8 } elseif( $wgRequest->getVal( 'user' ) ) {
9 $userOrig = $wgRequest->getVal( 'user' );
11 $wgOut->addHTML( RestrictUserForm
::selectUserForm() );
14 $isIP = User
::isIP( $userOrig );
18 $user = User
::getCanonicalName( $userOrig );
19 $uid = User
::idFromName( $user );
20 if( !$uid && !$isIP ) {
21 $err = '<strong class="error">' . wfMsgHtml( 'restrictuser-notfound' ) . '</strong>';
22 $wgOut->addHTML( RestrictUserForm
::selectUserForm( $userOrig, $err ) );
25 $wgOut->addHTML( RestrictUserForm
::selectUserForm( $user ) );
27 UserRestriction
::purgeExpired();
28 $old = UserRestriction
::fetchForUser( $user, true );
30 RestrictUserForm
::pageRestrictionForm( $uid, $user, $old );
31 RestrictUserForm
::namespaceRestrictionForm( $uid, $user, $old );
33 $old = UserRestriction
::fetchForUser( $user, true ); // Renew it after possible changes in previous two functions
35 $wgOut->addHTML( RestrictUserForm
::existingRestrictions( $old ) );
39 class RestrictUserForm
{
40 public static function selectUserForm( $val = null, $error = null ) {
41 global $wgScript, $wgTitle;
42 $legend = wfMsgHtml( 'restrictuser-userselect' );
43 $s = "<fieldset><legend>{$legend}</legend><form action=\"{$wgScript}\">";
45 $s .= '<p>' . $error . '</p>';
46 $s .= Xml
::hidden( 'title', $wgTitle->getPrefixedDbKey() );
47 $form = array( 'restrictuser-user' => Xml
::input( 'user', false, $val ) );
48 $s .= Xml
::buildForm( $form, 'restrictuser-go' );
49 $s .= "</form></fieldset>";
53 public static function existingRestrictions( $restrictions ) {
54 require_once( dirname( __FILE__
) . '/SpecialListUserRestrictions.php' );
55 $legend = wfMsgHtml( 'restrictuser-existing' );
56 $s = "<fieldset><legend>{$legend}</legend><ul>";
57 foreach( $restrictions as $r )
58 $s .= UserRestrictionsPager
::formatRestriction( $r );
59 $s .= "</ul></fieldset>";
63 public static function pageRestrictionForm( $uid, $user, $oldRestrictions ) {
64 global $wgOut, $wgTitle, $wgRequest, $wgUser;
67 if( $wgRequest->wasPosted() && $wgRequest->getVal( 'type' ) == UserRestriction
::PAGE
&&
68 $wgUser->matchEditToken( $wgRequest->getVal( 'edittoken' ) ) ) {
69 $title = Title
::newFromText( $wgRequest->getVal( 'page' ) );
71 $error = wfMsgExt( 'restrictuser-badtitle', 'parseinline', $wgRequest->getVal( 'page' ) );
72 elseif( UserRestriction
::convertExpiry( $wgRequest->getVal( 'expiry' ) ) === false )
73 $error = wfMsgExt( 'restrictuser-badexpiry', 'parseinline', $wgRequest->getVal( 'expiry' ) );
75 foreach( $oldRestrictions as $r )
76 if( $r->isPage() && $r->getPage()->equals( $title ) )
77 $error = wfMsgExt( 'restrictuser-duptitle', 'parse' );
79 self
::doPageRestriction( $uid, $user );
83 $useRequestValues = $wgRequest->getVal( 'type' ) == UserRestriction
::PAGE
;
84 $legend = wfMsgHtml( 'restrictuser-legend-page' );
85 $wgOut->addHTML( "<fieldset><legend>{$legend}</legend>" );
87 $wgOut->addHTML( '<strong class="error">' . $error . '</strong>' );
89 $wgOut->addHTML( '<strong class="success">' . wfMsgExt( 'restrictuser-success',
90 'parseinline', $user ) . '</strong>' );
91 $wgOut->addHTML( Xml
::openElement( 'form', array( 'action' => $wgTitle->getLocalUrl(),
92 'method' => 'post' ) ) );
93 $wgOut->addHTML( Xml
::hidden( 'type', UserRestriction
::PAGE
) );
94 $wgOut->addHTML( Xml
::hidden( 'edittoken', $wgUser->editToken() ) );
95 $wgOut->addHTML( Xml
::hidden( 'user', $user ) );
97 $form['restrictuser-title'] = Xml
::input( 'page', false,
98 $useRequestValues ?
$wgRequest->getVal( 'page' ) : false );
99 $form['restrictuser-expiry'] = Xml
::input( 'expiry', false,
100 $useRequestValues ?
$wgRequest->getVal( 'expiry' ) : false );
101 $form['restrictuser-reason'] = Xml
::input( 'reason', false,
102 $useRequestValues ?
$wgRequest->getVal( 'reason' ) : false );
103 $wgOut->addHTML( Xml
::buildForm( $form, 'restrictuser-sumbit' ) );
104 $wgOut->addHTML( "</form></fieldset>" );
107 public static function doPageRestriction( $uid, $user ) {
108 global $wgUser, $wgRequest;
109 $r = new UserRestriction();
110 $r->setType( UserRestriction
::PAGE
);
111 $r->setPage( Title
::newFromText( $wgRequest->getVal( 'page' ) ) );
112 $r->setSubjectId( $uid );
113 $r->setSubjectText( $user );
114 $r->setBlockerId( $wgUser->getId() );
115 $r->setBlockerText( $wgUser->getName() );
116 $r->setReason( $wgRequest->getVal( 'reason' ) );
117 $r->setExpiry( UserRestriction
::convertExpiry( $wgRequest->getVal( 'expiry' ) ) );
118 $r->setTimestamp( wfTimestampNow( TS_MW
) );
120 $logExpiry = $wgRequest->getVal( 'expiry' ) ?
$wgRequest->getVal( 'expiry' ) : Block
::infinity();
121 $l = new LogPage( 'restrict' );
122 $l->addEntry( 'restrict', Title
::makeTitle( NS_USER
, $user ), $r->getReason(),
123 array( $r->getType(), $r->getPage()->getFullText(), $logExpiry) );
126 public static function namespaceRestrictionForm( $uid, $user, $oldRestrictions ) {
127 global $wgOut, $wgTitle, $wgRequest, $wgUser, $wgContLang;
130 if( $wgRequest->wasPosted() && $wgRequest->getVal( 'type' ) == UserRestriction
::NAMESPACE &&
131 $wgUser->matchEditToken( $wgRequest->getVal( 'edittoken' ) ) ) {
132 $ns = $wgRequest->getVal( 'namespace' );
133 if( $wgContLang->getNsText( $ns ) === false )
134 $error = wfMsgExt( 'restrictuser-badnamespace', 'parseinline' );
135 elseif( UserRestriction
::convertExpiry( $wgRequest->getVal( 'expiry' ) ) === false )
136 $error = wfMsgExt( 'restrictuser-badexpiry', 'parseinline', $wgRequest->getVal( 'expiry' ) );
138 foreach( $oldRestrictions as $r )
139 if( $r->isNamespace() && $r->getNamespace() == $ns )
140 $error = wfMsgExt( 'restrictuser-dupnamespace', 'parse' );
142 self
::doNamespaceRestriction( $uid, $user );
146 $useRequestValues = $wgRequest->getVal( 'type' ) == UserRestriction
::NAMESPACE;
147 $legend = wfMsgHtml( 'restrictuser-legend-namespace' );
148 $wgOut->addHTML( "<fieldset><legend>{$legend}</legend>" );
150 $wgOut->addHTML( '<strong class="error">' . $error . '</strong>' );
152 $wgOut->addHTML( '<strong class="success">' . wfMsgExt( 'restrictuser-success',
153 'parseinline', $user ) . '</strong>' );
154 $wgOut->addHTML( Xml
::openElement( 'form', array( 'action' => $wgTitle->getLocalUrl(),
155 'method' => 'post' ) ) );
156 $wgOut->addHTML( Xml
::hidden( 'type', UserRestriction
::NAMESPACE ) );
157 $wgOut->addHTML( Xml
::hidden( 'edittoken', $wgUser->editToken() ) );
158 $wgOut->addHTML( Xml
::hidden( 'user', $user ) );
160 $form['restrictuser-namespace'] = Xml
::namespaceSelector( $wgRequest->getVal( 'namespace' ) );
161 $form['restrictuser-expiry'] = Xml
::input( 'expiry', false,
162 $useRequestValues ?
$wgRequest->getVal( 'expiry' ) : false );
163 $form['restrictuser-reason'] = Xml
::input( 'reason', false,
164 $useRequestValues ?
$wgRequest->getVal( 'reason' ) : false );
165 $wgOut->addHTML( Xml
::buildForm( $form, 'restrictuser-sumbit' ) );
166 $wgOut->addHTML( "</form></fieldset>" );
169 public static function doNamespaceRestriction( $uid, $user ) {
170 global $wgUser, $wgRequest;
171 $r = new UserRestriction();
172 $r->setType( UserRestriction
::NAMESPACE );
173 $r->setNamespace( $wgRequest->getVal( 'namespace' ) );
174 $r->setSubjectId( $uid );
175 $r->setSubjectText( $user );
176 $r->setBlockerId( $wgUser->getId() );
177 $r->setBlockerText( $wgUser->getName() );
178 $r->setReason( $wgRequest->getVal( 'reason' ) );
179 $r->setExpiry( UserRestriction
::convertExpiry( $wgRequest->getVal( 'expiry' ) ) );
180 $r->setTimestamp( wfTimestampNow( TS_MW
) );
182 $logExpiry = $wgRequest->getVal( 'expiry' ) ?
$wgRequest->getVal( 'expiry' ) : Block
::infinity();
183 $l = new LogPage( 'restrict' );
184 $l->addEntry( 'restrict', Title
::makeTitle( NS_USER
, $user ), $r->getReason(),
185 array( $r->getType(), $r->getNamespace(), $logExpiry ) );