From 317345b0df82461cae98b72643a5443932117a86 Mon Sep 17 00:00:00 2001 From: Florianschmidtwelzow Date: Sat, 4 Oct 2014 16:35:54 +0200 Subject: [PATCH] SpecialNewpages: Prepare for mw-ui Use HTMLForm instead of self-built table structure, to be prepared for use with MediaWiki UI. Bug: 71446 Change-Id: I5c03dc543b910aab27a26a5a223341be50893cf3 --- includes/AutoLoader.php | 2 + includes/htmlform/HTMLForm.php | 2 + includes/htmlform/HTMLSelectNamespace.php | 18 ++++ includes/htmlform/HTMLTagFilter.php | 15 +++ includes/specials/SpecialNewpages.php | 124 ++++++++++------------ 5 files changed, 92 insertions(+), 69 deletions(-) create mode 100644 includes/htmlform/HTMLSelectNamespace.php create mode 100644 includes/htmlform/HTMLTagFilter.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index cd6a8ca409..6909b8f1ba 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -106,6 +106,8 @@ $wgAutoloadLocalClasses = array( 'HTMLSelectField' => 'includes/htmlform/HTMLSelectField.php', 'HTMLSelectLimitField' => 'includes/htmlform/HTMLSelectLimitField.php', 'HTMLSelectOrOtherField' => 'includes/htmlform/HTMLSelectOrOtherField.php', + 'HTMLSelectNamespace' => 'includes/htmlform/HTMLSelectNamespace.php', + 'HTMLTagFilter' => 'includes/htmlform/HTMLTagFilter.php', 'HTMLSubmitField' => 'includes/htmlform/HTMLSubmitField.php', 'HTMLTextAreaField' => 'includes/htmlform/HTMLTextAreaField.php', 'HTMLTextField' => 'includes/htmlform/HTMLTextField.php', diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index 4511046ff4..62345b8cd4 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -115,6 +115,8 @@ class HTMLForm extends ContextSource { 'info' => 'HTMLInfoField', 'selectorother' => 'HTMLSelectOrOtherField', 'selectandother' => 'HTMLSelectAndOtherField', + 'namespaceselect' => 'HTMLSelectNamespace', + 'tagfilter' => 'HTMLTagFilter', 'submit' => 'HTMLSubmitField', 'hidden' => 'HTMLHiddenField', 'edittools' => 'HTMLEditTools', diff --git a/includes/htmlform/HTMLSelectNamespace.php b/includes/htmlform/HTMLSelectNamespace.php new file mode 100644 index 0000000000..96381062df --- /dev/null +++ b/includes/htmlform/HTMLSelectNamespace.php @@ -0,0 +1,18 @@ + $value, + 'all' => 'all' + ), array( + 'name' => $this->mName, + 'id' => $this->mID, + 'class' => 'namespaceselector', + ) + ); + } +} diff --git a/includes/htmlform/HTMLTagFilter.php b/includes/htmlform/HTMLTagFilter.php new file mode 100644 index 0000000000..da5e85c77a --- /dev/null +++ b/includes/htmlform/HTMLTagFilter.php @@ -0,0 +1,15 @@ +getOutput(); // Consume values $this->opts->consumeValue( 'offset' ); // don't carry offset, DWIW $namespace = $this->opts->consumeValue( 'namespace' ); @@ -216,77 +217,62 @@ class SpecialNewpages extends IncludableSpecialPage { } $hidden = implode( "\n", $hidden ); - $tagFilter = ChangeTags::buildTagFilterSelector( $tagFilterVal ); - if ( $tagFilter ) { - list( $tagFilterLabel, $tagFilterSelector ) = $tagFilter; - } + $form = array( + 'namespace' => array( + 'type' => 'namespaceselect', + 'name' => 'namespace', + 'label-message' => 'namespace', + 'default' => $namespace, + ), + 'nsinvert' => array( + 'type' => 'check', + 'name' => 'nsinvert', + 'label-message' => 'invert', + 'default' => $nsinvert, + 'tooltip' => $this->msg( 'tooltip-invert' )->text(), + ), + 'tagFilter' => array( + 'type' => 'tagfilter', + 'name' => 'tagfilter', + 'label-raw' => wfMessage( 'tag-filter' )->parse(), + 'default' => $tagFilterVal, + ), + 'username' => array( + 'type' => 'text', + 'name' => 'username', + 'label-message' => 'newpages-username', + 'default' => $userText, + 'id' => 'mw-np-username', + 'size' => 30, + 'cssclass' => 'mw-autocomplete-user', // used by mediawiki.userSuggest + ), + ); + + $htmlForm = new HTMLForm( $form, $this->getContext() ); + + $htmlForm->setSubmitText( $this->msg( 'allpagessubmit' )->text() ); + $htmlForm->setSubmitProgressive(); + // The form should be visible on each request (inclusive requests with submitted forms), so + // return always false here. + $htmlForm->setSubmitCallback( + function() { + return false; + } + ); + $htmlForm->setMethod( 'get' ); + + $out->addHtml( Xml::fieldset( $this->msg( 'newpages' )->text() ) ); - $this->getOutput()->addModules( 'mediawiki.userSuggest' ); - - $form = Xml::openElement( 'form', array( 'action' => wfScript() ) ) . - Html::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) . - Xml::fieldset( $this->msg( 'newpages' )->text() ) . - Xml::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) . - ' - ' . - Xml::label( $this->msg( 'namespace' )->text(), 'namespace' ) . - ' - ' . - Html::namespaceSelector( - array( - 'selected' => $namespace, - 'all' => 'all', - ), array( - 'name' => 'namespace', - 'id' => 'namespace', - 'class' => 'namespaceselector', - ) - ) . ' ' . - Xml::checkLabel( - $this->msg( 'invert' )->text(), - 'invert', - 'nsinvert', - $nsinvert, - array( 'title' => $this->msg( 'tooltip-invert' )->text() ) + $htmlForm->show(); + + $out->addHtml( + Html::rawElement( + 'div', + null, + $this->filterLinks() ) . - ' - ' . ( $tagFilter ? ( - ' - ' . - $tagFilterLabel . - ' - ' . - $tagFilterSelector . - ' - ' ) : '' ) . - ' - ' . - Xml::label( $this->msg( 'newpages-username' )->text(), 'mw-np-username' ) . - ' - ' . - Xml::input( 'username', 30, $userText, array( - 'id' => 'mw-np-username', - 'class' => 'mw-autocomplete-user', // used by mediawiki.userSuggest - ) ) . - ' - ' . - ' - ' . - Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . - ' - ' . - ' - - ' . - $this->filterLinks() . - ' - ' . - Xml::closeElement( 'table' ) . - Xml::closeElement( 'fieldset' ) . - $hidden . - Xml::closeElement( 'form' ); - - $this->getOutput()->addHTML( $form ); + Xml::closeElement( 'fieldset' ) + ); } /** -- 2.20.1