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 )
52 global $wgOut, $wgUser, $wgLang, $wgSysopUserBans;
54 $wgOut->setPagetitle( wfMsg( 'unblockip' ) );
55 $wgOut->addWikiText( wfMsg( 'unblockiptext' ) );
57 $ipa = wfMsgHtml( $wgSysopUserBans ?
'ipadressorusername' : 'ipaddress' );
58 $ipr = wfMsgHtml( 'ipbreason' );
59 $ipus = wfMsgHtml( 'ipusubmit' );
60 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Ipblocklist" );
61 $action = $titleObj->escapeLocalURL( "action=submit" );
64 $wgOut->setSubtitle( wfMsg( "formerror" ) );
65 $wgOut->addWikitext( "<span class='error'>{$err}</span>\n" );
67 $token = htmlspecialchars( $wgUser->editToken() );
70 <form id=\"unblockip\" method=\"post\" action=\"{$action}\">
73 <td align='right'>{$ipa}:</td>
75 <input tabindex='1' type='text' size='20' name=\"wpUnblockAddress\" value=\"" . htmlspecialchars( $this->ip
) . "\" />
79 <td align='right'>{$ipr}:</td>
81 <input tabindex='1' type='text' size='40' name=\"wpUnblockReason\" value=\"" . htmlspecialchars( $this->reason
) . "\" />
87 <input tabindex='2' type='submit' name=\"wpBlock\" value=\"{$ipus}\" />
91 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
97 global $wgOut, $wgUser, $wgLang;
100 $this->ip
= trim( $this->ip
);
102 if ( $this->ip
{0} == "#" ) {
103 $block->mId
= substr( $this->ip
, 1 );
105 $block->mAddress
= $this->ip
;
108 # Delete block (if it exists)
109 # We should probably check for errors rather than just declaring success
113 $log = new LogPage( 'block' );
114 $log->addEntry( 'unblock', Title
::makeTitle( NS_USER
, $this->ip
), $this->reason
);
117 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Ipblocklist" );
118 $success = $titleObj->getFullURL( "action=success&ip=" . urlencode( $this->ip
) );
119 $wgOut->redirect( $success );
122 function showList( $msg ) {
125 $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
127 $wgOut->setSubtitle( $msg );
130 list( $this->limit
, $this->offset
) = $wgRequest->getLimitOffset();
133 $paging = '<p>' . wfViewPrevNext( $this->offset
, $this->limit
,
134 Title
::makeTitle( NS_SPECIAL
, 'Ipblocklist' ),
135 'ip=' . urlencode( $this->ip
) ) . "</p>\n";
136 $wgOut->addHTML( $paging );
138 $search = $this->searchForm();
139 $wgOut->addHTML( $search );
141 $wgOut->addHTML( "<ul>" );
142 if( !Block
::enumBlocks( array( &$this, "addRow" ), 0 ) ) {
143 // FIXME hack to solve #bug 1487
144 $wgOut->addHTML( '<li>'.wfMsgHtml( 'ipblocklistempty' ).'</li>' );
146 $wgOut->addHTML( "</ul>\n" );
147 $wgOut->addHTML( $paging );
150 function searchForm() {
153 wfElement( 'form', array(
154 'action' => $wgTitle->getLocalUrl() ),
156 wfElement( 'input', array(
159 'value' => 'search' ) ).
160 wfElement( 'input', array(
163 'value' => $this->limit
) ).
164 wfElement( 'input', array(
166 'value' => $this->ip
) ) .
167 wfElement( 'input', array(
169 'value' => wfMsg( 'search' ) ) ) .
174 * Callback function to output a block
176 function addRow( $block, $tag ) {
177 global $wgOut, $wgUser, $wgLang, $wgContLang;
179 if( $this->ip
!= '' ) {
180 if( $block->mAuto
) {
181 if( stristr( $block->mId
, $this->ip
) == false ) {
185 if( stristr( $block->mAddress
, $this->ip
) == false ) {
191 // Loading blocks is fast; displaying them is slow.
192 // Quick hack for paging.
194 if( $this->counter
<= $this->offset
) {
197 if( $this->counter
- $this->offset
> $this->limit
) {
201 $fname = 'IPUnblockForm-addRow';
202 wfProfileIn( $fname );
204 static $sk=null, $msg=null;
207 $sk = $wgUser->getSkin();
208 if( is_null( $msg ) ) {
210 foreach( array( 'infiniteblock', 'expiringblock', 'contribslink', 'unblocklink' ) as $key ) {
211 $msg[$key] = wfMsgHtml( $key );
213 $msg['blocklistline'] = wfMsg( 'blocklistline' );
216 # Hide addresses blocked by User::spreadBlocks, for privacy
217 $addr = $block->mAuto ?
"#{$block->mId}" : $block->mAddress
;
219 $name = $block->getByName();
220 $ulink = $sk->makeKnownLinkObj( Title
::makeTitle( NS_USER
, $name ), $name );
221 $formattedTime = $wgLang->timeanddate( $block->mTimestamp
, true );
223 if ( $block->mExpiry
=== "" ) {
224 $formattedExpiry = $msg['infiniteblock'];
226 $formattedExpiry = wfMsgReplaceArgs( $msg['expiringblock'],
227 array( $wgLang->timeanddate( $block->mExpiry
, true ) ) );
230 $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $ulink, $addr, $formattedExpiry ) );
232 $wgOut->addHTML( "<li>{$line}" );
234 if ( !$block->mAuto
) {
235 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Contributions" );
236 $wgOut->addHTML( ' (' . $sk->makeKnownLinkObj($titleObj, $msg['contribslink'], "target={$block->mAddress}") . ')' );
239 if ( $wgUser->isAllowed('block') ) {
240 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Ipblocklist" );
241 $wgOut->addHTML( ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&ip=' . urlencode( $addr ) ) . ')' );
243 $wgOut->addHTML( $sk->commentBlock( $block->mReason
) );
244 $wgOut->addHTML( "</li>\n" );
245 wfProfileOut( $fname );