3 if( !defined( 'MEDIAWIKI' ) )
10 require_once( 'AjaxFunctions.php' );
11 require_once( 'AjaxResponse.php' );
13 class AjaxDispatcher
{
18 function AjaxDispatcher() {
19 wfProfileIn( 'AjaxDispatcher::AjaxDispatcher' );
23 if (! empty($_GET["rs"])) {
27 if (!empty($_POST["rs"])) {
31 if ($this->mode
== "get") {
32 $this->func_name
= $_GET["rs"];
33 if (! empty($_GET["rsargs"])) {
34 $this->args
= $_GET["rsargs"];
36 $this->args
= array();
39 $this->func_name
= $_POST["rs"];
40 if (! empty($_POST["rsargs"])) {
41 $this->args
= $_POST["rsargs"];
43 $this->args
= array();
46 wfProfileOut( 'AjaxDispatcher::AjaxDispatcher' );
49 function performAction() {
50 global $wgAjaxExportList, $wgOut;
52 if ( empty( $this->mode
) ) {
55 wfProfileIn( 'AjaxDispatcher::performAction' );
57 if (! in_array( $this->func_name
, $wgAjaxExportList ) ) {
58 header( 'Status: 400 Bad Request', true, 400 );
59 echo "unknown function {$this->func_name}";
62 $result = call_user_func_array($this->func_name
, $this->args
);
64 if ( $result === false ||
$result === NULL ) {
65 header( 'Status: 500 Internal Error', true, 500 );
66 echo "{$this->func_name} returned no data";
69 if ( is_string( $result ) ) {
70 $result= new AjaxResponse( $result );
73 $result->sendHeaders();
77 } catch (Exception
$e) {
78 if (!headers_sent()) {
79 header( 'Status: 500 Internal Error', true, 500 );
80 print $e->getMessage();
82 print $e->getMessage();
87 wfProfileOut( 'AjaxDispatcher::performAction' );