jenkins-bot has submitted this change and it was merged.

Change subject: Use FormSpecialPage in SpecialGlobalBlockStatus
......................................................................


Use FormSpecialPage in SpecialGlobalBlockStatus

Other changes:
* Some minor code style changes
* Replaced successub message with buildSubtitleLinks()
* Removed redundant "return to list" from two messages

Change-Id: Ia6f90df41f2acfff47dcbfce30d7694238da5e56
---
M i18n/en.json
M includes/specials/SpecialGlobalBlockStatus.php
2 files changed, 68 insertions(+), 116 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index ef3c07e..5f748bb 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -73,10 +73,8 @@
        "globalblocking-whitelist-submit": "Change local status",
        "globalblocking-whitelist-whitelisted": "You have successfully disabled 
the global block #$2 on the IP address '''$1''' on {{SITENAME}}.",
        "globalblocking-whitelist-dewhitelisted": "You have successfully 
re-enabled the global block #$2 on the IP address '''$1''' on {{SITENAME}}.",
-       "globalblocking-whitelist-successsub": "Local status successfully 
changed.",
-       "globalblocking-whitelist-nochange": "You made no change to the local 
status of this block.\n[[Special:GlobalBlockList|Return to the global block 
list]].",
-       "globalblocking-whitelist-errors": "Your change to the local status of 
a global block was unsuccessful, for the following 
{{PLURAL:$1|reason|reasons}}:",
-       "globalblocking-whitelist-intro": "You can use this form to edit the 
local status of a global block.\nIf a global block is disabled on this wiki, 
users on the affected IP address will be able to edit 
normally.\n[[Special:GlobalBlockList|Return to the global block list]].",
+       "globalblocking-whitelist-nochange": "You made no change to the local 
status of this block.",
+       "globalblocking-whitelist-intro": "You can use this form to edit the 
local status of a global block.\nIf a global block is disabled on this wiki, 
users on the affected IP address will be able to edit normally.",
        "globalblocking-ipblocked": "'''Your IP address has been blocked on all 
wikis.'''\n\nThe block was made by $1 ($2).\nThe reason given is ''$3''.\n\n* 
Start of block: $4\n* Expiry of block: $5\n\nYou can contact $1 to discuss the 
block.\nYou cannot use the \"{{int:emailuser}}\" feature unless a valid email 
address is specified in your [[Special:Preferences|account preferences]] and 
you have not been blocked from using it.\nYour current IP address is 
$6.\nPlease include all above details in any queries you make.",
        "globalblocking-ipblocked-xff": "'''One or more proxy servers used by 
