$vals['emailauthenticated'] = wfTimestamp( TS_ISO_8601, $auth );
}
}
+
+ if ( isset( $this->prop['acceptlang'] ) ) {
+ $vals['acceptlang'] = $this->getAcceptLang();
+ $result->setIndexedTagName( $vals['acceptlang'], 'lang' );
+ }
return $vals;
}
+
+ protected function getAcceptLang() {
+ // Modified version of code found at http://www.thefutureoftheweb.com/blog/use-accept-language-header
+ if ( !isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) {
+ return array();
+ }
+
+ // Break up string into pieces (languages and q factors)
+ $lang_parse = null;
+ preg_match_all( '/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0(\.[0-9]+))?)?/i',
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse );
+
+ if ( !count( $lang_parse[1] ) ) {
+ return array();
+ }
+ // Create a list like "en" => 0.8
+ $langs = array_combine( $lang_parse[1], $lang_parse[4] );
+ // Set default q factor to 1
+ foreach ( $langs as $lang => $val ) {
+ if ( $val === '' ) {
+ $langs[$lang] = 1;
+ }
+ }
+ // Sort list
+ arsort( $langs, SORT_NUMERIC );
+
+ // Format for API output
+ $retval = array();
+ foreach ( $langs as $lang => $val ) {
+ $r = array( 'q' => $val );
+ ApiResult::setContent( $r, $lang );
+ $retval[] = $r;
+ }
+ return $retval;
+ }
protected function getRateLimits() {
global $wgUser, $wgRateLimits;
'editcount',
'ratelimits',
'email',
+ 'acceptlang',
)
)
);
' editcount - adds the current user\'s edit count',
' ratelimits - lists all rate limits applying to the current user',
' email - adds the user\'s email address and email authentication date',
+ ' acceptlang - echoes the Accept-Language header sent by the client in a structured format',
)
);
}