2006-03-27 18:53:15 +00:00
|
|
|
<?php
|
2007-05-05 00:06:20 +00:00
|
|
|
/**
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @defgroup Ajax Ajax
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Ajax
|
2007-05-05 00:06:20 +00:00
|
|
|
* Handle ajax requests and send them to the proper handler.
|
|
|
|
|
*/
|
2006-03-27 18:53:15 +00:00
|
|
|
|
2007-04-04 05:22:37 +00:00
|
|
|
/**
|
2007-04-24 06:53:31 +00:00
|
|
|
* Object-Oriented Ajax functions.
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Ajax
|
2007-04-04 05:22:37 +00:00
|
|
|
*/
|
2006-03-27 18:53:15 +00:00
|
|
|
class AjaxDispatcher {
|
2010-08-13 21:39:51 +00:00
|
|
|
/** The way the request was made, either a 'get' or a 'post' */
|
|
|
|
|
private $mode;
|
|
|
|
|
|
2007-05-05 00:06:20 +00:00
|
|
|
/** Name of the requested handler */
|
2010-08-13 21:39:51 +00:00
|
|
|
private $func_name;
|
2007-05-05 00:06:20 +00:00
|
|
|
|
|
|
|
|
/** Arguments passed */
|
2010-08-13 21:39:51 +00:00
|
|
|
private $args;
|
2006-03-27 18:53:15 +00:00
|
|
|
|
2007-05-05 00:06:20 +00:00
|
|
|
/** Load up our object with user supplied data */
|
2010-08-13 21:39:51 +00:00
|
|
|
function __construct() {
|
2006-12-26 23:53:34 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2006-03-27 18:53:15 +00:00
|
|
|
|
2010-08-13 21:39:51 +00:00
|
|
|
$this->mode = "";
|
|
|
|
|
|
|
|
|
|
if ( ! empty( $_GET["rs"] ) ) {
|
|
|
|
|
$this->mode = "get";
|
2006-03-27 18:53:15 +00:00
|
|
|
}
|
2010-08-13 21:39:51 +00:00
|
|
|
|
|
|
|
|
if ( !empty( $_POST["rs"] ) ) {
|
|
|
|
|
$this->mode = "post";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch( $this->mode ) {
|
|
|
|
|
case 'get':
|
|
|
|
|
$this->func_name = isset( $_GET["rs"] ) ? $_GET["rs"] : '';
|
|
|
|
|
if ( ! empty( $_GET["rsargs"] ) ) {
|
|
|
|
|
$this->args = $_GET["rsargs"];
|
|
|
|
|
} else {
|
|
|
|
|
$this->args = array();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'post':
|
|
|
|
|
$this->func_name = isset( $_POST["rs"] ) ? $_POST["rs"] : '';
|
|
|
|
|
if ( ! empty( $_POST["rsargs"] ) ) {
|
|
|
|
|
$this->args = $_POST["rsargs"];
|
|
|
|
|
} else {
|
|
|
|
|
$this->args = array();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return;
|
|
|
|
|
# Or we could throw an exception:
|
|
|
|
|
# throw new MWException( __METHOD__ . ' called without any data (mode empty).' );
|
2006-03-27 18:53:15 +00:00
|
|
|
}
|
2007-05-05 00:06:20 +00:00
|
|
|
|
2006-12-26 23:53:34 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2006-03-27 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-05 00:06:20 +00:00
|
|
|
/** Pass the request to our internal function.
|
|
|
|
|
* BEWARE! Data are passed as they have been supplied by the user,
|
|
|
|
|
* they should be carefully handled in the function processing the
|
|
|
|
|
* request.
|
|
|
|
|
*/
|
2006-03-27 18:53:15 +00:00
|
|
|
function performAction() {
|
2011-11-28 23:18:55 +00:00
|
|
|
global $wgAjaxExportList, $wgOut, $wgUser;
|
2007-01-09 20:25:28 +00:00
|
|
|
|
2010-08-13 21:39:51 +00:00
|
|
|
if ( empty( $this->mode ) ) {
|
2006-03-27 18:53:15 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2010-02-14 22:07:30 +00:00
|
|
|
|
2006-12-26 23:53:34 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2006-03-27 18:53:15 +00:00
|
|
|
|
2010-02-14 22:07:30 +00:00
|
|
|
if ( ! in_array( $this->func_name, $wgAjaxExportList ) ) {
|
2008-06-28 19:40:14 +00:00
|
|
|
wfDebug( __METHOD__ . ' Bad Request for unknown function ' . $this->func_name . "\n" );
|
|
|
|
|
|
2010-05-30 14:28:54 +00:00
|
|
|
wfHttpError(
|
|
|
|
|
400,
|
|
|
|
|
'Bad Request',
|
|
|
|
|
"unknown function " . (string) $this->func_name
|
|
|
|
|
);
|
2011-11-28 23:18:55 +00:00
|
|
|
} elseif ( !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true )
|
|
|
|
|
&& !$wgUser->isAllowed( 'read' ) )
|
|
|
|
|
{
|
|
|
|
|
wfHttpError(
|
|
|
|
|
403,
|
|
|
|
|
'Forbidden',
|
|
|
|
|
'You must log in to view pages.' );
|
2006-03-27 18:53:15 +00:00
|
|
|
} else {
|
2008-06-28 19:40:14 +00:00
|
|
|
wfDebug( __METHOD__ . ' dispatching ' . $this->func_name . "\n" );
|
|
|
|
|
|
2007-07-01 18:24:47 +00:00
|
|
|
if ( strpos( $this->func_name, '::' ) !== false ) {
|
|
|
|
|
$func = explode( '::', $this->func_name, 2 );
|
|
|
|
|
} else {
|
|
|
|
|
$func = $this->func_name;
|
|
|
|
|
}
|
2010-05-30 14:28:54 +00:00
|
|
|
|
2006-08-29 15:43:34 +00:00
|
|
|
try {
|
2010-02-14 22:07:30 +00:00
|
|
|
$result = call_user_func_array( $func, $this->args );
|
2007-01-09 20:25:28 +00:00
|
|
|
|
2009-12-11 21:07:27 +00:00
|
|
|
if ( $result === false || $result === null ) {
|
2010-02-14 22:07:30 +00:00
|
|
|
wfDebug( __METHOD__ . ' ERROR while dispatching '
|
|
|
|
|
. $this->func_name . "(" . var_export( $this->args, true ) . "): "
|
2008-06-28 19:40:14 +00:00
|
|
|
. "no data returned\n" );
|
|
|
|
|
|
2007-02-21 01:02:47 +00:00
|
|
|
wfHttpError( 500, 'Internal Error',
|
|
|
|
|
"{$this->func_name} returned no data" );
|
2010-05-30 14:28:54 +00:00
|
|
|
} else {
|
2006-08-29 15:43:34 +00:00
|
|
|
if ( is_string( $result ) ) {
|
2010-02-14 22:07:30 +00:00
|
|
|
$result = new AjaxResponse( $result );
|
2006-08-29 15:43:34 +00:00
|
|
|
}
|
2007-01-09 20:25:28 +00:00
|
|
|
|
2006-08-29 15:43:34 +00:00
|
|
|
$result->sendHeaders();
|
|
|
|
|
$result->printText();
|
2008-06-28 19:40:14 +00:00
|
|
|
|
|
|
|
|
wfDebug( __METHOD__ . ' dispatch complete for ' . $this->func_name . "\n" );
|
2006-08-29 15:43:34 +00:00
|
|
|
}
|
2010-02-14 22:07:30 +00:00
|
|
|
} catch ( Exception $e ) {
|
|
|
|
|
wfDebug( __METHOD__ . ' ERROR while dispatching '
|
|
|
|
|
. $this->func_name . "(" . var_export( $this->args, true ) . "): "
|
|
|
|
|
. get_class( $e ) . ": " . $e->getMessage() . "\n" );
|
2008-06-28 19:40:14 +00:00
|
|
|
|
2010-02-14 22:07:30 +00:00
|
|
|
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-08-24 17:01:45 +00:00
|
|
|
$wgOut = null;
|
2011-02-10 16:39:53 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2006-03-27 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
}
|