From: jenkins-bot Date: Tue, 6 Dec 2016 18:14:41 +0000 (+0000) Subject: Merge "Convert Special:DeletedContributions to use OOUI." X-Git-Tag: 1.31.0-rc.0~4663 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=e758226c91935a1df2b6fd3ed1f18922d8bfb45b;hp=6730ddee23120973e5d0d42bd5c666fc1c964acd Merge "Convert Special:DeletedContributions to use OOUI." --- diff --git a/includes/specials/SpecialDeletedContributions.php b/includes/specials/SpecialDeletedContributions.php index ad1204638c..2936754988 100644 --- a/includes/specials/SpecialDeletedContributions.php +++ b/includes/specials/SpecialDeletedContributions.php @@ -26,9 +26,11 @@ * @ingroup SpecialPage */ class DeletedContributionsPage extends SpecialPage { + /** @var FormOptions */ + protected $mOpts; + function __construct() { - parent::__construct( 'DeletedContributions', 'deletedhistory', - /*listed*/true, /*function*/false, /*file*/false ); + parent::__construct( 'DeletedContributions', 'deletedhistory' ); } /** @@ -40,40 +42,43 @@ class DeletedContributionsPage extends SpecialPage { function execute( $par ) { $this->setHeaders(); $this->outputHeader(); + $this->checkPermissions(); $user = $this->getUser(); - if ( !$this->userCanExecute( $user ) ) { - $this->displayRestrictionError(); - - return; - } - - $request = $this->getRequest(); $out = $this->getOutput(); $out->setPageTitle( $this->msg( 'deletedcontributions-title' ) ); - $options = []; + $opts = new FormOptions(); + + $opts->add( 'target', '' ); + $opts->add( 'namespace', '' ); + $opts->add( 'limit', 20 ); + + $opts->fetchValuesFromRequest( $this->getRequest() ); + $opts->validateIntBounds( 'limit', 0, $this->getConfig()->get( 'QueryPageDefaultLimit' ) ); if ( $par !== null ) { - $target = $par; - } else { - $target = $request->getVal( 'target' ); + $opts->setValue( 'target', $par ); } + $ns = $opts->getValue( 'namespace' ); + if ( $ns !== null && $ns !== '' ) { + $opts->setValue( 'namespace', intval( $ns ) ); + } + + $this->mOpts = $opts; + + $target = $opts->getValue( 'target' ); if ( !strlen( $target ) ) { - $out->addHTML( $this->getForm( '' ) ); + $this->getForm(); return; } - $options['limit'] = $request->getInt( 'limit', - $this->getConfig()->get( 'QueryPageDefaultLimit' ) ); - $options['target'] = $target; - $userObj = User::newFromName( $target, false ); if ( !$userObj ) { - $out->addHTML( $this->getForm( '' ) ); + $this->getForm(); return; } @@ -82,16 +87,9 @@ class DeletedContributionsPage extends SpecialPage { $target = $userObj->getName(); $out->addSubtitle( $this->getSubTitle( $userObj ) ); - $ns = $request->getVal( 'namespace', null ); - if ( $ns !== null && $ns !== '' ) { - $options['namespace'] = intval( $ns ); - } else { - $options['namespace'] = ''; - } - - $out->addHTML( $this->getForm( $options ) ); + $this->getForm(); - $pager = new DeletedContribsPager( $this->getContext(), $target, $options['namespace'] ); + $pager = new DeletedContribsPager( $this->getContext(), $target, $opts->getValue( 'namespace' ) ); if ( !$pager->getNumRows() ) { $out->addWikiMsg( 'nocontribs' ); @@ -187,76 +185,35 @@ class DeletedContributionsPage extends SpecialPage { /** * Generates the namespace selector form with hidden attributes. - * @param array $options The options to be included. - * @return string */ - function getForm( $options ) { - $options['title'] = $this->getPageTitle()->getPrefixedText(); - if ( !isset( $options['target'] ) ) { - $options['target'] = ''; - } else { - $options['target'] = str_replace( '_', ' ', $options['target'] ); - } - - if ( !isset( $options['namespace'] ) ) { - $options['namespace'] = ''; - } - - if ( !isset( $options['contribs'] ) ) { - $options['contribs'] = 'user'; - } - - if ( $options['contribs'] == 'newbie' ) { - $options['target'] = ''; - } - - $f = Xml::openElement( 'form', [ 'method' => 'get', 'action' => wfScript() ] ); - - foreach ( $options as $name => $value ) { - if ( in_array( $name, [ 'namespace', 'target', 'contribs' ] ) ) { - continue; - } - $f .= "\t" . Html::hidden( $name, $value ) . "\n"; - } + function getForm() { + $opts = $this->mOpts; + + $formDescriptor = [ + 'target' => [ + 'type' => 'user', + 'name' => 'target', + 'label-message' => 'sp-contributions-username', + 'default' => $opts->getValue( 'target' ), + 'ipallowed' => true, + ], - $this->getOutput()->addModules( 'mediawiki.userSuggest' ); - - $f .= Xml::openElement( 'fieldset' ); - $f .= Xml::element( 'legend', [], $this->msg( 'sp-contributions-search' )->text() ); - $f .= Xml::tags( - 'label', - [ 'for' => 'target' ], - $this->msg( 'sp-contributions-username' )->parse() - ) . ' '; - $f .= Html::input( - 'target', - $options['target'], - 'text', - [ - 'size' => '20', - 'required' => '', - 'class' => [ - 'mw-autocomplete-user', // used by mediawiki.userSuggest - ], - ] + ( $options['target'] ? [] : [ 'autofocus' ] ) - ) . ' '; - $f .= Html::namespaceSelector( - [ - 'selected' => $options['namespace'], + 'namespace' => [ + 'type' => 'namespaceselect', + 'name' => 'namespace', + 'label-message' => 'namespace', 'all' => '', - 'label' => $this->msg( 'namespace' )->text() ], - [ - 'name' => 'namespace', - 'id' => 'namespace', - 'class' => 'namespaceselector', - ] - ) . ' '; - $f .= Xml::submitButton( $this->msg( 'sp-contributions-submit' )->text() ); - $f .= Xml::closeElement( 'fieldset' ); - $f .= Xml::closeElement( 'form' ); - - return $f; + ]; + + $form = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) + ->setWrapperLegendMsg( 'sp-contributions-search' ) + ->setSubmitTextMsg( 'sp-contributions-submit' ) + // prevent setting subpage and 'target' parameter at the same time + ->setAction( $this->getPageTitle()->getLocalURL() ) + ->setMethod( 'get' ) + ->prepareForm() + ->displayForm( false ); } /**