* support GENDER in 'blocklog-showlog' and 'blocklog-showsuppresslog'
[lhc/web/wiklou.git] / includes / specials / SpecialBlockip.php
index 80b0805..2d9ab1c 100644 (file)
@@ -42,6 +42,8 @@ function wfSpecialBlockip( $par ) {
  */
 class IPBlockForm {
        var $BlockAddress, $BlockExpiry, $BlockReason;
+       // The maximum number of edits a user can have and still be hidden
+       const HIDEUSER_CONTRIBLIMIT = 1000;
 
        public function __construct( $par ) {
                global $wgRequest, $wgUser, $wgBlockAllowsUTEdit;
@@ -59,7 +61,10 @@ class IPBlockForm {
                $this->BlockAnonOnly = $wgRequest->getBool( 'wpAnonOnly', $byDefault );
                $this->BlockCreateAccount = $wgRequest->getBool( 'wpCreateAccount', $byDefault );
                $this->BlockEnableAutoblock = $wgRequest->getBool( 'wpEnableAutoblock', $byDefault );
-               $this->BlockEmail = $wgRequest->getBool( 'wpEmailBan', false );
+               $this->BlockEmail = false;
+               if( self::canBlockEmail( $wgUser ) ) {
+                       $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;
@@ -149,11 +154,13 @@ class IPBlockForm {
                                        {$mIpaddress}
                                </td>
                                <td class='mw-input'>" .
-                                       Xml::input( 'wpBlockAddress', 45, $this->BlockAddress,
-                                               array(
-                                                       'tabindex' => '1',
-                                                       'id' => 'mw-bi-target',
-                                                       'onchange' => 'updateBlockOptions()' ) ). "
+                                       Html::input( 'wpBlockAddress', $this->BlockAddress, 'text', array(
+                                               'tabindex' => '1',
+                                               'id' => 'mw-bi-target',
+                                               'onchange' => 'updateBlockOptions()',
+                                               'size' => '45',
+                                               'required' => ''
+                                       ) + ( $this->BlockAddress ? array() : array( 'autofocus' ) ) ). "
                                </td>
                        </tr>
                        <tr>"
@@ -198,8 +205,12 @@ class IPBlockForm {
                                        {$mIpbreason}
                                </td>
                                <td class='mw-input'>" .
-                                       Xml::input( 'wpBlockReason', 45, $this->BlockReason,
-                                               array( 'tabindex' => '5', 'id' => 'mw-bi-reason', 'maxlength'=> '200' ) ) . "
+                               Html::input( 'wpBlockReason', $this->BlockReason, 'text', array(
+                                       'tabindex' => '5',
+                                       'id' => 'mw-bi-reason',
+                                       'maxlength' => '200',
+                                       'size' => '45'
+                               ) + ( $this->BlockAddress ? array( 'autofocus' ) : array() ) ) . "
                                </td>
                        </tr>
                        <tr id='wpAnonOnlyRow'>
@@ -228,8 +239,7 @@ class IPBlockForm {
                        </tr>"
                );
 
-               global $wgSysopEmailBans, $wgBlockAllowsUTEdit;
-               if( $wgSysopEmailBans && $wgUser->isAllowed( 'blockemail' ) ) {
+               if( self::canBlockEmail( $wgUser ) ) {
                        $wgOut->addHTML("
                                <tr id='wpEnableEmailBan'>
                                        <td>&nbsp;</td>
@@ -267,6 +277,9 @@ class IPBlockForm {
                                </td>
                        </tr>"
                );
+               
+               # Can we explicitly disallow the use of user_talk?
+               global $wgBlockAllowsUTEdit;
                if( $wgBlockAllowsUTEdit ){
                        $wgOut->addHTML("
                                <tr id='wpAllowUsertalkRow'>
@@ -306,6 +319,16 @@ class IPBlockForm {
                        $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) );
                }
        }
+       
+       /**
+        * Can we do an email block?
+        * @param User $user The sysop wanting to make a block
+        * @return boolean
+        */
+       public static function canBlockEmail( $user ) {
+               global $wgEnableUserEmail, $wgSysopEmailBans;
+               return ($wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ));
+       }
 
        /**
         * Backend block code.
@@ -397,7 +420,7 @@ class IPBlockForm {
                        } else if( $expiry !== 'infinity' ) {
                                // Bad expiry.
                                return array('ipb_expiry_temp');
-                       } else if( User::edits($userId) > 3000 ) {
+                       } else if( User::edits($userId) > self::HIDEUSER_CONTRIBLIMIT ) {
                                // Typically, the user should have a handful of edits.
                                // Disallow hiding users with many edits for performance.
                                return array('ipb_hide_invalid');
@@ -450,7 +473,7 @@ class IPBlockForm {
 
                        # Set *_deleted fields if requested
                        if( $this->BlockHideName ) {
-                               self::suppressUserName( $this->BlockAddress, $userId, $reasonstr );
+                               self::suppressUserName( $this->BlockAddress, $userId );
                        }
 
                        # Only show watch link when this is no range block
@@ -480,20 +503,7 @@ class IPBlockForm {
                }
        }
        
-       public static function suppressUserName( $name, $userId, $reason = '' ) {
-               $user = User::newFromName( $name, false );
-               # Delete the user pages that exists
-               $title = $user->getUserPage();
-               if( ($id = $title->getArticleID(GAID_FOR_UPDATE)) ) {
-                       $article = new Article( $title );
-                       $article->doDeleteArticle( $reason, true /*suppress*/, $id );
-               }
-               # Delete the user talk pages that exists
-               $title = $user->getTalkPage();
-               if( $id = $title->getArticleID(GAID_FOR_UPDATE) ) {
-                       $article = new Article( $title );
-                       $article->doDeleteArticle( $reason, true /*suppress*/, $id );
-               }
+       public static function suppressUserName( $name, $userId ) {
                $op = '|'; // bitwise OR
                return self::setUsernameBitfields( $name, $userId, $op );
        }
@@ -510,7 +520,7 @@ class IPBlockForm {
                $delAction = LogPage::DELETED_ACTION | Revision::DELETED_RESTRICTED;
                # Normalize user name
                $userTitle = Title::makeTitleSafe( NS_USER, $name );
-               $userDbKey = $userTitle->getDBKey();
+               $userDbKey = $userTitle->getDBkey();
                # To suppress, we OR the current bitfields with Revision::DELETED_USER
                # to put a 1 in the username *_deleted bit. To unsuppress we AND the
                # current bitfields with the inverse of Revision::DELETED_USER. The
@@ -575,22 +585,44 @@ class IPBlockForm {
 
        private function showLogFragment( $out, $title ) {
                global $wgUser;
-               $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'block' ) ) );
-               $count = LogEventsList::showLogExtract( $out, 'block', $title->getPrefixedText(), '', 10 );
-               if( $count > 10 ) {
-                       $out->addHTML( $wgUser->getSkin()->link(
-                               SpecialPage::getTitleFor( 'Log' ),
-                               wfMsgHtml( 'blocklog-fulllog' ),
-                               array(),
-                               array(
-                                       'type' => 'block',
-                                       'page' => $title->getPrefixedText() ) ) );
-               }
+
+               // Used to support GENDER in 'blocklog-showlog' and 'blocklog-showsuppresslog'
+               $userBlocked = $title->getText();
+
+               LogEventsList::showLogExtract(
+                       $out,
+                       'block',
+                       $title->getPrefixedText(),
+                       '',
+                       array(
+                               'lim' => 10,
+                               'msgKey' => array(
+                                       'blocklog-showlog',
+                                       $userBlocked
+                               ),
+                               'showIfEmpty' => false
+                       )
+               );
+
                // Add suppression block entries if allowed
-               if( $wgUser->isAllowed('hideuser') ) {
-                       $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'suppress' ) ) );
+               if( $wgUser->isAllowed( 'hideuser' ) ) {
                        LogEventsList::showLogExtract( $out, 'suppress', $title->getPrefixedText(), '',
-                               10, array('log_action' => array('block','reblock','unblock')) );
+                               array(
+                                       'lim' => 10,
+                                       'conds' => array(
+                                               'log_action' => array(
+                                                       'block',
+                                                       'reblock',
+                                                       'unblock'
+                                               )
+                                       ),
+                                       'msgKey' => array(
+                                               'blocklog-showsuppresslog',
+                                               $userBlocked
+                                       ),
+                                       'showIfEmpty' => false
+                               )
+                       );
                }
        }
 
@@ -632,7 +664,13 @@ class IPBlockForm {
                        $links[] = $this->getContribsLink( $skin );
                $links[] = $this->getUnblockLink( $skin );
                $links[] = $this->getBlockListLink( $skin );
-               $links[] = $skin->makeLink ( 'MediaWiki:Ipbreason-dropdown', wfMsgHtml( 'ipb-edit-dropdown' ) );
+               $title = Title::makeTitle( NS_MEDIAWIKI, 'Ipbreason-dropdown' );
+               $links[] = $skin->link(
+                       $title,
+                       wfMsgHtml( 'ipb-edit-dropdown' ),
+                       array(),
+                       array( 'action' => 'edit' )
+               );
                return '<p class="mw-ipb-conveniencelinks">' . $wgLang->pipeList( $links ) . '</p>';
        }
        
@@ -645,7 +683,7 @@ class IPBlockForm {
         */
        private function getContribsLink( $skin ) {
                $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->BlockAddress );
-               return $skin->link( $contribsPage, wfMsgHtml( 'ipb-blocklist-contribs', $this->BlockAddress ) );
+               return $skin->link( $contribsPage, wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->BlockAddress ) );
        }
 
        /**
@@ -658,13 +696,21 @@ class IPBlockForm {
         */
        private function getUnblockLink( $skin ) {
                $list = SpecialPage::getTitleFor( 'Ipblocklist' );
+               $query = array( 'action' => 'unblock' );
+
                if( $this->BlockAddress ) {
-                       $addr = htmlspecialchars( strtr( $this->BlockAddress, '_', ' ' ) );
-                       return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-unblock-addr', $addr ),
-                               'action=unblock&ip=' . urlencode( $this->BlockAddress ) );
+                       $addr = strtr( $this->BlockAddress, '_', ' ' );
+                       $message = wfMsg( 'ipb-unblock-addr', $addr );
+                       $query['ip'] = $this->BlockAddress;
                } else {
-                       return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-unblock' ),      'action=unblock' );
+                       $message = wfMsg( 'ipb-unblock' );
                }
+               return $skin->linkKnown(
+                       $list,
+                       htmlspecialchars($message),
+                       array(),
+                       $query
+               );
        }
 
        /**
@@ -675,13 +721,22 @@ class IPBlockForm {
         */
        private function getBlockListLink( $skin ) {
                $list = SpecialPage::getTitleFor( 'Ipblocklist' );
+               $query = array();
+
                if( $this->BlockAddress ) {
-                       $addr = htmlspecialchars( strtr( $this->BlockAddress, '_', ' ' ) );
-                       return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-blocklist-addr', $addr ),
-                               'ip=' . urlencode( $this->BlockAddress ) );
+                       $addr = strtr( $this->BlockAddress, '_', ' ' );
+                       $message = wfMsg( 'ipb-blocklist-addr', $addr );
+                       $query['ip'] = $this->BlockAddress;
                } else {
-                       return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-blocklist' ) );
+                       $message = wfMsg( 'ipb-blocklist' );
                }
+
+               return $skin->linkKnown(
+                       $list,
+                       htmlspecialchars($message),
+                       array(),
+                       $query
+               );
        }
        
        /**