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 | /** @var bool Whether this HTTP request is "safe" (even if it is an HTTP post) */ |
||
| 84 | protected $markedAsSafe = false; |
||
| 85 | |||
| 86 | public function __construct() { |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Extract relevant query arguments from the http request uri's path |
||
| 97 | * to be merged with the normal php provided query arguments. |
||
| 98 | * Tries to use the REQUEST_URI data if available and parses it |
||
| 99 | * according to the wiki's configuration looking for any known pattern. |
||
| 100 | * |
||
| 101 | * If the REQUEST_URI is not provided we'll fall back on the PATH_INFO |
||
| 102 | * provided by the server if any and use that to set a 'title' parameter. |
||
| 103 | * |
||
| 104 | * @param string $want If this is not 'all', then the function |
||
| 105 | * will return an empty array if it determines that the URL is |
||
| 106 | * inside a rewrite path. |
||
| 107 | * |
||
| 108 | * @return array Any query arguments found in path matches. |
||
| 109 | */ |
||
| 110 | public static function getPathInfo( $want = 'all' ) { |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Work out an appropriate URL prefix containing scheme and host, based on |
||
| 189 | * information detected from $_SERVER |
||
| 190 | * |
||
| 191 | * @return string |
||
| 192 | */ |
||
| 193 | public static function detectServer() { |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Detect the protocol from $_SERVER. |
||
| 234 | * This is for use prior to Setup.php, when no WebRequest object is available. |
||
| 235 | * At other times, use the non-static function getProtocol(). |
||
| 236 | * |
||
| 237 | * @return array |
||
| 238 | */ |
||
| 239 | public static function detectProtocol() { |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Get the number of seconds to have elapsed since request start, |
||
| 251 | * in fractional seconds, with microsecond resolution. |
||
| 252 | * |
||
| 253 | * @return float |
||
| 254 | * @since 1.25 |
||
| 255 | */ |
||
| 256 | public function getElapsedTime() { |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Get the unique request ID. |
||
| 262 | * This is either the value of the UNIQUE_ID envvar (if present) or a |
||
| 263 | * randomly-generated 24-character string. |
||
| 264 | * |
||
| 265 | * @return string |
||
| 266 | * @since 1.27 |
||
| 267 | */ |
||
| 268 | public static function getRequestId() { |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Override the unique request ID. This is for sub-requests, such as jobs, |
||
| 279 | * that wish to use the same id but are not part of the same execution context. |
||
| 280 | * |
||
| 281 | * @param string $id |
||
| 282 | * @since 1.27 |
||
| 283 | */ |
||
| 284 | public static function overrideRequestId( $id ) { |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Get the current URL protocol (http or https) |
||
| 290 | * @return string |
||
| 291 | */ |
||
| 292 | public function getProtocol() { |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Check for title, action, and/or variant data in the URL |
||
| 301 | * and interpolate it into the GET variables. |
||
| 302 | * This should only be run after $wgContLang is available, |
||
| 303 | * as we may need the list of language variants to determine |
||
| 304 | * available variant URLs. |
||
| 305 | */ |
||
| 306 | public function interpolateTitle() { |
||
| 317 | |||
| 318 | /** |
||
| 319 | * URL rewriting function; tries to extract page title and, |
||
| 320 | * optionally, one other fixed parameter value from a URL path. |
||
| 321 | * |
||
| 322 | * @param string $path The URL path given from the client |
||
| 323 | * @param array $bases One or more URLs, optionally with $1 at the end |
||
| 324 | * @param string|bool $key If provided, the matching key in $bases will be |
||
| 325 | * passed on as the value of this URL parameter |
||
| 326 | * @return array Array of URL variables to interpolate; empty if no match |
||
| 327 | */ |
||
| 328 | static function extractTitle( $path, $bases, $key = false ) { |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Recursively normalizes UTF-8 strings in the given array. |
||
| 349 | * |
||
| 350 | * @param string|array $data |
||
| 351 | * @return array|string Cleaned-up version of the given |
||
| 352 | * @private |
||
| 353 | */ |
||
| 354 | function normalizeUnicode( $data ) { |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Fetch a value from the given array or return $default if it's not set. |
||
| 370 | * |
||
| 371 | * @param array $arr |
||
| 372 | * @param string $name |
||
| 373 | * @param mixed $default |
||
| 374 | * @return mixed |
||
| 375 | */ |
||
| 376 | private function getGPCVal( $arr, $name, $default ) { |
||
| 396 | |||
| 397 | /** |
||
| 398 | * Fetch a scalar from the input or return $default if it's not set. |
||
| 399 | * Returns a string. Arrays are discarded. Useful for |
||
| 400 | * non-freeform text inputs (e.g. predefined internal text keys |
||
| 401 | * selected by a drop-down menu). For freeform input, see getText(). |
||
| 402 | * |
||
| 403 | * @param string $name |
||
| 404 | * @param string $default Optional default (or null) |
||
| 405 | * @return string |
||
| 406 | */ |
||
| 407 | public function getVal( $name, $default = null ) { |
||
| 418 | |||
| 419 | /** |
||
| 420 | * Set an arbitrary value into our get/post data. |
||
| 421 | * |
||
| 422 | * @param string $key Key name to use |
||
| 423 | * @param mixed $value Value to set |
||
| 424 | * @return mixed Old value if one was present, null otherwise |
||
| 425 | */ |
||
| 426 | public function setVal( $key, $value ) { |
||
| 431 | |||
| 432 | /** |
||
| 433 | * Unset an arbitrary value from our get/post data. |
||
| 434 | * |
||
| 435 | * @param string $key Key name to use |
||
| 436 | * @return mixed Old value if one was present, null otherwise |
||
| 437 | */ |
||
| 438 | public function unsetVal( $key ) { |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Fetch an array from the input or return $default if it's not set. |
||
| 450 | * If source was scalar, will return an array with a single element. |
||
| 451 | * If no source and no default, returns null. |
||
| 452 | * |
||
| 453 | * @param string $name |
||
| 454 | * @param array $default Optional default (or null) |
||
| 455 | * @return array |
||
| 456 | */ |
||
| 457 | public function getArray( $name, $default = null ) { |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Fetch an array of integers, or return $default if it's not set. |
||
| 468 | * If source was scalar, will return an array with a single element. |
||
| 469 | * If no source and no default, returns null. |
||
| 470 | * If an array is returned, contents are guaranteed to be integers. |
||
| 471 | * |
||
| 472 | * @param string $name |
||
| 473 | * @param array $default Option default (or null) |
||
| 474 | * @return array Array of ints |
||
| 475 | */ |
||
| 476 | public function getIntArray( $name, $default = null ) { |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Fetch an integer value from the input or return $default if not set. |
||
| 486 | * Guaranteed to return an integer; non-numeric input will typically |
||
| 487 | * return 0. |
||
| 488 | * |
||
| 489 | * @param string $name |
||
| 490 | * @param int $default |
||
| 491 | * @return int |
||
| 492 | */ |
||
| 493 | public function getInt( $name, $default = 0 ) { |
||
| 496 | |||
| 497 | /** |
||
| 498 | * Fetch an integer value from the input or return null if empty. |
||
| 499 | * Guaranteed to return an integer or null; non-numeric input will |
||
| 500 | * typically return null. |
||
| 501 | * |
||
| 502 | * @param string $name |
||
| 503 | * @return int|null |
||
| 504 | */ |
||
| 505 | public function getIntOrNull( $name ) { |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Fetch a floating point value from the input or return $default if not set. |
||
| 514 | * Guaranteed to return a float; non-numeric input will typically |
||
| 515 | * return 0. |
||
| 516 | * |
||
| 517 | * @since 1.23 |
||
| 518 | * @param string $name |
||
| 519 | * @param float $default |
||
| 520 | * @return float |
||
| 521 | */ |
||
| 522 | public function getFloat( $name, $default = 0.0 ) { |
||
| 525 | |||
| 526 | /** |
||
| 527 | * Fetch a boolean value from the input or return $default if not set. |
||
| 528 | * Guaranteed to return true or false, with normal PHP semantics for |
||
| 529 | * boolean interpretation of strings. |
||
| 530 | * |
||
| 531 | * @param string $name |
||
| 532 | * @param bool $default |
||
| 533 | * @return bool |
||
| 534 | */ |
||
| 535 | public function getBool( $name, $default = false ) { |
||
| 538 | |||
| 539 | /** |
||
| 540 | * Fetch a boolean value from the input or return $default if not set. |
||
| 541 | * Unlike getBool, the string "false" will result in boolean false, which is |
||
| 542 | * useful when interpreting information sent from JavaScript. |
||
| 543 | * |
||
| 544 | * @param string $name |
||
| 545 | * @param bool $default |
||
| 546 | * @return bool |
||
| 547 | */ |
||
| 548 | public function getFuzzyBool( $name, $default = false ) { |
||
| 551 | |||
| 552 | /** |
||
| 553 | * Return true if the named value is set in the input, whatever that |
||
| 554 | * value is (even "0"). Return false if the named value is not set. |
||
| 555 | * Example use is checking for the presence of check boxes in forms. |
||
| 556 | * |
||
| 557 | * @param string $name |
||
| 558 | * @return bool |
||
| 559 | */ |
||
| 560 | public function getCheck( $name ) { |
||
| 565 | |||
| 566 | /** |
||
| 567 | * Fetch a text string from the given array or return $default if it's not |
||
| 568 | * set. Carriage returns are stripped from the text, and with some language |
||
| 569 | * modules there is an input transliteration applied. This should generally |
||
| 570 | * be used for form "<textarea>" and "<input>" fields. Used for |
||
| 571 | * user-supplied freeform text input (for which input transformations may |
||
| 572 | * be required - e.g. Esperanto x-coding). |
||
| 573 | * |
||
| 574 | * @param string $name |
||
| 575 | * @param string $default Optional |
||
| 576 | * @return string |
||
| 577 | */ |
||
| 578 | public function getText( $name, $default = '' ) { |
||
| 584 | |||
| 585 | /** |
||
| 586 | * Extracts the given named values into an array. |
||
| 587 | * If no arguments are given, returns all input values. |
||
| 588 | * No transformation is performed on the values. |
||
| 589 | * |
||
| 590 | * @return array |
||
| 591 | */ |
||
| 592 | public function getValues() { |
||
| 607 | |||
| 608 | /** |
||
| 609 | * Returns the names of all input values excluding those in $exclude. |
||
| 610 | * |
||
| 611 | * @param array $exclude |
||
| 612 | * @return array |
||
| 613 | */ |
||
| 614 | public function getValueNames( $exclude = [] ) { |
||
| 617 | |||
| 618 | /** |
||
| 619 | * Get the values passed in the query string. |
||
| 620 | * No transformation is performed on the values. |
||
| 621 | * |
||
| 622 | * @return array |
||
| 623 | */ |
||
| 624 | public function getQueryValues() { |
||
| 627 | |||
| 628 | /** |
||
| 629 | * Return the contents of the Query with no decoding. Use when you need to |
||
| 630 | * know exactly what was sent, e.g. for an OAuth signature over the elements. |
||
| 631 | * |
||
| 632 | * @return string |
||
| 633 | */ |
||
| 634 | public function getRawQueryString() { |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Return the contents of the POST with no decoding. Use when you need to |
||
| 640 | * know exactly what was sent, e.g. for an OAuth signature over the elements. |
||
| 641 | * |
||
| 642 | * @return string |
||
| 643 | */ |
||
| 644 | public function getRawPostString() { |
||
| 650 | |||
| 651 | /** |
||
| 652 | * Return the raw request body, with no processing. Cached since some methods |
||
| 653 | * disallow reading the stream more than once. As stated in the php docs, this |
||
| 654 | * does not work with enctype="multipart/form-data". |
||
| 655 | * |
||
| 656 | * @return string |
||
| 657 | */ |
||
| 658 | public function getRawInput() { |
||
| 665 | |||
| 666 | /** |
||
| 667 | * Get the HTTP method used for this request. |
||
| 668 | * |
||
| 669 | * @return string |
||
| 670 | */ |
||
| 671 | public function getMethod() { |
||
| 674 | |||
| 675 | /** |
||
| 676 | * Returns true if the present request was reached by a POST operation, |
||
| 677 | * false otherwise (GET, HEAD, or command-line). |
||
| 678 | * |
||
| 679 | * Note that values retrieved by the object may come from the |
||
| 680 | * GET URL etc even on a POST request. |
||
| 681 | * |
||
| 682 | * @return bool |
||
| 683 | */ |
||
| 684 | public function wasPosted() { |
||
| 687 | |||
| 688 | /** |
||
| 689 | * Return the session for this request |
||
| 690 | * @since 1.27 |
||
| 691 | * @note For performance, keep the session locally if you will be making |
||
| 692 | * much use of it instead of calling this method repeatedly. |
||
| 693 | * @return Session |
||
| 694 | */ |
||
| 695 | public function getSession() { |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Set the session for this request |
||
| 710 | * @since 1.27 |
||
| 711 | * @private For use by MediaWiki\Session classes only |
||
| 712 | * @param SessionId $sessionId |
||
| 713 | */ |
||
| 714 | public function setSessionId( SessionId $sessionId ) { |
||
| 717 | |||
| 718 | /** |
||
| 719 | * Get the session id for this request, if any |
||
| 720 | * @since 1.27 |
||
| 721 | * @private For use by MediaWiki\Session classes only |
||
| 722 | * @return SessionId|null |
||
| 723 | */ |
||
| 724 | public function getSessionId() { |
||
| 727 | |||
| 728 | /** |
||
| 729 | * Returns true if the request has a persistent session. |
||
| 730 | * This does not necessarily mean that the user is logged in! |
||
| 731 | * |
||
| 732 | * @deprecated since 1.27, use |
||
| 733 | * \MediaWiki\Session\SessionManager::singleton()->getPersistedSessionId() |
||
| 734 | * instead. |
||
| 735 | * @return bool |
||
| 736 | */ |
||
| 737 | public function checkSessionCookie() { |
||
| 743 | |||
| 744 | /** |
||
| 745 | * Get a cookie from the $_COOKIE jar |
||
| 746 | * |
||
| 747 | * @param string $key The name of the cookie |
||
| 748 | * @param string $prefix A prefix to use for the cookie name, if not $wgCookiePrefix |
||
| 749 | * @param mixed $default What to return if the value isn't found |
||
| 750 | * @return mixed Cookie value or $default if the cookie not set |
||
| 751 | */ |
||
| 752 | public function getCookie( $key, $prefix = null, $default = null ) { |
||
| 759 | |||
| 760 | /** |
||
| 761 | * Return the path and query string portion of the main request URI. |
||
| 762 | * This will be suitable for use as a relative link in HTML output. |
||
| 763 | * |
||
| 764 | * @throws MWException |
||
| 765 | * @return string |
||
| 766 | */ |
||
| 767 | public static function getGlobalRequestURL() { |
||
| 803 | |||
| 804 | /** |
||
| 805 | * Return the path and query string portion of the request URI. |
||
| 806 | * This will be suitable for use as a relative link in HTML output. |
||
| 807 | * |
||
| 808 | * @throws MWException |
||
| 809 | * @return string |
||
| 810 | */ |
||
| 811 | public function getRequestURL() { |
||
| 814 | |||
| 815 | /** |
||
| 816 | * Return the request URI with the canonical service and hostname, path, |
||
| 817 | * and query string. This will be suitable for use as an absolute link |
||
| 818 | * in HTML or other output. |
||
| 819 | * |
||
| 820 | * If $wgServer is protocol-relative, this will return a fully |
||
| 821 | * qualified URL with the protocol that was used for this request. |
||
| 822 | * |
||
| 823 | * @return string |
||
| 824 | */ |
||
| 825 | public function getFullRequestURL() { |
||
| 828 | |||
| 829 | /** |
||
| 830 | * @param string $key |
||
| 831 | * @param string $value |
||
| 832 | * @return string |
||
| 833 | */ |
||
| 834 | public function appendQueryValue( $key, $value ) { |
||
| 837 | |||
| 838 | /** |
||
| 839 | * Appends or replaces value of query variables. |
||
| 840 | * |
||
| 841 | * @param array $array Array of values to replace/add to query |
||
| 842 | * @return string |
||
| 843 | */ |
||
| 844 | public function appendQueryArray( $array ) { |
||
| 851 | |||
| 852 | /** |
||
| 853 | * Check for limit and offset parameters on the input, and return sensible |
||
| 854 | * defaults if not given. The limit must be positive and is capped at 5000. |
||
| 855 | * Offset must be positive but is not capped. |
||
| 856 | * |
||
| 857 | * @param int $deflimit Limit to use if no input and the user hasn't set the option. |
||
| 858 | * @param string $optionname To specify an option other than rclimit to pull from. |
||
| 859 | * @return int[] First element is limit, second is offset |
||
| 860 | */ |
||
| 861 | public function getLimitOffset( $deflimit = 50, $optionname = 'rclimit' ) { |
||
| 885 | |||
| 886 | /** |
||
| 887 | * Return the path to the temporary file where PHP has stored the upload. |
||
| 888 | * |
||
| 889 | * @param string $key |
||
| 890 | * @return string|null String or null if no such file. |
||
| 891 | */ |
||
| 892 | public function getFileTempname( $key ) { |
||
| 896 | |||
| 897 | /** |
||
| 898 | * Return the upload error or 0 |
||
| 899 | * |
||
| 900 | * @param string $key |
||
| 901 | * @return int |
||
| 902 | */ |
||
| 903 | public function getUploadError( $key ) { |
||
| 907 | |||
| 908 | /** |
||
| 909 | * Return the original filename of the uploaded file, as reported by |
||
| 910 | * the submitting user agent. HTML-style character entities are |
||
| 911 | * interpreted and normalized to Unicode normalization form C, in part |
||
| 912 | * to deal with weird input from Safari with non-ASCII filenames. |
||
| 913 | * |
||
| 914 | * Other than this the name is not verified for being a safe filename. |
||
| 915 | * |
||
| 916 | * @param string $key |
||
| 917 | * @return string|null String or null if no such file. |
||
| 918 | */ |
||
| 919 | public function getFileName( $key ) { |
||
| 923 | |||
| 924 | /** |
||
| 925 | * Return a WebRequestUpload object corresponding to the key |
||
| 926 | * |
||
| 927 | * @param string $key |
||
| 928 | * @return WebRequestUpload |
||
| 929 | */ |
||
| 930 | public function getUpload( $key ) { |
||
| 933 | |||
| 934 | /** |
||
| 935 | * Return a handle to WebResponse style object, for setting cookies, |
||
| 936 | * headers and other stuff, for Request being worked on. |
||
| 937 | * |
||
| 938 | * @return WebResponse |
||
| 939 | */ |
||
| 940 | public function response() { |
||
| 948 | |||
| 949 | /** |
||
| 950 | * Initialise the header list |
||
| 951 | */ |
||
| 952 | protected function initHeaders() { |
||
| 973 | |||
| 974 | /** |
||
| 975 | * Get an array containing all request headers |
||
| 976 | * |
||
| 977 | * @return array Mapping header name to its value |
||
| 978 | */ |
||
| 979 | public function getAllHeaders() { |
||
| 983 | |||
| 984 | /** |
||
| 985 | * Get a request header, or false if it isn't set. |
||
| 986 | * |
||
| 987 | * @param string $name Case-insensitive header name |
||
| 988 | * @param int $flags Bitwise combination of: |
||
| 989 | * WebRequest::GETHEADER_LIST Treat the header as a comma-separated list |
||
| 990 | * of values, as described in RFC 2616 § 4.2. |
||
| 991 | * (since 1.26). |
||
| 992 | * @return string|array|bool False if header is unset; otherwise the |
||
| 993 | * header value(s) as either a string (the default) or an array, if |
||
| 994 | * WebRequest::GETHEADER_LIST flag was set. |
||
| 995 | */ |
||
| 996 | public function getHeader( $name, $flags = 0 ) { |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * Get data from the session |
||
| 1011 | * |
||
| 1012 | * @note Prefer $this->getSession() instead if making multiple calls. |
||
| 1013 | * @param string $key Name of key in the session |
||
| 1014 | * @return mixed |
||
| 1015 | */ |
||
| 1016 | public function getSessionData( $key ) { |
||
| 1019 | |||
| 1020 | /** |
||
| 1021 | * Set session data |
||
| 1022 | * |
||
| 1023 | * @note Prefer $this->getSession() instead if making multiple calls. |
||
| 1024 | * @param string $key Name of key in the session |
||
| 1025 | * @param mixed $data |
||
| 1026 | */ |
||
| 1027 | public function setSessionData( $key, $data ) { |
||
| 1030 | |||
| 1031 | /** |
||
| 1032 | * Check if Internet Explorer will detect an incorrect cache extension in |
||
| 1033 | * PATH_INFO or QUERY_STRING. If the request can't be allowed, show an error |
||
| 1034 | * message or redirect to a safer URL. Returns true if the URL is OK, and |
||
| 1035 | * false if an error message has been shown and the request should be aborted. |
||
| 1036 | * |
||
| 1037 | * @param array $extWhitelist |
||
| 1038 | * @throws HttpError |
||
| 1039 | * @return bool |
||
| 1040 | */ |
||
| 1041 | public function checkUrlExtension( $extWhitelist = [] ) { |
||
| 1057 | |||
| 1058 | /** |
||
| 1059 | * Attempt to redirect to a URL with a QUERY_STRING that's not dangerous in |
||
| 1060 | * IE 6. Returns true if it was successful, false otherwise. |
||
| 1061 | * |
||
| 1062 | * @param string $url |
||
| 1063 | * @return bool |
||
| 1064 | */ |
||
| 1065 | protected function doSecurityRedirect( $url ) { |
||
| 1090 | |||
| 1091 | /** |
||
| 1092 | * Parse the Accept-Language header sent by the client into an array |
||
| 1093 | * |
||
| 1094 | * @return array Array( languageCode => q-value ) sorted by q-value in |
||
| 1095 | * descending order then appearing time in the header in ascending order. |
||
| 1096 | * May contain the "language" '*', which applies to languages other than those explicitly listed. |
||
| 1097 | * This is aligned with rfc2616 section 14.4 |
||
| 1098 | * Preference for earlier languages appears in rfc3282 as an extension to HTTP/1.1. |
||
| 1099 | */ |
||
| 1100 | public function getAcceptLang() { |
||
| 1144 | |||
| 1145 | /** |
||
| 1146 | * Fetch the raw IP from the request |
||
| 1147 | * |
||
| 1148 | * @since 1.19 |
||
| 1149 | * |
||
| 1150 | * @throws MWException |
||
| 1151 | * @return string |
||
| 1152 | */ |
||
| 1153 | protected function getRawIP() { |
||
| 1167 | |||
| 1168 | /** |
||
| 1169 | * Work out the IP address based on various globals |
||
| 1170 | * For trusted proxies, use the XFF client IP (first of the chain) |
||
| 1171 | * |
||
| 1172 | * @since 1.19 |
||
| 1173 | * |
||
| 1174 | * @throws MWException |
||
| 1175 | * @return string |
||
| 1176 | */ |
||
| 1177 | public function getIP() { |
||
| 1242 | |||
| 1243 | /** |
||
| 1244 | * @param string $ip |
||
| 1245 | * @return void |
||
| 1246 | * @since 1.21 |
||
| 1247 | */ |
||
| 1248 | public function setIP( $ip ) { |
||
| 1251 | |||
| 1252 | /** |
||
| 1253 | * Whether this request should be identified as being "safe" |
||
| 1254 | * |
||
| 1255 | * This means that the client is not requesting any state changes and that database writes |
||
| 1256 | * are not inherently required. Ideally, no visible updates would happen at all. If they |
||
| 1257 | * must, then they should not be publically attributed to the end user. |
||
| 1258 | * |
||
| 1259 | * In more detail: |
||
| 1260 | * - Cache populations and refreshes MAY occur. |
||
| 1261 | * - Private user session updates and private server logging MAY occur. |
||
| 1262 | * - Updates to private viewing activity data MAY occur via DeferredUpdates. |
||
| 1263 | * - Other updates SHOULD NOT occur (e.g. modifying content assets). |
||
| 1264 | * |
||
| 1265 | * @return bool |
||
| 1266 | * @see https://tools.ietf.org/html/rfc7231#section-4.2.1 |
||
| 1267 | * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html |
||
| 1268 | * @since 1.28 |
||
| 1269 | */ |
||
| 1270 | public function isSafeRequest() { |
||
| 1283 | |||
| 1284 | /** |
||
| 1285 | * Mark this request is identified as being nullipotent even if it is a POST request |
||
| 1286 | * |
||
| 1287 | * POST requests are often used due to the need for a client payload, even if the request |
||
| 1288 | * is otherwise equivalent to a "safe method" request. |
||
| 1289 | * |
||
| 1290 | * @see https://tools.ietf.org/html/rfc7231#section-4.2.1 |
||
| 1291 | * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html |
||
| 1292 | * @since 1.28 |
||
| 1293 | */ |
||
| 1294 | public function markAsSafeRequest() { |
||
| 1297 | } |
||
| 1298 |
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.