Updated Dutch (nl) messages file, sent by Siebrand.
[mediawiki.git] / includes / AjaxDispatcher.php
blobce10eecd85fad6c328be1d519d74f666f7e15135
1 <?php
3 if( !defined( 'MEDIAWIKI' ) )
4 die( 1 );
6 if ( ! $wgUseAjax ) {
7 die( 1 );
10 require_once( 'AjaxFunctions.php' );
11 require_once( 'AjaxResponse.php' );
13 class AjaxDispatcher {
14 var $mode;
15 var $func_name;
16 var $args;
18 function AjaxDispatcher() {
19 wfProfileIn( 'AjaxDispatcher::AjaxDispatcher' );
21 $this->mode = "";
23 if (! empty($_GET["rs"])) {
24 $this->mode = "get";
27 if (!empty($_POST["rs"])) {
28 $this->mode = "post";
31 if ($this->mode == "get") {
32 $this->func_name = $_GET["rs"];
33 if (! empty($_GET["rsargs"])) {
34 $this->args = $_GET["rsargs"];
35 } else {
36 $this->args = array();
38 } else {
39 $this->func_name = $_POST["rs"];
40 if (! empty($_POST["rsargs"])) {
41 $this->args = $_POST["rsargs"];
42 } else {
43 $this->args = array();
46 wfProfileOut( 'AjaxDispatcher::AjaxDispatcher' );
49 function performAction() {
50 global $wgAjaxExportList, $wgOut;
52 if ( empty( $this->mode ) ) {
53 return;
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}";
60 } else {
61 try {
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";
68 else {
69 if ( is_string( $result ) ) {
70 $result= new AjaxResponse( $result );
73 $result->sendHeaders();
74 $result->printText();
77 } catch (Exception $e) {
78 if (!headers_sent()) {
79 header( 'Status: 500 Internal Error', true, 500 );
80 print $e->getMessage();
81 } else {
82 print $e->getMessage();
87 wfProfileOut( 'AjaxDispatcher::performAction' );
88 $wgOut = null;