90f68ecb317676e8f25522d29c3b245e1dab8a55
3 if( !defined( 'MEDIAWIKI' ) ) {
11 require_once( 'AjaxFunctions.php' );
14 * @todo Document - e.g. Provide top-level description of this class.
17 class AjaxDispatcher
{
22 function __construct() {
23 wfProfileIn( __METHOD__
);
27 if (! empty($_GET["rs"])) {
31 if (!empty($_POST["rs"])) {
35 if ($this->mode
== "get") {
36 $this->func_name
= isset( $_GET["rs"] ) ?
$_GET["rs"] : '';
37 if (! empty($_GET["rsargs"])) {
38 $this->args
= $_GET["rsargs"];
40 $this->args
= array();
43 $this->func_name
= isset( $_POST["rs"] ) ?
$_POST["rs"] : '';
44 if (! empty($_POST["rsargs"])) {
45 $this->args
= $_POST["rsargs"];
47 $this->args
= array();
50 wfProfileOut( __METHOD__
);
53 function performAction() {
54 global $wgAjaxExportList, $wgOut;
56 if ( empty( $this->mode
) ) {
59 wfProfileIn( __METHOD__
);
61 if (! in_array( $this->func_name
, $wgAjaxExportList ) ) {
62 wfHttpError( 400, 'Bad Request',
63 "unknown function " . (string) $this->func_name
);
66 $result = call_user_func_array($this->func_name
, $this->args
);
68 if ( $result === false ||
$result === NULL ) {
69 wfHttpError( 500, 'Internal Error',
70 "{$this->func_name} returned no data" );
73 if ( is_string( $result ) ) {
74 $result= new AjaxResponse( $result );
77 $result->sendHeaders();
81 } catch (Exception
$e) {
82 if (!headers_sent()) {
83 wfHttpError( 500, 'Internal Error',
86 print $e->getMessage();
91 wfProfileOut( __METHOD__
);