MediaWiki  REL1_31
Go to the documentation of this file.
1 <?php
11 namespace Wikimedia\Http;
35  public function parseWeights( $rawHeader ) {
36  //FIXME: The code below was copied and adapted from WebRequest::getAcceptLang.
37  // Move this utility class into core for reuse!
39  // first, strip header name
40  $rawHeader = preg_replace( '/^[-\w]+:\s*/', '', $rawHeader );
42  // Return values in lower case
43  $rawHeader = strtolower( $rawHeader );
45  // Break up string into pieces (values and q factors)
46  $value_parse = null;
47  preg_match_all( '@([a-z\d*]+([-+/.][a-z\d*]+)*)\s*(;\s*q\s*=\s*(1(\.0{0,3})?|0(\.\d{0,3})?)?)?@',
48  $rawHeader, $value_parse );
50  if ( !count( $value_parse[1] ) ) {
51  return [];
52  }
54  $values = $value_parse[1];
55  $qvalues = $value_parse[4];
56  $indices = range( 0, count( $value_parse[1] ) - 1 );
58  // Set default q factor to 1
59  foreach ( $indices as $index ) {
60  if ( $qvalues[$index] === '' ) {
61  $qvalues[$index] = 1;
62  } elseif ( $qvalues[$index] == 0 ) {
63  unset( $values[$index], $qvalues[$index], $indices[$index] );
64  } else {
65  $qvalues[$index] = (float)$qvalues[$index];
66  }
67  }
69  // Sort list. First by $qvalues, then by order. Reorder $values the same way
70  array_multisort( $qvalues, SORT_DESC, SORT_NUMERIC, $indices, $values );
72  // Create a list like "en" => 0.8
73  $weights = array_combine( $values, $qvalues );
75  return $weights;
76  }
78 }
Definition: HttpAcceptParser.php:13
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
Utility for parsing a HTTP Accept header value into a weight map.
Definition: HttpAcceptNegotiator.php:3
parseWeights( $rawHeader)
Parses an HTTP header into a weight map, that is an associative array mapping values to their respect...
Definition: HttpAcceptParser.php:35
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:22