Add the other existing $skin.css/.js to the message files too to be consistent
[lhc/web/wiklou.git] / includes / SpecialBlockip.php
index f059013..5ea25ca 100644 (file)
@@ -2,7 +2,8 @@
 /**
  * Constructor for Special:Blockip page
  *
- * @addtogroup SpecialPage
+ * @file
+ * @ingroup SpecialPage
  */
 
 /**
@@ -39,7 +40,7 @@ function wfSpecialBlockip( $par ) {
 /**
  * Form object for the Special:Blockip page.
  *
- * @addtogroup SpecialPage
+ * @ingroup SpecialPage
  */
 class IPBlockForm {
        var $BlockAddress, $BlockExpiry, $BlockReason;
@@ -62,35 +63,32 @@ class IPBlockForm {
                $this->BlockCreateAccount = $wgRequest->getBool( 'wpCreateAccount', $byDefault );
                $this->BlockEnableAutoblock = $wgRequest->getBool( 'wpEnableAutoblock', $byDefault );
                $this->BlockEmail = $wgRequest->getBool( 'wpEmailBan', false );
+               $this->BlockWatchUser = $wgRequest->getBool( 'wpWatchUser', false );
                # Re-check user's rights to hide names, very serious, defaults to 0
                $this->BlockHideName = ( $wgRequest->getBool( 'wpHideName', 0 ) && $wgUser->isAllowed( 'hideuser' ) ) ? 1 : 0;
        }
 
        function showForm( $err ) {
-               global $wgOut, $wgUser, $wgSysopUserBans, $wgContLang;
+               global $wgOut, $wgUser, $wgSysopUserBans;
 
                $wgOut->setPagetitle( wfMsg( 'blockip' ) );
-               $wgOut->addWikiText( wfMsg( 'blockiptext' ) );
+               $wgOut->addWikiMsg( 'blockiptext' );
 
                if($wgSysopUserBans) {
                        $mIpaddress = Xml::label( wfMsg( 'ipadressorusername' ), 'mw-bi-target' );
                } else {
-                       $mIpaddress = Xml::label( wfMsg( 'ipadress' ), 'mw-bi-target' );
+                       $mIpaddress = Xml::label( wfMsg( 'ipaddress' ), 'mw-bi-target' );
                }
                $mIpbexpiry = Xml::label( wfMsg( 'ipbexpiry' ), 'wpBlockExpiry' );
                $mIpbother = Xml::label( wfMsg( 'ipbother' ), 'mw-bi-other' );
-               $mIpbothertime = wfMsgHtml( 'ipbotheroption' );
                $mIpbreasonother = Xml::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' );
                $mIpbreason = Xml::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' );
-               $mIpbreasonotherlist = wfMsgHtml( 'ipbreasonotherlist' );
 
                $titleObj = SpecialPage::getTitleFor( 'Blockip' );
-               $action = $titleObj->escapeLocalURL( "action=submit" );
-               $alignRight = $wgContLang->isRtl() ? 'left' : 'right';
 
                if ( "" != $err ) {
                        $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
-                       $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
+                       $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $err ) );
                }
 
                $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
