summaryrefslogtreecommitdiff
path: root/includes/AjaxDispatcher.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/AjaxDispatcher.php')
-rw-r--r--includes/AjaxDispatcher.php60
1 files changed, 34 insertions, 26 deletions
diff --git a/includes/AjaxDispatcher.php b/includes/AjaxDispatcher.php
index 2084c366..618c2736 100644
--- a/includes/AjaxDispatcher.php
+++ b/includes/AjaxDispatcher.php
@@ -1,36 +1,22 @@
<?php
-//$wgRequestTime = microtime();
-
-// unset( $IP );
-// @ini_set( 'allow_url_fopen', 0 ); # For security...
-
-# Valid web server entry point, enable includes.
-# Please don't move this line to includes/Defines.php. This line essentially defines
-# a valid entry point. If you put it in includes/Defines.php, then any script that includes
-# it becomes an entry point, thereby defeating its purpose.
-// define( 'MEDIAWIKI', true );
-// require_once( './includes/Defines.php' );
-// require_once( './LocalSettings.php' );
-// require_once( 'includes/Setup.php' );
-require_once( 'AjaxFunctions.php' );
+if( !defined( 'MEDIAWIKI' ) )
+ die( 1 );
if ( ! $wgUseAjax ) {
die( 1 );
}
+require_once( 'AjaxFunctions.php' );
+
class AjaxDispatcher {
var $mode;
var $func_name;
var $args;
function AjaxDispatcher() {
- global $wgAjaxCachePolicy;
-
wfProfileIn( 'AjaxDispatcher::AjaxDispatcher' );
- $wgAjaxCachePolicy = new AjaxCachePolicy();
-
$this->mode = "";
if (! empty($_GET["rs"])) {
@@ -60,23 +46,45 @@ class AjaxDispatcher {
}
function performAction() {
- global $wgAjaxCachePolicy, $wgAjaxExportList;
+ global $wgAjaxExportList, $wgOut;
+
if ( empty( $this->mode ) ) {
return;
}
wfProfileIn( 'AjaxDispatcher::performAction' );
if (! in_array( $this->func_name, $wgAjaxExportList ) ) {
- echo "-:{$this->func_name} not callable";
+ header( 'Status: 400 Bad Request', true, 400 );
+ echo "unknown function {$this->func_name}";
} else {
- echo "+:";
- $result = call_user_func_array($this->func_name, $this->args);
- header( 'Content-Type: text/html; charset=utf-8', true );
- $wgAjaxCachePolicy->writeHeader();
- echo $result;
+ try {
+ $result = call_user_func_array($this->func_name, $this->args);
+
+ if ( $result === false || $result === NULL ) {
+ header( 'Status: 500 Internal Error', true, 500 );
+ echo "{$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()) {
+ header( 'Status: 500 Internal Error', true, 500 );
+ print $e->getMessage();
+ } else {
+ print $e->getMessage();
+ }
+ }
}
+
wfProfileOut( 'AjaxDispatcher::performAction' );
- exit;
+ $wgOut = null;
}
}