* Fix notice from uninitialized variable in date()
[mediawiki.git] / includes / SpecialBooksources.php
blob13994c404a937e04d15ea04ea96f615aac3fb046
1 <?php
3 # ISBNs in wiki pages will create links to this page, with
4 # the ISBN passed in via the query string.
6 function wfSpecialBooksources( $par )
8 global $wgRequest;
10 $isbn = $par;
11 if( empty( $par ) ) {
12 $isbn = $wgRequest->getVal( 'isbn' );
14 $isbn = preg_replace( '/[^0-9X]/', '', $isbn );
16 $bsl = new BookSourceList( $isbn );
17 $bsl->show();
20 class BookSourceList {
21 var $mIsbn;
23 function BookSourceList( $isbn ) {
24 $this->mIsbn = $isbn;
27 function show() {
28 global $wgOut;
30 $wgOut->setPagetitle( wfMsg( "booksources" ) );
31 if( empty( $this->mIsbn ) ) {
32 $this->askForm();
33 } else {
34 $this->showList();
38 function showList() {
39 global $wgOut, $wgUser, $wgLang;
40 $fname = "BookSourceList::showList()";
42 # First, see if we have a custom list setup in
43 # [[Wikipedia:Book sources]] or equivalent.
44 $bstitle = Title::makeTitle( NS_WIKIPEDIA, wfMsg( "booksources" ) );
45 $dbr =& wfGetDB( DB_SLAVE );
46 $bstext = $dbr->selectField( 'cur', 'cur_text', $bstitle->curCond(), $fname );
47 if( $bstext ) {
48 $bstext = str_replace( "MAGICNUMBER", $this->mIsbn, $bstext );
49 $wgOut->addWikiText( $bstext );
50 return;
53 # Otherwise, use the list of links in the default Language.php file.
54 $s = wfMsg( "booksourcetext" ) . "<ul>\n";
55 $bs = $wgLang->getBookstoreList() ;
56 $bsn = array_keys ( $bs ) ;
57 foreach ( $bsn as $name ) {
58 $adr = $bs[$name] ;
59 if ( ! $this->mIsbn ) {
60 $adr = explode( ":" , $adr , 2 );
61 $adr = explode( "/" , $adr[1] );
62 $a = "";
63 while ( $a == "" ) {
64 $a = array_shift( $adr );
66 $adr = "http://".$a ;
67 } else {
68 $adr = str_replace ( "$1" , $this->mIsbn , $adr ) ;
70 $name = htmlspecialchars( $name );
71 $adr = htmlspecialchars( $adr );
72 $s .= "<li><a href=\"{$adr}\" class=\"external\">{$name}</a></li>\n" ;
74 $s .= "</ul>\n";
76 $wgOut->addHTML( $s );
79 function askForm() {
80 global $wgOut, $wgLang, $wgTitle;
81 $fname = "BookSourceList::askForm()";
83 $action = $wgTitle->escapeLocalUrl();
84 $isbn = htmlspecialchars( wfMsg( "isbn" ) );
85 $go = htmlspecialchars( wfMsg( "go" ) );
86 $out = "<form action=\"$action\" method='post'>
87 $isbn: <input name='isbn' id='isbn' />
88 <input type='submit' value=\"$go\" />
89 </form>";
90 $wgOut->addHTML( $out );