Merge "Convert Special:DeletedContributions to use OOUI."
[lhc/web/wiklou.git] / includes / specials / SpecialDeletedContributions.php
index d625f82..2936754 100644 (file)
  * @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' );
 
@@ -135,7 +133,7 @@ class DeletedContributionsPage extends SpecialPage {
                if ( $userObj->isAnon() ) {
                        $user = htmlspecialchars( $userObj->getName() );
                } else {
-                       $user = $linkRenderer->makeKnownLink( $userObj->getUserPage(), $userObj->getName() );
+                       $user = $linkRenderer->makeLink( $userObj->getUserPage(), $userObj->getName() );
                }
                $links = '';
                $nt = $userObj->getUserPage();
@@ -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 );
        }
 
        /**