3 # Hypothetically, we could use a WebRequest object to fake a
4 # self-contained request.
6 ## Enable this to debug total elimination of register_globals
7 #define( "DEBUG_GLOBALS", 1 );
9 # Deal with importing all those nasssty globals and things
11 function WebRequest() {
12 if( defined('DEBUG_GLOBALS') ) error_reporting(E_ALL
);
14 $this->checkMagicQuotes();
15 $this->checkRegisterGlobals();
18 function &fix_magic_quotes( &$arr ) {
19 foreach( $arr as $key => $val ) {
20 if( is_array( $val ) ) {
21 $this->fix_magic_quotes( $arr[$key] );
23 $arr[$key] = stripslashes( $val );
29 function checkMagicQuotes() {
30 if ( get_magic_quotes_gpc() ) {
31 $this->fix_magic_quotes( $_COOKIE );
32 $this->fix_magic_quotes( $_ENV );
33 $this->fix_magic_quotes( $_GET );
34 $this->fix_magic_quotes( $_POST );
35 $this->fix_magic_quotes( $_REQUEST );
36 $this->fix_magic_quotes( $_SERVER );
37 } elseif( defined('DEBUG_GLOBALS') ) {
38 die("DEBUG_GLOBALS: turn on magic_quotes_gpc" );
42 function checkRegisterGlobals() {
43 if( ini_get( "register_globals" ) ) {
44 if( defined( "DEBUG_GLOBALS" ) ) {
45 die( "DEBUG_GLOBALS: Turn register_globals off!" );
48 if( !defined( "DEBUG_GLOBALS" ) ) {
49 # Insecure, but at least it'll run
50 import_request_variables( "GPC" );
55 function getGPCVal( &$arr, $name, $default ) {
56 if( isset( $arr[$name] ) ) {
63 function getGPCText( &$arr, $name, $default ) {
64 # Text fields may be in an alternate encoding which we should check.
65 # Also, strip CRLF line endings down to LF to achieve consistency.
67 if( isset( $arr[$name] ) ) {
68 return str_replace( "\r\n", "\n", $wgLang->recodeInput( $arr[$name] ) );
74 function getVal( $name, $default = NULL ) {
75 return $this->getGPCVal( $_REQUEST, $name, $default );
78 function getInt( $name, $default = 0 ) {
79 return IntVal( $this->getVal( $name, $default ) );
82 function getBool( $name, $default = false ) {
83 return $this->getVal( $name, $default ) ?
true : false;
86 function getCheck( $name ) {
87 # Checkboxes and buttons are only present when clicked
88 # Presence connotes truth, abscense false
89 $val = $this->getVal( $name, NULL );
93 function getText( $name, $default = "" ) {
94 return $this->getGPCText( $_REQUEST, $name, $default );
97 function wasPosted() {
98 return $_SERVER['REQUEST_METHOD'] == 'POST';
101 function checkSessionCookie() {
102 return isset( $_COOKIE[ini_get("session.name")] );