* Moved content from liveCmdLine.inc into commandLine.inc, obsoleting the former.
[mediawiki.git] / includes / SpecialIpblocklist.php
blob5b16cb16156e1e1e40c6568a72feedaa1ddcc803
1 <?php
3 function wfSpecialIpblocklist()
5 global $wgUser, $wgOut, $wgRequest;
7 $ip = $wgRequest->getVal( 'wpUnblockAddress', $wgRequest->getVal( 'ip' ) );
8 $reason = $wgRequest->getText( 'wpUnblockReason' );
9 $action = $wgRequest->getText( 'action' );
11 $ipu = new IPUnblockForm( $ip, $reason );
13 if ( "success" == $action ) {
14 $msg = wfMsg( "ipusuccess", $ip );
15 $ipu->showList( $msg );
16 } else if ( "submit" == $action && $wgRequest->wasPosted() ) {
17 if ( ! $wgUser->isSysop() ) {
18 $wgOut->sysopRequired();
19 return;
21 $ipu->doSubmit();
22 } else if ( "unblock" == $action ) {
23 $ipu->showForm( "" );
24 } else {
25 $ipu->showList( "" );
29 class IPUnblockForm {
30 var $ip, $reason;
32 function IPUnblockForm( $ip, $reason ) {
33 $this->ip = $ip;
34 $this->reason = $reason;
37 function showForm( $err )
39 global $wgOut, $wgUser, $wgLang;
41 $wgOut->setPagetitle( wfMsg( "unblockip" ) );
42 $wgOut->addWikiText( wfMsg( "unblockiptext" ) );
44 $ipa = wfMsg( "ipaddress" );
45 $ipr = wfMsg( "ipbreason" );
46 $ipus = htmlspecialchars( wfMsg( "ipusubmit" ) );
47 $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
48 $action = $titleObj->escapeLocalURL( "action=submit" );
50 if ( "" != $err ) {
51 $wgOut->setSubtitle( wfMsg( "formerror" ) );
52 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
55 $wgOut->addHTML( "
56 <form id=\"unblockip\" method=\"post\" action=\"{$action}\">
57 <table border='0'>
58 <tr>
59 <td align='right'>{$ipa}:</td>
60 <td align='left'>
61 <input tabindex='1' type='text' size='20' name=\"wpUnblockAddress\" value=\"" . htmlspecialchars( $this->ip ) . "\" />
62 </td>
63 </tr>
64 <tr>
65 <td align='right'>{$ipr}:</td>
66 <td align='left'>
67 <input tabindex='1' type='text' size='40' name=\"wpUnblockReason\" value=\"" . htmlspecialchars( $this->reason ) . "\" />
68 </td>
69 </tr>
70 <tr>
71 <td>&nbsp;</td>
72 <td align='left'>
73 <input tabindex='2' type='submit' name=\"wpBlock\" value=\"{$ipus}\" />
74 </td>
75 </tr>
76 </table>
77 </form>\n" );
81 function doSubmit()
83 global $wgOut, $wgUser, $wgLang;
85 $block = new Block();
86 $this->ip = trim( $this->ip );
88 if ( $this->ip{0} == "#" ) {
89 $block->mId = substr( $this->ip, 1 );
90 } else {
91 $block->mAddress = $this->ip;
94 # Delete block (if it exists)
95 # We should probably check for errors rather than just declaring success
96 $block->delete();
98 # Make log entry
99 $log = new LogPage( wfMsg( "blocklogpage" ), wfMsg( "blocklogtext" ) );
100 $action = wfMsg( "unblocklogentry", $this->ip );
101 $log->addEntry( $action, $this->reason );
103 # Report to the user
104 $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
105 $success = $titleObj->getFullURL( "action=success&ip=" . urlencode( $this->ip ) );
106 $wgOut->redirect( $success );
109 function showList( $msg )
111 global $wgOut;
113 $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
114 if ( "" != $msg ) {
115 $wgOut->setSubtitle( $msg );
117 $wgOut->addHTML( "<ul>" );
118 Block::enumBlocks( "wfAddRow", 0 );
119 $wgOut->addHTML( "</ul>\n" );
123 # Callback function to output a block
124 function wfAddRow( $block, $tag ) {
125 global $wgOut, $wgUser, $wgLang;
127 $sk = $wgUser->getSkin();
129 # Hide addresses blocked by User::spreadBlocks, for privacy
130 $addr = $block->mAuto ? "#{$block->mId}" : $block->mAddress;
132 $name = User::whoIs( $block->mBy );
133 $ulink = $sk->makeKnownLink( $wgLang->getNsText( Namespace::getUser() ). ":{$name}", $name );
134 $formattedTime = $wgLang->timeanddate( $block->mTimestamp, true );
136 if ( $block->mExpiry === "" ) {
137 $formattedExpiry = "indefinite";
138 } else {
139 $formattedExpiry = $wgLang->timeanddate( $block->mExpiry, true );
142 $line = wfMsg( "blocklistline", $formattedTime, $ulink, $addr, $formattedExpiry );
144 $wgOut->addHTML( "<li>{$line}" );
146 if ( !$block->mAuto ) {
147 $titleObj = Title::makeTitle( NS_SPECIAL, "Contributions" );
148 $clink = "<a href=\"" . $titleObj->escapeLocalURL( "target={$block->mAddress}" ) . "\">" .
149 wfMsg( "contribslink" ) . "</a>";
150 $wgOut->addHTML( " ({$clink})" );
153 if ( $wgUser->isSysop() ) {
154 $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
155 $ublink = "<a href=\"" .
156 $titleObj->escapeLocalURL( "action=unblock&ip=" . urlencode( $addr ) ) . "\">" .
157 wfMsg( "unblocklink" ) . "</a>";
158 $wgOut->addHTML( " ({$ublink})" );
160 if ( "" != $block->mReason ) {
161 $wgOut->addHTML( " <em>(" . wfEscapeHTML( $block->mReason ) .
162 ")</em>" );
164 $wgOut->addHTML( "</li>\n" );