MediaWiki  master
Pingback Class Reference

Send information about this MediaWiki instance to mediawiki.org. More...

Collaboration diagram for Pingback:

Public Member Functions

 __construct (Config $config, ILoadBalancer $lb, BagOStuff $cache, HttpRequestFactory $http, LoggerInterface $logger)
 
 run ()
 Maybe send a ping. More...
 

Static Public Member Functions

static getSystemInfo (Config $config)
 Collect basic data about this MediaWiki installation and return it as an associative array conforming to the Pingback schema on Meta-Wiki (https://meta.wikimedia.org/wiki/Schema:MediaWikiPingback). More...
 
static schedulePingback ()
 Schedule a deferred callable that will check if a pingback should be sent and (if so) proceed to send it. More...
 

Protected Member Functions

 getData ()
 Get the EventLogging packet to be sent to the server. More...
 

Protected Attributes

BagOStuff $cache
 
Config $config
 
HttpRequestFactory $http
 
string $key
 updatelog key (also used as cache/db lock key) More...
 
ILoadBalancer $lb
 
LoggerInterface $logger
 

Private Member Functions

 acquireLock ()
 Acquire lock for sending a pingback. More...
 
 fetchOrInsertId ()
 Get a unique, stable identifier for this wiki. More...
 
 markSent ()
 Record the fact that we have sent a pingback for this MediaWiki version, to ensure we don't submit data multiple times. More...
 
 postPingback (array $data)
 Serialize pingback data and send it to mediawiki.org via a POST request to its EventLogging beacon endpoint. More...
 
 wasRecentlySent ()
 Was a pingback sent in the last month for this MediaWiki version? More...
 

Detailed Description

Send information about this MediaWiki instance to mediawiki.org.

This service uses two kinds of rows in the update_log database table:

  • ul_key PingBack, this holds a random identifier for this wiki, created only once, when the first ping after wiki creation is sent.
  • ul_key Pingback-<MW_VERSION>, this holds a timestamp and is created once after each MediaWiki upgrade, and then updated up to once a month.

Definition at line 44 of file Pingback.php.

Constructor & Destructor Documentation

◆ __construct()

Pingback::__construct ( Config  $config,
ILoadBalancer  $lb,
BagOStuff  $cache,
HttpRequestFactory  $http,
LoggerInterface  $logger 
)
Parameters
Config$config
ILoadBalancer$lb
BagOStuff$cache
HttpRequestFactory$http
LoggerInterface$logger

Definition at line 71 of file Pingback.php.

References $cache, $config, $http, $lb, $logger, and MW_VERSION.

Member Function Documentation

◆ acquireLock()

Pingback::acquireLock ( )
private

Acquire lock for sending a pingback.

This ensures only one thread can attempt to send a pingback at any given time and that we wait an hour before retrying failed attempts.

Returns
bool Whether lock was acquired

Definition at line 147 of file Pingback.php.

References DB_MASTER.

Referenced by run().

◆ fetchOrInsertId()

Pingback::fetchOrInsertId ( )
private

Get a unique, stable identifier for this wiki.

If the identifier does not already exist, create it and save it in the database. The identifier is randomly-generated.

Exceptions
DBErrorIf identifier insert fails
Returns
string 32-character hex string

Definition at line 219 of file Pingback.php.

References $dbr, DB_MASTER, DB_REPLICA, and MWCryptRand\generateHex().

Referenced by getData().

◆ getData()

Pingback::getData ( )
protected

Get the EventLogging packet to be sent to the server.

Exceptions
DBErrorIf identifier insert fails
Returns
array

Definition at line 167 of file Pingback.php.

References fetchOrInsertId(), and getSystemInfo().

Referenced by run().

◆ getSystemInfo()

static Pingback::getSystemInfo ( Config  $config)
static

Collect basic data about this MediaWiki installation and return it as an associative array conforming to the Pingback schema on Meta-Wiki (https://meta.wikimedia.org/wiki/Schema:MediaWikiPingback).

Developers: If you're adding a new piece of data to this, please document this data at https://www.mediawiki.org/wiki/Manual:$wgPingback.

Definition at line 188 of file Pingback.php.

References $config, Config\get(), and MW_VERSION.

Referenced by WebInstallerName\execute(), and getData().

◆ markSent()

Pingback::markSent ( )
private

Record the fact that we have sent a pingback for this MediaWiki version, to ensure we don't submit data multiple times.

Exceptions
DBErrorIf timestamp upsert fails

Definition at line 272 of file Pingback.php.

References DB_MASTER.

Referenced by run().

◆ postPingback()

Pingback::postPingback ( array  $data)
private

Serialize pingback data and send it to mediawiki.org via a POST request to its EventLogging beacon endpoint.

The data encoding conforms to the expectations of EventLogging as used by Wikimedia Foundation for logging and processing analytic data.

Compare: https://gerrit.wikimedia.org/g/mediawiki/extensions/EventLogging/+/7e5fe4f1ef/includes/EventLogging.php#L32

The schema for the data is located at: https://meta.wikimedia.org/wiki/Schema:MediaWikiPingback

Parameters
array$dataPingback data as an associative array
Returns
bool

Definition at line 259 of file Pingback.php.

References FormatJson\encode().

Referenced by run().

◆ run()

Pingback::run ( )

Maybe send a ping.

Exceptions
DBErrorIf identifier insert fails
DBErrorIf timestamp upsert fails

Definition at line 92 of file Pingback.php.

References acquireLock(), getData(), markSent(), postPingback(), and wasRecentlySent().

◆ schedulePingback()

static Pingback::schedulePingback ( )
static

Schedule a deferred callable that will check if a pingback should be sent and (if so) proceed to send it.

Definition at line 288 of file Pingback.php.

References $config, DeferredUpdates\addCallableUpdate(), Config\get(), and ObjectCache\getLocalClusterInstance().

◆ wasRecentlySent()

Pingback::wasRecentlySent ( )
private

Was a pingback sent in the last month for this MediaWiki version?

Returns
bool

Definition at line 121 of file Pingback.php.

References $dbr, and DB_REPLICA.

Referenced by run().

Member Data Documentation

◆ $cache

BagOStuff Pingback::$cache
protected

Definition at line 58 of file Pingback.php.

Referenced by __construct().

◆ $config

Config Pingback::$config
protected

Definition at line 54 of file Pingback.php.

Referenced by __construct(), getSystemInfo(), and schedulePingback().

◆ $http

HttpRequestFactory Pingback::$http
protected

Definition at line 60 of file Pingback.php.

Referenced by __construct().

◆ $key

string Pingback::$key
protected

updatelog key (also used as cache/db lock key)

Definition at line 62 of file Pingback.php.

◆ $lb

ILoadBalancer Pingback::$lb
protected

Definition at line 56 of file Pingback.php.

Referenced by __construct().

◆ $logger

LoggerInterface Pingback::$logger
protected
Initial value:
=
private const SCHEMA_REV 15781718

Definition at line 52 of file Pingback.php.

Referenced by __construct().


The documentation for this class was generated from the following file: