r71050 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71049‎ | r71050 | r71051 >
Date:21:39, 13 August 2010
Author:simetrical
Status:ok (Comments)
Tags:
Comment:
Revert r70960 "AjaxDispatcher, now ~30 lines shorter and not using $_GET or $_POST"

Broke CategoryTree, see code review for the error message.
Modified paths:
  • /trunk/phase3/includes/AjaxDispatcher.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/AjaxDispatcher.php
@@ -18,25 +18,53 @@
1919 * @ingroup Ajax
2020 */
2121 class AjaxDispatcher {
 22+ /** The way the request was made, either a 'get' or a 'post' */
 23+ private $mode;
 24+
2225 /** Name of the requested handler */
23 - private $func_name = null;
 26+ private $func_name;
2427
2528 /** Arguments passed */
26 - private $args = array();
 29+ private $args;
2730
2831 /** Load up our object with user supplied data */
29 - public function __construct( WebRequest $req ) {
 32+ function __construct() {
3033 wfProfileIn( __METHOD__ );
3134
32 - $rs = $req->getVal( 'rs' );
33 - if( $rs !== null ) {
34 - $this->func_name = $rs;
 35+ $this->mode = "";
 36+
 37+ if ( ! empty( $_GET["rs"] ) ) {
 38+ $this->mode = "get";
3539 }
36 - $rsargs = $req->getVal( 'rsargs' );
37 - if( $rsargs !== null ) {
38 - $this->args = $rsargs;
 40+
 41+ if ( !empty( $_POST["rs"] ) ) {
 42+ $this->mode = "post";
3943 }
4044
 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+
4169 wfProfileOut( __METHOD__ );
4270 }
4371
@@ -48,7 +76,7 @@
4977 function performAction() {
5078 global $wgAjaxExportList, $wgOut;
5179
52 - if ( is_null( $this->func_name ) ) {
 80+ if ( empty( $this->mode ) ) {
5381 return;
5482 }
5583
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( $wgRequest );
 72+ $dispatcher = new AjaxDispatcher();
7373 $dispatcher->performAction();
7474 $mediaWiki->restInPeace();
7575 exit;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r70960AjaxDispatcher, now ~30 lines shorter and not using $_GET or $_POSTdemon14:34, 12 August 2010

Comments

#Comment by MaxSem (talk | contribs)   17:01, 14 August 2010

>see code review for the error message

Where it is?

#Comment by Simetrical (talk | contribs)   17:20, 15 August 2010

I could swear I had posted it before, but now I have for real. Maybe I had just previewed and didn't save.

Status & tagging log