r104353 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104352‎ | r104353 | r104354 >
Date:18:23, 27 November 2011
Author:johnduhart
Status:reverted (Comments)
Tags:
Comment:
This is the rework I was talking about in r104318 for 1.19. Instead of having Pager subclasses build HTML forms by hand build HTMLForm into the Pager class. Much less painful, no?

This is simply a first pass, there's many more classes to convert.
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)
  • /trunk/phase3/includes/Pager.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialActiveusers.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialAllmessages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialBlockList.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialListfiles.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialListusers.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -845,6 +845,15 @@
846846 public function getLegend( $key ) {
847847 return wfMsg( "{$this->mMessagePrefix}-$key" );
848848 }
 849+
 850+ /**
 851+ * Returns an array of fields in the form
 852+ *
 853+ * @return HTMLFormField[]
 854+ */
 855+ public function getFlatFields() {
 856+ return $this->mFlatFields;
 857+ }
849858 }
850859
851860 /**
@@ -1071,6 +1080,15 @@
10721081 return $html;
10731082 }
10741083
 1084+ /**
 1085+ * Returns the HTML name of the Field
 1086+ *
 1087+ * @return string
 1088+ */
 1089+ public function getName() {
 1090+ return $this->mName;
 1091+ }
 1092+
10751093 function getLabel() {
10761094 return $this->mLabel;
10771095 }
Index: trunk/phase3/includes/AutoLoader.php
@@ -104,6 +104,7 @@
105105 'HTMLHiddenField' => 'includes/HTMLForm.php',
106106 'HTMLInfoField' => 'includes/HTMLForm.php',
107107 'HTMLIntField' => 'includes/HTMLForm.php',
 108+ 'HTMLItemsPerPageField' => 'includes/Pager.php',
108109 'HTMLMultiSelectField' => 'includes/HTMLForm.php',
109110 'HTMLRadioField' => 'includes/HTMLForm.php',
110111 'HTMLSelectAndOtherField' => 'includes/HTMLForm.php',
@@ -743,7 +744,6 @@
744745 'EmailInvalidation' => 'includes/specials/SpecialConfirmemail.php',
745746 'FewestrevisionsPage' => 'includes/specials/SpecialFewestrevisions.php',
746747 'FileDuplicateSearchPage' => 'includes/specials/SpecialFileDuplicateSearch.php',
747 - 'HTMLBlockedUsersItemSelect' => 'includes/specials/SpecialBlockList.php',
748748 'ImportReporter' => 'includes/specials/SpecialImport.php',
749749 'IPBlockForm' => 'includes/specials/SpecialBlock.php',
750750 'LinkSearchPage' => 'includes/specials/SpecialLinkSearch.php',
Index: trunk/phase3/includes/specials/SpecialAllmessages.php
@@ -62,18 +62,18 @@
6363
6464 $out->addModuleStyles( 'mediawiki.special' );
6565
66 - $this->filter = $request->getVal( 'filter', 'all' );
67 - $this->prefix = $request->getVal( 'prefix', '' );
 66+ $this->filter = $request->getVal( 'wpFilter', 'all' );
 67+ $this->prefix = $request->getVal( 'wpPrefix', '' );
