X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialBooksources.php;h=72e0b888feb151a2e84249cbe65a53f3baf9139e;hb=edf7224639b6f45c0e6762a664cfb2e84beb8e0a;hp=fe90a4f90c5c1a37c9b48254aa4f26f5dbf2a58a;hpb=9fe2ba22f722a7e335f912a4db3c06b4613ba58a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialBooksources.php b/includes/specials/SpecialBooksources.php index fe90a4f90c..72e0b888fe 100644 --- a/includes/specials/SpecialBooksources.php +++ b/includes/specials/SpecialBooksources.php @@ -29,11 +29,6 @@ * @ingroup SpecialPage */ class SpecialBookSources extends SpecialPage { - /** - * ISBN passed to the page, if any - */ - private $isbn = ''; - public function __construct() { parent::__construct( 'Booksources' ); } @@ -44,18 +39,26 @@ class SpecialBookSources extends SpecialPage { * @param string $isbn ISBN passed as a subpage parameter */ public function execute( $isbn ) { + $out = $this->getOutput(); + $this->setHeaders(); $this->outputHeader(); - $this->isbn = self::cleanIsbn( $isbn ?: $this->getRequest()->getText( 'isbn' ) ); - $this->getOutput()->addHTML( $this->makeForm() ); - if ( $this->isbn !== '' ) { - if ( !self::isValidISBN( $this->isbn ) ) { - $this->getOutput()->wrapWikiMsg( + + // User provided ISBN + $isbn = $isbn ?: $this->getRequest()->getText( 'isbn' ); + $isbn = trim( $isbn ); + + $this->buildForm( $isbn ); + + if ( $isbn !== '' ) { + if ( !self::isValidISBN( $isbn ) ) { + $out->wrapWikiMsg( "
\n$1\n
", 'booksources-invalid-isbn' ); } - $this->showList(); + + $this->showList( $isbn ); } } @@ -116,50 +119,47 @@ class SpecialBookSources extends SpecialPage { /** * Generate a form to allow users to enter an ISBN * - * @return string + * @param string $isbn */ - private function makeForm() { - $form = Html::openElement( 'fieldset' ) . "\n"; - $form .= Html::element( - 'legend', - [], - $this->msg( 'booksources-search-legend' )->text() - ) . "\n"; - $form .= Html::openElement( 'form', [ 'method' => 'get', 'action' => wfScript() ] ) . "\n"; - $form .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ) . "\n"; - $form .= '

' . Xml::inputLabel( - $this->msg( 'booksources-isbn' )->text(), - 'isbn', - 'isbn', - 20, - $this->isbn, - [ 'autofocus' => '', 'class' => 'mw-ui-input-inline' ] - ); - - $form .= ' ' . Html::submitButton( - $this->msg( 'booksources-search' )->text(), - [], [ 'mw-ui-progressive' ] - ) . "

\n"; - - $form .= Html::closeElement( 'form' ) . "\n"; - $form .= Html::closeElement( 'fieldset' ) . "\n"; - - return $form; + private function buildForm( $isbn ) { + $formDescriptor = [ + 'isbn' => [ + 'type' => 'text', + 'name' => 'isbn', + 'label-message' => 'booksources-isbn', + 'default' => $isbn, + 'autofocus' => true, + 'required' => true, + ], + ]; + + $context = new DerivativeContext( $this->getContext() ); + $context->setTitle( $this->getPageTitle() ); + HTMLForm::factory( 'ooui', $formDescriptor, $context ) + ->setWrapperLegendMsg( 'booksources-search-legend' ) + ->setSubmitTextMsg( 'booksources-search' ) + ->setMethod( 'get' ) + ->prepareForm() + ->displayForm( false ); } /** * Determine where to get the list of book sources from, * format and output them * + * @param string $isbn * @throws MWException * @return bool */ - private function showList() { + private function showList( $isbn ) { + $out = $this->getOutput(); + global $wgContLang; + $isbn = self::cleanIsbn( $isbn ); # Hook to allow extensions to insert additional HTML, # e.g. for API-interacting plugins and so on - Hooks::run( 'BookInformation', [ $this->isbn, $this->getOutput() ] ); + Hooks::run( 'BookInformation', [ $isbn, $out ] ); # Check for a local page such as Project:Book_sources and use that if available $page = $this->msg( 'booksources' )->inContentLanguage()->text(); @@ -172,7 +172,7 @@ class SpecialBookSources extends SpecialPage { // XXX: in the future, this could be stored as structured data, defining a list of book sources $text = $content->getNativeData(); - $this->getOutput()->addWikiText( str_replace( 'MAGICNUMBER', $this->isbn, $text ) ); + $out->addWikiText( str_replace( 'MAGICNUMBER', $isbn, $text ) ); return true; } else { @@ -181,13 +181,13 @@ class SpecialBookSources extends SpecialPage { } # Fall back to the defaults given in the language file - $this->getOutput()->addWikiMsg( 'booksources-text' ); - $this->getOutput()->addHTML( '' ); return true; } @@ -195,12 +195,13 @@ class SpecialBookSources extends SpecialPage { /** * Format a book source list item * + * @param string $isbn * @param string $label Book source label * @param string $url Book source URL * @return string */ - private function makeListItem( $label, $url ) { - $url = str_replace( '$1', $this->isbn, $url ); + private function makeListItem( $isbn, $label, $url ) { + $url = str_replace( '$1', $isbn, $url ); return Html::rawElement( 'li', [], Html::element( 'a', [ 'href' => $url, 'class' => 'external' ], $label )