From 58f17c71e12ebba9592fb1ce6bfc2a8a810dd3f9 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Sat, 16 Dec 2006 19:20:44 +0000 Subject: [PATCH] * (bug 8164) Special:Booksources should use GET for form submission * Rewrite Special:Booksources to clean up interface and remove redundant code --- RELEASE-NOTES | 2 + includes/AutoLoader.php | 2 +- includes/SpecialBooksources.php | 182 +++++++++++++++--------------- includes/SpecialPage.php | 2 +- languages/messages/MessagesEn.php | 10 +- 5 files changed, 102 insertions(+), 96 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 76a1e85d64..292635838e 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -324,6 +324,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN MediaWiki:Sitenotice and MediaWiki:Anonnotice. * (bug 8044) When redirecting from the canonical name of the special page to the localised one, parameters/subpages are omitted +* (bug 8164) Special:Booksources should use GET for form submission +* Rewrite Special:Booksources to clean up interface and remove redundant code == Languages updated == diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 041df096c4..8de5608f06 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -158,7 +158,7 @@ function __autoload($className) { 'SpecialAllpages' => 'includes/SpecialAllpages.php', 'AncientPagesPage' => 'includes/SpecialAncientpages.php', 'IPBlockForm' => 'includes/SpecialBlockip.php', - 'BookSourceList' => 'includes/SpecialBooksources.php', + 'SpecialBookSources' => 'includes/SpecialBooksources.php', 'BrokenRedirectsPage' => 'includes/SpecialBrokenRedirects.php', 'CategoriesPage' => 'includes/SpecialCategories.php', 'EmailConfirmation' => 'includes/SpecialConfirmemail.php', diff --git a/includes/SpecialBooksources.php b/includes/SpecialBooksources.php index 40b5a10ba3..85b34cadcf 100644 --- a/includes/SpecialBooksources.php +++ b/includes/SpecialBooksources.php @@ -1,107 +1,107 @@ getVal( 'isbn' ); - } - $isbn = preg_replace( '/[^0-9X]/', '', $isbn ); - - $bsl = new BookSourceList( $isbn ); - $bsl->show(); -} /** + * 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 * * @package MediaWiki - * @subpackage SpecialPage + * @subpackage Special pages + * @author Rob Church + * @todo Validate ISBNs using the standard check-digit method */ -class BookSourceList { - var $mIsbn; +class SpecialBookSources extends SpecialPage { - function BookSourceList( $isbn ) { - $this->mIsbn = $isbn; + /** + * ISBN passed to the page, if any + */ + private $isbn = ''; + + /** + * Constructor + */ + public function __construct() { + parent::__construct( 'Booksources' ); } - - function show() { - global $wgOut; - - $wgOut->setPagetitle( wfMsg( "booksources" ) ); - if( $this->mIsbn == '' ) { - $this->askForm(); - } else { - $this->showList(); - } + + /** + * Show the special page + * + * @param $isbn ISBN passed as a subpage parameter + */ + public function execute( $isbn = false ) { + global $wgOut, $wgRequest; + $this->setHeaders(); + $this->isbn = $this->cleanIsbn( $isbn ? $isbn : $wgRequest->getText( 'isbn' ) ); + $wgOut->addHtml( $this->makeForm() ); + if( strlen( $this->isbn) > 0 ) + $wgOut->addHtml( $this->makeList() ); } - - function showList() { + + /** + * Trim ISBN and remove characters which aren't required + * + * @param $isbn Unclean ISBN + * @return string + */ + private function cleanIsbn( $isbn ) { + return trim( preg_replace( '![^0-9X]!', '', $isbn ) ); + } + + /** + * Generate a form to allow users to enter an ISBN + * + * @return string + */ + private function makeForm() { + global $wgScript; + $title = self::getTitleFor( 'Booksources' ); + $form = '
' . wfMsgHtml( 'booksources-search-legend' ) . ''; + $form .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); + $form .= Xml::hidden( 'title', $title->getPrefixedText() ); + $form .= '

' . Xml::inputLabel( wfMsg( 'booksources-isbn' ), 'isbn', 'isbn', false, $this->isbn ); + $form .= ' ' . Xml::submitButton( wfMsg( 'booksources-go' ) ) . '

'; + $form .= '
'; + $form .= Xml::closeElement( 'form' ); + return $form; + } + + /** + * Generate the list of book sources + * + * @return string + */ + private function makeList() { global $wgOut, $wgContLang; - - # First, see if we have a custom list setup in - # [[Wikipedia:Book sources]] or equivalent. - $bstitle = Title::makeTitleSafe( NS_PROJECT, wfMsg( "booksources" ) ); - if( $bstitle ) { - $revision = Revision::newFromTitle( $bstitle ); - if( $revision ) { - $bstext = $revision->getText(); - if( $bstext ) { - $bstext = str_replace( "MAGICNUMBER", $this->mIsbn, $bstext ); - $wgOut->addWikiText( $bstext ); - return; - } - } + + # Check for a local page such as Project:Book_sources and use that if available + $title = Title::makeTitleSafe( NS_PROJECT, wfMsg( 'booksources' ) ); # Should this be wfMsgForContent()? -- RC + if( is_object( $title ) && $title->exists() ) { + $rev = Revision::newFromTitle( $title ); + return $wgOut->parse( str_replace( 'MAGICNUMBER', $this->isbn, $rev->getText() ) ); } - - # Otherwise, use the list of links in the default Language.php file. - $s = wfMsgWikiHtml( 'booksourcetext' ) . "\n"; - - $wgOut->addHTML( $s ); + + # Fall back to the defaults given in the language file + $html = $wgOut->parse( wfMsg( 'booksources-text' ) ); + $html .= ''; + return $html; } - - function askForm() { - global $wgOut, $wgTitle; - - $action = $wgTitle->escapeLocalUrl(); - $isbn = htmlspecialchars( wfMsg( "isbn" ) ); - $go = htmlspecialchars( wfMsg( "go" ) ); - $out = "
- $isbn: - -
"; - $wgOut->addHTML( $out ); + + /** + * Format a book source list item + * + * @param $label Book source label + * @param $url Book source URL + * @return string + */ + private function makeListItem( $label, $url ) { + $url = str_replace( '$1', $this->isbn, $url ); + return '
  • ' . htmlspecialchars( $label ) . '
  • '; } + } ?> diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 50a8ae64cd..86438756cf 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -120,7 +120,7 @@ class SpecialPage 'Movepage' => array( 'UnlistedSpecialPage', 'Movepage' ), 'Blockme' => array( 'UnlistedSpecialPage', 'Blockme' ), 'Resetpass' => array( 'UnlistedSpecialPage', 'Resetpass' ), - 'Booksources' => array( 'SpecialPage', 'Booksources' ), + 'Booksources' => 'SpecialBookSources', 'Categories' => array( 'SpecialPage', 'Categories' ), 'Export' => array( 'SpecialPage', 'Export' ), 'Version' => array( 'SpecialPage', 'Version' ), diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 822f03a5b5..79185c945c 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1515,17 +1515,21 @@ a direct URL, and so may still be listed here despite being in active use.

    ', 'unusedcategoriestext' => 'The following category pages exist although no other article or category make use of them.', +# Book sources 'booksources' => 'Book sources', 'booksources-summary' => '', +'booksources-search-legend' => 'Search for book sources', +'booksources-isbn' => 'ISBN:', +'booksources-go' => 'Go', +'booksources-text' => 'Below is a list of links to other sites that sell new and used books, and may also have +further information about books you are looking for:', + 'categoriespagetext' => 'The following categories exist in the wiki.', 'data' => 'Data', 'userrights' => 'User rights management', 'userrights-summary' => '', 'groups' => 'User groups', -'booksourcetext' => "Below is a list of links to other sites that -sell new and used books, and may also have further information -about books you are looking for.", 'isbn' => 'ISBN', 'rfcurl' => 'http://www.ietf.org/rfc/rfc$1.txt', 'pubmedurl' => 'http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=pubmed&dopt=Abstract&list_uids=$1', -- 2.20.1