r70960 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70959‎ | r70960 | r70961 >
Date:14:34, 12 August 2010
Author:demon
Status:reverted (Comments)
Tags:
Comment:
AjaxDispatcher, now ~30 lines shorter and not using $_GET or $_POST
Modified paths:
  • /trunk/phase3/includes/AjaxDispatcher.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/AjaxDispatcher.php
@@ -18,53 +18,25 @@
1919 * @ingroup Ajax
2020 */
2121 class AjaxDispatcher {
22 - /** The way the request was made, either a 'get' or a 'post' */
23 - private $mode;
24 -
2522 /** Name of the requested handler */
26 - private $func_name;
 23+ private $func_name = null;
2724
2825 /** Arguments passed */
29 - private $args;
 26+ private $args = array();
3027
3128 /** Load up our object with user supplied data */
32 - function __construct() {
 29+ public function __construct( WebRequest $req ) {
3330 wfProfileIn( __METHOD__ );
3431
35 - $this->mode = "";
36 -
37 - if ( ! empty( $_GET["rs"] ) ) {
38 - $this->mode = "get";
 32+ $rs = $req->getVal( 'rs' );
 33+ if( $rs !== null ) {
 34+ $this->func_name = $rs;
3935 }
40 -
41 - if ( !empty( $_POST["rs"] ) ) {
42 - $this->mode = "post";
 36+ $rsargs = $req->getVal( 'rsargs' );
 37+ if( $rsargs !== null ) {
 38+ $this->args = $rsargs;
4339 }
4440
45 - switch( $this->mode ) {
46 - case 'get':
47 - $this->func_name = isset( $_GET["rs"] ) ? $_GET["rs"] : '';
48 - if ( ! empty( $_GET["rsargs"] ) ) {
49 - $this->args = $_GET["rsargs"];
50 - } else {
51 - $this->args = array();
52 - }
53 - break;
54 - case 'post':
55 - $this->func_name = isset( $_POST["rs"] ) ? $_POST["rs"] : '';
56 - if ( ! empty( $_POST["rsargs"] ) ) {
57 - $this->args = $_POST["rsargs"];
58 - } else {
59 - $this->args = array();
60 - }
61 - break;
62 - default:
63 - wfProfileOut( __METHOD__ );
64 - return;
65 - # Or we could throw an exception:
66 - # throw new MWException( __METHOD__ . ' called without any data (mode empty).' );
67 - }
68 -
6941 wfProfileOut( __METHOD__ );
7042 }
7143
@@ -76,7 +48,7 @@
7749 function performAction() {
7850 global $wgAjaxExportList, $wgOut;
7951
80 - if ( empty( $this->mode ) ) {
 52+ if ( is_null( $this->func_name ) ) {
8153 return;
8254 }
8355
Index: trunk/phase3/index.php
@@ -68,7 +68,7 @@
6969 #
7070 if( $wgUseAjax && $action == 'ajax' ) {
7171 require_once( $IP . '/includes/AjaxDispatcher.php' );
72 - $dispatcher = new AjaxDispatcher();
 72+ $dispatcher = new AjaxDispatcher( $wgRequest );
7373 $dispatcher->performAction();
7474 $mediaWiki->restInPeace();
7575 exit;

Follow-up revisions

RevisionCommit summaryAuthorDate
r71050Revert r70960 "AjaxDispatcher, now ~30 lines shorter and not using $_GET or $...simetrical21:39, 13 August 2010

Comments

#Comment by Simetrical (talk | contribs)   16:22, 15 August 2010

I can't find where I posted the error info . . . maybe I didn't. The error was when visiting the URL

//localhost/git-trunk/phase3/index.php?action=ajax&rs=efCategoryTreeAjaxWrapper&rsargs[]=Test&rsargs[]={%22mode%22:%200,%20%22hideprefix%22:%2020,%20%22showcount%22:%20true,%20%22namespaces%22:%20false}&rsargs[]=json

(Add http: to the front; I omitted it to avoid CR's broken URL mangling.) That returned a 500 code, with HTML contents

 
Warning: Missing argument 1 for efCategoryTreeAjaxWrapper() in /var/www/git-trunk/extensions/CategoryTree/CategoryTree.php on line 214
 
Warning: Missing argument 2 for efCategoryTreeAjaxWrapper() in /var/www/git-trunk/extensions/CategoryTree/CategoryTree.php on line 214
 
Notice: Undefined variable: options in /var/www/git-trunk/extensions/CategoryTree/CategoryTree.php on line 217
 
Notice: Undefined variable: options in /var/www/git-trunk/extensions/CategoryTree/CategoryTree.php on line 223
 
Notice: Undefined variable: category in /var/www/git-trunk/extensions/CategoryTree/CategoryTree.php on line 225
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>Internal Error</title></head><body><h1>Internal Error</h1><p>efCategoryTreeAjaxWrapper returned no data</p></body></html> 

Status & tagging log