-
Notifications
You must be signed in to change notification settings - Fork 2
/
getPage.php
82 lines (64 loc) · 1.81 KB
/
getPage.php
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* Retrieves content for the Embed Page extension of MediaWiki
*
* @author Scott McMillan
*/
/**
* return the content as javascript after encoding
*
*
* @param string $output raw HTML wiki page
* @return string prints the document.write content from $output
*/
function obMakeJavaScriptEmbedHandler($output){
return sprintf('document.write(unescape(decodeURIComponent("%s")));', rawurlencode($output));
}
ob_start("obMakeJavaScriptEmbedHandler");
/**
* return the raw HTML content of the action = render URL via cURL
*
* This is probably the worst way to do it but I cannot
* * find a hook to pull rendered rawHTML
* @param string $ptitle of the wiki page
* @return string content from the URL/webpage
*/
function getUrlContents($title){
// This is outside the loop so cannot access Globals
// ($wgServer passed with $ptitle)
$embedPageServer = "http://" . $_SERVER["SERVER_NAME"];
$embedPageUrl = "$embedPageServer"."$title?action=render";
if($_SERVER['HTTP_REFERER']){
$referer = $_SERVER['HTTP_REFERER'];
}else{
$referer = $_GET['referer'];
}
$crl = curl_init();
$timeout = 5;
curl_setopt ($crl, CURLOPT_URL,$embedPageUrl);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($crl, CURLOPT_HTTPHEADER, array(
'Referer: '.$referer,
'User-Agent: EmbedPage',
));
$ret = curl_exec($crl);
curl_close($crl);
return $ret;
}
// Get article title passed
$embedPageTitle = $_GET['title'];
if(empty($embedPageTitle)){
echo"Error: Wiki title was not specified.";
exit();
}else{
// Get the raw HTML content
$embedPageContent = getUrlContents($embedPageTitle);
if(empty($embedPageContent)){
echo"Error: retrieving wiki page content.";
exit();
}else{
print $embedPageContent;
}
}
?>