Index: trunk/phase3/includes/WebRequest.php |
— | — | @@ -43,11 +43,11 @@ |
44 | 44 | * @ingroup HTTP |
45 | 45 | */ |
46 | 46 | class WebRequest { |
47 | | - var $data = array(); |
| 47 | + protected $data = array(); |
48 | 48 | var $headers; |
49 | 49 | private $_response; |
50 | 50 | |
51 | | - function __construct() { |
| 51 | + public function __construct() { |
52 | 52 | /// @fixme This preemptive de-quoting can interfere with other web libraries |
53 | 53 | /// and increases our memory footprint. It would be cleaner to do on |
54 | 54 | /// demand; but currently we have no wrapper for $_SERVER etc. |
— | — | @@ -65,7 +65,7 @@ |
66 | 66 | * as we may need the list of language variants to determine |
67 | 67 | * available variant URLs. |
68 | 68 | */ |
69 | | - function interpolateTitle() { |
| 69 | + public function interpolateTitle() { |
70 | 70 | global $wgUsePathInfo; |
71 | 71 | if ( $wgUsePathInfo ) { |
72 | 72 | // PATH_INFO is mangled due to http://bugs.php.net/bug.php?id=31892 |
— | — | @@ -161,9 +161,8 @@ |
162 | 162 | * used for undoing the evil that is magic_quotes_gpc. |
163 | 163 | * @param $arr array: will be modified |
164 | 164 | * @return array the original array |
165 | | - * @private |
166 | 165 | */ |
167 | | - function &fix_magic_quotes( &$arr ) { |
| 166 | + private function &fix_magic_quotes( &$arr ) { |
168 | 167 | foreach( $arr as $key => $val ) { |
169 | 168 | if( is_array( $val ) ) { |
170 | 169 | $this->fix_magic_quotes( $arr[$key] ); |
— | — | @@ -179,10 +178,10 @@ |
180 | 179 | * through fix_magic_quotes to strip out the stupid slashes. |
181 | 180 | * WARNING: This should only be done once! Running a second |
182 | 181 | * time could damage the values. |
183 | | - * @private |
184 | 182 | */ |
185 | | - function checkMagicQuotes() { |
186 | | - if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) { |
| 183 | + private function checkMagicQuotes() { |
| 184 | + $this->mFixMagicQuotes = function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() |
| 185 | + if( $this->mFixMagicQuotes ) { |
187 | 186 | $this->fix_magic_quotes( $_COOKIE ); |
188 | 187 | $this->fix_magic_quotes( $_ENV ); |
189 | 188 | $this->fix_magic_quotes( $_GET ); |
— | — | @@ -216,9 +215,8 @@ |
217 | 216 | * @param $name string |
218 | 217 | * @param $default mixed |
219 | 218 | * @return mixed |
220 | | - * @private |
221 | 219 | */ |
222 | | - function getGPCVal( $arr, $name, $default ) { |
| 220 | + private function getGPCVal( $arr, $name, $default ) { |
223 | 221 | # PHP is so nice to not touch input data, except sometimes: |
224 | 222 | # http://us2.php.net/variables.external#language.variables.external.dot-in-names |
225 | 223 | # Work around PHP *feature* to avoid *bugs* elsewhere. |
— | — | @@ -250,7 +248,7 @@ |
251 | 249 | * @param $default string: optional default (or NULL) |
252 | 250 | * @return string |
253 | 251 | */ |
254 | | - function getVal( $name, $default = NULL ) { |
| 252 | + public function getVal( $name, $default = NULL ) { |
255 | 253 | $val = $this->getGPCVal( $this->data, $name, $default ); |
256 | 254 | if( is_array( $val ) ) { |
257 | 255 | $val = $default; |
— | — | @@ -268,7 +266,7 @@ |
269 | 267 | * @param $value mixed Value to set |
270 | 268 | * @return mixed old value if one was present, null otherwise |
271 | 269 | */ |
272 | | - function setVal( $key, $value ) { |
| 270 | + public function setVal( $key, $value ) { |
273 | 271 | $ret = isset( $this->data[$key] ) ? $this->data[$key] : null; |
274 | 272 | $this->data[$key] = $value; |
275 | 273 | return $ret; |
— | — | @@ -283,7 +281,7 @@ |
284 | 282 | * @param $default array: optional default (or NULL) |
285 | 283 | * @return array |
286 | 284 | */ |
287 | | - function getArray( $name, $default = NULL ) { |
| 285 | + public function getArray( $name, $default = NULL ) { |
288 | 286 | $val = $this->getGPCVal( $this->data, $name, $default ); |
289 | 287 | if( is_null( $val ) ) { |
290 | 288 | return null; |
— | — | @@ -302,7 +300,7 @@ |
303 | 301 | * @param $default array: option default (or NULL) |
304 | 302 | * @return array of ints |
305 | 303 | */ |
306 | | - function getIntArray( $name, $default = NULL ) { |
| 304 | + public function getIntArray( $name, $default = NULL ) { |
307 | 305 | $val = $this->getArray( $name, $default ); |
308 | 306 | if( is_array( $val ) ) { |
309 | 307 | $val = array_map( 'intval', $val ); |
— | — | @@ -318,7 +316,7 @@ |
319 | 317 | * @param $default int |
320 | 318 | * @return int |
321 | 319 | */ |
322 | | - function getInt( $name, $default = 0 ) { |
| 320 | + public function getInt( $name, $default = 0 ) { |
323 | 321 | return intval( $this->getVal( $name, $default ) ); |
324 | 322 | } |
325 | 323 | |
— | — | @@ -329,7 +327,7 @@ |
330 | 328 | * @param $name string |
331 | 329 | * @return int |
332 | 330 | */ |
333 | | - function getIntOrNull( $name ) { |
| 331 | + public function getIntOrNull( $name ) { |
334 | 332 | $val = $this->getVal( $name ); |
335 | 333 | return is_numeric( $val ) |
336 | 334 | ? intval( $val ) |
— | — | @@ -344,7 +342,7 @@ |
345 | 343 | * @param $default bool |
346 | 344 | * @return bool |
347 | 345 | */ |
348 | | - function getBool( $name, $default = false ) { |
| 346 | + public function getBool( $name, $default = false ) { |
349 | 347 | return $this->getVal( $name, $default ) ? true : false; |
350 | 348 | } |
351 | 349 | |
— | — | @@ -355,7 +353,7 @@ |
356 | 354 | * @param $name string |
357 | 355 | * @return bool |
358 | 356 | */ |
359 | | - function getCheck( $name ) { |
| 357 | + public function getCheck( $name ) { |
360 | 358 | # Checkboxes and buttons are only present when clicked |
361 | 359 | # Presence connotes truth, abscense false |
362 | 360 | $val = $this->getVal( $name, NULL ); |
— | — | @@ -374,7 +372,7 @@ |
375 | 373 | * @param $default string: optional |
376 | 374 | * @return string |
377 | 375 | */ |
378 | | - function getText( $name, $default = '' ) { |
| 376 | + public function getText( $name, $default = '' ) { |
379 | 377 | global $wgContLang; |
380 | 378 | $val = $this->getVal( $name, $default ); |
381 | 379 | return str_replace( "\r\n", "\n", |
— | — | @@ -386,7 +384,7 @@ |
387 | 385 | * If no arguments are given, returns all input values. |
388 | 386 | * No transformation is performed on the values. |
389 | 387 | */ |
390 | | - function getValues() { |
| 388 | + public function getValues() { |
391 | 389 | $names = func_get_args(); |
392 | 390 | if ( count( $names ) == 0 ) { |
393 | 391 | $names = array_keys( $this->data ); |
— | — | @@ -411,7 +409,7 @@ |
412 | 410 | * |
413 | 411 | * @return bool |
414 | 412 | */ |
415 | | - function wasPosted() { |
| 413 | + public function wasPosted() { |
416 | 414 | return $_SERVER['REQUEST_METHOD'] == 'POST'; |
417 | 415 | } |
418 | 416 | |
— | — | @@ -426,7 +424,7 @@ |
427 | 425 | * |
428 | 426 | * @return bool |
429 | 427 | */ |
430 | | - function checkSessionCookie() { |
| 428 | + public function checkSessionCookie() { |
431 | 429 | return isset( $_COOKIE[session_name()] ); |
432 | 430 | } |
433 | 431 | |
— | — | @@ -434,7 +432,7 @@ |
435 | 433 | * Return the path portion of the request URI. |
436 | 434 | * @return string |
437 | 435 | */ |
438 | | - function getRequestURL() { |
| 436 | + public function getRequestURL() { |
439 | 437 | if( isset( $_SERVER['REQUEST_URI'] ) ) { |
440 | 438 | $base = $_SERVER['REQUEST_URI']; |
441 | 439 | } elseif( isset( $_SERVER['SCRIPT_NAME'] ) ) { |
— | — | @@ -469,7 +467,7 @@ |
470 | 468 | * Return the request URI with the canonical service and hostname. |
471 | 469 | * @return string |
472 | 470 | */ |
473 | | - function getFullRequestURL() { |
| 471 | + public function getFullRequestURL() { |
474 | 472 | global $wgServer; |
475 | 473 | return $wgServer . $this->getRequestURL(); |
476 | 474 | } |
— | — | @@ -479,7 +477,7 @@ |
480 | 478 | * @param $query String: query string fragment; do not include initial '?' |
481 | 479 | * @return string |
482 | 480 | */ |
483 | | - function appendQuery( $query ) { |
| 481 | + public function appendQuery( $query ) { |
484 | 482 | global $wgTitle; |
485 | 483 | $basequery = ''; |
486 | 484 | foreach( $_GET as $var => $val ) { |
— | — | @@ -504,11 +502,11 @@ |
505 | 503 | * @param $query String: query string fragment; do not include initial '?' |
506 | 504 | * @return string |
507 | 505 | */ |
508 | | - function escapeAppendQuery( $query ) { |
| 506 | + public function escapeAppendQuery( $query ) { |
509 | 507 | return htmlspecialchars( $this->appendQuery( $query ) ); |
510 | 508 | } |
511 | 509 | |
512 | | - function appendQueryValue( $key, $value, $onlyquery = false ) { |
| 510 | + public function appendQueryValue( $key, $value, $onlyquery = false ) { |
513 | 511 | return $this->appendQueryArray( array( $key => $value ), $onlyquery ); |
514 | 512 | } |
515 | 513 | |
— | — | @@ -519,7 +517,7 @@ |
520 | 518 | * the complete URL |
521 | 519 | * @return string |
522 | 520 | */ |
523 | | - function appendQueryArray( $array, $onlyquery = false ) { |
| 521 | + public function appendQueryArray( $array, $onlyquery = false ) { |
524 | 522 | global $wgTitle; |
525 | 523 | $newquery = $_GET; |
526 | 524 | unset( $newquery['title'] ); |
— | — | @@ -537,7 +535,7 @@ |
538 | 536 | * @param $optionname String: to specify an option other than rclimit to pull from. |
539 | 537 | * @return array first element is limit, second is offset |
540 | 538 | */ |
541 | | - function getLimitOffset( $deflimit = 50, $optionname = 'rclimit' ) { |
| 539 | + public function getLimitOffset( $deflimit = 50, $optionname = 'rclimit' ) { |
542 | 540 | global $wgUser; |
543 | 541 | |
544 | 542 | $limit = $this->getInt( 'limit', 0 ); |
— | — | @@ -559,7 +557,7 @@ |
560 | 558 | * @param $key String: |
561 | 559 | * @return string or NULL if no such file. |
562 | 560 | */ |
563 | | - function getFileTempname( $key ) { |
| 561 | + public function getFileTempname( $key ) { |
564 | 562 | if( !isset( $_FILES[$key] ) ) { |
565 | 563 | return NULL; |
566 | 564 | } |
— | — | @@ -571,7 +569,7 @@ |
572 | 570 | * @param $key String: |
573 | 571 | * @return integer |
574 | 572 | */ |
575 | | - function getFileSize( $key ) { |
| 573 | + public function getFileSize( $key ) { |
576 | 574 | if( !isset( $_FILES[$key] ) ) { |
577 | 575 | return 0; |
578 | 576 | } |
— | — | @@ -583,7 +581,7 @@ |
584 | 582 | * @param $key String: |
585 | 583 | * @return integer |
586 | 584 | */ |
587 | | - function getUploadError( $key ) { |
| 585 | + public function getUploadError( $key ) { |
588 | 586 | if( !isset( $_FILES[$key] ) || !isset( $_FILES[$key]['error'] ) ) { |
589 | 587 | return 0/*UPLOAD_ERR_OK*/; |
590 | 588 | } |
— | — | @@ -601,7 +599,7 @@ |
602 | 600 | * @param $key String: |
603 | 601 | * @return string or NULL if no such file. |
604 | 602 | */ |
605 | | - function getFileName( $key ) { |
| 603 | + public function getFileName( $key ) { |
606 | 604 | if( !isset( $_FILES[$key] ) ) { |
607 | 605 | return NULL; |
608 | 606 | } |
— | — | @@ -619,9 +617,9 @@ |
620 | 618 | * Return a handle to WebResponse style object, for setting cookies, |
621 | 619 | * headers and other stuff, for Request being worked on. |
622 | 620 | */ |
623 | | - function response() { |
| 621 | + public function response() { |
624 | 622 | /* Lazy initialization of response object for this request */ |
625 | | - if (!is_object($this->_response)) { |
| 623 | + if ( !is_object( $this->_response ) ) { |
626 | 624 | $this->_response = new WebResponse; |
627 | 625 | } |
628 | 626 | return $this->_response; |
— | — | @@ -631,7 +629,7 @@ |
632 | 630 | * Get a request header, or false if it isn't set |
633 | 631 | * @param $name String: case-insensitive header name |
634 | 632 | */ |
635 | | - function getHeader( $name ) { |
| 633 | + public function getHeader( $name ) { |
636 | 634 | $name = strtoupper( $name ); |
637 | 635 | if ( function_exists( 'apache_request_headers' ) ) { |
638 | 636 | if ( !isset( $this->headers ) ) { |
— | — | @@ -657,13 +655,21 @@ |
658 | 656 | |
659 | 657 | /* |
660 | 658 | * Get data from $_SESSION |
| 659 | + * @param $key String Name of key in $_SESSION |
| 660 | + * @return mixed |
661 | 661 | */ |
662 | | - function getSessionData( $key ) { |
| 662 | + public function getSessionData( $key ) { |
663 | 663 | if( !isset( $_SESSION[$key] ) ) |
664 | 664 | return null; |
665 | 665 | return $_SESSION[$key]; |
666 | 666 | } |
667 | | - function setSessionData( $key, $data ) { |
| 667 | + |
| 668 | + /** |
| 669 | + * Set session data |
| 670 | + * @param $key String Name of key in $_SESSION |
| 671 | + * @param $data mixed |
| 672 | + */ |
| 673 | + public function setSessionData( $key, $data ) { |
668 | 674 | $_SESSION[$key] = $data; |
669 | 675 | } |
670 | 676 | } |
— | — | @@ -674,63 +680,65 @@ |
675 | 681 | * @ingroup HTTP |
676 | 682 | */ |
677 | 683 | class FauxRequest extends WebRequest { |
678 | | - var $wasPosted = false; |
| 684 | + private $wasPosted = false; |
| 685 | + private $session, $headers = array(); |
679 | 686 | |
680 | 687 | /** |
681 | 688 | * @param $data Array of *non*-urlencoded key => value pairs, the |
682 | 689 | * fake GET/POST values |
683 | 690 | * @param $wasPosted Bool: whether to treat the data as POST |
684 | 691 | */ |
685 | | - function FauxRequest( $data, $wasPosted = false, $session = null ) { |
| 692 | + public function __construct( $data, $wasPosted = false, $session = null ) { |
686 | 693 | if( is_array( $data ) ) { |
687 | 694 | $this->data = $data; |
688 | 695 | } else { |
689 | 696 | throw new MWException( "FauxRequest() got bogus data" ); |
690 | 697 | } |
691 | 698 | $this->wasPosted = $wasPosted; |
692 | | - $this->headers = array(); |
693 | | - $this->session = $session ? $session : array(); |
| 699 | + if( $session ) |
| 700 | + $this->session = $session; |
694 | 701 | } |
695 | | - |
696 | | - function notImplemented( $method ) { |
| 702 | + |
| 703 | + private function notImplemented( $method ) { |
697 | 704 | throw new MWException( "{$method}() not implemented" ); |
698 | 705 | } |
699 | 706 | |
700 | | - function getText( $name, $default = '' ) { |
| 707 | + public function getText( $name, $default = '' ) { |
701 | 708 | # Override; don't recode since we're using internal data |
702 | 709 | return (string)$this->getVal( $name, $default ); |
703 | 710 | } |
704 | 711 | |
705 | | - function getValues() { |
| 712 | + public function getValues() { |
706 | 713 | return $this->data; |
707 | 714 | } |
708 | 715 | |
709 | | - function wasPosted() { |
| 716 | + public function wasPosted() { |
710 | 717 | return $this->wasPosted; |
711 | 718 | } |
712 | 719 | |
713 | | - function checkSessionCookie() { |
| 720 | + public function checkSessionCookie() { |
714 | 721 | return false; |
715 | 722 | } |
716 | 723 | |
717 | | - function getRequestURL() { |
| 724 | + public function getRequestURL() { |
718 | 725 | $this->notImplemented( __METHOD__ ); |
719 | 726 | } |
720 | 727 | |
721 | | - function appendQuery( $query ) { |
| 728 | + public function appendQuery( $query ) { |
722 | 729 | $this->notImplemented( __METHOD__ ); |
723 | 730 | } |
724 | 731 | |
725 | | - function getHeader( $name ) { |
| 732 | + public function getHeader( $name ) { |
726 | 733 | return isset( $this->headers[$name] ) ? $this->headers[$name] : false; |
727 | 734 | } |
728 | 735 | |
729 | | - function getSessionData( $key ) { |
| 736 | + public function getSessionData( $key ) { |
730 | 737 | if( !isset( $this->session[$key] ) ) |
731 | 738 | return null; |
732 | 739 | return $this->session[$key]; |
733 | 740 | } |
734 | | - function setSessionData( $key, $data ) { |
| 741 | + |
| 742 | + public function setSessionData( $key, $data ) { |
735 | 743 | $this->notImplemented( __METHOD__ ); |
736 | 744 | } |
737 | 745 | |