Yet more doc tweaks:
[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 /**
13 * @todo Document - e.g. Provide top-level description of this class.
14 * @addtogroup Ajax
15 */
16 class AjaxDispatcher {
17 var $mode;
18 var $func_name;
19 var $args;
20
21 function __construct() {
22 wfProfileIn( __METHOD__ );
23
24 $this->mode = "";
25
26 if (! empty($_GET["rs"])) {
27 $this->mode = "get";
28 }
29
30 if (!empty($_POST["rs"])) {
31 $this->mode = "post";
32 }
33
34 if ($this->mode == "get") {
35 $this->func_name = isset( $_GET["rs"] ) ? $_GET["rs"] : '';
36 if (! empty($_GET["rsargs"])) {
37 $this->args = $_GET["rsargs"];
38 } else {
39 $this->args = array();
40 }
41 } else {
42 $this->func_name = isset( $_POST["rs"] ) ? $_POST["rs"] : '';
43 if (! empty($_POST["rsargs"])) {
44 $this->args = $_POST["rsargs"];
45 } else {
46 $this->args = array();
47 }
48 }
49 wfProfileOut( __METHOD__ );
50 }
51
52 function performAction() {
53 global $wgAjaxExportList, $wgOut;
54
55 if ( empty( $this->mode ) ) {
56 return;
57 }
58 wfProfileIn( __METHOD__ );
59
60 if (! in_array( $this->func_name, $wgAjaxExportList ) ) {
61 wfHttpError( 400, 'Bad Request',
62 "unknown function " . (string) $this->func_name );
63 } else {
64 try {
65 $result = call_user_func_array($this->func_name, $this->args);
66
67 if ( $result === false || $result === NULL ) {
68 wfHttpError( 500, 'Internal Error',
69 "{$this->func_name} returned no data" );
70 }
71 else {
72 if ( is_string( $result ) ) {
73 $result= new AjaxResponse( $result );
74 }
75
76 $result->sendHeaders();
77 $result->printText();
78 }
79
80 } catch (Exception $e) {
81 if (!headers_sent()) {
82 wfHttpError( 500, 'Internal Error',
83 $e->getMessage() );
84 } else {
85 print $e->getMessage();
86 }
87 }
88 }
89
90 wfProfileOut( __METHOD__ );
91 $wgOut = null;
92 }
93 }
94
95 ?>