Hello, I've got the following problem: I want to include the googleSearch into my wiki. Therefore I use the following implementation for mediawiki: <?php # Created by Matt Hart, Intuit, Inc. http://meta.wikimedia.org/wiki/User:MHart # Note that this is not really an extension in the scrict sense - it isn't added # to the extensions list and such. Rather it replaces the search. function wfGoogleSearch( $par='' ) { global $wgRequest, $wgUser; global $wgOut, $wgSitename; global $wgScriptPath; $searchPage = new SpecialSearch( $wgRequest, $wgUser ); $search = $wgRequest->getText( 'search', $par ); $start = $wgRequest->getText( 'start', $par); $wgOut->setPageTitle($search . " - Google Search"); $sitesearch = urlencode($_SERVER["HTTP_HOST"] . $wgScriptPath); # Google URL Parameters # site=ext_name : this is the Google appliance (GA) "collection" to search # client=name : this is the GA client that is allowed to make requests # as_sitesearch= : this restricts the results to this specific wiki, even on shared domains # so wikis.intuit.com/first gets its own results # likewise wikis.intuit.com/second gets its own $url = 'http://googlesearchurl.yoursite.com/search?q=' . urlencode($search) . '&output=xml&site= ext_name&client=name&as_sitesearch=' . $sitesearch . '&start=' . $start; $xmldata = file_get_contents($url); # This saves the file to a temp location so that XSLTPROC can # run on it. If you have Sablotron installed with PHP 5, you can # use it's XSLT functions. The following method, however, works with # any version of PHP. $xmlfile = tempnam("",""); $file = fopen($xmlfile,"w"); fwrite($file,$xmldata); fclose($file); $results = xsltproc('extensions/Google.xslt',$xmlfile); $wgOut->addHTML($results); unlink($xmlfile); $wgOut->output(); return; } function xsltproc($xslfile, $xmlfile) { $toexec = "xsltproc " . $xslfile . " " . $xmlfile; exec($toexec,$results); return implode("",$results); } ?> Code (markup): For the url: googlesearch.yoursite.com I use my local directory, where I am testing my extension: http://localhost/wiki/index.php/ If i am now testing this extension, searching for a word, there will appear the following fault:[file_get_contents]: failed to open stream: HTTP request failed! Can you help me? I'm disappointed that i cannot correct the mistake by my own.. Best regards, Daniel ------------------ XAMPP 1.5.3a PHP 5.1.4 Apache 2.2.2 Mysql 5.0.21
try something in the line of ob_start(); $xmldata = ob_get_contents($url); ob_end_clean(); Code (markup):
$xmldata = file_get_contents($url); Code (markup): make sure that $url doesn't end in a space (or tab, or newline... ), I was helping a guy who couldn't get file_get_contents() just to day and he took a list of URL and exploded them but forgot to use rtrim() to remove extra stuff and it gave him errors. ---- --- also, is the URL a real website?
That works, but now there follows another error: Call to a member function getID() on a non-object in.. (this line) if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) Code (markup): and this line I think refers to another file where I changed the normal SearchEngine: if( !$this->getVal('DisableInternalSearch') && !is_null( $search ) && $search !== '' ) { // Commented OUT the default search // require_once( 'includes/SpecialSearch.php' ); // $title = Title::makeTitle( NS_SPECIAL, 'Search' ); // wfSpecialSearch(); // Add GoogleSearch here AND see the line below where it's added wfGoogleSearch();} else if( !$title or $title->getDBkey() == '' ) { $title = Title::makeTitle( NS_SPECIAL, 'Badtitle' ); # Die now before we mess up $wgArticle and the skin stops working throw new ErrorPageError( 'badtitle', 'badtitletext' ); } else if ( $title->getText() == 'Search') { wfGoogleSearch(); } else if ( $title->getInterwiki() != '' )... Code (markup): Any ideas why this error occurs?Is the index of the "Search"Array zero and generates this one?
Oh, I haven't seen a fault in the description of this extension, so this topic is closed because it's no longer interesting for me. Thanks for your help!