@@ -99,176 +97,164 @@ class IPBlockForm {
                if (!$showblockoptions)
                        $mIpbother = $mIpbexpiry;
 
-               $blockExpiryFormOptions = "<option value=\"other\">$mIpbothertime</option>";
+               $blockExpiryFormOptions = Xml::option( wfMsg( 'ipbotheroption' ), 'other' );
                foreach (explode(',', $scBlockExpiryOptions) as $option) {
                        if ( strpos($option, ":") === false ) $option = "$option:$option";
                        list($show, $value) = explode(":", $option);
                        $show = htmlspecialchars($show);
                        $value = htmlspecialchars($value);
-                       $selected = "";
-                       if ($this->BlockExpiry === $value)
-                               $selected = ' selected="selected"';
-                       $blockExpiryFormOptions .= "<option value=\"$value\"$selected>$show</option>";
+                       $blockExpiryFormOptions .= Xml::option( $show, $value, $this->BlockExpiry === $value ? true : false ) . "\n";
                }
 
-               $scBlockReasonList = wfMsgForContent( 'ipbreason-dropdown' );
-               $blockReasonList = '';
-               if ( $scBlockReasonList != '' && $scBlockReasonList != '-' ) { 
-                       $blockReasonList = "<option value=\"other\">$mIpbreasonotherlist</option>";
-                       $optgroup = "";
-                       foreach ( explode( "\n", $scBlockReasonList ) as $option) {
-                               $value = trim( htmlspecialchars($option) );
-                               if ( $value == '' ) {
-                                       continue;
-                               } elseif ( substr( $value, 0, 1) == '*' && substr( $value, 1, 1) != '*' ) {
-                                       // A new group is starting ...
-                                       $value = trim( substr( $value, 1 ) );
-                                       $blockReasonList .= "$optgroup<optgroup label=\"$value\">";
-                                       $optgroup = "</optgroup>";
-                               } elseif ( substr( $value, 0, 2) == '**' ) {
-                                       // groupmember
-                                       $selected = "";
-                                       $value = trim( substr( $value, 2 ) );
-                                       if ( $this->BlockReasonList === $value)
-                                               $selected = ' selected="selected"';
-                                       $blockReasonList .= "<option value=\"$value\"$selected>$value</option>";
-                               } else {
-                                       // groupless block reason
-                                       $selected = "";
-                                       if ( $this->BlockReasonList === $value)
-                                               $selected = ' selected="selected"';
-                                       $blockReasonList .= "$optgroup<option value=\"$value\"$selected>$value</option>";
-                                       $optgroup = "";
-                               }
-                       }
-                       $blockReasonList .= $optgroup;
-               }
-
-               $token = $wgUser->editToken();
+               $reasonDropDown = Xml::listDropDown( 'wpBlockReasonList',
+                       wfMsgForContent( 'ipbreason-dropdown' ),
+                       wfMsgForContent( 'ipbreasonotherlist' ), '', 'wpBlockDropDown', 4 );
 
                global $wgStylePath, $wgStyleVersion;
-               $wgOut->addHTML( "
-<script type=\"text/javascript\" src=\"$wgStylePath/common/block.js?$wgStyleVersion\">
-</script>
-<form id=\"blockip\" method=\"post\" action=\"{$action}\">
-       <table border='0'>
-               <tr>
-                       <td align=\"$alignRight\">{$mIpaddress}</td>
-                       <td>
-                               " . Xml::input( 'wpBlockAddress', 45, $this->BlockAddress,
-                                       array(
-                                               'tabindex' => '1',
-                                               'id' => 'mw-bi-target',
-                                               'onchange' => 'updateBlockOptions()' ) ) . "
-                       </td>
-               </tr>
-               <tr>");
-               if ($showblockoptions) {
+               $wgOut->addHTML(
+                       Xml::tags( 'script', array( 'type' => 'text/javascript', 'src' => "$wgStylePath/common/block.js?$wgStyleVersion" ), '' ) .
+                       Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( "action=submit" ), 'id' => 'blockip' ) ) .
+                       Xml::openElement( 'fieldset' ) .
+                       Xml::element( 'legend', null, wfMsg( 'blockip-legend' ) ) .
+                       Xml::openElement( 'table', array ( 'border' => '0', 'id' => 'mw-blockip-table' ) ) .
+                       "<tr>
+                               <td class='mw-label'>
+                                       {$mIpaddress}
+                               </td>
+                               <td class='mw-input'>" .
+                                       Xml::input( 'wpBlockAddress', 45, $this->BlockAddress,
+                                               array(
+                                                       'tabindex' => '1',
+                                                       'id' => 'mw-bi-target',
+                                                       'onchange' => 'updateBlockOptions()' ) ). "
+                               </td>
+                       </tr>
+                       <tr>"
+               );
+               if ( $showblockoptions ) {
                        $wgOut->addHTML("
-                       <td align=\"$alignRight\">{$mIpbexpiry}</td>
-                       <td>
-                               <select tabindex='2' id='wpBlockExpiry' name=\"wpBlockExpiry\" onchange=\"considerChangingExpiryFocus()\">
-                                       $blockExpiryFormOptions
-                               </select>
-                       </td>
-                       ");
+                               <td class='mw-label'>
+                                       {$mIpbexpiry}
+                               </td>
+                               <td class='mw-input'>" .
+                                       Xml::tags( 'select',
+                                               array(
+                                                       'id' => 'wpBlockExpiry',
+                                                       'name' => 'wpBlockExpiry',
+                                                       'onchange' => 'considerChangingExpiryFocus()',
+                                                       'tabindex' => '2' ),
+                                               $blockExpiryFormOptions ) .
+                               "</td>"
+                       );
                }
                $wgOut->addHTML("
-               </tr>
-               <tr id='wpBlockOther'>
-                       <td align=\"$alignRight\">{$mIpbother}</td>
-                       <td>
-                               " . Xml::input( 'wpBlockOther', 45, $this->BlockOther,
-                                       array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
-                       </td>
-               </tr>");
-               if ( $blockReasonList != '' ) {
-                       $wgOut->addHTML("
+                       </tr>
+                       <tr id='wpBlockOther'>
+                               <td class='mw-label'>
+                                       {$mIpbother}
+                               </td>
+                               <td class='mw-input'>" .
+                                       Xml::input( 'wpBlockOther', 45, $this->BlockOther,
+                                               array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
+                               </td>
+                       </tr>
                        <tr>
-                               <td align=\"$alignRight\">{$mIpbreasonother}</td>
-                               <td>
-                                       <select tabindex='4' id=\"wpBlockReasonList\" name=\"wpBlockReasonList\">
-                                               $blockReasonList
-                                               </select>
+                               <td class='mw-label'>
+                                       {$mIpbreasonother}
                                </td>
-                       </tr>");
-               }
-               $wgOut->addHTML("
-               <tr id=\"wpBlockReason\">
-                       <td align=\"$alignRight\">{$mIpbreason}</td>
-                       <td>
-                               " . Xml::input( 'wpBlockReason', 45, $this->BlockReason,
-                                       array( 'tabindex' => '5', 'id' => 'mw-bi-reason',
-                                              'maxlength'=> '200' ) ) . "
-                       </td>
-               </tr>
-               <tr id='wpAnonOnlyRow'>
-                       <td>&nbsp;</td>
-                       <td>
-                               " . wfCheckLabel( wfMsgHtml( 'ipbanononly' ),
-                                       'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly,
-                                       array( 'tabindex' => '6' ) ) . "
-                       </td>
-               </tr>
-               <tr id='wpCreateAccountRow'>
-                       <td>&nbsp;</td>
-                       <td>
-                               " . wfCheckLabel( wfMsgHtml( 'ipbcreateaccount' ),
-                                       'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount,
-                                       array( 'tabindex' => '7' ) ) . "
-                       </td>
-               </tr>
-               <tr id='wpEnableAutoblockRow'>
-                       <td>&nbsp;</td>
-                       <td>
-                               " . wfCheckLabel( wfMsgHtml( 'ipbenableautoblock' ),
+                               <td class='mw-input'>
+                                       {$reasonDropDown}
+                               </td>
+                       </tr>
+                       <tr id=\"wpBlockReason\">
+                               <td class='mw-label'>
+                                       {$mIpbreason}
+                               </td>
+                               <td class='mw-input'>" .
+                                       Xml::input( 'wpBlockReason', 45, $this->BlockReason,
+                                               array( 'tabindex' => '5', 'id' => 'mw-bi-reason', 'maxlength'=> '200' ) ) . "
+                               </td>
+                       </tr>
+                       <tr id='wpAnonOnlyRow'>
+                               <td>&nbsp;</td>
+                               <td class='mw-input'>" .
+                               Xml::checkLabel( wfMsg( 'ipbanononly' ),
+                                               'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly,
+                                               array( 'tabindex' => '6' ) ) . "
+                               </td>
+                       </tr>
+                       <tr id='wpCreateAccountRow'>
+                               <td>&nbsp;</td>
+                               <td class='mw-input'>" .
+                                       Xml::checkLabel( wfMsg( 'ipbcreateaccount' ),
+                                               'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount,
+                                               array( 'tabindex' => '7' ) ) . "
+                               </td>
+                       </tr>
+                       <tr id='wpEnableAutoblockRow'>
+                               <td>&nbsp;</td>
+                               <td class='mw-input'>" .
+                                       Xml::checkLabel( wfMsg( 'ipbenableautoblock' ),
                                                'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock,
-                                                       array( 'tabindex' => '8' ) ) . "
-                       </td>
-               </tr>
-               ");
-               
+                                               array( 'tabindex' => '8' ) ) . "
+                               </td>
+                       </tr>"
+               );
+
                global $wgSysopEmailBans;
                if ( $wgSysopEmailBans && $wgUser->isAllowed( 'blockemail' ) ) {
                        $wgOut->addHTML("
-                       <tr id='wpEnableEmailBan'>
-                       <td>&nbsp;</td>
-                               <td>
-                                       " . wfCheckLabel( wfMsgHtml( 'ipbemailban' ),
+                               <tr id='wpEnableEmailBan'>
+                                       <td>&nbsp;</td>
+                                       <td class='mw-input'>" .
+                                               Xml::checkLabel( wfMsg( 'ipbemailban' ),
                                                        'wpEmailBan', 'wpEmailBan', $this->BlockEmail,
-                                                               array( 'tabindex' => '10' )) . "
-                               </td>
-                       </tr>
-                       ");
+                                                       array( 'tabindex' => '9' )) . "
+                                       </td>
+                               </tr>"
+                       );
                }
 
                // Allow some users to hide name from block log, blocklist and listusers
                if ( $wgUser->isAllowed( 'hideuser' ) ) {
                        $wgOut->addHTML("
-                       <tr id='wpEnableHideUser'>
-                       <td>&nbsp;</td>
-                               <td>
-                                       " . wfCheckLabel( wfMsgHtml( 'ipbhidename' ),
+                               <tr id='wpEnableHideUser'>
+                                       <td>&nbsp;</td>
+                                       <td class='mw-input'>" .
+                                               Xml::checkLabel( wfMsg( 'ipbhidename' ),
                                                        'wpHideName', 'wpHideName', $this->BlockHideName,
-                                                               array( 'tabindex' => '9' ) ) . "
-                               </td>
-                       </tr>
-                       ");
+                                                       array( 'tabindex' => '10' ) ) . "
+                                       </td>
+                               </tr>"
+                       );
                }
                
