Fix bug 2642 : watchdetails message using HTML instead of wiki syntax. Patch by zigge...
[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 * @package MediaWiki
7 * @subpackage SpecialPage
8 */
9
10 /**
11 * Constructor
12 */
13 function wfSpecialBooksources( $par ) {
14 global $wgRequest;
15
16 $isbn = $par;
17 if( empty( $par ) ) {
18 $isbn = $wgRequest->getVal( 'isbn' );
19 }
20 $isbn = preg_replace( '/[^0-9X]/', '', $isbn );
21
22 $bsl = new BookSourceList( $isbn );
23 $bsl->show();
24 }
25
26 /**
27 *
28 * @package MediaWiki
29 * @subpackage SpecialPage
30 */
31 class BookSourceList {
32 var $mIsbn;
33
34 function BookSourceList( $isbn ) {
35 $this->mIsbn = $isbn;
36 }
37
38 function show() {
39 global $wgOut;
40
41 $wgOut->setPagetitle( wfMsg( "booksources" ) );
42 if( empty( $this->mIsbn ) ) {
43 $this->askForm();
44 } else {
45 $this->showList();
46 }
47 }
48
49 function showList() {
50 global $wgOut, $wgUser, $wgContLang;
51 $fname = "BookSourceList::showList()";
52
53 # First, see if we have a custom list setup in
54 # [[Wikipedia:Book sources]] or equivalent.
55 $bstitle = Title::makeTitleSafe( NS_PROJECT, wfMsg( "booksources" ) );
56 $bsarticle = new Article( $bstitle );
57 if( $bsarticle->exists() ) {
58 $bstext = $bsarticle->getContent( false );
59 if( $bstext ) {
60 $bstext = str_replace( "MAGICNUMBER", $this->mIsbn, $bstext );
61 $wgOut->addWikiText( $bstext );
62 return;
63 }
64 }
65
66 # Otherwise, use the list of links in the default Language.php file.
67 $s = wfMsg( "booksourcetext" ) . "<ul>\n";
68 $bs = $wgContLang->getBookstoreList() ;
69 $bsn = array_keys ( $bs ) ;
70 foreach ( $bsn as $name ) {
71 $adr = $bs[$name] ;
72 if ( ! $this->mIsbn ) {
73 $adr = explode( ":" , $adr , 2 );
74 $adr = explode( "/" , $adr[1] );
75 $a = "";
76 while ( $a == "" ) {
77 $a = array_shift( $adr );
78 }
79 $adr = "http://".$a ;
80 } else {
81 $adr = str_replace ( "$1" , $this->mIsbn , $adr ) ;
82 }
83 $name = htmlspecialchars( $name );
84 $adr = htmlspecialchars( $adr );
85 $s .= "<li><a href=\"{$adr}\" class=\"external\">{$name}</a></li>\n" ;
86 }
87 $s .= "</ul>\n";
88
89 $wgOut->addHTML( $s );
90 }
91
92 function askForm() {
93 global $wgOut, $wgLang, $wgTitle;
94 $fname = "BookSourceList::askForm()";
95
96 $action = $wgTitle->escapeLocalUrl();
97 $isbn = htmlspecialchars( wfMsg( "isbn" ) );
98 $go = htmlspecialchars( wfMsg( "go" ) );
99 $out = "<form action=\"$action\" method='post'>
100 $isbn: <input name='isbn' id='isbn' />
101 <input type='submit' value=\"$go\" />
102 </form>";
103 $wgOut->addHTML( $out );
104 }
105 }
106
107 ?>