X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fspecials%2FSpecialBooksources.php;h=c187156beeb27ac078d939313ca6774b3cc52126;hp=11faa2803dc9248393358d740c855cf7a536eb5c;hb=4cebf80a894f1bc9f9e2f732c8b78d5237810343;hpb=20b4f9d311ba743b88e277907293e5f8f2bb6ee1 diff --git a/includes/specials/SpecialBooksources.php b/includes/specials/SpecialBooksources.php index 11faa2803d..ea9ddafed1 100644 --- a/includes/specials/SpecialBooksources.php +++ b/includes/specials/SpecialBooksources.php @@ -21,6 +21,8 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; + /** * Special page outputs information on sourcing a book with a particular ISBN * The parser creates links to this page when dealing with ISBNs in wikitext @@ -29,19 +31,12 @@ * @ingroup SpecialPage */ class SpecialBookSources extends SpecialPage { - /** - * ISBN passed to the page, if any - */ - protected $isbn = ''; - public function __construct() { parent::__construct( 'Booksources' ); } /** - * Show the special page - * - * @param string $isbn ISBN passed as a subpage parameter + * @param string|null $isbn ISBN passed as a subpage parameter */ public function execute( $isbn ) { $out = $this->getOutput(); @@ -49,19 +44,21 @@ class SpecialBookSources extends SpecialPage { $this->setHeaders(); $this->outputHeader(); - $this->isbn = self::cleanIsbn( $isbn ?: $this->getRequest()->getText( 'isbn' ) ); + // User provided ISBN + $isbn = $isbn ?: $this->getRequest()->getText( 'isbn' ); + $isbn = trim( $isbn ); - $this->buildForm(); + $this->buildForm( $isbn ); - if ( $this->isbn !== '' ) { - if ( !self::isValidISBN( $this->isbn ) ) { + if ( $isbn !== '' ) { + if ( !self::isValidISBN( $isbn ) ) { $out->wrapWikiMsg( "
\n$1\n
", 'booksources-invalid-isbn' ); } - $this->showList(); + $this->showList( $isbn ); } } @@ -121,20 +118,24 @@ class SpecialBookSources extends SpecialPage { /** * Generate a form to allow users to enter an ISBN + * + * @param string $isbn */ - private function buildForm() { + private function buildForm( $isbn ) { $formDescriptor = [ 'isbn' => [ 'type' => 'text', 'name' => 'isbn', 'label-message' => 'booksources-isbn', - 'default' => $this->isbn, + 'default' => $isbn, 'autofocus' => true, 'required' => true, ], ]; - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) + $context = new DerivativeContext( $this->getContext() ); + $context->setTitle( $this->getPageTitle() ); + HTMLForm::factory( 'ooui', $formDescriptor, $context ) ->setWrapperLegendMsg( 'booksources-search-legend' ) ->setSubmitTextMsg( 'booksources-search' ) ->setMethod( 'get' ) @@ -146,17 +147,17 @@ class SpecialBookSources extends SpecialPage { * 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, $out ] ); + 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(); @@ -168,8 +169,8 @@ class SpecialBookSources extends SpecialPage { if ( $content instanceof TextContent ) { // XXX: in the future, this could be stored as structured data, defining a list of book sources - $text = $content->getNativeData(); - $out->addWikiText( str_replace( 'MAGICNUMBER', $this->isbn, $text ) ); + $text = $content->getText(); + $out->addWikiTextAsInterface( str_replace( 'MAGICNUMBER', $isbn, $text ) ); return true; } else { @@ -180,9 +181,9 @@ class SpecialBookSources extends SpecialPage { # Fall back to the defaults given in the language file $out->addWikiMsg( 'booksources-text' ); $out->addHTML( '' ); @@ -192,12 +193,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 )