2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2006-12-16 19:20:44 +00:00
|
|
|
* 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
|
2004-09-02 23:28:24 +00:00
|
|
|
*
|
Some small doc tweaks to reduce Doxygen warnings, namely:
* @link. You might think @link would surely mean "here comes a web URL" ... but @link is a valid command
in Doxygen, which means an entirely different kind of link (an internal link to somewhere, so that you can separate
documentation and implementation). The result is a mess, and the best solution I can see is to use "@see" instead of "@link".
* Warning: argument `nourl' of command @param is not found in the argument list of Linker::makeMediaLinkObj($title,$text='')
* Moving few class descriptions to right above classes, and/or formatting into Javadoc style.
* "@addtogroup Special Pages" --> "@addtogroup SpecialPage" so that all special pages have the same @addtogroup tag.
* @fixme --> @todo (must have missed these before)
* "@param $specialPage @see" remove the "@" in the "@see" to stop warning.
* @throws wants type, then a brief description, to stop warning.
This last one is for PHPdocumentor only, but it fixes something for PHPDocumentor, and should be neutral for Doxygen:
* WARNING in includes/api/ApiFormatYaml_spyc.php on line 860: docblock template never terminated with /**#@-*/
2007-04-18 09:50:10 +00:00
|
|
|
* @addtogroup SpecialPage
|
2006-12-16 19:20:44 +00:00
|
|
|
* @author Rob Church <robchur@gmail.com>
|
|
|
|
|
* @todo Validate ISBNs using the standard check-digit method
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2006-12-16 19:20:44 +00:00
|
|
|
class SpecialBookSources extends SpecialPage {
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2006-12-16 19:20:44 +00:00
|
|
|
/**
|
|
|
|
|
* ISBN passed to the page, if any
|
|
|
|
|
*/
|
|
|
|
|
private $isbn = '';
|
2007-06-06 09:51:38 +00:00
|
|
|
|
2006-12-16 19:20:44 +00:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*/
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct( 'Booksources' );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2007-06-06 09:51:38 +00:00
|
|
|
|
2006-12-16 19:20:44 +00:00
|
|
|
/**
|
|
|
|
|
* Show the special page
|
|
|
|
|
*
|
|
|
|
|
* @param $isbn ISBN passed as a subpage parameter
|
|
|
|
|
*/
|
2007-05-05 20:31:08 +00:00
|
|
|
public function execute( $isbn ) {
|
2006-12-16 19:20:44 +00:00
|
|
|
global $wgOut, $wgRequest;
|
|
|
|
|
$this->setHeaders();
|
|
|
|
|
$this->isbn = $this->cleanIsbn( $isbn ? $isbn : $wgRequest->getText( 'isbn' ) );
|
2008-02-18 07:25:35 +00:00
|
|
|
$wgOut->addWikiMsg( 'booksources-summary' );
|
2006-12-16 19:20:44 +00:00
|
|
|
$wgOut->addHtml( $this->makeForm() );
|
2007-01-16 19:06:56 +00:00
|
|
|
if( strlen( $this->isbn ) > 0 )
|
2006-12-20 16:51:26 +00:00
|
|
|
$this->showList();
|
2004-04-09 06:27:18 +00:00
|
|
|
}
|
2007-06-06 09:51:38 +00:00
|
|
|
|
2006-12-16 19:20:44 +00:00
|
|
|
/**
|
|
|
|
|
* 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 ) );
|
|
|
|
|
}
|
2007-06-06 09:51:38 +00:00
|
|
|
|
2006-12-16 19:20:44 +00:00
|
|
|
/**
|
|
|
|
|
* Generate a form to allow users to enter an ISBN
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function makeForm() {
|
|
|
|
|
global $wgScript;
|
|
|
|
|
$title = self::getTitleFor( 'Booksources' );
|
|
|
|
|
$form = '<fieldset><legend>' . wfMsgHtml( 'booksources-search-legend' ) . '</legend>';
|
|
|
|
|
$form .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
|
|
|
|
|
$form .= Xml::hidden( 'title', $title->getPrefixedText() );
|
2006-12-19 05:35:35 +00:00
|
|
|
$form .= '<p>' . Xml::inputLabel( wfMsg( 'booksources-isbn' ), 'isbn', 'isbn', 20, $this->isbn );
|
2006-12-16 19:20:44 +00:00
|
|
|
$form .= ' ' . Xml::submitButton( wfMsg( 'booksources-go' ) ) . '</p>';
|
|
|
|
|
$form .= Xml::closeElement( 'form' );
|
2006-12-19 05:35:35 +00:00
|
|
|
$form .= '</fieldset>';
|
2006-12-16 19:20:44 +00:00
|
|
|
return $form;
|
|
|
|
|
}
|
2007-06-06 09:51:38 +00:00
|
|
|
|
2006-12-16 19:20:44 +00:00
|
|
|
/**
|
2006-12-20 16:51:26 +00:00
|
|
|
* Determine where to get the list of book sources from,
|
|
|
|
|
* format and output them
|
2006-12-16 19:20:44 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2006-12-20 16:51:26 +00:00
|
|
|
private function showList() {
|
2007-06-06 11:42:02 +00:00
|
|
|
global $wgOut, $wgContLang;
|
2007-06-06 09:51:38 +00:00
|
|
|
|
2007-01-16 19:06:56 +00:00
|
|
|
# Hook to allow extensions to insert additional HTML,
|
|
|
|
|
# e.g. for API-interacting plugins and so on
|
|
|
|
|
wfRunHooks( 'BookInformation', array( $this->isbn, &$wgOut ) );
|
2007-06-06 09:51:38 +00:00
|
|
|
|
2006-12-16 19:20:44 +00:00
|
|
|
# Check for a local page such as Project:Book_sources and use that if available
|
2007-06-06 11:42:02 +00:00
|
|
|
$title = Title::makeTitleSafe( NS_PROJECT, wfMsgForContent( 'booksources' ) ); # Show list in content language
|
2006-12-16 19:20:44 +00:00
|
|
|
if( is_object( $title ) && $title->exists() ) {
|
|
|
|
|
$rev = Revision::newFromTitle( $title );
|
2006-12-20 16:51:26 +00:00
|
|
|
$wgOut->addWikiText( str_replace( 'MAGICNUMBER', $this->isbn, $rev->getText() ) );
|
|
|
|
|
return true;
|
2004-04-09 06:27:18 +00:00
|
|
|
}
|
2007-06-06 09:51:38 +00:00
|
|
|
|
2006-12-16 19:20:44 +00:00
|
|
|
# Fall back to the defaults given in the language file
|
2008-02-18 07:25:35 +00:00
|
|
|
$wgOut->addWikiMsg( 'booksources-text' );
|
2006-12-20 16:51:26 +00:00
|
|
|
$wgOut->addHtml( '<ul>' );
|
2006-12-16 19:20:44 +00:00
|
|
|
$items = $wgContLang->getBookstoreList();
|
|
|
|
|
foreach( $items as $label => $url )
|
2006-12-20 16:51:26 +00:00
|
|
|
$wgOut->addHtml( $this->makeListItem( $label, $url ) );
|
|
|
|
|
$wgOut->addHtml( '</ul>' );
|
|
|
|
|
return true;
|
2004-04-09 06:27:18 +00:00
|
|
|
}
|
2006-12-16 19:20:44 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 '<li><a href="' . htmlspecialchars( $url ) . '">' . htmlspecialchars( $label ) . '</a></li>';
|
2003-05-19 21:30:19 +00:00
|
|
|
}
|
2006-12-16 19:20:44 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2007-06-29 01:19:14 +00:00
|
|
|
|