From 179e2f892d7811fa5613e1d6e0d5626e52c93b31 Mon Sep 17 00:00:00 2001 From: Sethakill Date: Wed, 18 May 2016 22:27:08 +0200 Subject: [PATCH] Convert Special:NewFiles to use OOUI. Other changes: * moved form from pager * added FormOptions Bug: T135680 Change-Id: I1d9c0a761fd3d71fe58c2621c9766c2c6dd39dcb --- includes/specials/SpecialNewimages.php | 62 +++++++++++++++-- includes/specials/pagers/NewFilesPager.php | 80 ++++------------------ 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/includes/specials/SpecialNewimages.php b/includes/specials/SpecialNewimages.php index 14391d2459..7d0f879b3e 100644 --- a/includes/specials/SpecialNewimages.php +++ b/includes/specials/SpecialNewimages.php @@ -33,21 +33,73 @@ class SpecialNewFiles extends IncludableSpecialPage { $out = $this->getOutput(); $this->addHelpLink( 'Help:New images' ); - $pager = new NewFilesPager( $this->getContext(), $par ); + $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; if ( !$this->including() ) { - $this->setTopText(); - $form = $pager->getForm(); - $form->prepareForm(); - $form->displayForm( '' ); + $this->buildForm(); } + $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'; } diff --git a/includes/specials/pagers/NewFilesPager.php b/includes/specials/pagers/NewFilesPager.php index ae5773617c..d1f9f40720 100644 --- a/includes/specials/pagers/NewFilesPager.php +++ b/includes/specials/pagers/NewFilesPager.php @@ -30,33 +30,30 @@ class NewFilesPager extends ReverseChronologicalPager { protected $gallery; /** - * @var bool + * @var FormOptions */ - protected $showBots; + protected $opts; /** - * @var bool + * @param IContextSource $context + * @param FormOptions $opts */ - 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 ); - } + function __construct( IContextSource $context, FormOptions $opts ) { + $this->opts = $opts; + + $this->setLimit( $opts->getValue( 'limit' ) ); parent::__construct( $context ); } function getQueryInfo() { + $opts = $this->opts; $conds = $jconds = []; $tables = [ 'image' ]; $fields = [ 'img_name', 'img_user', 'img_timestamp' ]; $options = []; - if ( !$this->showBots ) { + if ( !$opts->getValue( 'showbots' ) ) { $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' ); if ( count( $groupsWithBotPermission ) ) { @@ -72,7 +69,7 @@ class NewFilesPager extends ReverseChronologicalPager { } } - if ( $this->hidePatrolled ) { + if ( $opts->getValue( 'hidepatrolled' ) ) { $tables[] = 'recentchanges'; $conds['rc_type'] = RC_LOG; $conds['rc_log_type'] = 'upload'; @@ -92,9 +89,10 @@ class NewFilesPager extends ReverseChronologicalPager { $options[] = 'STRAIGHT_JOIN'; } - if ( !$this->getConfig()->get( 'MiserMode' ) && $this->like !== null ) { + $likeVal = $opts->getValue( 'like' ); + if ( !$this->getConfig()->get( 'MiserMode' ) && $likeVal !== '' ) { $dbr = wfGetDB( DB_SLAVE ); - $likeObj = Title::newFromText( $this->like ); + $likeObj = Title::newFromText( $likeVal ); if ( $likeObj instanceof Title ) { $like = $dbr->buildLike( $dbr->anyString(), @@ -154,54 +152,4 @@ class NewFilesPager extends ReverseChronologicalPager { . "
\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; - } } -- 2.20.1