6868
6969 $this->table = new AllmessagesTablePager(
7070 $this,
7171 array(),
72 - wfGetLangObj( $request->getVal( 'lang', $par ) )
 72+ wfGetLangObj( $request->getVal( 'wpLanguage', $par ) )
7373 );
7474
7575 $this->langcode = $this->table->lang->getCode();
7676
77 - $out->addHTML( $this->table->buildForm() .
 77+ $out->addHTML( $this->table->buildHTMLForm() .
7878 $this->table->getNavigationBar() .
7979 $this->table->getBody() .
8080 $this->table->getNavigationBar() );
@@ -120,14 +120,14 @@
121121
122122 $request = $this->getRequest();
123123
124 - if( $request->getVal( 'filter', 'all' ) === 'all' ){
 124+ if( $request->getVal( 'wpFilter', 'all' ) === 'all' ){
125125 $this->custom = null; // So won't match in either case
126126 } else {
127 - $this->custom = ($request->getVal( 'filter' ) == 'unmodified');
 127+ $this->custom = ($request->getVal( 'wpFilter' ) == 'unmodified');
128128 }
129129
130 - $prefix = $this->getLanguage()->ucfirst( $request->getVal( 'prefix', '' ) );
131 - $prefix = $prefix != '' ? Title::makeTitleSafe( NS_MEDIAWIKI, $request->getVal( 'prefix', null ) ) : null;
 130+ $prefix = $this->getLanguage()->ucfirst( $request->getVal( 'wpPrefix', '' ) );
 131+ $prefix = $prefix != '' ? Title::makeTitleSafe( NS_MEDIAWIKI, $request->getVal( 'wpPrefix', null ) ) : null;
132132 if( $prefix !== null ){
133133 $this->displayPrefix = $prefix->getDBkey();
134134 $this->prefix = '/^' . preg_quote( $this->displayPrefix ) . '/i';
@@ -145,85 +145,50 @@
146146 }
147147 }
148148
149 - function buildForm() {
150 - global $wgScript;
 149+ protected function getHTMLFormFields() {
 150+ $f = array(
 151+ 'Prefix' => array(
 152+ 'type' => 'text',
 153+ 'label-message' => 'allmessages-prefix',
 154+ 'size' => 20,
 155+ ),
 156+ 'Filter' => array(
 157+ 'type' => 'radio',
 158+ 'label-message' => 'allmessages-filter',
 159+ 'options' => array(
 160+ $this->msg( 'allmessages-filter-unmodified' )->text() => 'unmodified',
 161+ $this->msg( 'allmessages-filter-all' )->text() => 'all',
 162+ $this->msg( 'allmessages-filter-modified' )->text() => 'modified',
 163+ ),
 164+ 'flatlist' => true,
 165+ ),
 166+ 'Language' => array(
 167+ 'type' => 'select',
 168+ 'label-message' => 'allmessages-language',
 169+ 'options' => array(), // This is filled in below
 170+ 'default' => $this->langcode,
 171+ ),
 172+ 'Limit' => $this->getHTMLFormLimitSelect(),
 173+ );
151174
152175 $languages = Language::getLanguageNames( false );
153176 ksort( $languages );
154177
155 - $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) .
156 - Xml::fieldset( $this->msg( 'allmessages-filter-legend' )->text() ) .
157 - Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
158 - Xml::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
159 - '<tr>
160 - <td class="mw-label">' .
161 - Xml::label( $this->msg( 'allmessages-prefix' )->text(), 'mw-allmessages-form-prefix' ) .
162 - "</td>\n
163 - <td class=\"mw-input\">" .
164 - Xml::input( 'prefix', 20, str_replace( '_', ' ', $this->displayPrefix ), array( 'id' => 'mw-allmessages-form-prefix' ) ) .
165 - "</td>\n
166 - </tr>
167 - <tr>\n
168 - <td class='mw-label'>" .
169 - $this->msg( 'allmessages-filter' )->escaped() .
170 - "</td>\n
171 - <td class='mw-input'>" .
172 - Xml::radioLabel( $this->msg( 'allmessages-filter-unmodified' )->text(),
173 - 'filter',
174 - 'unmodified',
175 - 'mw-allmessages-form-filter-unmodified',
176 - ( $this->filter == 'unmodified' )
177 - ) .
178 - Xml::radioLabel( $this->msg( 'allmessages-filter-all' )->text(),
179 - 'filter',
180 - 'all',
181 - 'mw-allmessages-form-filter-all',
182 - ( $this->filter == 'all' )
183 - ) .
184 - Xml::radioLabel( $this->msg( 'allmessages-filter-modified' )->text(),
185 - 'filter',
186 - 'modified',
187 - 'mw-allmessages-form-filter-modified',
188 - ( $this->filter == 'modified' )
189 - ) .
190 - "</td>\n
191 - </tr>
192 - <tr>\n
193 - <td class=\"mw-label\">" .
194 - Xml::label( $this->msg( 'allmessages-language' )->text(), 'mw-allmessages-form-lang' ) .
195 - "</td>\n
196 - <td class=\"mw-input\">" .
197 - Xml::openElement( 'select', array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ) );
198 -
199 - foreach( $languages as $lang => $name ) {
200 - $selected = $lang == $this->langcode;
201 - $out .= Xml::option( $lang . ' - ' . $name, $lang, $selected ) . "\n";
 178+ foreach( $languages as $code => $name ) {
 179+ $f['Language']['options'][ "$code - $name" ] = $code;
202180 }
203 - $out .= Xml::closeElement( 'select' ) .
204 - "</td>\n
205 - </tr>" .
206181
207 - '<tr>
208 - <td class="mw-label">' .
209 - Xml::label( $this->msg( 'table_pager_limit_label' )->text(), 'mw-table_pager_limit_label' ) .
210 - '</td>
211 - <td class="mw-input">' .
212 - $this->getLimitSelect() .
213 - '</td>
214 - <tr>
215 - <td></td>
216 - <td>' .
217 - Xml::submitButton( $this->msg( 'allmessages-filter-submit' )->text() ) .
218 - "</td>\n
219 - </tr>" .
 182+ return $f;
 183+ }
220184
221 - Xml::closeElement( 'table' ) .
222 - $this->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang', 'limit' ) ) .
223 - Xml::closeElement( 'fieldset' ) .
224 - Xml::closeElement( 'form' );
225 - return $out;
 185+ protected function getHTMLFormLegend() {
 186+ return 'allmessages-filter-legend';
226187 }
227188
 189+ protected function getHTMLFormSubmit() {
 190+ return 'allmessages-filter-submit';
 191+ }
 192+
228193 function getAllMessages( $descending ) {
229194 wfProfileIn( __METHOD__ );
230195 $messageNames = Language::getLocalisationCache()->getSubitemList( 'en', 'messages' );
Index: trunk/phase3/includes/specials/SpecialBlockList.php
@@ -43,7 +43,6 @@
4444 $this->setHeaders();
4545 $this->outputHeader();
4646 $out = $this->getOutput();
47 - $lang = $this->getLanguage();
4847 $out->setPageTitle( $this->msg( 'ipblocklist' ) );
4948 $out->addModuleStyles( 'mediawiki.special' );
5049
@@ -62,46 +61,6 @@
6362 return;
6463 }
6564
66 - # Just show the block list
67 - $fields = array(
68 - 'Target' => array(
69 - 'type' => 'text',
70 - 'label-message' => 'ipadressorusername',
71 - 'tabindex' => '1',
72 - 'size' => '45',
73 - 'default' => $this->target,
74 - ),
75 - 'Options' => array(
76 - 'type' => 'multiselect',
77 - 'options' => array(
78 - wfMsg( 'blocklist-userblocks' ) => 'userblocks',
79 - wfMsg( 'blocklist-tempblocks' ) => 'tempblocks',
80 - wfMsg( 'blocklist-addressblocks' ) => 'addressblocks',
81 - wfMsg( 'blocklist-rangeblocks' ) => 'rangeblocks',
82 - ),
83 - 'flatlist' => true,
84 - ),
85 - 'Limit' => array(
86 - 'class' => 'HTMLBlockedUsersItemSelect',
87 - 'label-message' => 'table_pager_limit_label',
88 - 'options' => array(
89 - $lang->formatNum( 20 ) => 20,
90 - $lang->formatNum( 50 ) => 50,
91 - $lang->formatNum( 100 ) => 100,
92 - $lang->formatNum( 250 ) => 250,
93 - $lang->formatNum( 500 ) => 500,
94 - ),
95 - 'name' => 'limit',
96 - 'default' => 50,
97 - ),
98 - );
99 - $form = new HTMLForm( $fields, $this->getContext() );
100 - $form->setMethod( 'get' );
101 - $form->setWrapperLegend( wfMsg( 'ipblocklist-legend' ) );
102 - $form->setSubmitText( wfMsg( 'ipblocklist-submit' ) );
103 - $form->prepareForm();
104 -
105 - $form->displayForm( '' );
10665 $this->showList();
10766 }
10867
@@ -176,6 +135,7 @@
177136 }
178137
179138 $pager = new BlockListPager( $this, $conds );
 139+ $out->addHTML( $pager->buildHTMLForm() );
