* Subtitle success message when unblocking a block ID instead of a pseudo link like...
[lhc/web/wiklou.git] / includes / SpecialIpblocklist.php
index 9b10f42..8e7aeb1 100644 (file)
@@ -1,8 +1,7 @@
 <?php
 /**
  *
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
  */
 
 /**
@@ -10,7 +9,7 @@
  */
 function wfSpecialIpblocklist() {
        global $wgUser, $wgOut, $wgRequest;
-
+       
        $ip = $wgRequest->getVal( 'wpUnblockAddress', $wgRequest->getVal( 'ip' ) );
        $id = $wgRequest->getVal( 'id' );
        $reason = $wgRequest->getText( 'wpUnblockReason' );
@@ -19,32 +18,60 @@ function wfSpecialIpblocklist() {
 
        $ipu = new IPUnblockForm( $ip, $id, $reason );
 
-       if ( "success" == $action ) {
-               $ipu->showList( $wgOut->parse( wfMsg( 'unblocked', $successip ) ) );
-       } else if ( "submit" == $action && $wgRequest->wasPosted() &&
-               $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
-               if ( ! $wgUser->isAllowed('block') ) {
+       if( $action == 'unblock' ) {
+               # Check permissions
+               if( !$wgUser->isAllowed( 'block' ) ) {
                        $wgOut->permissionRequired( 'block' );
                        return;
                }
+               # Check for database lock
+               if( wfReadOnly() ) {
+                       $wgOut->readOnlyPage();
+                       return;
+               }
+               # Show unblock form
+               $ipu->showForm( '' );
+       } elseif( $action == 'submit' && $wgRequest->wasPosted()
+               && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
+               # Check permissions
+               if( !$wgUser->isAllowed( 'block' ) ) {
+                       $wgOut->permissionRequired( 'block' );
+                       return;
+               }
+               # Check for database lock
+               if( wfReadOnly() ) {
+                       $wgOut->readOnlyPage();
+                       return;
+               }
+               # Remove blocks and redirect user to success page
                $ipu->doSubmit();
-       } else if ( "unblock" == $action ) {
-               $ipu->showForm( "" );
+       } elseif( $action == 'success' ) {
+               # Inform the user of a successful unblock
+               # (No need to check permissions or locks here,
+               # if something was done, then it's too late!)
+               if ( substr( $successip, 0, 1) == '#' ) {
+                       // A block ID was unblocked
+                       $ipu->showList( $wgOut->parse( wfMsg( 'unblocked-ID', $successip ) ) );
+               } else {
+                       // A username/IP was unblocked
+                       $ipu->showList( $wgOut->parse( wfMsg( 'unblocked', $successip ) ) );
+               }
        } else {
-               $ipu->showList( "" );
+               # Just show the block list
+               $ipu->showList( '' );
        }
+
 }
 
 /**
- *
- * @package MediaWiki
- * @subpackage SpecialPage
+ * implements Special:ipblocklist GUI
+ * @addtogroup SpecialPage
  */
 class IPUnblockForm {
        var $ip, $reason, $id;
 
        function IPUnblockForm( $ip, $id, $reason ) {
-               $this->ip = $ip;
+               $this->ip = strtr( $ip, '_', ' ' );
                $this->id = $id;
                $this->reason = $reason;
        }
@@ -59,7 +86,7 @@ class IPUnblockForm {
                $ipr = wfMsgHtml( 'ipbreason' );
                $ipus = wfMsgHtml( 'ipusubmit' );
                $titleObj = SpecialPage::getTitleFor( "Ipblocklist" );
-               $action = $titleObj->escapeLocalURL( "action=submit" );
+               $action = $titleObj->getLocalURL( "action=submit" );
 
                if ( "" != $err ) {
                        $wgOut->setSubtitle( wfMsg( "formerror" ) );
@@ -72,39 +99,43 @@ class IPUnblockForm {
                        $block = Block::newFromID( $this->id );
                        if ( $block ) {
                                $encName = htmlspecialchars( $block->getRedactedName() );
-                               $encId = htmlspecialchars( $this->id );
-                               $addressPart = $encName . "<input type='hidden' name=\"id\" value=\"$encId\" />";
+                               $encId = $this->id;
+                               $addressPart = $encName . Xml::hidden( 'id', $encId );
                        }
                }
                if ( !$addressPart ) {
-                       $addressPart = "<input tabindex='1' type='text' size='20' " .
-                               "name=\"wpUnblockAddress\" value=\"" . htmlspecialchars( $this->ip ) . "\" />";
+                       $addressPart = Xml::input( 'wpUnblockAddress', 20, $this->ip, array( 'type' => 'text', 'tabindex' => '1' ) );
                }
 
-               $wgOut->addHTML( "
-<form id=\"unblockip\" method=\"post\" action=\"{$action}\">
-       <table border='0'>
-               <tr>
-                       <td align='right'>{$ipa}:</td>
-                       <td align='left'>
-                               {$addressPart}
-                       </td>
-               </tr>
-               <tr>
-                       <td align='right'>{$ipr}:</td>
-                       <td align='left'>
-                               <input tabindex='1' type='text' size='40' name=\"wpUnblockReason\" value=\"" . htmlspecialchars( $this->reason ) . "\" />
-                       </td>
-               </tr>
-               <tr>
-                       <td>&nbsp;</td>
-                       <td align='left'>
-                               <input tabindex='2' type='submit' name=\"wpBlock\" value=\"{$ipus}\" />
-                       </td>
-               </tr>
-       </table>
-       <input type='hidden' name='wpEditToken' value=\"{$token}\" />
-</form>\n" );
+               $wgOut->addHTML(
+                       Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'unblockip' ) ) .
+                       Xml::openElement( 'table', array( 'border' => '0' ) ).
+                       "<tr>
+                               <td align='right'>
+                                       {$ipa}:
+                               </td>
+                               <td align='left'>
+                                       {$addressPart}
+                               </td>
+                       </tr>
+                       <tr>
+                               <td align='right'>
+                                       {$ipr}:
+                               </td>
+                               <td align='left'>" .
+                                       Xml::input( 'wpUnblockReason', 40, $this->reason, array( 'type' => 'text', 'tabindex' => '2' ) ) .
+                               "</td>
+                       </tr>
+                       <tr>
+                               <td>&nbsp;</td>
+                               <td align='left'>" .
+                                       Xml::submitButton( $ipus, array( 'name' => 'wpBlock', 'tabindex' => '3' ) ) .
+                               "</td>
+                       </tr>" .
+                       Xml::closeElement( 'table' ) .
+                       Xml::hidden( 'wpEditToken', $token ) .
+                       Xml::closeElement( 'form' ) . "\n"
+               );
 
        }
 
@@ -154,7 +185,7 @@ class IPUnblockForm {
        }
 
        function showList( $msg ) {
-               global $wgOut;
+               global $wgOut, $wgUser;
 
                $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
                if ( "" != $msg ) {
@@ -167,6 +198,10 @@ class IPUnblockForm {
                }
 
                $conds = array();
+               $matches = array();
+               // Is user allowed to see all the blocks?
+               if ( !$wgUser->isAllowed( 'oversight' ) )
+                       $conds['ipb_deleted'] = 0;
                if ( $this->ip == '' ) {
                        // No extra conditions
                } elseif ( substr( $this->ip, 0, 1 ) == '#' ) {
@@ -174,7 +209,7 @@ class IPUnblockForm {
                } elseif ( IP::toUnsigned( $this->ip ) !== false ) {
                        $conds['ipb_address'] = $this->ip;
                        $conds['ipb_auto'] = 0;
-               } elseif( preg_match( "/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\\/(\\d{1,2})$/", $this->ip, $matches ) ) {
+               } elseif( preg_match( '/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\\/(\\d{1,2})$/', $this->ip, $matches ) ) {
                        $conds['ipb_address'] = Block::normaliseRange( $this->ip );
                        $conds['ipb_auto'] = 0;
                } else {
@@ -188,17 +223,21 @@ class IPUnblockForm {
                        }
                }
 
+                # TODO: difference message between
+               #       a) an real empty list and
+               #       b) requested ip/username not on list
                $pager = new IPBlocklistPager( $this, $conds );
-               $s = $pager->getNavigationBar() .
-                       $this->searchForm();
                if ( $pager->getNumRows() ) {
+                       $s = $this->searchForm() .
+                               $pager->getNavigationBar();
                        $s .= "<ul>" . 
                                $pager->getBody() .
                                "</ul>";
+                       $s .= $pager->getNavigationBar();
                } else {
-                       $s .= '<p>' . wfMsgHTML( 'ipblocklistempty' ) . '</p>';
+                       $s = $this->searchForm() .
+                               '<p>' . wfMsgHTML( 'ipblocklistempty' ) . '</p>';
                }
-               $s .= $pager->getNavigationBar();
                $wgOut->addHTML( $s );
        }
 
@@ -222,7 +261,7 @@ class IPUnblockForm {
                                'value' => $this->ip ) ) .
                        wfElement( 'input', array(
                                'type' => 'submit',
-                               'value' => wfMsg( 'search' ) ) ) .
+                               'value' => wfMsg( 'ipblocklist-submit' ) ) ) .
                        '</form>';
        }
 
@@ -250,9 +289,10 @@ class IPUnblockForm {
                }
 
                # Prepare links to the blocker's user and talk pages
+               $blocker_id = $block->getBy();
                $blocker_name = $block->getByName();
-               $blocker = $sk->MakeLinkObj( Title::makeTitle( NS_USER, $blocker_name ), $blocker_name );
-               $blocker .= ' (' . $sk->makeLinkObj( Title::makeTitle( NS_USER_TALK, $blocker_name ), $wgLang->getNsText( NS_TALK ) ) . ')';
+               $blocker = $sk->userLink( $blocker_id, $blocker_name );
+               $blocker .= $sk->userToolLinks( $blocker_id, $blocker_name );
 
                # Prepare links to the block target's user and contribs. pages (as applicable, don't do it for autoblocks)
                if( $block->mAuto ) {
@@ -285,19 +325,27 @@ class IPUnblockForm {
 
                $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $blocker, $target, $properties ) );
 
-               $s = "<li>{$line}";
-
+               $unblocklink = '';
                if ( $wgUser->isAllowed('block') ) {
                        $titleObj = SpecialPage::getTitleFor( "Ipblocklist" );
-                       $s .= ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&id=' . urlencode( $block->mId ) ) . ')';
+                       $unblocklink = ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&id=' . urlencode( $block->mId ) ) . ')';
                }
-               $s .= $sk->commentBlock( $block->mReason );
-               $s .= "</li>\n";
+               
+               $comment = $sk->commentBlock( $block->mReason );
+               
+               $s = "{$line} $comment";        
+               if ( $block->mHideName )
+                       $s = '<span class="history-deleted">' . $s . '</span>';
+                               
                wfProfileOut( __METHOD__ );
-               return $s;
+               return "<li>$s $unblocklink</li>\n";
        }
 }
 
+/**
+ * @todo document
+ * @addtogroup Pager
+ */
 class IPBlocklistPager extends ReverseChronologicalPager {
        public $mForm, $mConds;