21use Wikimedia\Assert\Assert;
39 private static $counters = [
'edits',
'pages',
'articles',
'users',
'images' ];
44 $this->articles = $good;
51 Assert::parameterType( __CLASS__, $update,
'$update' );
53 foreach ( self::$counters
as $field ) {
54 $this->$field += $update->$field;
63 $update =
new self( 0, 0, 0 );
65 foreach ( self::$counters
as $field ) {
66 if ( isset( $deltas[$field] ) && $deltas[$field] ) {
67 $update->$field = $deltas[$field];
82 if ( $rate && ( $rate < 0 || mt_rand( 0, $rate - 1 ) != 0 ) ) {
86 DeferredUpdates::addCallableUpdate( [ $this,
'tryDBUpdateInternal' ] );
97 $lockKey =
wfWikiID() .
':site_stats';
101 if ( !$dbw->lockIsFree( $lockKey, __METHOD__ )
102 || !$dbw->lock( $lockKey, __METHOD__, 1 )
110 $this->
edits += ( $pd[
'ss_total_edits'][
'+'] - $pd[
'ss_total_edits'][
'-'] );
111 $this->articles += ( $pd[
'ss_good_articles'][
'+'] - $pd[
'ss_good_articles'][
'-'] );
112 $this->
pages += ( $pd[
'ss_total_pages'][
'+'] - $pd[
'ss_total_pages'][
'-'] );
113 $this->users += ( $pd[
'ss_users'][
'+'] - $pd[
'ss_users'][
'-'] );
114 $this->images += ( $pd[
'ss_images'][
'+'] - $pd[
'ss_images'][
'-'] );
120 $this->
appendUpdate( $updates,
'ss_good_articles', $this->articles );
122 $this->
appendUpdate( $updates,
'ss_users', $this->users );
123 $this->
appendUpdate( $updates,
'ss_images', $this->images );
124 if ( $updates !=
'' ) {
125 $dbw->update(
'site_stats', [ $updates ], [], __METHOD__ );
132 $dbw->unlock( $lockKey, __METHOD__ );
146 # Get non-bot users than did some recent action other than making accounts.
147 # If account creation is included, the number gets inflated ~20+ fold on enwiki.
148 $activeUsers =
$dbr->selectField(
150 'COUNT( DISTINCT rc_user_text )',
154 'rc_log_type != ' .
$dbr->addQuotes(
'newusers' ) .
' OR rc_log_type IS NULL',
162 [
'ss_active_users' => intval( $activeUsers ) ],
163 [
'ss_row_id' => 1 ],
174 $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
175 foreach ( [
'edits',
'articles',
'pages',
'users',
'images' ]
as $type ) {
176 $delta = $this->$type;
177 if ( $delta !== 0 ) {
178 $stats->updateCount(
"site.$type", $delta );
202 $sql .=
"$field=$field-" . abs( $delta );
204 $sql .=
"$field=$field+" . abs( $delta );
216 return $cache->makeKey(
'sitestatsupdate',
'pendingdelta',
$type, $sign );
226 $cache = MediaWikiServices::getInstance()->getMainObjectStash();
233 $magnitude = abs( $delta );
234 $cache->incrWithInit( $key, 0, $magnitude, $magnitude );
242 $cache = MediaWikiServices::getInstance()->getMainObjectStash();
245 foreach ( [
'ss_total_edits',
246 'ss_good_articles',
'ss_total_pages',
'ss_users',
'ss_images' ]
as $type
249 $flg = BagOStuff::READ_LATEST;
262 $cache = MediaWikiServices::getInstance()->getMainObjectStash();
264 foreach ( $pd
as $type => $deltas ) {
265 foreach ( $deltas
as $sign => $magnitude ) {
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgActiveUserDays
How many days user must be idle before he is considered inactive.
$wgSiteStatsAsyncFactor
Set this to an integer to only do synchronous site_stats updates one every this many updates.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
interface is intended to be more or less compatible with the PHP memcached client.
Class for handling updates to the site_stats table.
adjustPending( $type, $delta)
Adjust the pending deltas for a stat type.
static factory(array $deltas)
doUpdate()
Perform the actual work.
getPendingDeltas()
Get pending delta counters for each stat type.
tryDBUpdateInternal()
Do not call this outside of SiteStatsUpdate.
__construct( $views, $edits, $good, $pages=0, $users=0)
appendUpdate(&$sql, $field, $delta)
removePendingDeltas(array $pd)
Reduce pending delta counters after updates have been applied.
merge(MergeableUpdate $update)
Merge this update with $update.
static cacheUpdate( $dbw)
getTypeCacheKey(BagOStuff $cache, $type, $sign)
The ContentHandler facility adds support for arbitrary content types on wiki pages
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 then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if so it s not worth the trouble Since there is a job queue in the jobs which is used to update link tables of transcluding pages after edits
when a variable name is used in a it is silently declared as a new local masking the global
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
the array() calling protocol came about after MediaWiki 1.4rc1.
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
Interface that deferrable updates should implement.
Interface that deferrable updates can implement.