From 7a62c8d5425f99c6288b2e04d82b61119c7cac86 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Wed, 23 Feb 2011 20:23:35 +0000 Subject: [PATCH] Factorise common code: * Made appendQuery() use appendQueryArray() by using wfCgiToArray() * Introduced getQueryValues() to get values passed in the query string; FauxRequest will return an empty array when faking a POST request --- includes/WebRequest.php | 62 +++++++++++++---------------------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/includes/WebRequest.php b/includes/WebRequest.php index b3d6edc993..5035adf1dd 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -442,6 +442,16 @@ class WebRequest { return $retVal; } + /** + * Get the values passed in the query string. + * No transformation is performed on the values. + * + * @return Array + */ + public function getQueryValues() { + return $_GET; + } + /** * Returns true if the present request was reached by a POST operation, * false otherwise (GET, HEAD, or command-line). @@ -541,25 +551,7 @@ class WebRequest { * @return String */ public function appendQuery( $query ) { - global $wgTitle; - $basequery = ''; - foreach( $_GET as $var => $val ) { - if ( $var == 'title' ) { - continue; - } - if ( is_array( $val ) ) { - /* This will happen given a request like - * http://en.wikipedia.org/w/index.php?title[]=Special:Userlogin&returnto[]=Main_Page - */ - continue; - } - $basequery .= '&' . urlencode( $var ) . '=' . urlencode( $val ); - } - $basequery .= '&' . $query; - - # Trim the extra & - $basequery = substr( $basequery, 1 ); - return $wgTitle->getLocalURL( $basequery ); + return $this->appendQueryArray( wfCgiToArray( $query ) ); } /** @@ -586,7 +578,7 @@ class WebRequest { */ public function appendQueryArray( $array, $onlyquery = false ) { global $wgTitle; - $newquery = $_GET; + $newquery = $this->getQueryValues(); unset( $newquery['title'] ); $newquery = array_merge( $newquery, $array ); $query = wfArrayToCGI( $newquery ); @@ -995,6 +987,14 @@ class FauxRequest extends WebRequest { return $this->data; } + public function getQueryValues() { + if ( $this->wasPosted ) { + return array(); + } else { + return $this->data; + } + } + public function wasPosted() { return $this->wasPosted; } @@ -1007,28 +1007,6 @@ class FauxRequest extends WebRequest { $this->notImplemented( __METHOD__ ); } - public function appendQuery( $query ) { - global $wgTitle; - $basequery = ''; - foreach( $this->data as $var => $val ) { - if ( $var == 'title' ) { - continue; - } - if ( is_array( $val ) ) { - /* This will happen given a request like - * http://en.wikipedia.org/w/index.php?title[]=Special:Userlogin&returnto[]=Main_Page - */ - continue; - } - $basequery .= '&' . urlencode( $var ) . '=' . urlencode( $val ); - } - $basequery .= '&' . $query; - - # Trim the extra & - $basequery = substr( $basequery, 1 ); - return $wgTitle->getLocalURL( $basequery ); - } - public function getHeader( $name ) { return isset( $this->headers[$name] ) ? $this->headers[$name] : false; } -- 2.20.1