180140 if ( $pager->getNumRows() ) {
181141 $out->addHTML(
182142 $pager->getNavigationBar() .
@@ -399,6 +359,37 @@
400360 return $info;
401361 }
402362
 363+ protected function getHTMLFormFields() {
 364+ return array(
 365+ 'Target' => array(
 366+ 'type' => 'text',
 367+ 'label-message' => 'ipadressorusername',
 368+ 'tabindex' => '1',
 369+ 'size' => '45',
 370+ //'default' => $this->target,
 371+ ),
 372+ 'Options' => array(
 373+ 'type' => 'multiselect',
 374+ 'options' => array(
 375+ wfMsg( 'blocklist-userblocks' ) => 'userblocks',
 376+ wfMsg( 'blocklist-tempblocks' ) => 'tempblocks',
 377+ wfMsg( 'blocklist-addressblocks' ) => 'addressblocks',
 378+ wfMsg( 'blocklist-rangeblocks' ) => 'rangeblocks',
 379+ ),
 380+ 'flatlist' => true,
 381+ ),
 382+ 'Limit' => $this->getHTMLFormLimitSelect(),
 383+ );
 384+ }
 385+
 386+ protected function getHTMLFormSubmit() {
 387+ return 'ipblocklist-submit';
 388+ }
 389+
 390+ protected function getHTMLFormLegend() {
 391+ return 'ipblocklist-legend';
 392+ }
 393+
403394 public function getTableClass(){
404395 return 'TablePager mw-blocklist';
405396 }
@@ -447,33 +438,4 @@
448439 $lb->execute();
449440 wfProfileOut( __METHOD__ );
450441 }
451 -}
452 -
453 -/**
454 - * Items per page dropdown. Essentially a crap workaround for bug 32603.
455 - *
456 - * @todo Do not release 1.19 with this.
457 - */
458 -class HTMLBlockedUsersItemSelect extends HTMLSelectField {
459 - /**
460 - * Basically don't do any validation. If it's a number that's fine. Also,
461 - * add it to the list if it's not there already
462 - *
463 - * @param $value
464 - * @param $alldata
465 - * @return bool
466 - */
467 - function validate( $value, $alldata ) {
468 - if ( $value == '' ) {
469 - return true;
470 - }
471 -
472 - if ( !in_array( $value, $this->mParams['options'] ) ) {
473 - $this->mParams['options'][ $this->mParent->getLanguage()->formatNum( $value ) ] = intval($value);
474 - asort( $this->mParams['options'] );
475 - }
476 -
477 - return true;
478 - }
479 -
480 -}
 442+}
