From: Glaisher Date: Wed, 28 Oct 2015 12:29:45 +0000 (+0500) Subject: Use HTMLForm in Special:AllPages X-Git-Tag: 1.31.0-rc.0~9055^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=731654cf413621e47802c3d6e7737b1f9e6db6dd Use HTMLForm in Special:AllPages Renamed namespaceForm to outputHTMLForm and make it protected Also made sure that this is the only place where it's used https://github.com/search?q=namespaceForm+%40wikimedia&ref=reposearch&type=Code Also make HTMLSelectNamespace's work when 'all' is set to null. Change-Id: Ia559b52464bceaf1202e3a6696728781bb62cdbc --- diff --git a/includes/htmlform/HTMLSelectNamespace.php b/includes/htmlform/HTMLSelectNamespace.php index 4efdfbf306..597c27a337 100644 --- a/includes/htmlform/HTMLSelectNamespace.php +++ b/includes/htmlform/HTMLSelectNamespace.php @@ -5,7 +5,11 @@ class HTMLSelectNamespace extends HTMLFormField { public function __construct( $params ) { parent::__construct( $params ); - $this->mAllValue = isset( $this->mParams['all'] ) ? $this->mParams['all'] : 'all'; + + $this->mAllValue = array_key_exists( 'all', $params ) + ? $params['all'] + : 'all'; + } function getInputHTML( $value ) { diff --git a/includes/specials/SpecialAllPages.php b/includes/specials/SpecialAllPages.php index 0c1a941a9a..2446270085 100644 --- a/includes/specials/SpecialAllPages.php +++ b/includes/specials/SpecialAllPages.php @@ -71,7 +71,7 @@ class SpecialAllPages extends IncludableSpecialPage { $namespace = $request->getInt( 'namespace' ); $hideredirects = $request->getBool( 'hideredirects', false ); - $namespaces = $this->getContext()->getLanguage()->getNamespaces(); + $namespaces = $this->getLanguage()->getNamespaces(); $out->setPageTitle( ( $namespace > 0 && array_key_exists( $namespace, $namespaces ) ) ? @@ -90,64 +90,55 @@ class SpecialAllPages extends IncludableSpecialPage { } /** - * HTML for the top form + * Outputs the HTMLForm used on this page * * @param int $namespace A namespace constant (default NS_MAIN). * @param string $from DbKey we are starting listing at. * @param string $to DbKey we are ending listing at. - * @param bool $hideredirects Dont show redirects (default false) - * @return string + * @param bool $hideRedirects Dont show redirects (default false) */ - function namespaceForm( $namespace = NS_MAIN, $from = '', $to = '', $hideredirects = false ) { - $t = $this->getPageTitle(); - $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) ); - $out .= Xml::openElement( - 'form', - array( 'method' => 'get', 'action' => $this->getConfig()->get( 'Script' ) ) + protected function outputHTMLForm( $namespace = NS_MAIN, + $from = '', $to = '', $hideRedirects = false + ) { + $fields = array( + 'from' => array( + 'type' => 'text', + 'name' => 'from', + 'id' => 'nsfrom', + 'size' => 30, + 'label-message' => 'allpagesfrom', + 'default' => str_replace( '_', ' ', $from ), + ), + 'to' => array( + 'type' => 'text', + 'name' => 'to', + 'id' => 'nsto', + 'size' => 30, + 'label-message' => 'allpagesto', + 'default' => str_replace( '_', ' ', $to ), + ), + 'namespace' => array( + 'type' => 'namespaceselect', + 'name' => 'namespace', + 'id' => 'namespace', + 'label-message' => 'namespace', + 'all' => null, + 'value' => $namespace, + ), + 'hideredirects' => array( + 'type' => 'check', + 'name' => 'hideredirects', + 'id' => 'hidredirects', + 'label-message' => 'allpages-hide-redirects', + 'value' => $hideRedirects, + ), ); - $out .= Html::hidden( 'title', $t->getPrefixedText() ); - $out .= Xml::openElement( 'fieldset' ); - $out .= Xml::element( 'legend', null, $this->msg( 'allpages' )->text() ); - $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) ); - $out .= " - " . - Xml::label( $this->msg( 'allpagesfrom' )->text(), 'nsfrom' ) . - " - " . - Xml::input( 'from', 30, str_replace( '_', ' ', $from ), array( 'id' => 'nsfrom' ) ) . - " - - - " . - Xml::label( $this->msg( 'allpagesto' )->text(), 'nsto' ) . - " - " . - Xml::input( 'to', 30, str_replace( '_', ' ', $to ), array( 'id' => 'nsto' ) ) . - " - - - " . - Xml::label( $this->msg( 'namespace' )->text(), 'namespace' ) . - " - " . - Html::namespaceSelector( - array( 'selected' => $namespace ), - array( 'name' => 'namespace', 'id' => 'namespace' ) - ) . ' ' . - Xml::checkLabel( - $this->msg( 'allpages-hide-redirects' )->text(), - 'hideredirects', - 'hideredirects', - $hideredirects - ) . ' ' . - Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . - " -"; - $out .= Xml::closeElement( 'table' ); - $out .= Xml::closeElement( 'fieldset' ); - $out .= Xml::closeElement( 'form' ); - $out .= Xml::closeElement( 'div' ); - return $out; + $form = HTMLForm::factory( 'table', $fields, $this->getContext() ); + $form->setMethod( 'get' ) + ->setWrapperLegendMsg( 'allpages' ) + ->setSubmitTextMsg( 'allpagessubmit' ) + ->prepareForm() + ->displayForm( false ); } /** @@ -317,7 +308,7 @@ class SpecialAllPages extends IncludableSpecialPage { ); } - $topOut = $this->namespaceForm( $namespace, $from, $to, $hideredirects ); + $this->outputHTMLForm( $namespace, $from, $to, $hideredirects ); if ( count( $navLinks ) ) { // Add pagination links @@ -326,11 +317,11 @@ class SpecialAllPages extends IncludableSpecialPage { $this->getLanguage()->pipeList( $navLinks ) ); - $topOut .= $pagination; + $output->addHTML( $pagination ); $out .= Html::element( 'hr' ) . $pagination; // Footer } - $output->addHTML( $topOut . $out ); + $output->addHTML( $out ); } /**