Replaced old memcached client with new one
[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 = preg_replace( '/[^0-9X]/', '', $_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 $bstitle = Title::newFromText( wfmsg( "booksources" ) );
34 $sql = "SELECT cur_text FROM cur " .
35 "WHERE cur_namespace=4 and cur_title='" .
36 wfStrencode( $bstitle->getDBkey() ) . "'";
37 $res = wfQuery( $sql, DB_READ, $fname );
38 if( ( $s = wfFetchObject( $res ) ) and ( $s->cur_text != "" ) ) {
39 $bstext = $s->cur_text;
40 $bstext = str_replace( "MAGICNUMBER", $this->mIsbn, $bstext );
41 $noautolist = 1;
42 }
43 }
44
45 $wgOut->addWikiText( $bstext );
46
47 # If ISBN is blank, just show a list of links to the
48 # home page of the various book sites. Otherwise, show
49 # a list of links directly to the book.
50
51 if( !$noautolist ) { # only do this if we haven't already shown [[Wikipedia:Book sources]]
52 $s = "<ul>\n";
53 $bs = $wgLang->getBookstoreList() ;
54 $bsn = array_keys ( $bs ) ;
55 foreach ( $bsn as $name ) {
56 $adr = $bs[$name] ;
57 if ( ! $this->mIsbn ) {
58 $adr = explode ( ":" , $adr , 2 ) ;
59 $adr = explode ( "/" , $adr[1] ) ;
60 $a = "" ;
61 while ( $a == "" ) $a = array_shift ( $adr ) ;
62 $adr = "http://".$a ;
63 } else {
64 $adr = str_replace ( "$1" , $this->mIsbn , $adr ) ;
65 }
66 $s .= "<li><a href=\"{$adr}\" class=\"external\">{$name}</a></li>\n" ;
67 }
68 $s .= "</ul>\n";
69
70 $wgOut->addHTML( $s );
71 }
72 }
73 }
74
75 ?>