$out is needed here
[lhc/web/wiklou.git] / includes / SpecialIpblocklist.php
index 7278adc..7121fb9 100644 (file)
@@ -76,22 +76,25 @@ class IPUnblockForm {
                $this->reason = $reason;
        }
 
+       /**
+        * Generates the unblock form
+        * @param $err string: error message
+        * @return $out string: HTML form
+        */
        function showForm( $err ) {
                global $wgOut, $wgUser, $wgSysopUserBans, $wgContLang;
 
                $wgOut->setPagetitle( wfMsg( 'unblockip' ) );
-               $wgOut->addWikiText( wfMsg( 'unblockiptext' ) );
+               $wgOut->addWikiMsg( 'unblockiptext' );
 
                $ipa = wfMsgHtml( $wgSysopUserBans ? 'ipadressorusername' : 'ipaddress' );
-               $ipr = wfMsgHtml( 'ipbreason' );
-               $ipus = wfMsgHtml( 'ipusubmit' );
                $titleObj = SpecialPage::getTitleFor( "Ipblocklist" );
                $action = $titleObj->getLocalURL( "action=submit" );
                $alignRight = $wgContLang->isRtl() ? 'left' : 'right';
 
                if ( "" != $err ) {
                        $wgOut->setSubtitle( wfMsg( "formerror" ) );
-                       $wgOut->addWikitext( "<span class='error'>{$err}</span>\n" );
+                       $wgOut->addWikiText( "<span class='error'>{$err}</span>\n" );
                }
                $token = htmlspecialchars( $wgUser->editToken() );
 
@@ -110,7 +113,9 @@ class IPUnblockForm {
 
                $wgOut->addHTML(
                        Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'unblockip' ) ) .
-                       Xml::openElement( 'table', array( 'border' => '0' ) ).
+                       Xml::openElement( 'fieldset' ) .
+                       Xml::element( 'legend', null, wfMsg( 'ipb-unblock' ) ) .
+                       Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-unblock-table' ) ).
                        "<tr>
                                <td align='$alignRight'>
                                        {$ipa}
@@ -120,9 +125,9 @@ class IPUnblockForm {
                                </td>
                        </tr>
                        <tr>
-                               <td align='$alignRight'>
-                                       {$ipr}
-                               </td>
+                               <td align='$alignRight'>" .
+                                       Xml::label( wfMsg( 'ipbreason' ), 'wpUnblockReason' ) . 
+                               "</td>
                                <td>" .
                                        Xml::input( 'wpUnblockReason', 40, $this->reason, array( 'type' => 'text', 'tabindex' => '2' ) ) .
                                "</td>
@@ -130,67 +135,89 @@ class IPUnblockForm {
                        <tr>
                                <td>&nbsp;</td>
                                <td>" .
-                                       Xml::submitButton( $ipus, array( 'name' => 'wpBlock', 'tabindex' => '3' ) ) .
+                                       Xml::submitButton( wfMsg( 'ipusubmit' ), array( 'name' => 'wpBlock', 'tabindex' => '3' ) ) .
                                "</td>
                        </tr>" .
                        Xml::closeElement( 'table' ) .
+                       Xml::closeElement( 'fieldset' ) .
                        Xml::hidden( 'wpEditToken', $token ) .
                        Xml::closeElement( 'form' ) . "\n"
                );
 
        }
 
-       function doSubmit() {
-               global $wgOut;
+       const UNBLOCK_SUCCESS = 0; // Success
+       const UNBLOCK_NO_SUCH_ID = 1; // No such block ID
+       const UNBLOCK_USER_NOT_BLOCKED = 2; // IP wasn't blocked
+       const UNBLOCK_BLOCKED_AS_RANGE = 3; // IP is part of a range block
+       const UNBLOCK_UNKNOWNERR = 4; // Unknown error
 
-               if ( $this->id ) {
-                       $block = Block::newFromID( $this->id );
-                       if ( $block ) {
-                               $this->ip = $block->getRedactedName();
+       /**
+        * Backend code for unblocking. doSubmit() wraps around this.
+        * $range is only used when UNBLOCK_BLOCKED_AS_RANGE is returned, in which
+        * case it contains the range $ip is part of.
+        * @return array array(message key, parameters) on failure, empty array on success
+        */
+
+       static function doUnblock(&$id, &$ip, &$reason, &$range = null)
+       {
+               if ( $id ) {
+                       $block = Block::newFromID( $id );
+                       if ( !$block ) {
+                               return array('ipb_cant_unblock', htmlspecialchars($id));
                        }
+                       $ip = $block->getRedactedName();
                } else {
                        $block = new Block();
-                       $this->ip = trim( $this->ip );
-                       if ( substr( $this->ip, 0, 1 ) == "#" ) {
-                               $id = substr( $this->ip, 1 );
+                       $ip = trim( $ip );
+                       if ( substr( $ip, 0, 1 ) == "#" ) {
+                               $id = substr( $ip, 1 );
                                $block = Block::newFromID( $id );
+                               if( !$block ) {
+                                       return array('ipb_cant_unblock', htmlspecialchars($id));
+                               }
+                               $ip = $block->getRedactedName();
                        } else {
-                               $block = Block::newFromDB( $this->ip );
-
+                               $block = Block::newFromDB( $ip );
                                if ( !$block ) { 
-                                       $block = null;
-                               } else if ( $block->mRangeStart != $block->mRangeEnd
-                                               && !strstr ( $this->ip, "/" ) ) {
+                                       return array('ipb_cant_unblock', htmlspecialchars($id));
+                               }
+                               if( $block->mRangeStart != $block->mRangeEnd
+                                               && !strstr( $ip, "/" ) ) {
                                        /* If the specified IP is a single address, and the block is
                                         * a range block, don't unblock the range. */
-
-                                       $this->showForm ( wfMsg ( 'ipb_blocked_as_range', $this->ip, $block->mAddress ) );
-                                       return;
+                                        $range = $block->mAddress;
+                                        return array('ipb_blocked_as_range', $ip, $range);
                                }
                        }
                }
-               $success = false;
-               if ( $block ) {
-                       # Delete block
-                       if ( $block->delete() ) {
-                               # Make log entry
-                               $log = new LogPage( 'block' );
-                               $log->addEntry( 'unblock', Title::makeTitle( NS_USER, $this->ip ), $this->reason );
-                               $success = true;
-                       }
+               // Yes, this is really necessary
+               $id = $block->mId;
+
+               # Delete block
+               if ( !$block->delete() ) {
+                       return array('ipb_cant_unblock', htmlspecialchars($id));
                }
 
-               if ( $success ) {
-                       # Report to the user
-                       $titleObj = SpecialPage::getTitleFor( "Ipblocklist" );
-                       $success = $titleObj->getFullURL( "action=success&successip=" . urlencode( $this->ip ) );
-                       $wgOut->redirect( $success );
-               } else {
-                       if ( !$this->ip && $this->id ) {
-                               $this->ip = '#' . $this->id;
-                       }
-                       $this->showForm( wfMsg( 'ipb_cant_unblock', htmlspecialchars( $this->id ) ) );
+               # Make log entry
+               $log = new LogPage( 'block' );
+               $log->addEntry( 'unblock', Title::makeTitle( NS_USER, $ip ), $reason );
+               return array();
+       }
+
+       function doSubmit() {
+               global $wgOut;
+               $retval = self::doUnblock($this->id, $this->ip, $this->reason, $range);
+               if(!empty($retval))
+               {
+                       $key = array_shift($retval);
+                       $this->showForm(wfMsgReal($key, $retval));
+                       return;
                }
+               # Report to the user
+               $titleObj = SpecialPage::getTitleFor( "Ipblocklist" );
+               $success = $titleObj->getFullURL( "action=success&successip=" . urlencode( $this->ip ) );
+               $wgOut->redirect( $success );
        }
 
        function showList( $msg ) {
@@ -209,7 +236,7 @@ class IPUnblockForm {
                $conds = array();
                $matches = array();
                // Is user allowed to see all the blocks?
-               if ( !$wgUser->isAllowed( 'oversight' ) )
+               if ( !$wgUser->isAllowed( 'suppress' ) )
                        $conds['ipb_deleted'] = 0;
                if ( $this->ip == '' ) {
                        // No extra conditions
@@ -242,9 +269,9 @@ class IPUnblockForm {
                        );
                } elseif ( $this->ip != '') {
                        $wgOut->addHTML( $this->searchForm() );
-                       $wgOut->addWikiText( wfMsg( 'ipblocklist-no-results' ) );
+                       $wgOut->addWikiMsg( 'ipblocklist-no-results' );
                } else {
-                       $wgOut->addWikiText( wfMsg( 'ipblocklist-empty' ) );
+                       $wgOut->addWikiMsg( 'ipblocklist-empty' );
                }
        }
 
@@ -372,7 +399,7 @@ class IPBlocklistPager extends ReverseChronologicalPager {
                # Usernames and titles are in fact related by a simple substitution of space -> underscore
                # The last few lines of Title::secureAndSplit() tell the story.
                while ( $row = $this->mResult->fetchObject() ) {
-                       $name = str_replace( ' ', '_', $row->user_name );
+                       $name = str_replace( ' ', '_', $row->ipb_by_text );
                        $lb->add( NS_USER, $name );
                        $lb->add( NS_USER_TALK, $name );
                        $name = str_replace( ' ', '_', $row->ipb_address );
@@ -393,10 +420,9 @@ class IPBlocklistPager extends ReverseChronologicalPager {
        function getQueryInfo() {
                $conds = $this->mConds;
                $conds[] = 'ipb_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
-               $conds[] = 'ipb_by=user_id';
                return array(
-                       'tables' => array( 'ipblocks', 'user' ),
-                       'fields' => $this->mDb->tableName( 'ipblocks' ) . '.*,user_name',
+                       'tables' => 'ipblocks',
+                       'fields' => '*',
                        'conds' => $conds,
                );
        }