+               # Watchlist their user page?
                $wgOut->addHTML("
-               <tr>
-                       <td style='padding-top: 1em'>&nbsp;</td>
-                       <td style='padding-top: 1em'>
-                               " . Xml::submitButton( wfMsg( 'ipbsubmit' ),
-                                                       array( 'name' => 'wpBlock', 'tabindex' => '11' ) ) . "
-                       </td>
-               </tr>
-       </table>" .
-       Xml::hidden( 'wpEditToken', $token ) .
-"</form>
-<script type=\"text/javascript\">updateBlockOptions()</script>
-\n" );
+                       <tr id='wpEnableWatchUser'>
+                               <td>&nbsp;</td>
+                               <td class='mw-input'>" .
+                                       Xml::checkLabel( wfMsg( 'ipbwatchuser' ),
+                                               'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser,
+                                               array( 'tabindex' => '11' ) ) . "
+                               </td>
+                       </tr>"
+               );
+
+               $wgOut->addHTML("
+                       <tr>
+                               <td style='padding-top: 1em'>&nbsp;</td>
+                               <td  class='mw-submit' style='padding-top: 1em'>" .
+                                       Xml::submitButton( wfMsg( 'ipbsubmit' ),
+                                               array( 'name' => 'wpBlock', 'tabindex' => '12' ) ) . "
+                               </td>
+                       </tr>" .
+                       Xml::closeElement( 'table' ) .
+                       Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
+                       Xml::closeElement( 'fieldset' ) .
+                       Xml::closeElement( 'form' ) .
+                       Xml::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
+               );
 
                $wgOut->addHtml( $this->getConvenienceLinks() );
 
