Followup r80122, protected, just incase it's needed..
[lhc/web/wiklou.git] / includes / specials / SpecialBlockip.php
index 8acc9b5..438bc35 100644 (file)
@@ -1,60 +1,78 @@
 <?php
 /**
- * Constructor for Special:Blockip page
+ * Implements Special:Blockip
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
  * @ingroup SpecialPage
  */
 
 /**
- * Constructor
+ * A special page that allows users with 'block' right to block users from
+ * editing pages and other actions
+ *
+ * @ingroup SpecialPage
  */
-function wfSpecialBlockip( $par ) {
-       global $wgUser, $wgOut, $wgRequest;
+class IPBlockForm extends SpecialPage {
+       var $BlockAddress, $BlockExpiry, $BlockReason, $BlockReasonList, $BlockOther, $BlockAnonOnly, $BlockCreateAccount,
+               $BlockEnableAutoblock, $BlockEmail, $BlockHideName, $BlockAllowUsertalk, $BlockReblock;
+       // The maximum number of edits a user can have and still be hidden
+       const HIDEUSER_CONTRIBLIMIT = 1000;
 
-       # Can't block when the database is locked
-       if( wfReadOnly() ) {
-               $wgOut->readOnlyPage();
-               return;
-       }
-       # Permission check
-       if( !$wgUser->isAllowed( 'block' ) ) {
-               $wgOut->permissionRequired( 'block' );
-               return;
+       public function __construct() {
+               parent::__construct( 'Blockip', 'block' );
        }
 
-       $ipb = new IPBlockForm( $par );
+       public function execute( $par ) {
+               global $wgUser, $wgOut, $wgRequest;
+
+               # Can't block when the database is locked
+               if( wfReadOnly() ) {
+                       $wgOut->readOnlyPage();
+                       return;
+               }
+               # Permission check
+               if( !$this->userCanExecute( $wgUser ) ) {
+                       $wgOut->permissionRequired( 'block' );
+                       return;
+               }
+
+               $this->setup( $par );
        
-       # bug 15810: blocked admins should have limited access here
-       if ( $wgUser->isBlocked() ) {
-               $status = IPBlockForm::checkUnblockSelf( $ipb->BlockAddress );
-               if ( $status !== true ) {
-                       throw new ErrorPageError( 'badaccess', $status );
+               # bug 15810: blocked admins should have limited access here
+               if ( $wgUser->isBlocked() ) {
+                       $status = IPBlockForm::checkUnblockSelf( $this->BlockAddress );
+                       if ( $status !== true ) {
+                               throw new ErrorPageError( 'badaccess', $status );
+                       }
                }
-       }
 
-       $action = $wgRequest->getVal( 'action' );
-       if( 'success' == $action ) {
-               $ipb->showSuccess();
-       } elseif( $wgRequest->wasPosted() && 'submit' == $action &&
-               $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
-               $ipb->doSubmit();
-       } else {
-               $ipb->showForm( '' );
+               $action = $wgRequest->getVal( 'action' );
+               if( 'success' == $action ) {
+                       $this->showSuccess();
+               } elseif( $wgRequest->wasPosted() && 'submit' == $action &&
+                       $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
+                       $this->doSubmit();
+               } else {
+                       $this->showForm( '' );
+               }
        }
-}
-
-/**
- * Form object for the Special:Blockip page.
- *
- * @ingroup SpecialPage
- */
-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 ) {
+       private function setup( $par ) {
                global $wgRequest, $wgUser, $wgBlockAllowsUTEdit;
 
                $this->BlockAddress = $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) );
@@ -105,6 +123,9 @@ class IPBlockForm {
 
                $titleObj = SpecialPage::getTitleFor( 'Blockip' );
                $user = User::newFromName( $this->BlockAddress );
+               if ( is_object( $user ) || User::isIP( $this->BlockAddress ) ) {
+                       $wgUser->getSkin()->setRelevantUser( is_object($user) ? $user : User::newFromName( $this->BlockAddress, false ) );
+               }
 
                $alreadyBlocked = false;
                $otherBlockedMsgs = array();
@@ -146,7 +167,7 @@ class IPBlockForm {
                # Show other blocks from extensions, i.e. GlockBlocking and TorBlock
                if( count( $otherBlockedMsgs ) ) {
                        $wgOut->addHTML(
-                               Html::rawElement( 'h2', array(), wfMsgExt( 'ipb-otherblocks-header', 'parseinline',  count( $otherBlockedMsgs ) ) ) . "\n"
+                               Html::rawElement( 'h2', array(), wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockedMsgs ) ) ) . "\n"
                        );
                        $list = '';
                        foreach( $otherBlockedMsgs as $link ) {
@@ -157,7 +178,7 @@ class IPBlockForm {
 
                # Username/IP is blocked already locally
                if( $alreadyBlocked ) {
-                       $wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress );
+                       $wgOut->wrapWikiMsg( "<div class='mw-ipb-needreblock'>\n$1\n</div>", array( 'ipb-needreblock', $this->BlockAddress ) );
                }
 
                $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
@@ -171,16 +192,15 @@ class IPBlockForm {
                        list( $show, $value ) = explode( ':', $option );
                        $show = htmlspecialchars( $show );
                        $value = htmlspecialchars( $value );
-                       $blockExpiryFormOptions .= Xml::option( $show, $value, $this->BlockExpiry === $value ? true : false ) . "\n";
+                       $blockExpiryFormOptions .= Xml::option( $show, $value, $this->BlockExpiry === $value ) . "\n";
                }
 
                $reasonDropDown = Xml::listDropDown( 'wpBlockReasonList',
                        wfMsgForContent( 'ipbreason-dropdown' ),
                        wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList, 'wpBlockDropDown', 4 );
 
-               global $wgStylePath, $wgStyleVersion;
+               $wgOut->addModules( 'mediawiki.legacy.block' );
                $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' ) ) .
@@ -250,7 +270,7 @@ class IPBlockForm {
                                </td>
                        </tr>
                        <tr id='wpAnonOnlyRow'>
-                               <td>&nbsp;</td>
+                               <td>&#160;</td>
                                <td class='mw-input'>" .
                                Xml::checkLabel( wfMsg( 'ipbanononly' ),
                                                'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly,
@@ -258,7 +278,7 @@ class IPBlockForm {
                                </td>
                        </tr>
                        <tr id='wpCreateAccountRow'>
-                               <td>&nbsp;</td>
+                               <td>&#160;</td>
                                <td class='mw-input'>" .
                                        Xml::checkLabel( wfMsg( 'ipbcreateaccount' ),
                                                'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount,
@@ -266,7 +286,7 @@ class IPBlockForm {
                                </td>
                        </tr>
                        <tr id='wpEnableAutoblockRow'>
-                               <td>&nbsp;</td>
+                               <td>&#160;</td>
                                <td class='mw-input'>" .
                                        Xml::checkLabel( wfMsg( 'ipbenableautoblock' ),
                                                'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock,
@@ -278,7 +298,7 @@ class IPBlockForm {
                if( self::canBlockEmail( $wgUser ) ) {
                        $wgOut->addHTML("
                                <tr id='wpEnableEmailBan'>
-                                       <td>&nbsp;</td>
+                                       <td>&#160;</td>
                                        <td class='mw-input'>" .
                                                Xml::checkLabel( wfMsg( 'ipbemailban' ),
                                                        'wpEmailBan', 'wpEmailBan', $this->BlockEmail,
@@ -292,7 +312,7 @@ class IPBlockForm {
                if( $wgUser->isAllowed( 'hideuser' ) ) {
                        $wgOut->addHTML("
                                <tr id='wpEnableHideUser'>
-                                       <td>&nbsp;</td>
+                                       <td>&#160;</td>
                                        <td class='mw-input'><strong>" .
                                                Xml::checkLabel( wfMsg( 'ipbhidename' ),
                                                        'wpHideName', 'wpHideName', $this->BlockHideName,
@@ -307,7 +327,7 @@ class IPBlockForm {
                if( $wgUser->isLoggedIn() ) {
                        $wgOut->addHTML("
                        <tr id='wpEnableWatchUser'>
-                               <td>&nbsp;</td>
+                               <td>&#160;</td>
                                <td class='mw-input'>" .
                                        Xml::checkLabel( wfMsg( 'ipbwatchuser' ),
                                                'wpWatchUser', 'wpWatchUser', $this->BlockWatchUser,
@@ -322,7 +342,7 @@ class IPBlockForm {
                if( $wgBlockAllowsUTEdit ){
                        $wgOut->addHTML("
                                <tr id='wpAllowUsertalkRow'>
-                                       <td>&nbsp;</td>
+                                       <td>&#160;</td>
                                        <td class='mw-input'>" .
                                                Xml::checkLabel( wfMsg( 'ipballowusertalk' ),
                                                        'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk,
@@ -334,18 +354,18 @@ class IPBlockForm {
 
                $wgOut->addHTML("
                        <tr>
-                               <td style='padding-top: 1em'>&nbsp;</td>
+                               <td style='padding-top: 1em'>&#160;</td>
                                <td  class='mw-submit' style='padding-top: 1em'>" .
                                        Xml::submitButton( wfMsg( $alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit' ),
-                                               array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . "
+                                               array( 'name' => 'wpBlock', 'tabindex' => '13' )
+                                                       + $wgUser->getSkin()->tooltipAndAccessKeyAttribs( 'blockip-block' ) ). "
                                </td>
                        </tr>" .
                        Xml::closeElement( 'table' ) .
-                       Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
-                       ( $alreadyBlocked ? Xml::hidden( 'wpChangeBlock', 1 ) : "" ) .
+                       Html::hidden( 'wpEditToken', $wgUser->editToken() ) .
+                       ( $alreadyBlocked ? Html::hidden( 'wpChangeBlock', 1 ) : "" ) .
                        Xml::closeElement( 'fieldset' ) .
-                       Xml::closeElement( 'form' ) .
-                       Xml::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
+                       Xml::closeElement( 'form' )
                );
 
                $wgOut->addHTML( $this->getConvenienceLinks() );
@@ -361,8 +381,8 @@ class IPBlockForm {
 
        /**
         * Can we do an email block?
-        * @param User $user The sysop wanting to make a block
-        * @return boolean
+        * @param $user User: the sysop wanting to make a block
+        * @return Boolean
         */
        public static function canBlockEmail( $user ) {
                global $wgEnableUserEmail, $wgSysopEmailBans;
@@ -793,32 +813,20 @@ class IPBlockForm {
         * @return string
         */
        private function getBlockListLink( $skin ) {
-               $list = SpecialPage::getTitleFor( 'Ipblocklist' );
-               $query = array();
-
-               if( $this->BlockAddress ) {
-                       $addr = strtr( $this->BlockAddress, '_', ' ' );
-                       $message = wfMsg( 'ipb-blocklist-addr', $addr );
-                       $query['ip'] = $this->BlockAddress;
-               } else {
-                       $message = wfMsg( 'ipb-blocklist' );
-               }
-
                return $skin->linkKnown(
-                       $list,
-                       htmlspecialchars( $message ),
-                       array(),
-                       $query
+                       SpecialPage::getTitleFor( 'Ipblocklist' ),
+                       wfMsg( 'ipb-blocklist' )
                );
        }
 
        /**
         * Block a list of selected users
-        * @param array $users
-        * @param string $reason
-        * @param string $tag replaces user pages
-        * @param string $talkTag replaces user talk pages
-        * @returns array, list of html-safe usernames
+        *
+        * @param $users Array
+        * @param $reason String
+        * @param $tag String: replaces user pages
+        * @param $talkTag String: replaces user talk pages
+        * @return Array: list of html-safe usernames
         */
        public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) {
                global $wgUser;