r53734 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53733‎ | r53734 | r53735 >
Date:00:14, 25 July 2009
Author:demon
Status:ok
Tags:
Comment:
Declare visibility on almost all of these, minor code style tweaks.
Modified paths:
  • /trunk/phase3/includes/WebRequest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/WebRequest.php
@@ -43,11 +43,11 @@
4444 * @ingroup HTTP
4545 */
4646 class WebRequest {
47 - var $data = array();
 47+ protected $data = array();
4848 var $headers;
4949 private $_response;
5050
51 - function __construct() {
 51+ public function __construct() {
5252 /// @fixme This preemptive de-quoting can interfere with other web libraries
5353 /// and increases our memory footprint. It would be cleaner to do on
5454 /// demand; but currently we have no wrapper for $_SERVER etc.
@@ -65,7 +65,7 @@
6666 * as we may need the list of language variants to determine
6767 * available variant URLs.
6868 */
69 - function interpolateTitle() {
 69+ public function interpolateTitle() {
7070 global $wgUsePathInfo;
7171 if ( $wgUsePathInfo ) {
7272 // PATH_INFO is mangled due to http://bugs.php.net/bug.php?id=31892
@@ -161,9 +161,8 @@
162162 * used for undoing the evil that is magic_quotes_gpc.
163163 * @param $arr array: will be modified
164164 * @return array the original array
165 - * @private
166165 */
167 - function &fix_magic_quotes( &$arr ) {
 166+ private function &fix_magic_quotes( &$arr ) {
168167 foreach( $arr as $key => $val ) {
169168 if( is_array( $val ) ) {
170169 $this->fix_magic_quotes( $arr[$key] );
@@ -179,10 +178,10 @@
180179 * through fix_magic_quotes to strip out the stupid slashes.
181180 * WARNING: This should only be done once! Running a second
182181 * time could damage the values.
183 - * @private
184182 */
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 ) {
187186 $this->fix_magic_quotes( $_COOKIE );
188187 $this->fix_magic_quotes( $_ENV );
189188 $this->fix_magic_quotes( $_GET );
@@ -216,9 +215,8 @@
217216 * @param $name string
218217 * @param $default mixed
219218 * @return mixed
220 - * @private
221219 */
222 - function getGPCVal( $arr, $name, $default ) {
 220+ private function getGPCVal( $arr, $name, $default ) {
223221 # PHP is so nice to not touch input data, except sometimes:
224222 # http://us2.php.net/variables.external#language.variables.external.dot-in-names
225223 # Work around PHP *feature* to avoid *bugs* elsewhere.
@@ -250,7 +248,7 @@
251249 * @param $default string: optional default (or NULL)
252250 * @return string
253251 */
254 - function getVal( $name, $default = NULL ) {
 252+ public function getVal( $name, $default = NULL ) {
255253 $val = $this->getGPCVal( $this->data, $name, $default );
256254 if( is_array( $val ) ) {
257255 $val = $default;
@@ -268,7 +266,7 @@
269267 * @param $value mixed Value to set
270268 * @return mixed old value if one was present, null otherwise
271269 */
272 - function setVal( $key, $value ) {
 270+ public function setVal( $key, $value ) {
273271 $ret = isset( $this->data[$key] ) ? $this->data[$key] : null;
274272 $this->data[$key] = $value;
275273 return $ret;
@@ -283,7 +281,7 @@
284282 * @param $default array: optional default (or NULL)
285283 * @return array
286284 */
287 - function getArray( $name, $default = NULL ) {
 285+ public function getArray( $name, $default = NULL ) {
288286 $val = $this->getGPCVal( $this->data, $name, $default );
289287 if( is_null( $val ) ) {
290288 return null;
@@ -302,7 +300,7 @@
303301 * @param $default array: option default (or NULL)
304302 * @return array of ints
305303 */
306 - function getIntArray( $name, $default = NULL ) {
 304+ public function getIntArray( $name, $default = NULL ) {
307305 $val = $this->getArray( $name, $default );
308306 if( is_array( $val ) ) {
309307 $val = array_map( 'intval', $val );
@@ -318,7 +316,7 @@
319317 * @param $default int
320318 * @return int
321319 */
322 - function getInt( $name, $default = 0 ) {
 320+ public function getInt( $name, $default = 0 ) {
323321 return intval( $this->getVal( $name, $default ) );
324322 }
325323
@@ -329,7 +327,7 @@
330328 * @param $name string
331329 * @return int
332330 */
333 - function getIntOrNull( $name ) {
 331+ public function getIntOrNull( $name ) {
334332 $val = $this->getVal( $name );
335333 return is_numeric( $val )
336334 ? intval( $val )
@@ -344,7 +342,7 @@
345343 * @param $default bool
346344 * @return bool
347345 */
348 - function getBool( $name, $default = false ) {
 346+ public function getBool( $name, $default = false ) {
349347 return $this->getVal( $name, $default ) ? true : false;
350348 }
351349
@@ -355,7 +353,7 @@
356354 * @param $name string
357355 * @return bool
358356 */
359 - function getCheck( $name ) {
 357+ public function getCheck( $name ) {
360358 # Checkboxes and buttons are only present when clicked
361359 # Presence connotes truth, abscense false
362360 $val = $this->getVal( $name, NULL );
@@ -374,7 +372,7 @@
375373 * @param $default string: optional
376374 * @return string
377375 */
378 - function getText( $name, $default = '' ) {
 376+ public function getText( $name, $default = '' ) {
379377 global $wgContLang;
380378 $val = $this->getVal( $name, $default );
381379 return str_replace( "\r\n", "\n",
@@ -386,7 +384,7 @@
387385 * If no arguments are given, returns all input values.
388386 * No transformation is performed on the values.
389387 */
390 - function getValues() {
 388+ public function getValues() {
391389 $names = func_get_args();
392390 if ( count( $names ) == 0 ) {
393391 $names = array_keys( $this->data );
@@ -411,7 +409,7 @@
412410 *
413411 * @return bool
414412 */
415 - function wasPosted() {
 413+ public function wasPosted() {
416414 return $_SERVER['REQUEST_METHOD'] == 'POST';
417415 }
418416
@@ -426,7 +424,7 @@
427425 *
428426 * @return bool
429427 */
430 - function checkSessionCookie() {
 428+ public function checkSessionCookie() {
431429 return isset( $_COOKIE[session_name()] );
432430 }
433431
@@ -434,7 +432,7 @@
435433 * Return the path portion of the request URI.
436434 * @return string
437435 */
438 - function getRequestURL() {
 436+ public function getRequestURL() {
439437 if( isset( $_SERVER['REQUEST_URI'] ) ) {
440438 $base = $_SERVER['REQUEST_URI'];
441439 } elseif( isset( $_SERVER['SCRIPT_NAME'] ) ) {
@@ -469,7 +467,7 @@
470468 * Return the request URI with the canonical service and hostname.
471469 * @return string
472470 */
473 - function getFullRequestURL() {
 471+ public function getFullRequestURL() {
474472 global $wgServer;
475473 return $wgServer . $this->getRequestURL();
476474 }
@@ -479,7 +477,7 @@
480478 * @param $query String: query string fragment; do not include initial '?'
481479 * @return string
482480 */
483 - function appendQuery( $query ) {
 481+ public function appendQuery( $query ) {
484482 global $wgTitle;
485483 $basequery = '';
486484 foreach( $_GET as $var => $val ) {
@@ -504,11 +502,11 @@
505503 * @param $query String: query string fragment; do not include initial '?'
506504 * @return string
507505 */
508 - function escapeAppendQuery( $query ) {
 506+ public function escapeAppendQuery( $query ) {
509507 return htmlspecialchars( $this->appendQuery( $query ) );
510508 }
511509
512 - function appendQueryValue( $key, $value, $onlyquery = false ) {
 510+ public function appendQueryValue( $key, $value, $onlyquery = false ) {
513511 return $this->appendQueryArray( array( $key => $value ), $onlyquery );
514512 }
515513
@@ -519,7 +517,7 @@
520518 * the complete URL
521519 * @return string
522520 */
523 - function appendQueryArray( $array, $onlyquery = false ) {
 521+ public function appendQueryArray( $array, $onlyquery = false ) {
524522 global $wgTitle;
525523 $newquery = $_GET;
526524 unset( $newquery['title'] );
@@ -537,7 +535,7 @@
538536 * @param $optionname String: to specify an option other than rclimit to pull from.
539537 * @return array first element is limit, second is offset
540538 */
541 - function getLimitOffset( $deflimit = 50, $optionname = 'rclimit' ) {
 539+ public function getLimitOffset( $deflimit = 50, $optionname = 'rclimit' ) {
542540 global $wgUser;
543541
544542 $limit = $this->getInt( 'limit', 0 );
@@ -559,7 +557,7 @@
560558 * @param $key String:
561559 * @return string or NULL if no such file.
562560 */
563 - function getFileTempname( $key ) {
 561+ public function getFileTempname( $key ) {
564562 if( !isset( $_FILES[$key] ) ) {
565563 return NULL;
566564 }
@@ -571,7 +569,7 @@
572570 * @param $key String:
573571 * @return integer
574572 */
575 - function getFileSize( $key ) {
 573+ public function getFileSize( $key ) {
576574 if( !isset( $_FILES[$key] ) ) {
577575 return 0;
578576 }
@@ -583,7 +581,7 @@
584582 * @param $key String:
585583 * @return integer
586584 */
587 - function getUploadError( $key ) {
 585+ public function getUploadError( $key ) {
588586 if( !isset( $_FILES[$key] ) || !isset( $_FILES[$key]['error'] ) ) {
589587 return 0/*UPLOAD_ERR_OK*/;
590588 }
@@ -601,7 +599,7 @@
602600 * @param $key String:
603601 * @return string or NULL if no such file.
604602 */
605 - function getFileName( $key ) {
 603+ public function getFileName( $key ) {
606604 if( !isset( $_FILES[$key] ) ) {
607605 return NULL;
608606 }
@@ -619,9 +617,9 @@
620618 * Return a handle to WebResponse style object, for setting cookies,
621619 * headers and other stuff, for Request being worked on.
622620 */
623 - function response() {
 621+ public function response() {
624622 /* Lazy initialization of response object for this request */
625 - if (!is_object($this->_response)) {
 623+ if ( !is_object( $this->_response ) ) {
626624 $this->_response = new WebResponse;
627625 }
628626 return $this->_response;
@@ -631,7 +629,7 @@
632630 * Get a request header, or false if it isn't set
633631 * @param $name String: case-insensitive header name
634632 */
635 - function getHeader( $name ) {
 633+ public function getHeader( $name ) {
636634 $name = strtoupper( $name );
637635 if ( function_exists( 'apache_request_headers' ) ) {
638636 if ( !isset( $this->headers ) ) {
@@ -657,13 +655,21 @@
658656
659657 /*
660658 * Get data from $_SESSION
 659+ * @param $key String Name of key in $_SESSION
 660+ * @return mixed
661661 */
662 - function getSessionData( $key ) {
 662+ public function getSessionData( $key ) {
663663 if( !isset( $_SESSION[$key] ) )
664664 return null;
665665 return $_SESSION[$key];
666666 }
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 ) {
668674 $_SESSION[$key] = $data;
669675 }
670676 }
@@ -674,63 +680,65 @@
675681 * @ingroup HTTP
676682 */
677683 class FauxRequest extends WebRequest {
678 - var $wasPosted = false;
 684+ private $wasPosted = false;
 685+ private $session, $headers = array();
679686
680687 /**
681688 * @param $data Array of *non*-urlencoded key => value pairs, the
682689 * fake GET/POST values
683690 * @param $wasPosted Bool: whether to treat the data as POST
684691 */
685 - function FauxRequest( $data, $wasPosted = false, $session = null ) {
 692+ public function __construct( $data, $wasPosted = false, $session = null ) {
686693 if( is_array( $data ) ) {
687694 $this->data = $data;
688695 } else {
689696 throw new MWException( "FauxRequest() got bogus data" );
690697 }
691698 $this->wasPosted = $wasPosted;
692 - $this->headers = array();
693 - $this->session = $session ? $session : array();
 699+ if( $session )
 700+ $this->session = $session;
694701 }
695 -
696 - function notImplemented( $method ) {
 702+
 703+ private function notImplemented( $method ) {
697704 throw new MWException( "{$method}() not implemented" );
698705 }
699706
700 - function getText( $name, $default = '' ) {
 707+ public function getText( $name, $default = '' ) {
701708 # Override; don't recode since we're using internal data
702709 return (string)$this->getVal( $name, $default );
703710 }
704711
705 - function getValues() {
 712+ public function getValues() {
706713 return $this->data;
707714 }
708715
709 - function wasPosted() {
 716+ public function wasPosted() {
710717 return $this->wasPosted;
711718 }
712719
713 - function checkSessionCookie() {
 720+ public function checkSessionCookie() {
714721 return false;
715722 }
716723
717 - function getRequestURL() {
 724+ public function getRequestURL() {
718725 $this->notImplemented( __METHOD__ );
719726 }
720727
721 - function appendQuery( $query ) {
 728+ public function appendQuery( $query ) {
722729 $this->notImplemented( __METHOD__ );
723730 }
724731
725 - function getHeader( $name ) {
 732+ public function getHeader( $name ) {
726733 return isset( $this->headers[$name] ) ? $this->headers[$name] : false;
727734 }
728735
729 - function getSessionData( $key ) {
 736+ public function getSessionData( $key ) {
730737 if( !isset( $this->session[$key] ) )
731738 return null;
732739 return $this->session[$key];
733740 }
734 - function setSessionData( $key, $data ) {
 741+
 742+ public function setSessionData( $key, $data ) {
735743 $this->notImplemented( __METHOD__ );
736744 }
737745

Status & tagging log