wiki.techinc.nl/includes/SpecialBooksources.php

108 lines
2.3 KiB
PHP
Raw Normal View History

<?php
/**
* ISBNs in wiki pages will create links to this page, with the ISBN passed
* in via the query string.
*
* @package MediaWiki
* @subpackage SpecialPage
*/
2003-04-14 23:10:40 +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();
}
/**
*
* @package MediaWiki
* @subpackage SpecialPage
*/
2003-04-14 23:10:40 +00:00
class BookSourceList {
var $mIsbn;
2003-04-14 23:10:40 +00:00
function BookSourceList( $isbn ) {
2003-04-14 23:10:40 +00:00
$this->mIsbn = $isbn;
}
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 == '' ) {
$this->askForm();
} else {
$this->showList();
}
}
2006-01-07 13:31:29 +00:00
function showList() {
2005-12-04 18:27:59 +00:00
global $wgOut, $wgContLang;
2006-01-07 13:31:29 +00:00
# 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;
}
2005-07-03 13:03:33 +00:00
}
}
2006-01-07 13:31:29 +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";
$bs = $wgContLang->getBookstoreList() ;
$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 );
}
$adr = "http://".$a ;
} else {
$adr = str_replace ( "$1" , $this->mIsbn , $adr ) ;
}
$name = htmlspecialchars( $name );
$adr = htmlspecialchars( $adr );
$s .= "<li><a href=\"{$adr}\" class=\"external\">{$name}</a></li>\n" ;
}
$s .= "</ul>\n";
$wgOut->addHTML( $s );
}
2006-01-07 13:31:29 +00:00
function askForm() {
2005-12-04 18:27:59 +00:00
global $wgOut, $wgTitle;
2006-01-07 13:31:29 +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-04-14 23:10:40 +00:00
}
?>