3 if( !defined( 'MEDIAWIKI' ) )
10 require_once( 'AjaxFunctions.php' );
13 * @todo Document - e.g. Provide top-level description of this class.
15 class AjaxDispatcher
{
20 function __construct() {
21 wfProfileIn( __METHOD__
);
25 if (! empty($_GET["rs"])) {
29 if (!empty($_POST["rs"])) {
33 if ($this->mode
== "get") {
34 $this->func_name
= isset( $_GET["rs"] ) ?
$_GET["rs"] : '';
35 if (! empty($_GET["rsargs"])) {
36 $this->args
= $_GET["rsargs"];
38 $this->args
= array();
41 $this->func_name
= isset( $_POST["rs"] ) ?
$_POST["rs"] : '';
42 if (! empty($_POST["rsargs"])) {
43 $this->args
= $_POST["rsargs"];
45 $this->args
= array();
48 wfProfileOut( __METHOD__
);
51 function performAction() {
52 global $wgAjaxExportList, $wgOut;
54 if ( empty( $this->mode
) ) {
57 wfProfileIn( __METHOD__
);
59 if (! in_array( $this->func_name
, $wgAjaxExportList ) ) {
60 wfHttpError( 400, 'Bad Request',
61 "unknown function " . (string) $this->func_name
);
64 $result = call_user_func_array($this->func_name
, $this->args
);
66 if ( $result === false ||
$result === NULL ) {
67 wfHttpError( 500, 'Internal Error',
68 "{$this->func_name} returned no data" );
71 if ( is_string( $result ) ) {
72 $result= new AjaxResponse( $result );
75 $result->sendHeaders();
79 } catch (Exception
$e) {
80 if (!headers_sent()) {
81 wfHttpError( 500, 'Internal Error',
84 print $e->getMessage();
89 wfProfileOut( __METHOD__
);