Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

SpecialBooksources.php

Go to the documentation of this file.
00001 <?php 00002 00003 # ISBNs in wiki pages will create links to this page, with 00004 # the ISBN passed in via the query string. 00005 00006 function wfSpecialBooksources( $par ) 00007 { 00008 global $wgRequest; 00009 00010 $isbn = $par; 00011 if( empty( $par ) ) { 00012 $isbn = $wgRequest->getVal( 'isbn' ); 00013 } 00014 $isbn = preg_replace( '/[^0-9X]/', '', $isbn ); 00015 00016 $bsl = new BookSourceList( $isbn ); 00017 $bsl->show(); 00018 } 00019 00020 class BookSourceList { 00021 var $mIsbn; 00022 00023 function BookSourceList( $isbn ) { 00024 $this->mIsbn = $isbn; 00025 } 00026 00027 function show() { 00028 global $wgOut; 00029 00030 $wgOut->setPagetitle( wfMsg( "booksources" ) ); 00031 if( empty( $this->mIsbn ) ) { 00032 $this->askForm(); 00033 } else { 00034 $this->showList(); 00035 } 00036 } 00037 00038 function showList() { 00039 global $wgOut, $wgUser, $wgLang; 00040 $fname = "BookSourceList::showList()"; 00041 00042 # First, see if we have a custom list setup in 00043 # [[Wikipedia:Book sources]] or equivalent. 00044 $bstitle = Title::newFromText( wfmsg( "booksources" ) ); 00045 $sql = "SELECT cur_text FROM cur " . 00046 "WHERE cur_namespace=4 and cur_title='" . 00047 wfStrencode( $bstitle->getDBkey() ) . "'"; 00048 $res = wfQuery( $sql, DB_READ, $fname ); 00049 if( ( $s = wfFetchObject( $res ) ) and ( $s->cur_text != "" ) ) { 00050 $bstext = $s->cur_text; 00051 $bstext = str_replace( "MAGICNUMBER", $this->mIsbn, $bstext ); 00052 00053 $wgOut->addWikiText( $bstext ); 00054 return; 00055 } 00056 00057 # Otherwise, use the list of links in the default Language.php file. 00058 $s = wfMsg( "booksourcetext" ) . "<ul>\n"; 00059 $bs = $wgLang->getBookstoreList() ; 00060 $bsn = array_keys ( $bs ) ; 00061 foreach ( $bsn as $name ) { 00062 $adr = $bs[$name] ; 00063 if ( ! $this->mIsbn ) { 00064 $adr = explode( ":" , $adr , 2 ); 00065 $adr = explode( "/" , $adr[1] ); 00066 $a = ""; 00067 while ( $a == "" ) { 00068 $a = array_shift( $adr ); 00069 } 00070 $adr = "http://".$a ; 00071 } else { 00072 $adr = str_replace ( "$1" , $this->mIsbn , $adr ) ; 00073 } 00074 $name = htmlspecialchars( $name ); 00075 $adr = htmlspecialchars( $adr ); 00076 $s .= "<li><a href=\"{$adr}\" class=\"external\">{$name}</a></li>\n" ; 00077 } 00078 $s .= "</ul>\n"; 00079 00080 $wgOut->addHTML( $s ); 00081 } 00082 00083 function askForm() { 00084 global $wgOut, $wgLang, $wgTitle; 00085 $fname = "BookSourceList::askForm()"; 00086 00087 $action = $wgTitle->escapeLocalUrl(); 00088 $isbn = htmlspecialchars( wfMsg( "isbn" ) ); 00089 $go = htmlspecialchars( wfMsg( "go" ) ); 00090 $out = "<form action=\"$action\" method='post'> 00091 $isbn: <input name='isbn' id='isbn' /> 00092 <input type='submit' value=\"$go\" /> 00093 </form>"; 00094 $wgOut->addHTML( $out ); 00095 } 00096 } 00097 00098 ?>

Generated on Tue Jun 29 23:40:07 2004 for Mediawiki by doxygen 1.3.7