Changing comments layout preparing for generated documentation with Phpdocumentor
[lhc/web/wiklou.git] / includes / SpecialBooksources.php
1 <?php
2 /**
3 * ISBNs in wiki pages will create links to this page, with the ISBN passed
4 * in via the query string.
5 *
6 *
7 */
8
9 /**
10 * Constructor
11 */
12 function wfSpecialBooksources( $par ) {
13 global $wgRequest;
14
15 $isbn = $par;
16 if( empty( $par ) ) {
17 $isbn = $wgRequest->getVal( 'isbn' );
18 }
19 $isbn = preg_replace( '/[^0-9X]/', '', $isbn );
20
21 $bsl = new BookSourceList( $isbn );
22 $bsl->show();
23 }
24
25 /**
26 *
27 */
28 class BookSourceList {
29 var $mIsbn;
30
31 function BookSourceList( $isbn ) {
32 $this->mIsbn = $isbn;
33 }
34
35 function show() {
36 global $wgOut;
37
38 $wgOut->setPagetitle( wfMsg( "booksources" ) );
39 if( empty( $this->mIsbn ) ) {
40 $this->askForm();
41 } else {
42 $this->showList();
43 }
44 }
45
46 function showList() {
47 global $wgOut, $wgUser, $wgLang;
48 $fname = "BookSourceList::showList()";
49
50 # First, see if we have a custom list setup in
51 # [[Wikipedia:Book sources]] or equivalent.
52 $bstitle = Title::makeTitleSafe( NS_PROJECT, wfMsg( "booksources" ) );
53 $dbr =& wfGetDB( DB_SLAVE );
54 $bstext = $dbr->selectField( 'cur', 'cur_text', $bstitle->curCond(), $fname );
55 if( $bstext ) {
56 $bstext = str_replace( "MAGICNUMBER", $this->mIsbn, $bstext );
57 $wgOut->addWikiText( $bstext );
58 return;
59 }
60
61 # Otherwise, use the list of links in the default Language.php file.
62 $s = wfMsg( "booksourcetext" ) . "<ul>\n";
63 $bs = $wgLang->getBookstoreList() ;
64 $bsn = array_keys ( $bs ) ;
65 foreach ( $bsn as $name ) {
66 $adr = $bs[$name] ;
67 if ( ! $this->mIsbn ) {
68 $adr = explode( ":" , $adr , 2 );
69 $adr = explode( "/" , $adr[1] );
70 $a = "";
71 while ( $a == "" ) {
72 $a = array_shift( $adr );
73 }
74 $adr = "http://".$a ;
75 } else {
76 $adr = str_replace ( "$1" , $this->mIsbn , $adr ) ;
77 }
78 $name = htmlspecialchars( $name );
79 $adr = htmlspecialchars( $adr );
80 $s .= "<li><a href=\"{$adr}\" class=\"external\">{$name}</a></li>\n" ;
81 }
82 $s .= "</ul>\n";
83
84 $wgOut->addHTML( $s );
85 }
86
87 function askForm() {
88 global $wgOut, $wgLang, $wgTitle;
89 $fname = "BookSourceList::askForm()";
90
91 $action = $wgTitle->escapeLocalUrl();
92 $isbn = htmlspecialchars( wfMsg( "isbn" ) );
93 $go = htmlspecialchars( wfMsg( "go" ) );
94 $out = "<form action=\"$action\" method='post'>
95 $isbn: <input name='isbn' id='isbn' />
96 <input type='submit' value=\"$go\" />
97 </form>";
98 $wgOut->addHTML( $out );
99 }
100 }
101
102 ?>