Remove unneeded commented code, that I accidently added in r82461
[mediawiki.git] / includes / AjaxDispatcher.php
blob0f1d74b5989632a7ddafcb243af07398dd7be07b
1 <?php
2 /**
3 * @defgroup Ajax Ajax
5 * @file
6 * @ingroup Ajax
7 * Handle ajax requests and send them to the proper handler.
8 */
10 if ( !defined( 'MEDIAWIKI' ) ) {
11 die( 1 );
14 require_once( 'AjaxFunctions.php' );
16 /**
17 * Object-Oriented Ajax functions.
18 * @ingroup Ajax
20 class AjaxDispatcher {
21 /** The way the request was made, either a 'get' or a 'post' */
22 private $mode;
24 /** Name of the requested handler */
25 private $func_name;
27 /** Arguments passed */
28 private $args;
30 /** Load up our object with user supplied data */
31 function __construct() {
32 wfProfileIn( __METHOD__ );
34 $this->mode = "";
36 if ( ! empty( $_GET["rs"] ) ) {
37 $this->mode = "get";
40 if ( !empty( $_POST["rs"] ) ) {
41 $this->mode = "post";
44 switch( $this->mode ) {
45 case 'get':
46 $this->func_name = isset( $_GET["rs"] ) ? $_GET["rs"] : '';
47 if ( ! empty( $_GET["rsargs"] ) ) {
48 $this->args = $_GET["rsargs"];
49 } else {
50 $this->args = array();
52 break;
53 case 'post':
54 $this->func_name = isset( $_POST["rs"] ) ? $_POST["rs"] : '';
55 if ( ! empty( $_POST["rsargs"] ) ) {
56 $this->args = $_POST["rsargs"];
57 } else {
58 $this->args = array();
60 break;
61 default:
62 wfProfileOut( __METHOD__ );
63 return;
64 # Or we could throw an exception:
65 # throw new MWException( __METHOD__ . ' called without any data (mode empty).' );
68 wfProfileOut( __METHOD__ );
71 /** Pass the request to our internal function.
72 * BEWARE! Data are passed as they have been supplied by the user,
73 * they should be carefully handled in the function processing the
74 * request.
76 function performAction() {
77 global $wgAjaxExportList, $wgOut;
79 if ( empty( $this->mode ) ) {
80 return;
83 wfProfileIn( __METHOD__ );
85 if ( ! in_array( $this->func_name, $wgAjaxExportList ) ) {
86 wfDebug( __METHOD__ . ' Bad Request for unknown function ' . $this->func_name . "\n" );
88 wfHttpError(
89 400,
90 'Bad Request',
91 "unknown function " . (string) $this->func_name
93 } else {
94 wfDebug( __METHOD__ . ' dispatching ' . $this->func_name . "\n" );
96 if ( strpos( $this->func_name, '::' ) !== false ) {
97 $func = explode( '::', $this->func_name, 2 );
98 } else {
99 $func = $this->func_name;
102 try {
103 $result = call_user_func_array( $func, $this->args );
105 if ( $result === false || $result === null ) {
106 wfDebug( __METHOD__ . ' ERROR while dispatching '
107 . $this->func_name . "(" . var_export( $this->args, true ) . "): "
108 . "no data returned\n" );
110 wfHttpError( 500, 'Internal Error',
111 "{$this->func_name} returned no data" );
112 } else {
113 if ( is_string( $result ) ) {
114 $result = new AjaxResponse( $result );
117 $result->sendHeaders();
118 $result->printText();
120 wfDebug( __METHOD__ . ' dispatch complete for ' . $this->func_name . "\n" );
122 } catch ( Exception $e ) {
123 wfDebug( __METHOD__ . ' ERROR while dispatching '
124 . $this->func_name . "(" . var_export( $this->args, true ) . "): "
125 . get_class( $e ) . ": " . $e->getMessage() . "\n" );
127 if ( !headers_sent() ) {
128 wfHttpError( 500, 'Internal Error',
129 $e->getMessage() );
130 } else {
131 print $e->getMessage();
136 $wgOut = null;
137 wfProfileOut( __METHOD__ );