summaryrefslogtreecommitdiff
path: root/includes/AjaxDispatcher.php
blob: 2084c3667a5f30b9bbd1ddd25c114b4e76aade1a (plain)
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
83
<?php

//$wgRequestTime = microtime();

// unset( $IP );
// @ini_set( 'allow_url_fopen', 0 ); # For security...

# Valid web server entry point, enable includes.
# Please don't move this line to includes/Defines.php. This line essentially defines
# a valid entry point. If you put it in includes/Defines.php, then any script that includes
# it becomes an entry point, thereby defeating its purpose.
// define( 'MEDIAWIKI', true );
// require_once( './includes/Defines.php' );
// require_once( './LocalSettings.php' );
// require_once( 'includes/Setup.php' );
require_once( 'AjaxFunctions.php' );

if ( ! $wgUseAjax ) {
	die( 1 );
}

class AjaxDispatcher {
	var $mode;
	var $func_name;
	var $args;

	function AjaxDispatcher() {
		global $wgAjaxCachePolicy;

		wfProfileIn( 'AjaxDispatcher::AjaxDispatcher' );

		$wgAjaxCachePolicy = new AjaxCachePolicy();

		$this->mode = "";

		if (! empty($_GET["rs"])) {
			$this->mode = "get";
		}

		if (!empty($_POST["rs"])) {
			$this->mode = "post";
		}

		if ($this->mode == "get") {
			$this->func_name = $_GET["rs"];
			if (! empty($_GET["rsargs"])) {
				$this->args = $_GET["rsargs"];
			} else {
				$this->args = array();
			}
		} else {
			$this->func_name = $_POST["rs"];
			if (! empty($_POST["rsargs"])) {
				$this->args = $_POST["rsargs"];
			} else {
				$this->args = array();
			}
		}
		wfProfileOut( 'AjaxDispatcher::AjaxDispatcher' );
	}

	function performAction() {
		global $wgAjaxCachePolicy, $wgAjaxExportList;
		if ( empty( $this->mode ) ) {
			return;
		}
		wfProfileIn( 'AjaxDispatcher::performAction' );

		if (! in_array( $this->func_name, $wgAjaxExportList ) ) {
			echo "-:{$this->func_name} not callable";
		} else {
			echo "+:";
			$result = call_user_func_array($this->func_name, $this->args);
			header( 'Content-Type: text/html; charset=utf-8', true );
			$wgAjaxCachePolicy->writeHeader();
			echo $result;
		}
		wfProfileOut( 'AjaxDispatcher::performAction' );
		exit;
	}
}

?>