same minor typo as in LocalSettings (in example config url)
[mediawiki.git] / includes / SpecialBooksources.php
blobc7630f5e22d8b299a5c4bd2f3ebc09f723e962b9
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 = preg_replace( '/[^0-9X]/', '', $_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) {
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;
45 $wgOut->addWikiText( $bstext );
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.
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 ) ;
66 $s .= "<li><a href=\"{$adr}\" class=\"external\">{$name}</a></li>\n" ;
68 $s .= "</ul>\n";
70 $wgOut->addHTML( $s );