r82694 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82693‎ | r82694 | r82695 >
Date:20:23, 23 February 2011
Author:ialex
Status:ok
Tags:
Comment:
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
Modified paths:
  • /trunk/phase3/includes/WebRequest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/WebRequest.php
@@ -443,6 +443,16 @@
444444 }
445445
446446 /**
 447+ * Get the values passed in the query string.
 448+ * No transformation is performed on the values.
 449+ *
 450+ * @return Array
 451+ */
 452+ public function getQueryValues() {
 453+ return $_GET;
 454+ }
 455+
 456+ /**
447457 * Returns true if the present request was reached by a POST operation,
448458 * false otherwise (GET, HEAD, or command-line).
449459 *
@@ -541,25 +551,7 @@
542552 * @return String
543553 */
544554 public function appendQuery( $query ) {
545 - global $wgTitle;
546 - $basequery = '';
547 - foreach( $_GET as $var => $val ) {
548 - if ( $var == 'title' ) {
549 - continue;
550 - }
551 - if ( is_array( $val ) ) {
552 - /* This will happen given a request like
553 - * http://en.wikipedia.org/w/index.php?title[]=Special:Userlogin&returnto[]=Main_Page
554 - */
555 - continue;
556 - }
557 - $basequery .= '&' . urlencode( $var ) . '=' . urlencode( $val );
558 - }
559 - $basequery .= '&' . $query;
560 -
561 - # Trim the extra &
562 - $basequery = substr( $basequery, 1 );
563 - return $wgTitle->getLocalURL( $basequery );
 555+ return $this->appendQueryArray( wfCgiToArray( $query ) );
564556 }
565557
566558 /**
@@ -586,7 +578,7 @@
587579 */
588580 public function appendQueryArray( $array, $onlyquery = false ) {
589581 global $wgTitle;
590 - $newquery = $_GET;
 582+ $newquery = $this->getQueryValues();
591583 unset( $newquery['title'] );
592584 $newquery = array_merge( $newquery, $array );
593585 $query = wfArrayToCGI( $newquery );
@@ -995,6 +987,14 @@
996988 return $this->data;
997989 }
998990
 991+ public function getQueryValues() {
 992+ if ( $this->wasPosted ) {
 993+ return array();
 994+ } else {
 995+ return $this->data;
 996+ }
 997+ }
 998+
999999 public function wasPosted() {
10001000 return $this->wasPosted;
10011001 }
@@ -1007,28 +1007,6 @@
10081008 $this->notImplemented( __METHOD__ );
10091009 }
10101010
1011 - public function appendQuery( $query ) {
1012 - global $wgTitle;
1013 - $basequery = '';
1014 - foreach( $this->data as $var => $val ) {
1015 - if ( $var == 'title' ) {
1016 - continue;
1017 - }
1018 - if ( is_array( $val ) ) {
1019 - /* This will happen given a request like
1020 - * http://en.wikipedia.org/w/index.php?title[]=Special:Userlogin&returnto[]=Main_Page
1021 - */
1022 - continue;
1023 - }
1024 - $basequery .= '&' . urlencode( $var ) . '=' . urlencode( $val );
1025 - }
1026 - $basequery .= '&' . $query;
1027 -
1028 - # Trim the extra &
1029 - $basequery = substr( $basequery, 1 );
1030 - return $wgTitle->getLocalURL( $basequery );
1031 - }
1032 -
10331011 public function getHeader( $name ) {
10341012 return isset( $this->headers[$name] ) ? $this->headers[$name] : false;
10351013 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r97317$wgRequest->getQueryValues(); does not exist until r82694preilly19:03, 16 September 2011

Status & tagging log