From 9db190c7e736ec8d063187d4241b59feaf7dc2d1 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 22 Jun 2011 11:28:20 +0200 Subject: update to MediaWiki 1.17.0 --- includes/WebRequest.php | 525 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 397 insertions(+), 128 deletions(-) (limited to 'includes/WebRequest.php') diff --git a/includes/WebRequest.php b/includes/WebRequest.php index 877f7cf6..940b693f 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -1,35 +1,28 @@ + * http://www.mediawiki.org/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file */ -# Copyright (C) 2003 Brion Vibber -# http://www.mediawiki.org/ -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# http://www.gnu.org/copyleft/gpl.html - - -/** - * Some entry points may use this file without first enabling the - * autoloader. - */ -if ( !function_exists( '__autoload' ) ) { - require_once( dirname(__FILE__) . '/normal/UtfNormal.php' ); -} - /** * The WebRequest class encapsulates getting at data passed in the * URL or via a POSTed form, handling remove of "magic quotes" slashes, @@ -44,7 +37,12 @@ if ( !function_exists( '__autoload' ) ) { */ class WebRequest { protected $data, $headers = array(); - private $_response; + + /** + * Lazy-init response object + * @var WebResponse + */ + private $response; public function __construct() { /// @todo Fixme: this preemptive de-quoting can interfere with other web libraries @@ -67,6 +65,11 @@ class WebRequest { public function interpolateTitle() { global $wgUsePathInfo; + // bug 16019: title interpolation on API queries is useless and possible harmful + if ( defined( 'MW_API' ) ) { + return; + } + if ( $wgUsePathInfo ) { // PATH_INFO is mangled due to http://bugs.php.net/bug.php?id=31892 // And also by Apache 2.x, double slashes are converted to single slashes. @@ -160,6 +163,7 @@ class WebRequest { /** * Recursively strips slashes from the given array; * used for undoing the evil that is magic_quotes_gpc. + * * @param $arr array: will be modified * @return array the original array */ @@ -195,6 +199,7 @@ class WebRequest { /** * Recursively normalizes UTF-8 strings in the given array. + * * @param $data string or array * @return cleaned-up version of the given * @private @@ -214,9 +219,9 @@ class WebRequest { /** * Fetch a value from the given array or return $default if it's not set. * - * @param $arr array - * @param $name string - * @param $default mixed + * @param $arr Array + * @param $name String + * @param $default Mixed * @return mixed */ private function getGPCVal( $arr, $name, $default ) { @@ -247,9 +252,9 @@ class WebRequest { * non-freeform text inputs (e.g. predefined internal text keys * selected by a drop-down menu). For freeform input, see getText(). * - * @param $name string - * @param $default string: optional default (or NULL) - * @return string + * @param $name String + * @param $default String: optional default (or NULL) + * @return String */ public function getVal( $name, $default = null ) { $val = $this->getGPCVal( $this->data, $name, $default ); @@ -265,9 +270,10 @@ class WebRequest { /** * Set an aribtrary value into our get/post data. - * @param $key string Key name to use - * @param $value mixed Value to set - * @return mixed old value if one was present, null otherwise + * + * @param $key String: key name to use + * @param $value Mixed: value to set + * @return Mixed: old value if one was present, null otherwise */ public function setVal( $key, $value ) { $ret = isset( $this->data[$key] ) ? $this->data[$key] : null; @@ -280,9 +286,9 @@ class WebRequest { * If source was scalar, will return an array with a single element. * If no source and no default, returns NULL. * - * @param $name string - * @param $default array: optional default (or NULL) - * @return array + * @param $name String + * @param $default Array: optional default (or NULL) + * @return Array */ public function getArray( $name, $default = null ) { $val = $this->getGPCVal( $this->data, $name, $default ); @@ -299,9 +305,9 @@ class WebRequest { * If no source and no default, returns NULL. * If an array is returned, contents are guaranteed to be integers. * - * @param $name string - * @param $default array: option default (or NULL) - * @return array of ints + * @param $name String + * @param $default Array: option default (or NULL) + * @return Array of ints */ public function getIntArray( $name, $default = null ) { $val = $this->getArray( $name, $default ); @@ -315,9 +321,10 @@ class WebRequest { * Fetch an integer value from the input or return $default if not set. * Guaranteed to return an integer; non-numeric input will typically * return 0. - * @param $name string - * @param $default int - * @return int + * + * @param $name String + * @param $default Integer + * @return Integer */ public function getInt( $name, $default = 0 ) { return intval( $this->getVal( $name, $default ) ); @@ -327,8 +334,9 @@ class WebRequest { * Fetch an integer value from the input or return null if empty. * Guaranteed to return an integer or null; non-numeric input will * typically return null. - * @param $name string - * @return int + * + * @param $name String + * @return Integer */ public function getIntOrNull( $name ) { $val = $this->getVal( $name ); @@ -341,20 +349,35 @@ class WebRequest { * Fetch a boolean value from the input or return $default if not set. * Guaranteed to return true or false, with normal PHP semantics for * boolean interpretation of strings. - * @param $name string - * @param $default bool - * @return bool + * + * @param $name String + * @param $default Boolean + * @return Boolean */ public function getBool( $name, $default = false ) { - return $this->getVal( $name, $default ) ? true : false; + return (bool)$this->getVal( $name, $default ); + } + + /** + * Fetch a boolean value from the input or return $default if not set. + * Unlike getBool, the string "false" will result in boolean false, which is + * useful when interpreting information sent from JavaScript. + * + * @param $name String + * @param $default Boolean + * @return Boolean + */ + public function getFuzzyBool( $name, $default = false ) { + return $this->getBool( $name, $default ) && strcasecmp( $this->getVal( $name ), 'false' ) !== 0; } /** * Return true if the named value is set in the input, whatever that * value is (even "0"). Return false if the named value is not set. * Example use is checking for the presence of check boxes in forms. - * @param $name string - * @return bool + * + * @param $name String + * @return Boolean */ public function getCheck( $name ) { # Checkboxes and buttons are only present when clicked @@ -365,15 +388,15 @@ class WebRequest { /** * Fetch a text string from the given array or return $default if it's not - * set. \r is stripped from the text, and with some language modules there - * is an input transliteration applied. This should generally be used for - * form