3 if( !defined( 'MEDIAWIKI' ) )
10 require_once( 'AjaxFunctions.php' );
13 * @todo Document - e.g. Provide top-level description of this class.
16 class AjaxDispatcher
{
21 function __construct() {
22 wfProfileIn( __METHOD__
);
26 if (! empty($_GET["rs"])) {
30 if (!empty($_POST["rs"])) {
34 if ($this->mode
== "get") {
35 $this->func_name
= isset( $_GET["rs"] ) ?
$_GET["rs"] : '';
36 if (! empty($_GET["rsargs"])) {
37 $this->args
= $_GET["rsargs"];
39 $this->args
= array();
42 $this->func_name
= isset( $_POST["rs"] ) ?
$_POST["rs"] : '';
43 if (! empty($_POST["rsargs"])) {
44 $this->args
= $_POST["rsargs"];
46 $this->args
= array();
49 wfProfileOut( __METHOD__
);
52 function performAction() {
53 global $wgAjaxExportList, $wgOut;
55 if ( empty( $this->mode
) ) {
58 wfProfileIn( __METHOD__
);
60 if (! in_array( $this->func_name
, $wgAjaxExportList ) ) {
61 wfHttpError( 400, 'Bad Request',
62 "unknown function " . (string) $this->func_name
);
65 $result = call_user_func_array($this->func_name
, $this->args
);
67 if ( $result === false ||
$result === NULL ) {
68 wfHttpError( 500, 'Internal Error',
69 "{$this->func_name} returned no data" );
72 if ( is_string( $result ) ) {
73 $result= new AjaxResponse( $result );
76 $result->sendHeaders();
80 } catch (Exception
$e) {
81 if (!headers_sent()) {
82 wfHttpError( 500, 'Internal Error',
85 print $e->getMessage();
90 wfProfileOut( __METHOD__
);