Fix http://bugzilla.wikipedia.org/show_bug.cgi?id=511 . Stop showing whatlinkshere...
[mediawiki.git] / includes / SpecialBooksources.php
bloba00d4fb3597361d29e4c4fa8fb1b0aab1063d8df
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, $wgLang;
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 $dbr =& wfGetDB( DB_SLAVE );
57 $bstext = $dbr->selectField( 'cur', 'cur_text', $bstitle->curCond(), $fname );
58 if( $bstext ) {
59 $bstext = str_replace( "MAGICNUMBER", $this->mIsbn, $bstext );
60 $wgOut->addWikiText( $bstext );
61 return;
64 # Otherwise, use the list of links in the default Language.php file.
65 $s = wfMsg( "booksourcetext" ) . "<ul>\n";
66 $bs = $wgLang->getBookstoreList() ;
67 $bsn = array_keys ( $bs ) ;
68 foreach ( $bsn as $name ) {
69 $adr = $bs[$name] ;
70 if ( ! $this->mIsbn ) {
71 $adr = explode( ":" , $adr , 2 );
72 $adr = explode( "/" , $adr[1] );
73 $a = "";
74 while ( $a == "" ) {
75 $a = array_shift( $adr );
77 $adr = "http://".$a ;
78 } else {
79 $adr = str_replace ( "$1" , $this->mIsbn , $adr ) ;
81 $name = htmlspecialchars( $name );
82 $adr = htmlspecialchars( $adr );
83 $s .= "<li><a href=\"{$adr}\" class=\"external\">{$name}</a></li>\n" ;
85 $s .= "</ul>\n";
87 $wgOut->addHTML( $s );
90 function askForm() {
91 global $wgOut, $wgLang, $wgTitle;
92 $fname = "BookSourceList::askForm()";
94 $action = $wgTitle->escapeLocalUrl();
95 $isbn = htmlspecialchars( wfMsg( "isbn" ) );
96 $go = htmlspecialchars( wfMsg( "go" ) );
97 $out = "<form action=\"$action\" method='post'>
98 $isbn: <input name='isbn' id='isbn' />
99 <input type='submit' value=\"$go\" />
100 </form>";
101 $wgOut->addHTML( $out );