c16b7eb8d619c521b76535ec4bd31d8dfa8198c3
[lhc/web/wiklou.git] / includes / SpecialBooksources.php
1 <?
2
3 # ISBNs in wiki pages will create links to this page, with
4 # the ISBN passed in via the query string.
5
6 function wfSpecialBooksources()
7 {
8 $isbn = $_REQUEST["isbn"];
9
10 $bsl = new BookSourceList( $isbn );
11 $bsl->show();
12 }
13
14 class BookSourceList {
15
16 var $mIsbn;
17
18 function BookSourceList( $isbn )
19 {
20 $this->mIsbn = $isbn;
21 }
22
23 function show()
24 {
25 global $wgOut, $wgUser, $wgLang;
26 global $ip, $wpBlockAddress, $wpBlockReason;
27 $fname="BookSourceList->show()";
28
29 $wgOut->setPagetitle( wfMsg( "booksources" ) );
30 $bstext=wfMsg( "booksourcetext" );
31
32 if($this->mIsbn)
33 {
34 $bstitle=Title::newFromText(wfmsg("booksources"));
35 $sql="SELECT cur_text FROM cur WHERE cur_namespace=4 and cur_title='" . $bstitle->getPrefixedDBkey()."'";
36 $res=wfQuery($sql,$fname);
37 if( ($s=wfFetchObject($res)) and ($s->cur_text!="")) {
38
39 $bstext=$s->cur_text;
40 $bstext=str_replace("WIKI-ISBN",$this->mIsbn,$bstext);
41 $noautolist=1;
42 }
43
44 }
45
46
47 $wgOut->addWikiText( $bstext );
48
49
50 # If ISBN is blank, just show a list of links to the
51 # home page of the various book sites. Otherwise, show
52 # a list of links directly to the book.
53
54 if(!$noautolist) { # only do this if we haven't already shown [[Wikipedia:Book sources]]
55 $s = "<ul>\n";
56 $bs = $wgLang->getBookstoreList() ;
57 $bsn = array_keys ( $bs ) ;
58 foreach ( $bsn as $name ) {
59 $adr = $bs[$name] ;
60 if ( ! $this->mIsbn ) {
61 $adr = explode ( ":" , $adr , 2 ) ;
62 $adr = explode ( "/" , $adr[1] ) ;
63 $a = "" ;
64 while ( $a == "" ) $a = array_shift ( $adr ) ;
65 $adr = "http://".$a ;
66 } else {
67 $adr = str_replace ( "$1" , $this->mIsbn , $adr ) ;
68 }
69 $s .= "<li><a href=\"{$adr}\">{$name}</a></li>\n" ;
70 }
71 $s .= "</ul>\n";
72
73 $wgOut->addHTML( $s );
74 }
75 }
76 }
77
78 ?>