your request is globally blocked'''\n\nThe block was made by $1 ($2).\nThe 
reason given is ''$3''.\n\n* Start of block: $4\n* Expiry of block: $5\n\nYou 
can contact $1 to discuss the block.\nYou cannot use the \"{{int:emailuser}}\" 
feature unless a valid email address is specified in your 
[[Special:Preferences|account preferences]] and you have not been blocked from 
using it.\nThe blocked proxy address was $6.\nPlease include all above details 
in any queries you make.",
        "globalblocking-blocked-nopassreset": "You cannot reset user's 
passwords because you are blocked globally.",
diff --git a/includes/specials/SpecialGlobalBlockStatus.php 
b/includes/specials/SpecialGlobalBlockStatus.php
index 9a3abdd..a673237 100644
--- a/includes/specials/SpecialGlobalBlockStatus.php
+++ b/includes/specials/SpecialGlobalBlockStatus.php
@@ -1,83 +1,41 @@
 <?php
 
-class SpecialGlobalBlockStatus extends SpecialPage {
-       public $mAddress, $mReason;
+class SpecialGlobalBlockStatus extends FormSpecialPage {
+       private $mAddress, $mCurrentStatus, $mWhitelistStatus;
 
        function __construct() {
                parent::__construct( 'GlobalBlockStatus', 
'globalblock-whitelist' );
        }
 
+       /**
+        * @param string $par not used currently
+        */
        function execute( $par ) {
+               global $wgApplyGlobalBlocks;
                $this->setHeaders();
-
-               $this->loadParameters();
+               $this->checkExecutePermissions( $this->getUser() );
 
                $out = $this->getOutput();
+               $out->enableClientCache( false );
                $out->setPageTitle( $this->msg( 'globalblocking-whitelist' ) );
                $out->setSubtitle( GlobalBlocking::buildSubtitleLinks( $this ) 
);
-               $out->setRobotPolicy( "noindex,nofollow" );
-               $out->setArticleRelated( false );
-               $out->enableClientCache( false );
 
-               if ( !$this->userCanExecute( $this->getUser() ) ) {
-                       $this->displayRestrictionError();
-                       return;
-               }
-
-               global $wgApplyGlobalBlocks;
                if ( !$wgApplyGlobalBlocks ) {
                        $out->addWikiMsg( 'globalblocking-whitelist-notapplied' 
);
                        return;
                }
-
-               $errors = '';
-
-               $request = $this->getRequest();
-               if ( $request->wasPosted() && $this->getUser()->matchEditToken( 
$request->getVal( 'wpEditToken' ) ) ) {
-                       // They want to submit. Let's have a look.
-                       $errors = $this->trySubmit();
-                       if ( !$errors ) {
-                               // Success!
-                               return;
-                       }
-               }
-
-               $errorstr = '';
-
-               if ( is_array( $errors ) && count( $errors ) > 0 ) {
-                       foreach ( $errors as $error ) {
-                               if ( is_array( $error ) ) {
-                                       $msg = array_shift( $error );
-                               } else {
-                                       $msg = $error;
-                                       $error = array();
-                               }
-                               $errorstr .= Xml::tags( 'li', null, $this->msg( 
$msg, $error )->parse() );
-                       }
-
-                       $errorstr = $this->msg( 
'globalblocking-whitelist-errors' )
-                               ->numParams( count( $errors ) )->parseAsBlock() 
.
-                               Xml::tags( 'ul', array( 'class' => 'error' ), 
$errorstr );
-
-                       $errorstr = Xml::tags( 'div', array( 'class' => 'error' 
), $errorstr );
-               }
-
-               $this->form( $errorstr );
+               $this->loadParameters();
+               $this->getForm()->show();
        }
 
-       function loadParameters() {
+       private function loadParameters() {
                $request = $this->getRequest();
                $ip = trim( $request->getText( 'address' ) );
-               $this->mAddress = ( $ip !== '' || $request->wasPosted() )
-                       ? IP::sanitizeRange( $ip )
-                       : '';
-               $this->mReason = $request->getText( 'wpReason' );
+               $this->mAddress = ( $ip !== '' || $request->wasPosted() ) ? 
IP::sanitizeRange( $ip ) : '';
                $this->mWhitelistStatus = $request->getCheck( 
'wpWhitelistStatus' );
-               $this->mEditToken = $request->getText( 'wpEditToken' );
 
                if ( $this->mAddress ) {
                        $this->mCurrentStatus = ( 
GlobalBlocking::getWhitelistInfoByIP( $this->mAddress ) !== false );
-
                        if ( !$request->wasPosted() ) {
                                $this->mWhitelistStatus = $this->mCurrentStatus;
                        }
@@ -86,7 +44,34 @@
                }
        }
 
-       function trySubmit() {
+       protected function alterForm( HTMLForm $form ) {
+               $form->setPreText( $this->msg( 'globalblocking-whitelist-intro' 
)->parse() );
+               $form->setWrapperLegendMsg( 'globalblocking-whitelist-legend' );
+               $form->setSubmitTextMsg( 'globalblocking-whitelist-submit' );
+       }
+
+       protected function getFormFields() {
+               return array(
+                       'address' => array(
+                               'name' => 'address',
+                               'type' => 'text',
+                               'id' => 'mw-globalblocking-ipaddress',
+                               'label-message' => 'globalblocking-ipaddress',
+                               'default' => $this->mAddress,
+                       ),
+                       'Reason' => array(
+                               'type' => 'text',
+                               'label-message' => 
'globalblocking-whitelist-reason'
+                       ),
+                       'WhitelistStatus' => array(
+                               'type' => 'check',
+                               'label-message' => 
'globalblocking-whitelist-statuslabel',
+                               'default' => $this->mCurrentStatus
+                       )
+               );
+       }
+
+       public function onSubmit( array $data ) {
                $ip = $this->mAddress;
 
                // Is it blocked?
@@ -94,91 +79,60 @@
                        return array( array( 'globalblocking-notblocked', $ip ) 
);
                }
 
-               $new_status = $this->mWhitelistStatus;
-               $cur_status = $this->mCurrentStatus;
-
-               // Already whitelisted.
-               if ( $cur_status == $new_status ) {
+               // Local status wasn't changed.
+               if ( $this->mCurrentStatus == $this->mWhitelistStatus ) {
                        return array( 'globalblocking-whitelist-nochange' );
                }
 
                $dbw = wfGetDB( DB_MASTER );
-
-               $out = $this->getOutput();
-               if ( $new_status == true ) {
-                       $gdbr = GlobalBlocking::getGlobalBlockingDatabase( 
DB_SLAVE );
+               $log = new LogPage( 'gblblock' );
+               if ( $this->mWhitelistStatus == true ) {
+                       // Add to whitelist
 
                        // Find the expiry of the block. This is important so 
that we can store it in the
                        // global_block_whitelist table, which allows us to 
purge it when the block has expired.
+                       $gdbr = GlobalBlocking::getGlobalBlockingDatabase( 
DB_SLAVE );
                        $expiry = $gdbr->selectField( 'globalblocks', 
'gb_expiry', array( 'gb_id' => $id ), __METHOD__ );
 
                        $row = array(
                                'gbw_by' => $this->getUser()->getId(),
                                'gbw_by_text' => $this->getUser()->getName(),
-                               'gbw_reason' => $this->mReason,
+                               'gbw_reason' => trim( $data['Reason'] ),
                                'gbw_address' => $ip,
                                'gbw_expiry' => $expiry,
                                'gbw_id' => $id
                        );
                        $dbw->replace( 'global_block_whitelist', array( 
'gbw_id' ), $row, __METHOD__ );
 
-                       $page = new LogPage( 'gblblock' );
-                       $page->addEntry( 'whitelist', Title::makeTitleSafe( 
NS_USER, $ip ), $this->mReason );
-
-                       $out->addWikiMsg( 
'globalblocking-whitelist-whitelisted', $ip, $id );
+                       $log->addEntry( 'whitelist', Title::makeTitleSafe( 
NS_USER, $ip ), $data['Reason'] );
+                       $successMsg = 'globalblocking-whitelist-whitelisted';
                } else {
-                       // Delete the row from the database
+                       // Remove from whitelist
                        $dbw->delete( 'global_block_whitelist', array( 'gbw_id' 
=> $id ), __METHOD__ );
 
-                       $page = new LogPage( 'gblblock' );
-                       $page->addEntry( 'dwhitelist', Title::makeTitleSafe( 
NS_USER, $ip ), $this->mReason );
-                       $out->addWikiMsg( 
'globalblocking-whitelist-dewhitelisted', $ip, $id );
+                       $log->addEntry( 'dwhitelist', Title::makeTitleSafe( 
NS_USER, $ip ), $data['Reason'] );
+                       $successMsg = 'globalblocking-whitelist-dewhitelisted';
                }
 
+               return $this->showSuccess( $ip, $id, $successMsg );
+       }
+
+       /**
+        * @param string $ip
+        * @param int $id
+        * @param string $successMsg
+        * @return bool
+        */
+       protected function showSuccess( $ip, $id, $successMsg ) {
                $link = Linker::linkKnown(
                        SpecialPage::getTitleFor( 'GlobalBlockList' ),
                        $this->msg( 'globalblocking-return' )->escaped()
                );
-               $out->addHTML( $link );
-
-               $out->setSubtitle( $this->msg( 
'globalblocking-whitelist-successsub' ) );
-
-               return array();
-       }
-
-       function form( $error ) {
                $out = $this->getOutput();
-               $out->addWikiMsg( 'globalblocking-whitelist-intro' );
-
-               $out->addHTML( $error );
-
-               $form = '';
-               $form .= Xml::openElement( 'fieldset' ) . Xml::element( 
'legend', null, $this->msg( 'globalblocking-whitelist-legend' )->text() );
-               $form .= Xml::openElement( 'form', array( 'method' => 'post', 
'action' => $this->getPageTitle()->getFullURL(), 'name' => 
'globalblock-whitelist' ) );
-
-               $form .= Html::hidden( 'title', 
$this->getPageTitle()->getPrefixedText() );
-               $form .= Html::hidden( 'action', 'whitelist' );
-
-               $fields = array();
-
-               // uses ipaddress msg
-               $fields['globalblocking-ipaddress'] = Xml::input( 'address', 
45, $this->mAddress );
-               $fields['globalblocking-whitelist-reason'] = Xml::input( 
'wpReason', 45, $this->mReason );
-               $fields['globalblocking-whitelist-status'] = Xml::checkLabel(
-                       $this->msg( 'globalblocking-whitelist-statuslabel' 
)->text(),
-                       'wpWhitelistStatus',
-                       'wpWhitelistStatus',
-                       $this->mCurrentStatus
-               );
-
-               $form .= Xml::buildForm( $fields, 
'globalblocking-whitelist-submit' );
-
-               $form .= Html::hidden( 'wpEditToken', 
$this->getUser()->getEditToken() );
-
-               $form .= Xml::closeElement( 'form' );
-               $form .= Xml::closeElement( 'fieldset' );
-
-               $out->addHTML( $form );
+               $out->setSubtitle( GlobalBlocking::buildSubtitleLinks( $this ) 
);
+               $out->addWikiMsg( $successMsg, $ip, $id );
+               $out->addHTML( $link );
+               return true;
        }
 
        protected function getGroupName() {

-- 
To view, visit https://gerrit.wikimedia.org/r/213594
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia6f90df41f2acfff47dcbfce30d7694238da5e56
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/GlobalBlocking
Gerrit-Branch: master
Gerrit-Owner: Glaisher <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Glaisher <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to