\ No newline at end of file
Index: trunk/phase3/includes/specials/SpecialListfiles.php
@@ -35,8 +35,8 @@
3636 $userName = $par;
3737 $search = '';
3838 } else {
39 - $userName = $this->getRequest()->getText( 'user', $par );
40 - $search = $this->getRequest()->getText( 'ilsearch', '' );
 39+ $userName = $this->getRequest()->getText( 'wpUsername', $par );
 40+ $search = $this->getRequest()->getText( 'wpSearch', '' );
4141 }
4242
4343 $pager = new ImageListPager( $this->getContext(), $userName, $search, $this->including() );
@@ -44,7 +44,7 @@
4545 if ( $this->including() ) {
4646 $html = $pager->getBody();
4747 } else {
48 - $form = $pager->getForm();
 48+ $form = $pager->buildHTMLForm();
4949 $body = $pager->getBody();
5050 $nav = $pager->getNavigationBar();
5151 $html = "$form<br />\n$body<br />\n$nav";
@@ -234,32 +234,37 @@
235235 }
236236 }
237237
238 - function getForm() {
239 - global $wgScript, $wgMiserMode;
240 - $inputForm = array();
241 - $inputForm['table_pager_limit_label'] = $this->getLimitSelect();
 238+ protected function getHTMLFormFields() {
 239+ global $wgMiserMode;
 240+ $f = array(
 241+ 'Limit' => $this->getHTMLFormLimitSelect(),
 242+ );
 243+
242244 if ( !$wgMiserMode ) {
243 - $inputForm['listfiles_search_for'] = Html::input( 'ilsearch', $this->mSearch, 'text',
244 - array(
245 - 'size' => '40',
246 - 'maxlength' => '255',
247 - 'id' => 'mw-ilsearch',
248 - ) );
 245+ $f['Search'] = array(
 246+ 'type' => 'text',
 247+ 'label-message' => 'listfiles_search_for',
 248+ 'maxlength' => 255,
 249+ );
249250 }
250 - $inputForm['username'] = Html::input( 'user', $this->mUserName, 'text', array(
251 - 'size' => '40',
252 - 'maxlength' => '255',
253 - 'id' => 'mw-listfiles-user',
254 - ) );
255 - return Html::openElement( 'form',
256 - array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listfiles-form' ) ) .
257 - Xml::fieldset( wfMsg( 'listfiles' ) ) .
258 - Xml::buildForm( $inputForm, 'table_pager_limit_submit' ) .
259 - $this->getHiddenFields( array( 'limit', 'ilsearch', 'user' ) ) .
260 - Html::closeElement( 'fieldset' ) .
261 - Html::closeElement( 'form' ) . "\n";
 251+
 252+ $f['Username'] = array(
 253+ 'type' => 'text',
 254+ 'label-message' => 'username',
 255+ 'maxlength' => 255,
 256+ );
 257+
 258+ return $f;
262259 }
263260
 261+ protected function getHTMLFormLegend() {
 262+ return 'listfiles';
 263+ }
 264+
 265+ protected function getHTMLFormSubmit() {
 266+ return 'table_pager_limit_submit';
 267+ }
 268+
264269 function getTableClass() {
265270 return 'listfiles ' . parent::getTableClass();
266271 }
Index: trunk/phase3/includes/specials/SpecialListusers.php
@@ -44,19 +44,19 @@
4545 $symsForAll = array( '*', 'user' );
4646 if ( $parms[0] != '' && ( in_array( $par, User::getAllGroups() ) || in_array( $par, $symsForAll ) ) ) {
4747 $this->requestedGroup = $par;
48 - $un = $request->getText( 'username' );
 48+ $un = $request->getText( 'wpUsername' );
4949 } elseif ( count( $parms ) == 2 ) {
5050 $this->requestedGroup = $parms[0];
5151 $un = $parms[1];
5252 } else {
53 - $this->requestedGroup = $request->getVal( 'group' );
54 - $un = ( $par != '' ) ? $par : $request->getText( 'username' );
 53+ $this->requestedGroup = $request->getVal( 'wpGroup' );
 54+ $un = ( $par != '' ) ? $par : $request->getText( 'wpUsername' );
5555 }
5656 if ( in_array( $this->requestedGroup, $symsForAll ) ) {
5757 $this->requestedGroup = '';
5858 }
59 - $this->editsOnly = $request->getBool( 'editsOnly' );
60 - $this->creationSort = $request->getBool( 'creationSort' );
 59+ $this->editsOnly = $request->getBool( 'wpEditsOnly' );
 60+ $this->creationSort = $request->getBool( 'wpCreationSort' );
6161
6262 $this->requestedUser = '';
6363 if ( $un != '' ) {
@@ -182,41 +182,43 @@
183183 return parent::getBody();
184184 }
185185
186 - function getPageHeader( ) {
187 - global $wgScript;
188 - $self = $this->getTitle();
 186+ protected function getHTMLFormFields() {
 187+ $f = array(
 188+ 'Username' => array(
 189+ 'type' => 'text',
 190+ 'label-message' => 'listusersfrom',
 191+ 'size' => 30,
 192+ ),
 193+ 'Group' => array(
 194+ 'type' => 'select',
 195+ 'label-message' => 'group',
 196+ 'options' => array(
 197+ $this->msg( 'group-all' )->escaped() => '',
 198+ ),
 199+ ),
 200+ 'EditsOnly' => array(
 201+ 'type' => 'check',
 202+ 'label-message' => 'listusers-editsonly',
 203+ ),
 204+ 'CreationSort' => array(
 205+ 'type' => 'check',
 206+ 'label-message' => 'listusers-creationsort',
 207+ ),
 208+ );
189209
190 - # Form tag
191 - $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' ) ) .
192 - Xml::fieldset( wfMsg( 'listusers' ) ) .
193 - Html::hidden( 'title', $self->getPrefixedDbKey() );
 210+ foreach( $this->getAllGroups() as $group => $groupText ) {
 211+ $f['Group']['options'][$groupText] = $group;
 212+ }
194213
195 - # Username field
196 - $out .= Xml::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
197 - Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
 214+ return $f;
 215+ }
198216
199 - # Group drop-down list
200 - $out .= Xml::label( wfMsg( 'group' ), 'group' ) . ' ' .
201 - Xml::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) .
202 - Xml::option( wfMsg( 'group-all' ), '' );
203 - foreach( $this->getAllGroups() as $group => $groupText )
204 - $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup );
205 - $out .= Xml::closeElement( 'select' ) . '<br />';
206 - $out .= Xml::checkLabel( wfMsg('listusers-editsonly'), 'editsOnly', 'editsOnly', $this->editsOnly );
207 - $out .= '&#160;';
208 - $out .= Xml::checkLabel( wfMsg('listusers-creationsort'), 'creationSort', 'creationSort', $this->creationSort );
209 - $out .= '<br />';
 217+ protected function getHTMLFormSubmit() {
 218+ return 'allpagessubmit';
 219+ }
210220
211 - wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) );
212 -
213 - # Submit button and form bottom
214 - $out .= Html::hidden( 'limit', $this->mLimit );
215 - $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
216 - wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) );
217 - $out .= Xml::closeElement( 'fieldset' ) .
218 - Xml::closeElement( 'form' );
219 -
220 - return $out;
 221+ protected function getHTMLFormLegend() {
 222+ return 'listusers';
221223 }
222224
223225 /**
@@ -295,7 +297,7 @@
296298 # getBody() first to check, if empty
297299 $usersbody = $up->getBody();
298300
299 - $s = $up->getPageHeader();
 301+ $s = $up->buildHTMLForm();
300302 if( $usersbody ) {
301303 $s .= $up->getNavigationBar();
302304 $s .= Html::rawElement( 'ul', array(), $usersbody );
Index: trunk/phase3/includes/specials/SpecialActiveusers.php
@@ -53,7 +53,7 @@
5454 parent::__construct( $context );
5555
5656 $this->RCMaxAge = $wgActiveUserDays;
57 - $un = $this->getRequest()->getText( 'username', $par );
 57+ $un = $this->getRequest()->getText( 'wpUsername', $par );
5858 $this->requestedUser = '';
5959 if ( $un != '' ) {
6060 $username = Title::makeTitleSafe( NS_USER, $un );
@@ -68,16 +68,16 @@
6969 public function setupOptions() {
7070 $this->opts = new FormOptions();
7171
72 - $this->opts->add( 'hidebots', false, FormOptions::BOOL );
73 - $this->opts->add( 'hidesysops', false, FormOptions::BOOL );
 72+ $this->opts->add( 'wpHideBots', false, FormOptions::BOOL );
 73+ $this->opts->add( 'wpHideSysops', false, FormOptions::BOOL );
7474
7575 $this->opts->fetchValuesFromRequest( $this->getRequest() );
7676
7777 $this->groups = array();
78 - if ( $this->opts->getValue( 'hidebots' ) == 1 ) {
 78+ if ( $this->opts->getValue( 'wpHideBots' ) == 1 ) {
7979 $this->groups['bot'] = true;
8080 }
81 - if ( $this->opts->getValue( 'hidesysops' ) == 1 ) {
 81+ if ( $this->opts->getValue( 'wpHideSysops' ) == 1 ) {
8282 $this->groups['sysop'] = true;
8383 }
8484 }
@@ -143,30 +143,32 @@
144144 return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
145145 }
146146
147 - function getPageHeader() {
148 - global $wgScript;
 147+ protected function getHTMLFormFields() {
 148+ $f = array(
 149+ 'Username' => array(
 150+ 'type' => 'text',
 151+ 'label-message' => 'activeusers-from',
 152+ 'size' => 30,
 153+ ),
 154+ 'HideBots' => array(
 155+ 'type' => 'check',
 156+ 'label-message' => 'activeusers-hidebots',
 157+ ),
 158+ 'HideSysops' => array(
 159+ 'type' => 'check',
 160+ 'label-message' => 'activeusers-hidesysops',
 161+ ),
 162+ );
149163
150 - $self = $this->getTitle();
151 - $limit = $this->mLimit ? Html::hidden( 'limit', $this->mLimit ) : '';
 164+ return $f;
 165+ }
152166
153 - $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
154 - $out .= Xml::fieldset( $this->msg( 'activeusers' )->text() ) . "\n";
155 - $out .= Html::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
 167+ protected function getHTMLFormLegend() {
 168+ return 'activeusers';
 169+ }
156170
157 - $out .= Xml::inputLabel( $this->msg( 'activeusers-from' )->text(),
158 - 'username', 'offset', 20, $this->requestedUser ) . '<br />';# Username field
159 -
160 - $out .= Xml::checkLabel( $this->msg( 'activeusers-hidebots' )->text(),
161 - 'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ) );
162 -
163 - $out .= Xml::checkLabel( $this->msg( 'activeusers-hidesysops' )->text(),
164 - 'hidesysops', 'hidesysops', $this->opts->getValue( 'hidesysops' ) ) . '<br />';
165 -
166 - $out .= Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n";# Submit button and form bottom
167 - $out .= Xml::closeElement( 'fieldset' );
168 - $out .= Xml::closeElement( 'form' );
169 -
170 - return $out;
 171+ protected function getHTMLFormSubmit() {
 172+ return 'allpagessubmit';
171173 }
172174 }
173175
@@ -202,7 +204,7 @@
203205 # getBody() first to check, if empty
204206 $usersbody = $up->getBody();
205207
206 - $out->addHTML( $up->getPageHeader() );
 208+ $out->addHTML( $up->buildHTMLForm() );
207209 if ( $usersbody ) {
208210 $out->addHTML(
209211 $up->getNavigationBar() .
Index: trunk/phase3/includes/Pager.php
@@ -560,6 +560,48 @@
561561 }
562562
563563 /**
 564+ * Assembles an HTMLForm for the Pager and returns the HTML
 565+ *
 566+ * @return string
 567+ */
 568+ public function buildHTMLForm() {
 569+ if ( $this->getHTMLFormFields() === null ) {
 570+ throw new MWException( __METHOD__ . " was called without any form fields being defined" );
 571+ }
 572+
 573+ $form = new HTMLForm( $this->getHTMLFormFields(), $this->getContext() );
 574+ $form->setMethod( 'get' );
 575+ $form->setWrapperLegendMsg( $this->getHTMLFormLegend() );
 576+ $form->setSubmitTextMsg( $this->getHTMLFormSubmit() );
 577+ $this->addHiddenFields( $form );
 578+ $this->modifyHTMLForm( $form );
 579+ $form->prepareForm();
 580+
 581+ return $form->getHTML( '' );
 582+ }
 583+
 584+ /**
 585+ * Adds hidden elements to forms for things that are in the query string.
 586+ * This is so that parameters like offset stick through form submissions
 587+ *
 588+ * @param HTMLForm $form
 589+ */
 590+ protected function addHiddenFields( HTMLForm $form ) {
 591+ $query = $this->getRequest()->getQueryValues();
 592+ $fieldsBlacklist = array( 'title' );
 593+ $fields = $form->getFlatFields();
 594+ foreach ( $fields as $name => $field ) {
 595+ $fieldsBlacklist[] = $field->getName();
 596+ }
 597+ foreach ( $query as $name => $value ) {
 598+ if ( in_array( $name, $fieldsBlacklist ) ) {
 599+ continue;
 600+ }
 601+ $form->addHiddenField( $name, $value );
 602+ }
 603+ }
 604+
 605+ /**
564606 * Abstract formatting function. This should return an HTML string
565607 * representing the result row $row. Rows will be concatenated and
566608 * returned by getBody()
@@ -635,6 +677,43 @@
636678 * @return Boolean
637679 */
638680 protected function getDefaultDirections() { return false; }
 681+
 682+ /**
 683+ * Returns an array for HTMLForm fields for the pager
 684+ *
 685+ * Only used if the pager makes use of HTMLForms
 686+ *
 687+ * @return array|null
 688+ */
 689+ protected function getHTMLFormFields() { return null; }
 690+
 691+ /**
 692+ * Message name for the fieldset legend text
 693+ *
 694+ * Only used if the pager makes use of HTMLForms
 695+ *
 696+ * @return string
 697+ */
 698+ protected function getHTMLFormLegend() { return ''; }
 699+
 700+ /**
 701+ * Message name for the submit button text
 702+ *
 703+ * Only used if the pager makes use of HTMLForms
 704+ *
 705+ * @return string
 706+ */
 707+ protected function getHTMLFormSubmit() { return ''; }
 708+
 709+ /**
 710+ * If the pager needs to do any modifications to the Form, override this
 711+ * function.
 712+ *
 713+ * Only used if the pager makes use of HTMLForms
 714+ *
 715+ * @param HTMLForm $form
 716+ */
 717+ protected function modifyHTMLForm( HTMLForm $form ) {}
