Revision history for WikipediaAction

Revision [18729]

Last edited on 2008-01-28 00:12:34 by RolandStens [Modified links pointing to docs server]

No Differences

Revision [12600]

Edited on 2006-01-10 23:05:23 by RolandStens [Modified links pointing to docs server]
Another version of the code that does the same but now with some more error checking and multiple language support as suggested by DarTar.
// wikipedia action
// This action will insert the content of the supplied topic in your page.
// Usage examples: {{wikipedia topic="Workflow"}}
// {{wikipedia topic="Madrid" lang="es"}}
function fetchUrlWithoutHanging($url)
// Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed

// Suppress error reporting so Web site visitors are unaware if the feed fails

// Extract resource path and domain from URL ready for fsockopen

$url = str_replace("http://","",$url);
$urlComponents = explode("/",$url);
$domain = $urlComponents[0];
$resourcePath = str_replace($domain,"",$url);

// Establish a connection
$socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds);

if (!$socketConnection)
// You may wish to remove the following debugging line on a live Web site
print("WikiPedia Error: ");
} // end if
else {
$xml = '';
fputs($socketConnection, "GET /$resourcePath HTTP/1.0\r\nHost: $domain\r\n\r\n");

// Loop until end of file
while (!feof($socketConnection))
$xml .= fgets($socketConnection, 128);
} // end while

fclose ($socketConnection);

} // end else


} // end function

if (!isset($vars['lang'])) $lang = 'en';
else $lang = $vars['lang'];
if ($file = fetchUrlWithoutHanging('http://'.$lang.''.$topic))
$file = str_replace('href="/', 'href="http://'.$lang.'', $file);
preg_match_all('#<!-- start content -->(.*?)<!-- end content -->#es', $file, $ar);
if (is_array($ar[1])) echo $ar[1][0];
else echo '';
echo 'http://'.$lang.''.$topic.' could not be found!';

Revision [12112]

Edited on 2005-12-06 08:09:41 by DarTar [adding category]

Revision [12109]

Edited on 2005-12-05 23:35:35 by RolandStens [adding category]
Extracted and changed from:
Mediawiki MySite class DOCS (ver. 0.1.0)
AUTHOR: Piotr Maliński
Site: | - Polish
License: GPL

Revision [12106]

The oldest known version of this page was created on 2005-12-05 23:25:24 by RolandStens [adding category]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki