Localisation updates Cantonese, Chinese and Old/Late Time Chinese
[lhc/web/wiklou.git] / includes / SpecialBlockip.php
index 1041ff6..d456035 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,6 +63,7 @@ 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;
        }
@@ -86,7 +88,7 @@ class IPBlockForm {
 
                if ( "" != $err ) {
                        $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
-                       $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $err ) ); 
+                       $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $err ) );
                }
 
                $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
@@ -105,7 +107,7 @@ class IPBlockForm {
                }
 
                $reasonDropDown = Xml::listDropDown( 'wpBlockReasonList',
-                       wfMsgForContent( 'ipbreason-dropdown' ), 
+                       wfMsgForContent( 'ipbreason-dropdown' ),
                        wfMsgForContent( 'ipbreasonotherlist' ), '', 'wpBlockDropDown', 4 );
 
                global $wgStylePath, $wgStyleVersion;
@@ -135,7 +137,7 @@ class IPBlockForm {
                                        {$mIpbexpiry}
                                </td>
                                <td class='mw-input'>" .
-                                       Xml::tags( 'select', 
+                                       Xml::tags( 'select',
                                                array(
                                                        'id' => 'wpBlockExpiry',
                                                        'name' => 'wpBlockExpiry',
@@ -226,13 +228,25 @@ class IPBlockForm {
                                </tr>"
                        );
                }
+               
+               # Watchlist their user page?
+               $wgOut->addHTML("
+                       <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' => '11' ) ) . "
+                                               array( 'name' => 'wpBlock', 'tabindex' => '12' ) ) . "
                                </td>
                        </tr>" .
                        Xml::closeElement( 'table' ) .
@@ -270,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();
@@ -300,9 +314,9 @@ 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 ? $user->getName() : $this->BlockAddress ) );
@@ -328,27 +342,23 @@ 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');
                }
 
                # 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);
 
+               if ( $this->BlockWatchUser ) { 
+                       $wgUser->addWatch ( Title::makeTitle( NS_USER, $this->BlockAddress ) );
+               }
+               
                if (wfRunHooks('BlockIp', array(&$block, &$wgUser))) {
 
                        if ( !$block->insert() ) {
@@ -477,4 +487,3 @@ class IPBlockForm {
                }
        }
 }
-