639718 }
640719
641720
@@ -1072,6 +1151,27 @@
10731152 }
10741153
10751154 /**
 1155+ * Returns an HTMLFormField definition for the "Items per page:" dropdown
 1156+ *
 1157+ * @return array
 1158+ */
 1159+ protected function getHTMLFormLimitSelect() {
 1160+ $f = array(
 1161+ 'class' => 'HTMLItemsPerPageField',
 1162+ 'label-message' => 'table_pager_limit_label',
 1163+ 'options' => array(),
 1164+ 'default' => $this->mDefaultLimit,
 1165+ 'name' => 'limit',
 1166+ );
 1167+
 1168+ foreach( $this->mLimitsShown as $limit ) {
 1169+ $f['options'][$this->getLanguage()->formatNum( $limit )] = $limit;
 1170+ }
 1171+
 1172+ return $f;
 1173+ }
 1174+
 1175+ /**
10761176 * Get <input type="hidden"> elements for use in a method="get" form.
10771177 * Resubmits all defined elements of the query string, except for a
10781178 * blacklist, passed in the $blacklist parameter.
@@ -1158,3 +1258,30 @@
11591259 */
11601260 abstract function getFieldNames();
11611261 }
 1262+
 1263+/**
 1264+ * Items per page dropdown for HTMLForm
 1265+ */
 1266+class HTMLItemsPerPageField extends HTMLSelectField {
 1267+ /**
 1268+ * Basically don't do any validation. If it's a number that's fine. Also,
 1269+ * add it to the list if it's not there already
 1270+ *
 1271+ * @param $value
 1272+ * @param $alldata
 1273+ * @return bool
 1274+ */
 1275+ function validate( $value, $alldata ) {
 1276+ if ( $value == '' ) {
 1277+ return true;
 1278+ }
 1279+
 1280+ if ( !in_array( $value, $this->mParams['options'] ) ) {
 1281+ $this->mParams['options'][ $this->mParent->getLanguage()->formatNum( $value ) ] = intval($value);
 1282+ asort( $this->mParams['options'] );
 1283+ }
 1284+
 1285+ return true;
 1286+ }
 1287+
 1288+}
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r104354Followup r104353, fixing a regression in the BlockListjohnduhart18:28, 27 November 2011
r104356Followup r104353, updating Special:NewFilesjohnduhart19:03, 27 November 2011
r104358Followup r104353, updating Special:Categoriesjohnduhart19:17, 27 November 2011
r104383Followup r104353, updating Special:ProtectedTitles...johnduhart00:31, 28 November 2011
r105338Revert r104353, r104354, r104356, r104358, r104383: changes to pagers break...brion19:32, 6 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r104318Bug 32603 - limit option is missing on Special:BlockList...johnduhart22:15, 26 November 2011

Comments

#Comment by Nikerabbit (talk | contribs)   05:29, 29 November 2011

Not nice to break all existing urls with parameters.

#Comment by Brion VIBBER (talk | contribs)   19:27, 6 December 2011

Example: http://translatewiki.net/wiki/Special:ListUsers?group=bureaucrat

the new code wants 'wpGroup' instead of 'group', breaking existing links.

#Comment by Brion VIBBER (talk | contribs)   19:29, 6 December 2011

I'm going to do a provisional revert on these for now.

Status & tagging log