From 22906ba398581f2490733b9f176de2f6fe659d32 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Fri, 3 Jan 2014 01:39:13 -0800 Subject: [PATCH] Turn HTMLBlockedUsersItemSelect into HTMLSelectLimitField Makes it a "real" HTMLForm option that other code can re-use Change-Id: If0fb7332daf991b790bbf87e825229dccb10b360 --- includes/AutoLoader.php | 2 +- includes/htmlform/HTMLForm.php | 1 + includes/htmlform/HTMLSelectLimitField.php | 35 +++++++++++++++++++++ includes/specials/SpecialBlockList.php | 36 +--------------------- 4 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 includes/htmlform/HTMLSelectLimitField.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index c879258bf1..a5e37ba48e 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -102,6 +102,7 @@ $wgAutoloadLocalClasses = array( 'HTMLRadioField' => 'includes/htmlform/HTMLRadioField.php', 'HTMLSelectAndOtherField' => 'includes/htmlform/HTMLSelectAndOtherField.php', 'HTMLSelectField' => 'includes/htmlform/HTMLSelectField.php', + 'HTMLSelectLimitField' => 'includes/htmlform/HTMLSelectLimitField.php', 'HTMLSelectOrOtherField' => 'includes/htmlform/HTMLSelectOrOtherField.php', 'HTMLSubmitField' => 'includes/htmlform/HTMLSubmitField.php', 'HTMLTextAreaField' => 'includes/htmlform/HTMLTextAreaField.php', @@ -951,7 +952,6 @@ $wgAutoloadLocalClasses = array( 'EmailInvalidation' => 'includes/specials/SpecialConfirmemail.php', 'FewestrevisionsPage' => 'includes/specials/SpecialFewestrevisions.php', 'FileDuplicateSearchPage' => 'includes/specials/SpecialFileDuplicateSearch.php', - 'HTMLBlockedUsersItemSelect' => 'includes/specials/SpecialBlockList.php', 'ImageListPager' => 'includes/specials/SpecialListfiles.php', 'ImportReporter' => 'includes/specials/SpecialImport.php', 'LinkSearchPage' => 'includes/specials/SpecialLinkSearch.php', diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index 33346948e2..509f4893eb 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -106,6 +106,7 @@ class HTMLForm extends ContextSource { 'select' => 'HTMLSelectField', 'radio' => 'HTMLRadioField', 'multiselect' => 'HTMLMultiSelectField', + 'limitselect' => 'HTMLSelectLimitField', 'check' => 'HTMLCheckField', 'toggle' => 'HTMLCheckField', 'int' => 'HTMLIntField', diff --git a/includes/htmlform/HTMLSelectLimitField.php b/includes/htmlform/HTMLSelectLimitField.php new file mode 100644 index 0000000000..e7f1c047ce --- /dev/null +++ b/includes/htmlform/HTMLSelectLimitField.php @@ -0,0 +1,35 @@ +mParams['options'] ) + && $value == intval( $value ) + && $value > 0 + ) { + // This adds the explicitly requested limit value to the drop-down, + // then makes sure it's sorted correctly so when we output the list + // later, the custom option doesn't just show up last. + $this->mParams['options'][$this->mParent->getLanguage()->formatNum( $value )] = + intval( $value ); + asort( $this->mParams['options'] ); + } + + return true; + } +} diff --git a/includes/specials/SpecialBlockList.php b/includes/specials/SpecialBlockList.php index 9170e3eb7a..62fadb55cd 100644 --- a/includes/specials/SpecialBlockList.php +++ b/includes/specials/SpecialBlockList.php @@ -84,7 +84,7 @@ class SpecialBlockList extends SpecialPage { 'flatlist' => true, ), 'Limit' => array( - 'class' => 'HTMLBlockedUsersItemSelect', + 'type' => 'limitselect', 'label-message' => 'table_pager_limit_label', 'options' => array( $lang->formatNum( 20 ) => 20, @@ -457,37 +457,3 @@ class BlockListPager extends TablePager { wfProfileOut( __METHOD__ ); } } - -/** - * Items per page dropdown. Essentially a crap workaround for bug 32603. - */ -class HTMLBlockedUsersItemSelect extends HTMLSelectField { - /** - * Basically don't do any validation. If it's a number that's fine. Also, - * add it to the list if it's not there already - * - * @param string $value - * @param array $alldata - * @return bool - */ - function validate( $value, $alldata ) { - if ( $value == '' ) { - return true; - } - - // Let folks pick an explicit limit not from our list, as long as it's a real numbr. - if ( !in_array( $value, $this->mParams['options'] ) - && $value == intval( $value ) - && $value > 0 - ) { - // This adds the explicitly requested limit value to the drop-down, - // then makes sure it's sorted correctly so when we output the list - // later, the custom option doesn't just show up last. - $this->mParams['options'][$this->mParent->getLanguage()->formatNum( $value )] = - intval( $value ); - asort( $this->mParams['options'] ); - } - - return true; - } -} -- 2.20.1