5 * @subpackage SpecialPage
11 function wfSpecialIpblocklist() {
12 global $wgUser, $wgOut, $wgRequest;
14 $ip = $wgRequest->getVal( 'wpUnblockAddress', $wgRequest->getVal( 'ip' ) );
15 $reason = $wgRequest->getText( 'wpUnblockReason' );
16 $action = $wgRequest->getText( 'action' );
18 $ipu = new IPUnblockForm( $ip, $reason );
20 if ( "success" == $action ) {
21 $msg = wfMsg( "ipusuccess", htmlspecialchars( $ip ) );
22 $ipu->showList( $msg );
23 } else if ( "submit" == $action && $wgRequest->wasPosted() &&
24 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
25 if ( ! $wgUser->isAllowed('block') ) {
26 $wgOut->sysopRequired();
30 } else if ( "unblock" == $action ) {
40 * @subpackage SpecialPage
45 function IPUnblockForm( $ip, $reason ) {
47 $this->reason
= $reason;
50 function showForm( $err ) {
51 global $wgOut, $wgUser, $wgSysopUserBans;
53 $wgOut->setPagetitle( wfMsg( 'unblockip' ) );
54 $wgOut->addWikiText( wfMsg( 'unblockiptext' ) );
56 $ipa = wfMsgHtml( $wgSysopUserBans ?
'ipadressorusername' : 'ipaddress' );
57 $ipr = wfMsgHtml( 'ipbreason' );
58 $ipus = wfMsgHtml( 'ipusubmit' );
59 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Ipblocklist" );
60 $action = $titleObj->escapeLocalURL( "action=submit" );
63 $wgOut->setSubtitle( wfMsg( "formerror" ) );
64 $wgOut->addWikitext( "<span class='error'>{$err}</span>\n" );
66 $token = htmlspecialchars( $wgUser->editToken() );
69 <form id=\"unblockip\" method=\"post\" action=\"{$action}\">
72 <td align='right'>{$ipa}:</td>
74 <input tabindex='1' type='text' size='20' name=\"wpUnblockAddress\" value=\"" . htmlspecialchars( $this->ip
) . "\" />
78 <td align='right'>{$ipr}:</td>
80 <input tabindex='1' type='text' size='40' name=\"wpUnblockReason\" value=\"" . htmlspecialchars( $this->reason
) . "\" />
86 <input tabindex='2' type='submit' name=\"wpBlock\" value=\"{$ipus}\" />
90 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
96 global $wgOut, $wgUser;
99 $this->ip
= trim( $this->ip
);
101 if ( $this->ip
{0} == "#" ) {
102 $block->mId
= substr( $this->ip
, 1 );
104 $block->mAddress
= $this->ip
;
107 # Delete block (if it exists)
108 # We should probably check for errors rather than just declaring success
112 $log = new LogPage( 'block' );
113 $log->addEntry( 'unblock', Title
::makeTitle( NS_USER
, $this->ip
), $this->reason
);
116 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Ipblocklist" );
117 $success = $titleObj->getFullURL( "action=success&ip=" . urlencode( $this->ip
) );
118 $wgOut->redirect( $success );
121 function showList( $msg ) {
124 $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
126 $wgOut->setSubtitle( $msg );
129 list( $this->limit
, $this->offset
) = $wgRequest->getLimitOffset();
132 $paging = '<p>' . wfViewPrevNext( $this->offset
, $this->limit
,
133 Title
::makeTitle( NS_SPECIAL
, 'Ipblocklist' ),
134 'ip=' . urlencode( $this->ip
) ) . "</p>\n";
135 $wgOut->addHTML( $paging );
137 $search = $this->searchForm();
138 $wgOut->addHTML( $search );
140 $wgOut->addHTML( "<ul>" );
141 if( !Block
::enumBlocks( array( &$this, "addRow" ), 0 ) ) {
142 // FIXME hack to solve #bug 1487
143 $wgOut->addHTML( '<li>'.wfMsgHtml( 'ipblocklistempty' ).'</li>' );
145 $wgOut->addHTML( "</ul>\n" );
146 $wgOut->addHTML( $paging );
149 function searchForm() {
152 wfElement( 'form', array(
153 'action' => $wgTitle->getLocalUrl() ),
155 wfElement( 'input', array(
158 'value' => 'search' ) ).
159 wfElement( 'input', array(
162 'value' => $this->limit
) ).
163 wfElement( 'input', array(
165 'value' => $this->ip
) ) .
166 wfElement( 'input', array(
168 'value' => wfMsg( 'search' ) ) ) .
173 * Callback function to output a block
175 function addRow( $block, $tag ) {
176 global $wgOut, $wgUser, $wgLang;
178 if( $this->ip
!= '' ) {
179 if( $block->mAuto
) {
180 if( stristr( $block->mId
, $this->ip
) == false ) {
184 if( stristr( $block->mAddress
, $this->ip
) == false ) {
190 // Loading blocks is fast; displaying them is slow.
191 // Quick hack for paging.
193 if( $this->counter
<= $this->offset
) {
196 if( $this->counter
- $this->offset
> $this->limit
) {
200 $fname = 'IPUnblockForm-addRow';
201 wfProfileIn( $fname );
203 static $sk=null, $msg=null;
206 $sk = $wgUser->getSkin();
207 if( is_null( $msg ) ) {
209 foreach( array( 'infiniteblock', 'expiringblock', 'contribslink', 'unblocklink' ) as $key ) {
210 $msg[$key] = wfMsgHtml( $key );
212 $msg['blocklistline'] = wfMsg( 'blocklistline' );
215 # Hide addresses blocked by User::spreadBlocks, for privacy
216 $addr = $block->mAuto ?
"#{$block->mId}" : $block->mAddress
;
218 $name = $block->getByName();
219 $ulink = $sk->makeKnownLinkObj( Title
::makeTitle( NS_USER
, $name ), $name );
220 $formattedTime = $wgLang->timeanddate( $block->mTimestamp
, true );
222 if ( $block->mExpiry
=== "" ) {
223 $formattedExpiry = $msg['infiniteblock'];
225 $formattedExpiry = wfMsgReplaceArgs( $msg['expiringblock'],
226 array( $wgLang->timeanddate( $block->mExpiry
, true ) ) );
229 $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $ulink, $addr, $formattedExpiry ) );
231 $wgOut->addHTML( "<li>{$line}" );
233 if ( !$block->mAuto
) {
234 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Contributions" );
235 $wgOut->addHTML( ' (' . $sk->makeKnownLinkObj($titleObj, $msg['contribslink'], "target={$block->mAddress}") . ')' );
238 if ( $wgUser->isAllowed('block') ) {
239 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Ipblocklist" );
240 $wgOut->addHTML( ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&ip=' . urlencode( $addr ) ) . ')' );
242 $wgOut->addHTML( $sk->commentBlock( $block->mReason
) );
243 $wgOut->addHTML( "</li>\n" );
244 wfProfileOut( $fname );