2006-03-27 18:53:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
2006-08-29 15:43:34 +00:00
|
|
|
if( !defined( 'MEDIAWIKI' ) )
|
|
|
|
|
die( 1 );
|
2006-03-27 18:53:15 +00:00
|
|
|
|
|
|
|
|
if ( ! $wgUseAjax ) {
|
2006-06-07 04:15:58 +00:00
|
|
|
die( 1 );
|
2006-03-27 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
2006-08-29 15:43:34 +00:00
|
|
|
require_once( 'AjaxFunctions.php' );
|
|
|
|
|
|
2006-03-27 18:53:15 +00:00
|
|
|
class AjaxDispatcher {
|
|
|
|
|
var $mode;
|
|
|
|
|
var $func_name;
|
|
|
|
|
var $args;
|
|
|
|
|
|
2007-01-20 13:34:31 +00:00
|
|
|
function __construct() {
|
2006-12-26 23:53:34 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2006-03-27 18:53:15 +00:00
|
|
|
|
|
|
|
|
$this->mode = "";
|
|
|
|
|
|
|
|
|
|
if (! empty($_GET["rs"])) {
|
|
|
|
|
$this->mode = "get";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($_POST["rs"])) {
|
|
|
|
|
$this->mode = "post";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->mode == "get") {
|
2007-01-09 09:51:53 +00:00
|
|
|
$this->func_name = isset( $_GET["rs"] ) ? $_GET["rs"] : '';
|
2006-03-27 18:53:15 +00:00
|
|
|
if (! empty($_GET["rsargs"])) {
|
|
|
|
|
$this->args = $_GET["rsargs"];
|
|
|
|
|
} else {
|
|
|
|
|
$this->args = array();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2007-01-09 09:51:53 +00:00
|
|
|
$this->func_name = isset( $_POST["rs"] ) ? $_POST["rs"] : '';
|
2006-03-27 18:53:15 +00:00
|
|
|
if (! empty($_POST["rsargs"])) {
|
|
|
|
|
$this->args = $_POST["rsargs"];
|
|
|
|
|
} else {
|
|
|
|
|
$this->args = array();
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-12-26 23:53:34 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2006-03-27 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function performAction() {
|
2006-08-29 15:43:34 +00:00
|
|
|
global $wgAjaxExportList, $wgOut;
|
2007-01-09 20:25:28 +00:00
|
|
|
|
2006-03-27 18:53:15 +00:00
|
|
|
if ( empty( $this->mode ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2006-12-26 23:53:34 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2006-03-27 18:53:15 +00:00
|
|
|
|
|
|
|
|
if (! in_array( $this->func_name, $wgAjaxExportList ) ) {
|
2007-02-21 01:02:47 +00:00
|
|
|
wfHttpError( 400, 'Bad Request',
|
|
|
|
|
"unknown function " . (string) $this->func_name );
|
2006-03-27 18:53:15 +00:00
|
|
|
} else {
|
2006-08-29 15:43:34 +00:00
|
|
|
try {
|
|
|
|
|
$result = call_user_func_array($this->func_name, $this->args);
|
2007-01-09 20:25:28 +00:00
|
|
|
|
2006-08-29 15:43:34 +00:00
|
|
|
if ( $result === false || $result === NULL ) {
|
2007-02-21 01:02:47 +00:00
|
|
|
wfHttpError( 500, 'Internal Error',
|
|
|
|
|
"{$this->func_name} returned no data" );
|
2006-08-29 15:43:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if ( is_string( $result ) ) {
|
|
|
|
|
$result= new AjaxResponse( $result );
|
|
|
|
|
}
|
2007-01-09 20:25:28 +00:00
|
|
|
|
2006-08-29 15:43:34 +00:00
|
|
|
$result->sendHeaders();
|
|
|
|
|
$result->printText();
|
|
|
|
|
}
|
2006-12-26 23:53:34 +00:00
|
|
|
|
2006-08-29 15:43:34 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
if (!headers_sent()) {
|
2007-02-21 01:02:47 +00:00
|
|
|
wfHttpError( 500, 'Internal Error',
|
|
|
|
|
$e->getMessage() );
|
2006-08-29 15:43:34 +00:00
|
|
|
} else {
|
|
|
|
|
print $e->getMessage();
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-03-27 18:53:15 +00:00
|
|
|
}
|
2007-01-09 20:25:28 +00:00
|
|
|
|
2006-12-26 23:53:34 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2006-08-24 17:01:45 +00:00
|
|
|
$wgOut = null;
|
2006-03-27 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|