OOP'ed Ajax functions, embedded in index.php for better compatibility with wikipedia...
[lhc/web/wiklou.git] / includes / AjaxDispatcher.php
1 <?php
2
3 //$wgRequestTime = microtime();
4
5 // unset( $IP );
6 // @ini_set( 'allow_url_fopen', 0 ); # For security...
7
8 # Valid web server entry point, enable includes.
9 # Please don't move this line to includes/Defines.php. This line essentially defines
10 # a valid entry point. If you put it in includes/Defines.php, then any script that includes
11 # it becomes an entry point, thereby defeating its purpose.
12 // define( 'MEDIAWIKI', true );
13 // require_once( './includes/Defines.php' );
14 // require_once( './LocalSettings.php' );
15 // require_once( 'includes/Setup.php' );
16 require_once( 'AjaxFunctions.php' );
17
18 if ( ! $wgUseAjax ) {
19 die ( -1 );
20 }
21
22 class AjaxDispatcher {
23 var $mode;
24 var $func_name;
25 var $args;
26
27 function AjaxDispatcher() {
28 global $wgAjaxCachePolicy;
29
30 wfProfileIn( 'AjaxDispatcher::AjaxDispatcher' );
31
32 $wgAjaxCachePolicy = new AjaxCachePolicy();
33
34 $this->mode = "";
35
36 if (! empty($_GET["rs"])) {
37 $this->mode = "get";
38 }
39
40 if (!empty($_POST["rs"])) {
41 $this->mode = "post";
42 }
43
44 if ($this->mode == "get") {
45 $this->func_name = $_GET["rs"];
46 if (! empty($_GET["rsargs"])) {
47 $this->args = $_GET["rsargs"];
48 } else {
49 $this->args = array();
50 }
51 } else {
52 $this->func_name = $_POST["rs"];
53 if (! empty($_POST["rsargs"])) {
54 $this->args = $_POST["rsargs"];
55 } else {
56 $this->args = array();
57 }
58 }
59 wfProfileOut( 'AjaxDispatcher::AjaxDispatcher' );
60 }
61
62 function performAction() {
63 global $wgAjaxCachePolicy, $wgAjaxExportList;
64 if ( empty( $this->mode ) ) {
65 return;
66 }
67 wfProfileIn( 'AjaxDispatcher::performAction' );
68
69 if (! in_array( $this->func_name, $wgAjaxExportList ) ) {
70 echo "-:{$this->func_name} not callable";
71 } else {
72 echo "+:";
73 $result = call_user_func_array($this->func_name, $this->args);
74 header( 'Content-Type: text/html; charset=utf-8', true );
75 $wgAjaxCachePolicy->writeHeader();
76 echo $result;
77 }
78 wfProfileOut( 'AjaxDispatcher::performAction' );
79 exit;
80 }
81 }
82
83 ?>