disable ipv6 cruft
[mediawiki.git] / includes / AjaxDispatcher.php
blobbb4709bb40afb108885c8f5fc42868b1253fea5f
1 <?php
3 if( !defined( 'MEDIAWIKI' ) )
4 die( 1 );
6 if ( ! $wgUseAjax ) {
7 die( 1 );
10 require_once( 'AjaxFunctions.php' );
12 /**
13 * @todo Document - e.g. Provide top-level description of this class.
15 class AjaxDispatcher {
16 var $mode;
17 var $func_name;
18 var $args;
20 function __construct() {
21 wfProfileIn( __METHOD__ );
23 $this->mode = "";
25 if (! empty($_GET["rs"])) {
26 $this->mode = "get";
29 if (!empty($_POST["rs"])) {
30 $this->mode = "post";
33 if ($this->mode == "get") {
34 $this->func_name = isset( $_GET["rs"] ) ? $_GET["rs"] : '';
35 if (! empty($_GET["rsargs"])) {
36 $this->args = $_GET["rsargs"];
37 } else {
38 $this->args = array();
40 } else {
41 $this->func_name = isset( $_POST["rs"] ) ? $_POST["rs"] : '';
42 if (! empty($_POST["rsargs"])) {
43 $this->args = $_POST["rsargs"];
44 } else {
45 $this->args = array();
48 wfProfileOut( __METHOD__ );
51 function performAction() {
52 global $wgAjaxExportList, $wgOut;
54 if ( empty( $this->mode ) ) {
55 return;
57 wfProfileIn( __METHOD__ );
59 if (! in_array( $this->func_name, $wgAjaxExportList ) ) {
60 wfHttpError( 400, 'Bad Request',
61 "unknown function " . (string) $this->func_name );
62 } else {
63 try {
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" );
70 else {
71 if ( is_string( $result ) ) {
72 $result= new AjaxResponse( $result );
75 $result->sendHeaders();
76 $result->printText();
79 } catch (Exception $e) {
80 if (!headers_sent()) {
81 wfHttpError( 500, 'Internal Error',
82 $e->getMessage() );
83 } else {
84 print $e->getMessage();
89 wfProfileOut( __METHOD__ );
90 $wgOut = null;