- echo "+:";
- $result = call_user_func_array($this->func_name, $this->args);
- header( 'Content-Type: text/html; charset=utf-8', true );
- $wgAjaxCachePolicy->writeHeader();
- echo $result;
+ if ( strpos( $this->func_name, '::' ) !== false ) {
+ $func = explode( '::', $this->func_name, 2 );
+ } else {
+ $func = $this->func_name;
+ }
+ try {
+ $result = call_user_func_array($func, $this->args);
+
+ if ( $result === false || $result === NULL ) {
+ wfHttpError( 500, 'Internal Error',
+ "{$this->func_name} returned no data" );
+ }
+ else {
+ if ( is_string( $result ) ) {
+ $result= new AjaxResponse( $result );
+ }
+
+ $result->sendHeaders();
+ $result->printText();
+ }
+
+ } catch (Exception $e) {
+ if (!headers_sent()) {
+ wfHttpError( 500, 'Internal Error',
+ $e->getMessage() );
+ } else {
+ print $e->getMessage();
+ }
+ }