whitespaces killing
[lhc/web/wiklou.git] / includes / AjaxDispatcher.php
1 <?php
2
3 if( !defined( 'MEDIAWIKI' ) )
4 die( 1 );
5
6 if ( ! $wgUseAjax ) {
7 die( 1 );
8 }
9
10 require_once( 'AjaxFunctions.php' );
11
12 class AjaxDispatcher {
13 var $mode;
14 var $func_name;
15 var $args;
16
17 function AjaxDispatcher() {
18 wfProfileIn( __METHOD__ );
19
20 $this->mode = "";
21
22 if (! empty($_GET["rs"])) {
23 $this->mode = "get";
24 }
25
26 if (!empty($_POST["rs"])) {
27 $this->mode = "post";
28 }
29
30 if ($this->mode == "get") {
31 $this->func_name = isset( $_GET["rs"] ) ? $_GET["rs"] : '';
32 if (! empty($_GET["rsargs"])) {
33 $this->args = $_GET["rsargs"];
34 } else {
35 $this->args = array();
36 }
37 } else {
38 $this->func_name = isset( $_POST["rs"] ) ? $_POST["rs"] : '';
39 if (! empty($_POST["rsargs"])) {
40 $this->args = $_POST["rsargs"];
41 } else {
42 $this->args = array();
43 }
44 }
45 wfProfileOut( __METHOD__ );
46 }
47
48 function performAction() {
49 global $wgAjaxExportList, $wgOut;
50
51 if ( empty( $this->mode ) ) {
52 return;
53 }
54 wfProfileIn( __METHOD__ );
55
56 if (! in_array( $this->func_name, $wgAjaxExportList ) ) {
57 header( 'Status: 400 Bad Request', true, 400 );
58 print "unknown function " . htmlspecialchars( (string) $this->func_name );
59 } else {
60 try {
61 $result = call_user_func_array($this->func_name, $this->args);
62
63 if ( $result === false || $result === NULL ) {
64 header( 'Status: 500 Internal Error', true, 500 );
65 echo "{$this->func_name} returned no data";
66 }
67 else {
68 if ( is_string( $result ) ) {
69 $result= new AjaxResponse( $result );
70 }
71
72 $result->sendHeaders();
73 $result->printText();
74 }
75
76 } catch (Exception $e) {
77 if (!headers_sent()) {
78 header( 'Status: 500 Internal Error', true, 500 );
79 print $e->getMessage();
80 } else {
81 print $e->getMessage();
82 }
83 }
84 }
85
86 wfProfileOut( __METHOD__ );
87 $wgOut = null;
88 }
89 }
90
91 ?>