-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwiki.php
More file actions
30 lines (24 loc) · 1.07 KB
/
wiki.php
File metadata and controls
30 lines (24 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
$in = $_REQUEST;
$in['q'] = array_key_exists('q', $in) ? $in['q'] : "NOFX";
if (array_key_exists('q', $in)) {
$topic = preg_replace("/\s/", "_", $in['q']);
if ((file_exists("cache/$topic.raw")) && (!array_key_exists('f', $in))) {
$content = file_get_contents("cache/$topic.raw");
$out = array("content"=>array("content"=>$content), "status"=>"ok");
} else {
$content = file_get_contents("https://en.wikipedia.org/w/index.php?title=$topic&action=raw");
if (!preg_match("/Wikimedia\sError/", $content)) {
file_put_contents("cache/$topic.raw", $content);
$out = array("content"=>array("content"=>$content), "status"=>"ok");
} else {
$out = array("status"=>"error", "content"=>"Error retrieving data for topic '$topic' (404?)");
}
}
} else {
$out = array("status"=>"error", "content"=>"Missing query parameter 'q'");
}
header("Content-type: application/json");
print json_encode($out);
exit;
?>