fix for double-escape
[mediawiki.git] / includes / SpecialBooksources.php
blob8e7aa72c81aeb37a5346dbe253c7d8ff71f524fb
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::newFromText( wfmsg( "booksources" ) );
45 $sql = "SELECT cur_text FROM cur " .
46 "WHERE cur_namespace=4 and cur_title='" .
47 wfStrencode( $bstitle->getDBkey() ) . "'";
48 $res = wfQuery( $sql, DB_READ, $fname );
49 if( ( $s = wfFetchObject( $res ) ) and ( $s->cur_text != "" ) ) {
50 $bstext = $s->cur_text;
51 $bstext = str_replace( "MAGICNUMBER", $this->mIsbn, $bstext );
53 $wgOut->addWikiText( $bstext );
54 return;
57 # Otherwise, use the list of links in the default Language.php file.
58 $s = wfMsg( "booksourcetext" ) . "<ul>\n";
59 $bs = $wgLang->getBookstoreList() ;
60 $bsn = array_keys ( $bs ) ;
61 foreach ( $bsn as $name ) {
62 $adr = $bs[$name] ;
63 if ( ! $this->mIsbn ) {
64 $adr = explode( ":" , $adr , 2 );
65 $adr = explode( "/" , $adr[1] );
66 $a = "";
67 while ( $a == "" ) {
68 $a = array_shift( $adr );
70 $adr = "http://".$a ;
71 } else {
72 $adr = str_replace ( "$1" , $this->mIsbn , $adr ) ;
74 $name = htmlspecialchars( $name );
75 $adr = htmlspecialchars( $adr );
76 $s .= "<li><a href=\"{$adr}\" class=\"external\">{$name}</a></li>\n" ;
78 $s .= "</ul>\n";
80 $wgOut->addHTML( $s );
83 function askForm() {
84 global $wgOut, $wgLang, $wgTitle;
85 $fname = "BookSourceList::askForm()";
87 $action = $wgTitle->escapeLocalUrl();
88 $isbn = htmlspecialchars( wfMsg( "isbn" ) );
89 $go = htmlspecialchars( wfMsg( "go" ) );
90 $out = "<form action=\"$action\" method='post'>
91 $isbn: <input name='isbn' id='isbn' />
92 <input type='submit' value=\"$go\" />
93 </form>";
94 $wgOut->addHTML( $out );