2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* ISBNs in wiki pages will create links to this page, with the ISBN passed
|
|
|
|
|
* in via the query string.
|
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
|
|
|
|
* @subpackage SpecialPage
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*/
|
|
|
|
|
function wfSpecialBooksources( $par ) {
|
2004-03-20 08:55:22 +00:00
|
|
|
global $wgRequest;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-03-20 08:55:22 +00:00
|
|
|
$isbn = $par;
|
|
|
|
|
if( empty( $par ) ) {
|
|
|
|
|
$isbn = $wgRequest->getVal( 'isbn' );
|
|
|
|
|
}
|
|
|
|
|
$isbn = preg_replace( '/[^0-9X]/', '', $isbn );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$bsl = new BookSourceList( $isbn );
|
|
|
|
|
$bsl->show();
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
|
|
|
|
* @subpackage SpecialPage
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-04-14 23:10:40 +00:00
|
|
|
class BookSourceList {
|
2006-05-11 22:40:38 +00:00
|
|
|
var $mIsbn;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-04-09 06:27:18 +00:00
|
|
|
function BookSourceList( $isbn ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mIsbn = $isbn;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-09 06:27:18 +00:00
|
|
|
function show() {
|
|
|
|
|
global $wgOut;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( "booksources" ) );
|
2005-07-16 22:07:38 +00:00
|
|
|
if( $this->mIsbn == '' ) {
|
2004-04-09 06:27:18 +00:00
|
|
|
$this->askForm();
|
|
|
|
|
} else {
|
|
|
|
|
$this->showList();
|
2003-05-19 21:01:09 +00:00
|
|
|
}
|
2004-04-09 06:27:18 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-04-09 06:27:18 +00:00
|
|
|
function showList() {
|
2005-12-04 18:27:59 +00:00
|
|
|
global $wgOut, $wgContLang;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-04-09 06:27:18 +00:00
|
|
|
# First, see if we have a custom list setup in
|
|
|
|
|
# [[Wikipedia:Book sources]] or equivalent.
|
2004-08-28 17:53:12 +00:00
|
|
|
$bstitle = Title::makeTitleSafe( NS_PROJECT, wfMsg( "booksources" ) );
|
2006-02-18 01:09:45 +00:00
|
|
|
if( $bstitle ) {
|
|
|
|
|
$revision = Revision::newFromTitle( $bstitle );
|
|
|
|
|
if( $revision ) {
|
|
|
|
|
$bstext = $revision->getText();
|
|
|
|
|
if( $bstext ) {
|
|
|
|
|
$bstext = str_replace( "MAGICNUMBER", $this->mIsbn, $bstext );
|
|
|
|
|
$wgOut->addWikiText( $bstext );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-07-03 13:03:33 +00:00
|
|
|
}
|
2004-04-09 06:27:18 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-04-09 06:27:18 +00:00
|
|
|
# Otherwise, use the list of links in the default Language.php file.
|
2005-09-14 14:56:37 +00:00
|
|
|
$s = wfMsgWikiHtml( 'booksourcetext' ) . "<ul>\n";
|
2004-09-24 16:24:43 +00:00
|
|
|
$bs = $wgContLang->getBookstoreList() ;
|
2004-04-09 06:27:18 +00:00
|
|
|
$bsn = array_keys ( $bs ) ;
|
|
|
|
|
foreach ( $bsn as $name ) {
|
|
|
|
|
$adr = $bs[$name] ;
|
|
|
|
|
if ( ! $this->mIsbn ) {
|
|
|
|
|
$adr = explode( ":" , $adr , 2 );
|
|
|
|
|
$adr = explode( "/" , $adr[1] );
|
|
|
|
|
$a = "";
|
|
|
|
|
while ( $a == "" ) {
|
|
|
|
|
$a = array_shift( $adr );
|
2003-05-19 21:01:09 +00:00
|
|
|
}
|
2004-04-09 06:27:18 +00:00
|
|
|
$adr = "http://".$a ;
|
|
|
|
|
} else {
|
|
|
|
|
$adr = str_replace ( "$1" , $this->mIsbn , $adr ) ;
|
2003-05-19 21:30:19 +00:00
|
|
|
}
|
2004-04-09 06:27:18 +00:00
|
|
|
$name = htmlspecialchars( $name );
|
|
|
|
|
$adr = htmlspecialchars( $adr );
|
|
|
|
|
$s .= "<li><a href=\"{$adr}\" class=\"external\">{$name}</a></li>\n" ;
|
2003-05-19 21:01:09 +00:00
|
|
|
}
|
2004-04-09 06:27:18 +00:00
|
|
|
$s .= "</ul>\n";
|
|
|
|
|
|
|
|
|
|
$wgOut->addHTML( $s );
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-04-09 06:27:18 +00:00
|
|
|
function askForm() {
|
2005-12-04 18:27:59 +00:00
|
|
|
global $wgOut, $wgTitle;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-04-09 06:27:18 +00:00
|
|
|
$action = $wgTitle->escapeLocalUrl();
|
|
|
|
|
$isbn = htmlspecialchars( wfMsg( "isbn" ) );
|
|
|
|
|
$go = htmlspecialchars( wfMsg( "go" ) );
|
|
|
|
|
$out = "<form action=\"$action\" method='post'>
|
|
|
|
|
$isbn: <input name='isbn' id='isbn' />
|
|
|
|
|
<input type='submit' value=\"$go\" />
|
|
|
|
|
</form>";
|
|
|
|
|
$wgOut->addHTML( $out );
|
2003-05-19 21:30:19 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|