Support for [[Wikipedia:Book sources]] (or localized text), content of
[mediawiki.git] / includes / SpecialBooksources.php
blobc16b7eb8d619c521b76535ec4bd31d8dfa8198c3
1 <?
3 # ISBNs in wiki pages will create links to this page, with
4 # the ISBN passed in via the query string.
6 function wfSpecialBooksources()
8 $isbn = $_REQUEST["isbn"];
10 $bsl = new BookSourceList( $isbn );
11 $bsl->show();
14 class BookSourceList {
16 var $mIsbn;
18 function BookSourceList( $isbn )
20 $this->mIsbn = $isbn;
23 function show()
25 global $wgOut, $wgUser, $wgLang;
26 global $ip, $wpBlockAddress, $wpBlockReason;
27 $fname="BookSourceList->show()";
29 $wgOut->setPagetitle( wfMsg( "booksources" ) );
30 $bstext=wfMsg( "booksourcetext" );
32 if($this->mIsbn)
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!="")) {
39 $bstext=$s->cur_text;
40 $bstext=str_replace("WIKI-ISBN",$this->mIsbn,$bstext);
41 $noautolist=1;
47 $wgOut->addWikiText( $bstext );
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.
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 ) ;
69 $s .= "<li><a href=\"{$adr}\">{$name}</a></li>\n" ;
71 $s .= "</ul>\n";
73 $wgOut->addHTML( $s );