Revert "Convert Special:NewFiles to use OOUI."
authorBartosz Dziewoński <matma.rex@gmail.com>
Tue, 24 May 2016 18:05:25 +0000 (18:05 +0000)
committerBartosz Dziewoński <matma.rex@gmail.com>
Tue, 24 May 2016 18:05:25 +0000 (18:05 +0000)
Removing the 'hidden' fields from the HTMLForm definition
means that they are no longer preserved when the form is
resubmitted. I think that's a problematic regression.

This reverts commit 179e2f892d7811fa5613e1d6e0d5626e52c93b31.

Change-Id: Ib84dca5119b7a5270b349c5d1164541a5f082d96

includes/specials/SpecialNewimages.php
includes/specials/pagers/NewFilesPager.php

index 7d0f879..14391d2 100644 (file)
@@ -33,73 +33,21 @@ class SpecialNewFiles extends IncludableSpecialPage {
                $out = $this->getOutput();
                $this->addHelpLink( 'Help:New images' );
 
-               $opts = new FormOptions();
-
-               $opts->add( 'like', '' );
-               $opts->add( 'showbots', false );
-               $opts->add( 'hidepatrolled', false );
-               $opts->add( 'limit', 50 );
-               $opts->add( 'offset', 0 );
-
-               $opts->fetchValuesFromRequest( $this->getRequest() );
-
-               if ( $par !== null ) {
-                       $opts->setValue( is_numeric( $par ) ? 'limit' : 'like', $par );
-               }
-
-               $opts->validateIntBounds( 'limit', 0, 500 );
-
-               $this->opts = $opts;
+               $pager = new NewFilesPager( $this->getContext(), $par );
 
                if ( !$this->including() ) {
-                       $this->buildForm();
+                       $this->setTopText();
+                       $form = $pager->getForm();
+                       $form->prepareForm();
+                       $form->displayForm( '' );
                }
 
-               $pager = new NewFilesPager( $this->getContext(), $opts );
-
                $out->addHTML( $pager->getBody() );
                if ( !$this->including() ) {
                        $out->addHTML( $pager->getNavigationBar() );
                }
        }
 
-       protected function buildForm() {
-               $formDescriptor = [
-                       'like' => [
-                               'type' => 'text',
-                               'label-message' => 'newimages-label',
-                               'name' => 'like',
-                       ],
-
-                       'showbots' => [
-                               'type' => 'check',
-                               'label-message' => 'newimages-showbots',
-                               'name' => 'showbots',
-                       ],
-
-                       'hidepatrolled' => [
-                               'type' => 'check',
-                               'label-message' => 'newimages-hidepatrolled',
-                               'name' => 'hidepatrolled',
-                       ],
-               ];
-
-               if ( $this->getConfig()->get( 'MiserMode' ) ) {
-                       unset( $formDescriptor['like'] );
-               }
-
-               if ( !$this->getUser()->useFilePatrol() ) {
-                       unset( $formDescriptor['hidepatrolled'] );
-               }
-
-               $form = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
-                       ->setWrapperLegendMsg( 'newimages-legend' )
-                       ->setSubmitTextMsg( 'ilsubmit' )
-                       ->setMethod( 'get' )
-                       ->prepareForm()
-                       ->displayForm( false );
-       }
-
        protected function getGroupName() {
                return 'changes';
        }
index d1f9f40..ae57736 100644 (file)
@@ -30,30 +30,33 @@ class NewFilesPager extends ReverseChronologicalPager {
        protected $gallery;
 
        /**
-        * @var FormOptions
+        * @var bool
         */
-       protected $opts;
+       protected $showBots;
 
        /**
-        * @param IContextSource $context
-        * @param FormOptions $opts
+        * @var bool
         */
-       function __construct( IContextSource $context, FormOptions $opts ) {
-               $this->opts = $opts;
-
-               $this->setLimit( $opts->getValue( 'limit' ) );
+       protected $hidePatrolled;
+
+       function __construct( IContextSource $context, $par = null ) {
+               $this->like = $context->getRequest()->getText( 'like' );
+               $this->showBots = $context->getRequest()->getBool( 'showbots', 0 );
+               $this->hidePatrolled = $context->getRequest()->getBool( 'hidepatrolled', 0 );
+               if ( is_numeric( $par ) ) {
+                       $this->setLimit( $par );
+               }
 
                parent::__construct( $context );
        }
 
        function getQueryInfo() {
-               $opts = $this->opts;
                $conds = $jconds = [];
                $tables = [ 'image' ];
                $fields = [ 'img_name', 'img_user', 'img_timestamp' ];
                $options = [];
 
-               if ( !$opts->getValue( 'showbots' ) ) {
+               if ( !$this->showBots ) {
                        $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
 
                        if ( count( $groupsWithBotPermission ) ) {
@@ -69,7 +72,7 @@ class NewFilesPager extends ReverseChronologicalPager {
                        }
                }
 
-               if ( $opts->getValue( 'hidepatrolled' ) ) {
+               if ( $this->hidePatrolled ) {
                        $tables[] = 'recentchanges';
                        $conds['rc_type'] = RC_LOG;
                        $conds['rc_log_type'] = 'upload';
@@ -89,10 +92,9 @@ class NewFilesPager extends ReverseChronologicalPager {
                        $options[] = 'STRAIGHT_JOIN';
                }
 
-               $likeVal = $opts->getValue( 'like' );
-               if ( !$this->getConfig()->get( 'MiserMode' ) && $likeVal !== '' ) {
+               if ( !$this->getConfig()->get( 'MiserMode' ) && $this->like !== null ) {
                        $dbr = wfGetDB( DB_SLAVE );
-                       $likeObj = Title::newFromText( $likeVal );
+                       $likeObj = Title::newFromText( $this->like );
                        if ( $likeObj instanceof Title ) {
                                $like = $dbr->buildLike(
                                        $dbr->anyString(),
@@ -152,4 +154,54 @@ class NewFilesPager extends ReverseChronologicalPager {
                        . "</i><br />\n"
                );
        }
+
+       function getForm() {
+               $fields = [
+                       'like' => [
+                               'type' => 'text',
+                               'label-message' => 'newimages-label',
+                               'name' => 'like',
+                       ],
+                       'showbots' => [
+                               'type' => 'check',
+                               'label-message' => 'newimages-showbots',
+                               'name' => 'showbots',
+                       ],
+                       'hidepatrolled' => [
+                               'type' => 'check',
+                               'label-message' => 'newimages-hidepatrolled',
+                               'name' => 'hidepatrolled',
+                       ],
+                       'limit' => [
+                               'type' => 'hidden',
+                               'default' => $this->mLimit,
+                               'name' => 'limit',
+                       ],
+                       'offset' => [
+                               'type' => 'hidden',
+                               'default' => $this->getRequest()->getText( 'offset' ),
+                               'name' => 'offset',
+                       ],
+               ];
+
+               if ( $this->getConfig()->get( 'MiserMode' ) ) {
+                       unset( $fields['like'] );
+               }
+
+               if ( !$this->getUser()->useFilePatrol() ) {
+                       unset( $fields['hidepatrolled'] );
+               }
+
+               $context = new DerivativeContext( $this->getContext() );
+               $context->setTitle( $this->getTitle() ); // Remove subpage
+               $form = new HTMLForm( $fields, $context );
+
+               $form->setSubmitTextMsg( 'ilsubmit' );
+               $form->setSubmitProgressive();
+
+               $form->setMethod( 'get' );
+               $form->setWrapperLegendMsg( 'newimages-legend' );
+
+               return $form;
+       }
 }