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 $ipu->showList( wfMsgWikiHtml( 'unblocked', $ip ) );
22 } else if ( "submit" == $action && $wgRequest->wasPosted() &&
23 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
24 if ( ! $wgUser->isAllowed('block') ) {
25 $wgOut->sysopRequired();
29 } else if ( "unblock" == $action ) {
39 * @subpackage SpecialPage
44 function IPUnblockForm( $ip, $reason ) {
46 $this->reason
= $reason;
49 function showForm( $err ) {
50 global $wgOut, $wgUser, $wgSysopUserBans;
52 $wgOut->setPagetitle( wfMsg( 'unblockip' ) );
53 $wgOut->addWikiText( wfMsg( 'unblockiptext' ) );
55 $ipa = wfMsgHtml( $wgSysopUserBans ?
'ipadressorusername' : 'ipaddress' );
56 $ipr = wfMsgHtml( 'ipbreason' );
57 $ipus = wfMsgHtml( 'ipusubmit' );
58 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Ipblocklist" );
59 $action = $titleObj->escapeLocalURL( "action=submit" );
62 $wgOut->setSubtitle( wfMsg( "formerror" ) );
63 $wgOut->addWikitext( "<span class='error'>{$err}</span>\n" );
65 $token = htmlspecialchars( $wgUser->editToken() );
68 <form id=\"unblockip\" method=\"post\" action=\"{$action}\">
71 <td align='right'>{$ipa}:</td>
73 <input tabindex='1' type='text' size='20' name=\"wpUnblockAddress\" value=\"" . htmlspecialchars( $this->ip
) . "\" />
77 <td align='right'>{$ipr}:</td>
79 <input tabindex='1' type='text' size='40' name=\"wpUnblockReason\" value=\"" . htmlspecialchars( $this->reason
) . "\" />
85 <input tabindex='2' type='submit' name=\"wpBlock\" value=\"{$ipus}\" />
89 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
98 $this->ip
= trim( $this->ip
);
100 if ( $this->ip
{0} == "#" ) {
101 $block->mId
= substr( $this->ip
, 1 );
103 $block->mAddress
= $this->ip
;
106 # Delete block (if it exists)
107 # We should probably check for errors rather than just declaring success
111 $log = new LogPage( 'block' );
112 $log->addEntry( 'unblock', Title
::makeTitle( NS_USER
, $this->ip
), $this->reason
);
115 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Ipblocklist" );
116 $success = $titleObj->getFullURL( "action=success&ip=" . urlencode( $this->ip
) );
117 $wgOut->redirect( $success );
120 function showList( $msg ) {
123 $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
125 $wgOut->setSubtitle( $msg );
128 list( $this->limit
, $this->offset
) = $wgRequest->getLimitOffset();
131 $paging = '<p>' . wfViewPrevNext( $this->offset
, $this->limit
,
132 Title
::makeTitle( NS_SPECIAL
, 'Ipblocklist' ),
133 'ip=' . urlencode( $this->ip
) ) . "</p>\n";
134 $wgOut->addHTML( $paging );
136 $search = $this->searchForm();
137 $wgOut->addHTML( $search );
139 $wgOut->addHTML( "<ul>" );
140 if( !Block
::enumBlocks( array( &$this, "addRow" ), 0 ) ) {
141 // FIXME hack to solve #bug 1487
142 $wgOut->addHTML( '<li>'.wfMsgHtml( 'ipblocklistempty' ).'</li>' );
144 $wgOut->addHTML( "</ul>\n" );
145 $wgOut->addHTML( $paging );
148 function searchForm() {
151 wfElement( 'form', array(
152 'action' => $wgTitle->getLocalUrl() ),
154 wfElement( 'input', array(
157 'value' => 'search' ) ).
158 wfElement( 'input', array(
161 'value' => $this->limit
) ).
162 wfElement( 'input', array(
164 'value' => $this->ip
) ) .
165 wfElement( 'input', array(
167 'value' => wfMsg( 'search' ) ) ) .
172 * Callback function to output a block
174 function addRow( $block, $tag ) {
175 global $wgOut, $wgUser, $wgLang;
177 if( $this->ip
!= '' ) {
178 if( $block->mAuto
) {
179 if( stristr( $block->mId
, $this->ip
) == false ) {
183 if( stristr( $block->mAddress
, $this->ip
) == false ) {
189 // Loading blocks is fast; displaying them is slow.
190 // Quick hack for paging.
192 if( $this->counter
<= $this->offset
) {
195 if( $this->counter
- $this->offset
> $this->limit
) {
199 $fname = 'IPUnblockForm-addRow';
200 wfProfileIn( $fname );
202 static $sk=null, $msg=null;
205 $sk = $wgUser->getSkin();
206 if( is_null( $msg ) ) {
208 foreach( array( 'infiniteblock', 'expiringblock', 'contribslink', 'unblocklink' ) as $key ) {
209 $msg[$key] = wfMsgHtml( $key );
211 $msg['blocklistline'] = wfMsg( 'blocklistline' );
212 $msg['contribslink'] = wfMsg( 'contribslink' );
216 # Prepare links to the blocker's user and talk pages
217 $blocker_name = $block->getByName();
218 $blocker = $sk->MakeLinkObj( Title
::makeTitle( NS_USER
, $blocker_name ), $blocker_name );
219 $blocker .= ' (' . $sk->makeLinkObj( Title
::makeTitle( NS_USER_TALK
, $blocker_name ), $wgLang->getNsText( NS_TALK
) ) . ')';
221 # Prepare links to the block target's user and contribs. pages (as applicable, don't do it for autoblocks)
222 if( $block->mAuto
) {
223 $target = '#' . $block->mId
; # Hide the IP addresses of auto-blocks; privacy
225 $target = $sk->makeLinkObj( Title
::makeTitle( NS_USER
, $block->mAddress
), $block->mAddress
);
226 $target .= ' (' . $sk->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions' ), $msg['contribslink'], 'target=' . urlencode( $block->mAddress
) ) . ')';
229 # Prep the address for the unblock link, masking autoblocks as before
230 $addr = $block->mAuto ?
'#' . $block->mId
: $block->mAddress
;
232 $formattedTime = $wgLang->timeanddate( $block->mTimestamp
, true );
234 if ( $block->mExpiry
=== "" ) {
235 $formattedExpiry = $msg['infiniteblock'];
237 $formattedExpiry = wfMsgReplaceArgs( $msg['expiringblock'],
238 array( $wgLang->timeanddate( $block->mExpiry
, true ) ) );
241 $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $blocker, $target, $formattedExpiry ) );
243 $wgOut->addHTML( "<li>{$line}" );
245 if ( $wgUser->isAllowed('block') ) {
246 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Ipblocklist" );
247 $wgOut->addHTML( ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&ip=' . urlencode( $addr ) ) . ')' );
249 $wgOut->addHTML( $sk->commentBlock( $block->mReason
) );
250 $wgOut->addHTML( "</li>\n" );
251 wfProfileOut( $fname );