48 $map = array_filter( $map,
function ( $w ) {
51 if ( !count( $map ) ) {
54 $this->sourceMap = $map;
57 foreach ( $map
as $location => $weight ) {
58 $hashes[$location] = sha1( $location );
60 uksort( $map,
function ( $a, $b )
use (
$hashes ) {
64 $sum = array_sum( $map );
66 foreach ( $map
as $location => $weight ) {
67 $standardMap[$location] = (int)floor( $weight / $sum * self::RING_SIZE );
71 foreach ( $standardMap
as $location => $weight ) {
73 $this->ring[$location] = [ $index, $index + $weight ];
78 $this->ring[
key( $this->ring )][1] = self::RING_SIZE;
102 $primaryLocation = null;
103 $spot = hexdec( substr( sha1( $item ), 0, 7 ) );
104 foreach ( $this->ring
as $location => $range ) {
105 if ( count( $locations ) >=
$limit ) {
110 if ( ( $range[0] <= $spot && $spot < $range[1] ) || $primaryLocation !== null ) {
111 if ( $primaryLocation === null ) {
112 $primaryLocation = $location;
114 $locations[] = $location;
118 reset( $this->ring );
119 while ( count( $locations ) <
$limit ) {
120 list( $location, ) = each( $this->ring );
121 if ( $location === $primaryLocation ) {
124 $locations[] = $location;
147 unset( $map[$location] );
149 return count( $map ) ?
new self( $map ) :
false;
160 if ( !isset( $this->sourceMap[$location] ) ) {
163 $expiry = time() + $ttl;
164 $this->liveRing = null;
165 $this->ejectionExpiries[$location] = $expiry;
166 $this->ejectionNextExpiry = min( $expiry, $this->ejectionNextExpiry );
168 return ( count( $this->ejectionExpiries ) < count( $this->sourceMap ) );
179 if ( $this->liveRing === null || $this->ejectionNextExpiry <= $now ) {
180 $this->ejectionExpiries = array_filter(
181 $this->ejectionExpiries,
182 function( $expiry )
use ( $now ) {
183 return ( $expiry > $now );
186 if ( count( $this->ejectionExpiries ) ) {
187 $map = array_diff_key( $this->sourceMap, $this->ejectionExpiries );
188 $this->liveRing = count( $map ) ?
new self( $map ) :
false;
190 $this->ejectionNextExpiry = min( $this->ejectionExpiries );
192 $this->liveRing = clone $this;
193 $this->liveRing->ejectionExpiries = [];
194 $this->liveRing->ejectionNextExpiry = INF;
195 $this->liveRing->liveRing = null;
197 $this->ejectionNextExpiry = INF;
200 if ( !$this->liveRing ) {
getLiveLocations($item, $limit)
Get the location of an item on the "live" ring, as well as the next locations.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
the array() calling protocol came about after MediaWiki 1.4rc1.
Array $liveRing
(location => (start, end))
Array $ring
(location => (start, end))
getLocation($item)
Get the location of an item on the ring.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Array $sourceMap
(location => weight)
getLocationWeights()
Get the map of locations to weight (ignores 0-weight items)
getLiveLocationWeights()
Get the map of "live" locations to weight (ignores 0-weight items)
Convenience class for weighted consistent hash rings.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
ejectFromLiveRing($location, $ttl)
Remove a location from the "live" hash ring.
getLiveRing()
Get the "live" hash ring (which does not include ejected locations)
getLocations($item, $limit)
Get the location of an item on the ring, as well as the next locations.
newWithoutLocation($location)
Get a new hash ring with a location removed from the ring.
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
Array $ejectionExpiries
(location => UNIX timestamp)
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
integer $ejectionNextExpiry
UNIX timestamp.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
getLiveLocation($item)
Get the location of an item on the "live" ring.