@@ -298,7 +284,7 @@ class IPBlockForm {
                $rxIP4 = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
                $rxIP6 = '\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}:\w{1,4}';
                $rxIP = "($rxIP4|$rxIP6)";
-               
+
                # Check for invalid specifications
                if ( !preg_match( "/^$rxIP$/", $this->BlockAddress ) ) {
                        $matches = array();
@@ -328,12 +314,12 @@ class IPBlockForm {
                                # Username block
                                if ( $wgSysopUserBans ) {
                                        $user = User::newFromName( $this->BlockAddress );
-                                       if( !is_null( $user ) && $user->getID() ) {
+                                       if( !is_null( $user ) && $user->getId() ) {
                                                # Use canonical name
-                                               $userId = $user->getID();
+                                               $userId = $user->getId();
                                                $this->BlockAddress = $user->getName();
                                        } else {
-                                               return array('nosuchusershort', htmlspecialchars($user->getName()));
+                                               return array('nosuchusershort', htmlspecialchars( $user ? $user->getName() : $this->BlockAddress ) );
                                        }
                                } else {
                                        return array('badipaddress');
@@ -356,28 +342,25 @@ class IPBlockForm {
                if (strlen($expirestr) == 0) {
                        return array('ipb_expiry_invalid');
                }
-
-               if ( $expirestr == 'infinite' || $expirestr == 'indefinite' ) {
-                       $expiry = Block::infinity();
-               } else {
-                       # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1
-                       $expiry = strtotime( $expirestr );
-
-                       if ( $expiry < 0 || $expiry === false ) {
-                               return array('ipb_expiry_invalid');
-                       }
-
-                       $expiry = wfTimestamp( TS_MW, $expiry );
+               
+               if ( false === ($expiry = Block::parseExpiryInput( $expirestr )) ) {
+                       // Bad expiry.
+                       return array('ipb_expiry_invalid');
+               }
+               
+               if( $this->BlockHideName && $expiry != 'infinity' ) {
+                       // Bad expiry.
+                       return array('ipb_expiry_temp');
                }
 
                # Create block
                # Note: for a user block, ipb_address is only for display purposes
-               $block = new Block( $this->BlockAddress, $userId, $wgUser->getID(),
+               $block = new Block( $this->BlockAddress, $userId, $wgUser->getId(),
                        $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly,
                        $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName,
-                       $this->BlockEmail);
+                       $this->BlockEmail );
 
-               if (wfRunHooks('BlockIp', array(&$block, &$wgUser))) {
+               if ( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) {
 
                        if ( !$block->insert() ) {
                                return array('ipb_already_blocked', htmlspecialchars($this->BlockAddress));
@@ -385,13 +368,17 @@ class IPBlockForm {
 
                        wfRunHooks('BlockIpComplete', array($block, $wgUser));
 
+                       if ( $this->BlockWatchUser ) { 
+                               $wgUser->addWatch ( Title::makeTitle( NS_USER, $this->BlockAddress ) );
+                       }
+
                        # Prepare log parameters
                        $logParams = array();
                        $logParams[] = $expirestr;
                        $logParams[] = $this->blockLogFlags();
 
                        # Make log entry, if the name is hidden, put it in the oversight log
-                       $log_type = ($this->BlockHideName) ? 'oversight' : 'block';
+                       $log_type = ($this->BlockHideName) ? 'suppress' : 'block';
                        $log = new LogPage( $log_type );
                        $log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ),
                          $reasonstr, $logParams );
@@ -426,15 +413,13 @@ class IPBlockForm {
 
                $wgOut->setPagetitle( wfMsg( 'blockip' ) );
                $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) );
-               $text = wfMsg( 'blockipsuccesstext', $this->BlockAddress );
-               $wgOut->addWikiText( $text );
+               $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress );
+               $wgOut->addHtml( $text );
        }
 
        function showLogFragment( $out, $title ) {
-               $out->addHtml( wfElement( 'h2', NULL, LogPage::logName( 'block' ) ) );
-               $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'block' ) );
-               $viewer = new LogViewer( new LogReader( $request ) );
-               $viewer->showList( $out );
+               $out->addHtml( Xml::element( 'h2', NULL, LogPage::logName( 'block' ) ) );
+               LogEventsList::showLogExtract( $out, 'block', $title->getPrefixedText() );
        }
 
        /**
@@ -465,7 +450,7 @@ class IPBlockForm {
        private function getConvenienceLinks() {
                global $wgUser;
                $skin = $wgUser->getSkin();
-               $links[] = $skin->makeLink ( 'MediaWiki:ipbreason-dropdown', wfMsgHtml( 'ipb-edit-dropdown' ) );
+               $links[] = $skin->makeLink ( 'MediaWiki:Ipbreason-dropdown', wfMsgHtml( 'ipb-edit-dropdown' ) );
                $links[] = $this->getUnblockLink( $skin );
                $links[] = $this->getBlockListLink( $skin );
                return '<p class="mw-ipb-conveniencelinks">' . implode( ' | ', $links ) . '</p>';
@@ -507,4 +492,3 @@ class IPBlockForm {
                }
        }
 }
-