3 if( !defined( 'MEDIAWIKI' ) )
10 require_once( 'AjaxFunctions.php' );
12 class AjaxDispatcher
{
17 function AjaxDispatcher() {
18 wfProfileIn( 'AjaxDispatcher::AjaxDispatcher' );
22 if (! empty($_GET["rs"])) {
26 if (!empty($_POST["rs"])) {
30 if ($this->mode
== "get") {
31 $this->func_name
= $_GET["rs"];
32 if (! empty($_GET["rsargs"])) {
33 $this->args
= $_GET["rsargs"];
35 $this->args
= array();
38 $this->func_name
= $_POST["rs"];
39 if (! empty($_POST["rsargs"])) {
40 $this->args
= $_POST["rsargs"];
42 $this->args
= array();
45 wfProfileOut( 'AjaxDispatcher::AjaxDispatcher' );
48 function performAction() {
49 global $wgAjaxExportList, $wgOut;
51 if ( empty( $this->mode
) ) {
54 wfProfileIn( 'AjaxDispatcher::performAction' );
56 if (! in_array( $this->func_name
, $wgAjaxExportList ) ) {
57 header( 'Status: 400 Bad Request', true, 400 );
58 echo "unknown function {$this->func_name}";
61 $result = call_user_func_array($this->func_name
, $this->args
);
63 if ( $result === false ||
$result === NULL ) {
64 header( 'Status: 500 Internal Error', true, 500 );
65 echo "{$this->func_name} returned no data";
68 if ( is_string( $result ) ) {
69 $result= new AjaxResponse( $result );
72 $result->sendHeaders();
76 } catch (Exception
$e) {
77 if (!headers_sent()) {
78 header( 'Status: 500 Internal Error', true, 500 );
79 print $e->getMessage();
81 print $e->getMessage();
86 wfProfileOut( 'AjaxDispatcher::performAction' );