* @todo Validate ISBNs using the standard check-digit method * @ingroup SpecialPage */ class SpecialBookSources extends SpecialPage { /** * ISBN passed to the page, if any */ private $isbn = ''; /** * Constructor */ public function __construct() { parent::__construct( 'Booksources' ); } /** * Show the special page * * @param string $isbn ISBN passed as a subpage parameter */ public function execute( $isbn ) { $this->setHeaders(); $this->outputHeader(); $this->isbn = self::cleanIsbn( $isbn ? $isbn : $this->getRequest()->getText( 'isbn' ) ); $this->getOutput()->addHTML( $this->makeForm() ); if ( strlen( $this->isbn ) > 0 ) { if ( !self::isValidISBN( $this->isbn ) ) { $this->getOutput()->wrapWikiMsg( "
' . Xml::inputLabel( $this->msg( 'booksources-isbn' )->text(), 'isbn', 'isbn', 20, $this->isbn, array( 'autofocus' => true ) ); $form .= ' ' . Xml::submitButton( $this->msg( 'booksources-go' )->text() ) . "
\n"; $form .= Html::closeElement( 'form' ) . "\n"; $form .= Html::closeElement( 'fieldset' ) . "\n"; return $form; } /** * Determine where to get the list of book sources from, * format and output them * * @throws MWException * @return string */ private function showList() { global $wgContLang; # Hook to allow extensions to insert additional HTML, # e.g. for API-interacting plugins and so on wfRunHooks( 'BookInformation', array( $this->isbn, $this->getOutput() ) ); # Check for a local page such as Project:Book_sources and use that if available $page = $this->msg( 'booksources' )->inContentLanguage()->text(); $title = Title::makeTitleSafe( NS_PROJECT, $page ); # Show list in content language if ( is_object( $title ) && $title->exists() ) { $rev = Revision::newFromTitle( $title, false, Revision::READ_NORMAL ); $content = $rev->getContent(); if ( $content instanceof TextContent ) { //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 ) ); return true; } else { throw new MWException( "Unexpected content type for book sources: " . $content->getModel() ); } } # Fall back to the defaults given in the language file $this->getOutput()->addWikiMsg( 'booksources-text' ); $this->getOutput()->addHTML( '