Old cached ParserOutput entries will have null for mHeadItems instead of an array.
[lhc/web/wiklou.git] / includes / AjaxDispatcher.php
1 <?php
2
3 if( !defined( 'MEDIAWIKI' ) )
4 die( 1 );
5
6 if ( ! $wgUseAjax ) {
7 die( 1 );
8 }
9
10 require_once( 'AjaxFunctions.php' );
11
12 /**
13 * @todo Document - e.g. Provide top-level description of this class.
14 */
15 class AjaxDispatcher {
16 var $mode;
17 var $func_name;
18 var $args;
19
20 function __construct() {
21 wfProfileIn( __METHOD__ );
22
23 $this->mode = "";
24
25 if (! empty($_GET["rs"])) {
26 $this->mode = "get";
27 }
28
29 if (!empty($_POST["rs"])) {
30 $this->mode = "post";
31 }
32
33 if ($this->mode == "get") {
34 $this->func_name = isset( $_GET["rs"] ) ? $_GET["rs"] : '';
35 if (! empty($_GET["rsargs"])) {
36 $this->args = $_GET["rsargs"];
37 } else {
38 $this->args = array();
39 }
40 } else {
41 $this->func_name = isset( $_POST["rs"] ) ? $_POST["rs"] : '';
42 if (! empty($_POST["rsargs"])) {
43 $this->args = $_POST["rsargs"];
44 } else {
45 $this->args = array();
46 }
47 }
48 wfProfileOut( __METHOD__ );
49 }
50
51 function performAction() {
52 global $wgAjaxExportList, $wgOut;
53
54 if ( empty( $this->mode ) ) {
55 return;
56 }
57 wfProfileIn( __METHOD__ );
58
59 if (! in_array( $this->func_name, $wgAjaxExportList ) ) {
60 wfHttpError( 400, 'Bad Request',
61 "unknown function " . (string) $this->func_name );
62 } else {
63 try {
64 $result = call_user_func_array($this->func_name, $this->args);
65
66 if ( $result === false || $result === NULL ) {
67 wfHttpError( 500, 'Internal Error',
68 "{$this->func_name} returned no data" );
69 }
70 else {
71 if ( is_string( $result ) ) {
72 $result= new AjaxResponse( $result );
73 }
74
75 $result->sendHeaders();
76 $result->printText();
77 }
78
79 } catch (Exception $e) {
80 if (!headers_sent()) {
81 wfHttpError( 500, 'Internal Error',
82 $e->getMessage() );
83 } else {
84 print $e->getMessage();
85 }
86 }
87 }
88
89 wfProfileOut( __METHOD__ );
90 $wgOut = null;
91 }
92 }
93
94 ?>