Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like WebRequest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WebRequest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 37 | class WebRequest { |
||
| 38 | protected $data, $headers = []; |
||
|
|
|||
| 39 | |||
| 40 | /** |
||
| 41 | * Flag to make WebRequest::getHeader return an array of values. |
||
| 42 | * @since 1.26 |
||
| 43 | */ |
||
| 44 | const GETHEADER_LIST = 1; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * The unique request ID. |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | private static $reqId; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Lazy-init response object |
||
| 54 | * @var WebResponse |
||
| 55 | */ |
||
| 56 | private $response; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Cached client IP address |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | private $ip; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * The timestamp of the start of the request, with microsecond precision. |
||
| 66 | * @var float |
||
| 67 | */ |
||
| 68 | protected $requestTime; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Cached URL protocol |
||
| 72 | * @var string |
||
| 73 | */ |
||
| 74 | protected $protocol; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var SessionId|null Session ID to use for this |
||
| 78 | * request. We can't save the session directly due to reference cycles not |
||
| 79 | * working too well (slow GC in Zend and never collected in HHVM). |
||
| 80 | */ |
||
| 81 | protected $sessionId = null; |
||
| 82 | |||
| 83 | public function __construct() { |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Extract relevant query arguments from the http request uri's path |
||
| 94 | * to be merged with the normal php provided query arguments. |
||
| 95 | * Tries to use the REQUEST_URI data if available and parses it |
||
| 96 | * according to the wiki's configuration looking for any known pattern. |
||
| 97 | * |
||
| 98 | * If the REQUEST_URI is not provided we'll fall back on the PATH_INFO |
||
| 99 | * provided by the server if any and use that to set a 'title' parameter. |
||
| 100 | * |
||
| 101 | * @param string $want If this is not 'all', then the function |
||
| 102 | * will return an empty array if it determines that the URL is |
||
| 103 | * inside a rewrite path. |
||
| 104 | * |
||
| 105 | * @return array Any query arguments found in path matches. |
||
| 106 | */ |
||
| 107 | public static function getPathInfo( $want = 'all' ) { |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Work out an appropriate URL prefix containing scheme and host, based on |
||
| 186 | * information detected from $_SERVER |
||
| 187 | * |
||
| 188 | * @return string |
||
| 189 | */ |
||
| 190 | public static function detectServer() { |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Detect the protocol from $_SERVER. |
||
| 231 | * This is for use prior to Setup.php, when no WebRequest object is available. |
||
| 232 | * At other times, use the non-static function getProtocol(). |
||
| 233 | * |
||
| 234 | * @return array |
||
| 235 | */ |
||
| 236 | public static function detectProtocol() { |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Get the number of seconds to have elapsed since request start, |
||
| 248 | * in fractional seconds, with microsecond resolution. |
||
| 249 | * |
||
| 250 | * @return float |
||
| 251 | * @since 1.25 |
||
| 252 | */ |
||
| 253 | public function getElapsedTime() { |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Get the unique request ID. |
||
| 259 | * This is either the value of the UNIQUE_ID envvar (if present) or a |
||
| 260 | * randomly-generated 24-character string. |
||
| 261 | * |
||
| 262 | * @return string |
||
| 263 | * @since 1.27 |
||
| 264 | */ |
||
| 265 | public static function getRequestId() { |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Override the unique request ID. This is for sub-requests, such as jobs, |
||
| 276 | * that wish to use the same id but are not part of the same execution context. |
||
| 277 | * |
||
| 278 | * @param string $id |
||
| 279 | * @since 1.27 |
||
| 280 | */ |
||
| 281 | public static function overrideRequestId( $id ) { |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Get the current URL protocol (http or https) |
||
| 287 | * @return string |
||
| 288 | */ |
||
| 289 | public function getProtocol() { |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Check for title, action, and/or variant data in the URL |
||
| 298 | * and interpolate it into the GET variables. |
||
| 299 | * This should only be run after $wgContLang is available, |
||
| 300 | * as we may need the list of language variants to determine |
||
| 301 | * available variant URLs. |
||
| 302 | */ |
||
| 303 | public function interpolateTitle() { |
||
| 314 | |||
| 315 | /** |
||
| 316 | * URL rewriting function; tries to extract page title and, |
||
| 317 | * optionally, one other fixed parameter value from a URL path. |
||
| 318 | * |
||
| 319 | * @param string $path The URL path given from the client |
||
| 320 | * @param array $bases One or more URLs, optionally with $1 at the end |
||
| 321 | * @param string $key If provided, the matching key in $bases will be |
||
| 322 | * passed on as the value of this URL parameter |
||
| 323 | * @return array Array of URL variables to interpolate; empty if no match |
||
| 324 | */ |
||
| 325 | static function extractTitle( $path, $bases, $key = false ) { |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Recursively normalizes UTF-8 strings in the given array. |
||
| 346 | * |
||
| 347 | * @param string|array $data |
||
| 348 | * @return array|string Cleaned-up version of the given |
||
| 349 | * @private |
||
| 350 | */ |
||
| 351 | function normalizeUnicode( $data ) { |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Fetch a value from the given array or return $default if it's not set. |
||
| 367 | * |
||
| 368 | * @param array $arr |
||
| 369 | * @param string $name |
||
| 370 | * @param mixed $default |
||
| 371 | * @return mixed |
||
| 372 | */ |
||
| 373 | private function getGPCVal( $arr, $name, $default ) { |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Fetch a scalar from the input or return $default if it's not set. |
||
| 396 | * Returns a string. Arrays are discarded. Useful for |
||
| 397 | * non-freeform text inputs (e.g. predefined internal text keys |
||
| 398 | * selected by a drop-down menu). For freeform input, see getText(). |
||
| 399 | * |
||
| 400 | * @param string $name |
||
| 401 | * @param string $default Optional default (or null) |
||
| 402 | * @return string |
||
| 403 | */ |
||
| 404 | public function getVal( $name, $default = null ) { |
||
| 415 | |||
| 416 | /** |
||
| 417 | * Set an arbitrary value into our get/post data. |
||
| 418 | * |
||
| 419 | * @param string $key Key name to use |
||
| 420 | * @param mixed $value Value to set |
||
| 421 | * @return mixed Old value if one was present, null otherwise |
||
| 422 | */ |
||
| 423 | public function setVal( $key, $value ) { |
||
| 428 | |||
| 429 | /** |
||
| 430 | * Unset an arbitrary value from our get/post data. |
||
| 431 | * |
||
| 432 | * @param string $key Key name to use |
||
| 433 | * @return mixed Old value if one was present, null otherwise |
||
| 434 | */ |
||
| 435 | public function unsetVal( $key ) { |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Fetch an array from the input or return $default if it's not set. |
||
| 447 | * If source was scalar, will return an array with a single element. |
||
| 448 | * If no source and no default, returns null. |
||
| 449 | * |
||
| 450 | * @param string $name |
||
| 451 | * @param array $default Optional default (or null) |
||
| 452 | * @return array |
||
| 453 | */ |
||
| 454 | public function getArray( $name, $default = null ) { |
||
| 462 | |||
| 463 | /** |
||
| 464 | * Fetch an array of integers, or return $default if it's not set. |
||
| 465 | * If source was scalar, will return an array with a single element. |
||
| 466 | * If no source and no default, returns null. |
||
| 467 | * If an array is returned, contents are guaranteed to be integers. |
||
| 468 | * |
||
| 469 | * @param string $name |
||
| 470 | * @param array $default Option default (or null) |
||
| 471 | * @return array Array of ints |
||
| 472 | */ |
||
| 473 | public function getIntArray( $name, $default = null ) { |
||
| 480 | |||
| 481 | /** |
||
| 482 | * Fetch an integer value from the input or return $default if not set. |
||
| 483 | * Guaranteed to return an integer; non-numeric input will typically |
||
| 484 | * return 0. |
||
| 485 | * |
||
| 486 | * @param string $name |
||
| 487 | * @param int $default |
||
| 488 | * @return int |
||
| 489 | */ |
||
| 490 | public function getInt( $name, $default = 0 ) { |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Fetch an integer value from the input or return null if empty. |
||
| 496 | * Guaranteed to return an integer or null; non-numeric input will |
||
| 497 | * typically return null. |
||
| 498 | * |
||
| 499 | * @param string $name |
||
| 500 | * @return int|null |
||
| 501 | */ |
||
| 502 | public function getIntOrNull( $name ) { |
||
| 508 | |||
| 509 | /** |
||
| 510 | * Fetch a floating point value from the input or return $default if not set. |
||
| 511 | * Guaranteed to return a float; non-numeric input will typically |
||
| 512 | * return 0. |
||
| 513 | * |
||
| 514 | * @since 1.23 |
||
| 515 | * @param string $name |
||
| 516 | * @param float $default |
||
| 517 | * @return float |
||
| 518 | */ |
||
| 519 | public function getFloat( $name, $default = 0.0 ) { |
||
| 522 | |||
| 523 | /** |
||
| 524 | * Fetch a boolean value from the input or return $default if not set. |
||
| 525 | * Guaranteed to return true or false, with normal PHP semantics for |
||
| 526 | * boolean interpretation of strings. |
||
| 527 | * |
||
| 528 | * @param string $name |
||
| 529 | * @param bool $default |
||
| 530 | * @return bool |
||
| 531 | */ |
||
| 532 | public function getBool( $name, $default = false ) { |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Fetch a boolean value from the input or return $default if not set. |
||
| 538 | * Unlike getBool, the string "false" will result in boolean false, which is |
||
| 539 | * useful when interpreting information sent from JavaScript. |
||
| 540 | * |
||
| 541 | * @param string $name |
||
| 542 | * @param bool $default |
||
| 543 | * @return bool |
||
| 544 | */ |
||
| 545 | public function getFuzzyBool( $name, $default = false ) { |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Return true if the named value is set in the input, whatever that |
||
| 551 | * value is (even "0"). Return false if the named value is not set. |
||
| 552 | * Example use is checking for the presence of check boxes in forms. |
||
| 553 | * |
||
| 554 | * @param string $name |
||
| 555 | * @return bool |
||
| 556 | */ |
||
| 557 | public function getCheck( $name ) { |
||
| 562 | |||
| 563 | /** |
||
| 564 | * Fetch a text string from the given array or return $default if it's not |
||
| 565 | * set. Carriage returns are stripped from the text, and with some language |
||
| 566 | * modules there is an input transliteration applied. This should generally |
||
| 567 | * be used for form "<textarea>" and "<input>" fields. Used for |
||
| 568 | * user-supplied freeform text input (for which input transformations may |
||
| 569 | * be required - e.g. Esperanto x-coding). |
||
| 570 | * |
||
| 571 | * @param string $name |
||
| 572 | * @param string $default Optional |
||
| 573 | * @return string |
||
| 574 | */ |
||
| 575 | public function getText( $name, $default = '' ) { |
||
| 581 | |||
| 582 | /** |
||
| 583 | * Extracts the given named values into an array. |
||
| 584 | * If no arguments are given, returns all input values. |
||
| 585 | * No transformation is performed on the values. |
||
| 586 | * |
||
| 587 | * @return array |
||
| 588 | */ |
||
| 589 | public function getValues() { |
||
| 604 | |||
| 605 | /** |
||
| 606 | * Returns the names of all input values excluding those in $exclude. |
||
| 607 | * |
||
| 608 | * @param array $exclude |
||
| 609 | * @return array |
||
| 610 | */ |
||
| 611 | public function getValueNames( $exclude = [] ) { |
||
| 614 | |||
| 615 | /** |
||
| 616 | * Get the values passed in the query string. |
||
| 617 | * No transformation is performed on the values. |
||
| 618 | * |
||
| 619 | * @return array |
||
| 620 | */ |
||
| 621 | public function getQueryValues() { |
||
| 624 | |||
| 625 | /** |
||
| 626 | * Return the contents of the Query with no decoding. Use when you need to |
||
| 627 | * know exactly what was sent, e.g. for an OAuth signature over the elements. |
||
| 628 | * |
||
| 629 | * @return string |
||
| 630 | */ |
||
| 631 | public function getRawQueryString() { |
||
| 634 | |||
| 635 | /** |
||
| 636 | * Return the contents of the POST with no decoding. Use when you need to |
||
| 637 | * know exactly what was sent, e.g. for an OAuth signature over the elements. |
||
| 638 | * |
||
| 639 | * @return string |
||
| 640 | */ |
||
| 641 | public function getRawPostString() { |
||
| 647 | |||
| 648 | /** |
||
| 649 | * Return the raw request body, with no processing. Cached since some methods |
||
| 650 | * disallow reading the stream more than once. As stated in the php docs, this |
||
| 651 | * does not work with enctype="multipart/form-data". |
||
| 652 | * |
||
| 653 | * @return string |
||
| 654 | */ |
||
| 655 | public function getRawInput() { |
||
| 662 | |||
| 663 | /** |
||
| 664 | * Get the HTTP method used for this request. |
||
| 665 | * |
||
| 666 | * @return string |
||
| 667 | */ |
||
| 668 | public function getMethod() { |
||
| 671 | |||
| 672 | /** |
||
| 673 | * Returns true if the present request was reached by a POST operation, |
||
| 674 | * false otherwise (GET, HEAD, or command-line). |
||
| 675 | * |
||
| 676 | * Note that values retrieved by the object may come from the |
||
| 677 | * GET URL etc even on a POST request. |
||
| 678 | * |
||
| 679 | * @return bool |
||
| 680 | */ |
||
| 681 | public function wasPosted() { |
||
| 684 | |||
| 685 | /** |
||
| 686 | * Return the session for this request |
||
| 687 | * @since 1.27 |
||
| 688 | * @note For performance, keep the session locally if you will be making |
||
| 689 | * much use of it instead of calling this method repeatedly. |
||
| 690 | * @return Session |
||
| 691 | */ |
||
| 692 | public function getSession() { |
||
| 704 | |||
| 705 | /** |
||
| 706 | * Set the session for this request |
||
| 707 | * @since 1.27 |
||
| 708 | * @private For use by MediaWiki\Session classes only |
||
| 709 | * @param SessionId $sessionId |
||
| 710 | */ |
||
| 711 | public function setSessionId( SessionId $sessionId ) { |
||
| 714 | |||
| 715 | /** |
||
| 716 | * Get the session id for this request, if any |
||
| 717 | * @since 1.27 |
||
| 718 | * @private For use by MediaWiki\Session classes only |
||
| 719 | * @return SessionId|null |
||
| 720 | */ |
||
| 721 | public function getSessionId() { |
||
| 724 | |||
| 725 | /** |
||
| 726 | * Returns true if the request has a persistent session. |
||
| 727 | * This does not necessarily mean that the user is logged in! |
||
| 728 | * |
||
| 729 | * @deprecated since 1.27, use |
||
| 730 | * \MediaWiki\Session\SessionManager::singleton()->getPersistedSessionId() |
||
| 731 | * instead. |
||
| 732 | * @return bool |
||
| 733 | */ |
||
| 734 | public function checkSessionCookie() { |
||
| 740 | |||
| 741 | /** |
||
| 742 | * Get a cookie from the $_COOKIE jar |
||
| 743 | * |
||
| 744 | * @param string $key The name of the cookie |
||
| 745 | * @param string $prefix A prefix to use for the cookie name, if not $wgCookiePrefix |
||
| 746 | * @param mixed $default What to return if the value isn't found |
||
| 747 | * @return mixed Cookie value or $default if the cookie not set |
||
| 748 | */ |
||
| 749 | public function getCookie( $key, $prefix = null, $default = null ) { |
||
| 756 | |||
| 757 | /** |
||
| 758 | * Return the path and query string portion of the main request URI. |
||
| 759 | * This will be suitable for use as a relative link in HTML output. |
||
| 760 | * |
||
| 761 | * @throws MWException |
||
| 762 | * @return string |
||
| 763 | */ |
||
| 764 | public static function getGlobalRequestURL() { |
||
| 800 | |||
| 801 | /** |
||
| 802 | * Return the path and query string portion of the request URI. |
||
| 803 | * This will be suitable for use as a relative link in HTML output. |
||
| 804 | * |
||
| 805 | * @throws MWException |
||
| 806 | * @return string |
||
| 807 | */ |
||
| 808 | public function getRequestURL() { |
||
| 811 | |||
| 812 | /** |
||
| 813 | * Return the request URI with the canonical service and hostname, path, |
||
| 814 | * and query string. This will be suitable for use as an absolute link |
||
| 815 | * in HTML or other output. |
||
| 816 | * |
||
| 817 | * If $wgServer is protocol-relative, this will return a fully |
||
| 818 | * qualified URL with the protocol that was used for this request. |
||
| 819 | * |
||
| 820 | * @return string |
||
| 821 | */ |
||
| 822 | public function getFullRequestURL() { |
||
| 825 | |||
| 826 | /** |
||
| 827 | * @param string $key |
||
| 828 | * @param string $value |
||
| 829 | * @return string |
||
| 830 | */ |
||
| 831 | public function appendQueryValue( $key, $value ) { |
||
| 834 | |||
| 835 | /** |
||
| 836 | * Appends or replaces value of query variables. |
||
| 837 | * |
||
| 838 | * @param array $array Array of values to replace/add to query |
||
| 839 | * @return string |
||
| 840 | */ |
||
| 841 | public function appendQueryArray( $array ) { |
||
| 848 | |||
| 849 | /** |
||
| 850 | * Check for limit and offset parameters on the input, and return sensible |
||
| 851 | * defaults if not given. The limit must be positive and is capped at 5000. |
||
| 852 | * Offset must be positive but is not capped. |
||
| 853 | * |
||
| 854 | * @param int $deflimit Limit to use if no input and the user hasn't set the option. |
||
| 855 | * @param string $optionname To specify an option other than rclimit to pull from. |
||
| 856 | * @return int[] First element is limit, second is offset |
||
| 857 | */ |
||
| 858 | public function getLimitOffset( $deflimit = 50, $optionname = 'rclimit' ) { |
||
| 882 | |||
| 883 | /** |
||
| 884 | * Return the path to the temporary file where PHP has stored the upload. |
||
| 885 | * |
||
| 886 | * @param string $key |
||
| 887 | * @return string|null String or null if no such file. |
||
| 888 | */ |
||
| 889 | public function getFileTempname( $key ) { |
||
| 893 | |||
| 894 | /** |
||
| 895 | * Return the upload error or 0 |
||
| 896 | * |
||
| 897 | * @param string $key |
||
| 898 | * @return int |
||
| 899 | */ |
||
| 900 | public function getUploadError( $key ) { |
||
| 904 | |||
| 905 | /** |
||
| 906 | * Return the original filename of the uploaded file, as reported by |
||
| 907 | * the submitting user agent. HTML-style character entities are |
||
| 908 | * interpreted and normalized to Unicode normalization form C, in part |
||
| 909 | * to deal with weird input from Safari with non-ASCII filenames. |
||
| 910 | * |
||
| 911 | * Other than this the name is not verified for being a safe filename. |
||
| 912 | * |
||
| 913 | * @param string $key |
||
| 914 | * @return string|null String or null if no such file. |
||
| 915 | */ |
||
| 916 | public function getFileName( $key ) { |
||
| 920 | |||
| 921 | /** |
||
| 922 | * Return a WebRequestUpload object corresponding to the key |
||
| 923 | * |
||
| 924 | * @param string $key |
||
| 925 | * @return WebRequestUpload |
||
| 926 | */ |
||
| 927 | public function getUpload( $key ) { |
||
| 930 | |||
| 931 | /** |
||
| 932 | * Return a handle to WebResponse style object, for setting cookies, |
||
| 933 | * headers and other stuff, for Request being worked on. |
||
| 934 | * |
||
| 935 | * @return WebResponse |
||
| 936 | */ |
||
| 937 | public function response() { |
||
| 945 | |||
| 946 | /** |
||
| 947 | * Initialise the header list |
||
| 948 | */ |
||
| 949 | protected function initHeaders() { |
||
| 970 | |||
| 971 | /** |
||
| 972 | * Get an array containing all request headers |
||
| 973 | * |
||
| 974 | * @return array Mapping header name to its value |
||
| 975 | */ |
||
| 976 | public function getAllHeaders() { |
||
| 980 | |||
| 981 | /** |
||
| 982 | * Get a request header, or false if it isn't set. |
||
| 983 | * |
||
| 984 | * @param string $name Case-insensitive header name |
||
| 985 | * @param int $flags Bitwise combination of: |
||
| 986 | * WebRequest::GETHEADER_LIST Treat the header as a comma-separated list |
||
| 987 | * of values, as described in RFC 2616 § 4.2. |
||
| 988 | * (since 1.26). |
||
| 989 | * @return string|array|bool False if header is unset; otherwise the |
||
| 990 | * header value(s) as either a string (the default) or an array, if |
||
| 991 | * WebRequest::GETHEADER_LIST flag was set. |
||
| 992 | */ |
||
| 993 | public function getHeader( $name, $flags = 0 ) { |
||
| 1005 | |||
| 1006 | /** |
||
| 1007 | * Get data from the session |
||
| 1008 | * |
||
| 1009 | * @note Prefer $this->getSession() instead if making multiple calls. |
||
| 1010 | * @param string $key Name of key in the session |
||
| 1011 | * @return mixed |
||
| 1012 | */ |
||
| 1013 | public function getSessionData( $key ) { |
||
| 1016 | |||
| 1017 | /** |
||
| 1018 | * Set session data |
||
| 1019 | * |
||
| 1020 | * @note Prefer $this->getSession() instead if making multiple calls. |
||
| 1021 | * @param string $key Name of key in the session |
||
| 1022 | * @param mixed $data |
||
| 1023 | */ |
||
| 1024 | public function setSessionData( $key, $data ) { |
||
| 1027 | |||
| 1028 | /** |
||
| 1029 | * Check if Internet Explorer will detect an incorrect cache extension in |
||
| 1030 | * PATH_INFO or QUERY_STRING. If the request can't be allowed, show an error |
||
| 1031 | * message or redirect to a safer URL. Returns true if the URL is OK, and |
||
| 1032 | * false if an error message has been shown and the request should be aborted. |
||
| 1033 | * |
||
| 1034 | * @param array $extWhitelist |
||
| 1035 | * @throws HttpError |
||
| 1036 | * @return bool |
||
| 1037 | */ |
||
| 1038 | public function checkUrlExtension( $extWhitelist = [] ) { |
||
| 1054 | |||
| 1055 | /** |
||
| 1056 | * Attempt to redirect to a URL with a QUERY_STRING that's not dangerous in |
||
| 1057 | * IE 6. Returns true if it was successful, false otherwise. |
||
| 1058 | * |
||
| 1059 | * @param string $url |
||
| 1060 | * @return bool |
||
| 1061 | */ |
||
| 1062 | protected function doSecurityRedirect( $url ) { |
||
| 1087 | |||
| 1088 | /** |
||
| 1089 | * Parse the Accept-Language header sent by the client into an array |
||
| 1090 | * |
||
| 1091 | * @return array Array( languageCode => q-value ) sorted by q-value in |
||
| 1092 | * descending order then appearing time in the header in ascending order. |
||
| 1093 | * May contain the "language" '*', which applies to languages other than those explicitly listed. |
||
| 1094 | * This is aligned with rfc2616 section 14.4 |
||
| 1095 | * Preference for earlier languages appears in rfc3282 as an extension to HTTP/1.1. |
||
| 1096 | */ |
||
| 1097 | public function getAcceptLang() { |
||
| 1141 | |||
| 1142 | /** |
||
| 1143 | * Fetch the raw IP from the request |
||
| 1144 | * |
||
| 1145 | * @since 1.19 |
||
| 1146 | * |
||
| 1147 | * @throws MWException |
||
| 1148 | * @return string |
||
| 1149 | */ |
||
| 1150 | protected function getRawIP() { |
||
| 1164 | |||
| 1165 | /** |
||
| 1166 | * Work out the IP address based on various globals |
||
| 1167 | * For trusted proxies, use the XFF client IP (first of the chain) |
||
| 1168 | * |
||
| 1169 | * @since 1.19 |
||
| 1170 | * |
||
| 1171 | * @throws MWException |
||
| 1172 | * @return string |
||
| 1173 | */ |
||
| 1174 | public function getIP() { |
||
| 1239 | |||
| 1240 | /** |
||
| 1241 | * @param string $ip |
||
| 1242 | * @return void |
||
| 1243 | * @since 1.21 |
||
| 1244 | */ |
||
| 1245 | public function setIP( $ip ) { |
||
| 1248 | } |
||
| 1249 |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.