* Removing the if($wgMetaNamespace === FALSE) line, inherited from the parent.
[mediawiki.git] / includes / SpecialBooksources.php
blobbd8596f4dbc02c9e3a08f07bf4a9a2a59011cb81
1 <?php
2 /**
3 * ISBNs in wiki pages will create links to this page, with the ISBN passed
4 * in via the query string.
6 * @package MediaWiki
7 * @subpackage SpecialPage
8 */
10 /**
11 * Constructor
13 function wfSpecialBooksources( $par ) {
14 global $wgRequest;
16 $isbn = $par;
17 if( empty( $par ) ) {
18 $isbn = $wgRequest->getVal( 'isbn' );
20 $isbn = preg_replace( '/[^0-9X]/', '', $isbn );
22 $bsl = new BookSourceList( $isbn );
23 $bsl->show();
26 /**
28 * @package MediaWiki
29 * @subpackage SpecialPage
31 class BookSourceList {
32 var $mIsbn;
34 function BookSourceList( $isbn ) {
35 $this->mIsbn = $isbn;
38 function show() {
39 global $wgOut;
41 $wgOut->setPagetitle( wfMsg( "booksources" ) );
42 if( empty( $this->mIsbn ) ) {
43 $this->askForm();
44 } else {
45 $this->showList();
49 function showList() {
50 global $wgOut, $wgUser, $wgContLang;
51 $fname = "BookSourceList::showList()";
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 $bstext = $bsarticle->getContent( false );
59 if( $bstext ) {
60 $bstext = str_replace( "MAGICNUMBER", $this->mIsbn, $bstext );
61 $wgOut->addWikiText( $bstext );
62 return;
65 # Otherwise, use the list of links in the default Language.php file.
66 $s = wfMsg( "booksourcetext" ) . "<ul>\n";
67 $bs = $wgContLang->getBookstoreList() ;
68 $bsn = array_keys ( $bs ) ;
69 foreach ( $bsn as $name ) {
70 $adr = $bs[$name] ;
71 if ( ! $this->mIsbn ) {
72 $adr = explode( ":" , $adr , 2 );
73 $adr = explode( "/" , $adr[1] );
74 $a = "";
75 while ( $a == "" ) {
76 $a = array_shift( $adr );
78 $adr = "http://".$a ;
79 } else {
80 $adr = str_replace ( "$1" , $this->mIsbn , $adr ) ;
82 $name = htmlspecialchars( $name );
83 $adr = htmlspecialchars( $adr );
84 $s .= "<li><a href=\"{$adr}\" class=\"external\">{$name}</a></li>\n" ;
86 $s .= "</ul>\n";
88 $wgOut->addHTML( $s );
91 function askForm() {
92 global $wgOut, $wgLang, $wgTitle;
93 $fname = "BookSourceList::askForm()";
95 $action = $wgTitle->escapeLocalUrl();
96 $isbn = htmlspecialchars( wfMsg( "isbn" ) );
97 $go = htmlspecialchars( wfMsg( "go" ) );
98 $out = "<form action=\"$action\" method='post'>
99 $isbn: <input name='isbn' id='isbn' />
100 <input type='submit' value=\"$go\" />
101 </form>";
102 $wgOut->addHTML( $out );