* Modified Special:Blockip to subclass SpecialPage
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sun, 1 Aug 2010 12:14:32 +0000 (12:14 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sun, 1 Aug 2010 12:14:32 +0000 (12:14 +0000)
includes/SpecialPage.php
includes/specials/SpecialBlockip.php

index ca58b7f..4e62dc5 100644 (file)
@@ -120,7 +120,7 @@ class SpecialPage {
                'CreateAccount'             => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ),
 
                # Users and rights
-               'Blockip'                   => array( 'SpecialPage', 'Blockip', 'block' ),
+               'Blockip'                   => 'IPBlockForm',
                'Ipblocklist'               => 'IPUnblockForm',
                'Unblock'                   => array( 'SpecialRedirectToSpecial', 'Unblock', 'Ipblocklist', false, array( 'uselang', 'ip', 'id' ), array( 'action' => 'unblock' ) ),
                'Resetpass'                 => 'SpecialResetpass',
index 837d83c..cbbbfb7 100644 (file)
  */
 
 /**
- * Constructor for Special:Blockip page
+ * Implements Special:Blockip
  *
- * @file
  * @ingroup SpecialPage
  */
-function wfSpecialBlockip( $par ) {
-       global $wgUser, $wgOut, $wgRequest;
+class IPBlockForm extends SpecialPage {
+       var $BlockAddress, $BlockExpiry, $BlockReason;
+       // 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( $ipb->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 ) );