Index: trunk/phase3/includes/WebRequest.php |
— | — | @@ -730,6 +730,8 @@ |
731 | 731 | /** |
732 | 732 | * Parse the Accept-Language header sent by the client into an array |
733 | 733 | * @return array( languageCode => q-value ) sorted by q-value in descending order |
| 734 | + * May contain the "language" '*', which applies to languages other than those explicitly listed. |
| 735 | + * This is aligned with rfc2616 section 14.4 |
734 | 736 | */ |
735 | 737 | public function getAcceptLang() { |
736 | 738 | // Modified version of code found at http://www.thefutureoftheweb.com/blog/use-accept-language-header |
— | — | @@ -738,22 +740,29 @@ |
739 | 741 | return array(); |
740 | 742 | } |
741 | 743 | |
| 744 | + // Return the language codes in lower case |
| 745 | + $acceptLang = strtolower( $acceptLang ); |
| 746 | + |
742 | 747 | // Break up string into pieces (languages and q factors) |
743 | 748 | $lang_parse = null; |
744 | | - preg_match_all( '/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0(\.[0-9]+))?)?/i', |
| 749 | + preg_match_all( '/([a-z]{1,8}(-[a-z]{1,8})?|\*)\s*(;\s*q\s*=\s*(1|0(\.[0-9]+)?)?)?/', |
745 | 750 | $acceptLang, $lang_parse ); |
746 | 751 | |
747 | 752 | if ( !count( $lang_parse[1] ) ) { |
748 | 753 | return array(); |
749 | 754 | } |
| 755 | + |
750 | 756 | // Create a list like "en" => 0.8 |
751 | 757 | $langs = array_combine( $lang_parse[1], $lang_parse[4] ); |
752 | 758 | // Set default q factor to 1 |
753 | 759 | foreach ( $langs as $lang => $val ) { |
754 | 760 | if ( $val === '' ) { |
755 | 761 | $langs[$lang] = 1; |
| 762 | + } else if ( $val == 0 ) { |
| 763 | + unset($langs[$lang]); |
756 | 764 | } |
757 | 765 | } |
| 766 | + |
758 | 767 | // Sort list |
759 | 768 | arsort( $langs, SORT_NUMERIC ); |
760 | 769 | return $langs; |