25use Psr\Log\LoggerInterface;
39 private const SCHEMA_REV = 15781718;
58 $this->config =
$config ?: RequestContext::getMain()->getConfig();
59 $this->logger =
$logger ?: LoggerFactory::getInstance( __CLASS__ );
68 return $this->config->get(
'Pingback' ) && !$this->
checkIfSent();
77 $timestamp =
$dbr->selectField(
80 [
'ul_key' => $this->key ],
83 if ( $timestamp ===
false ) {
87 if ( time() - (
int)$timestamp > 60 * 60 * 24 * 30 ) {
103 [
'ul_key' => $this->key,
'ul_value' => $timestamp ],
105 [
'ul_value' => $timestamp ],
119 $cache = ObjectCache::getLocalClusterInstance();
120 if ( !
$cache->add( $this->key, 1, 60 * 60 ) ) {
125 if ( !$dbw->lock( $this->key, __METHOD__, 0 ) ) {
146 'database' => $this->config->get(
'DBtype' ),
148 'PHP' => PHP_VERSION,
149 'OS' => PHP_OS .
' ' . php_uname(
'r' ),
150 'arch' => PHP_INT_SIZE === 8 ? 64 : 32,
151 'machine' => php_uname(
'm' ),
154 if ( isset( $_SERVER[
'SERVER_SOFTWARE'] ) ) {
155 $event[
'serverSoftware'] = $_SERVER[
'SERVER_SOFTWARE'];
158 $limit = ini_get(
'memory_limit' );
159 if ( $limit && $limit != -1 ) {
160 $event[
'memoryLimit'] = $limit;
173 'schema' =>
'MediaWikiPingback',
174 'revision' => self::SCHEMA_REV,
191 'updatelog',
'ul_value', [
'ul_key' =>
'PingBack' ], __METHOD__ );
193 if (
$id ==
false ) {
198 [
'ul_key' =>
'PingBack',
'ul_value' =>
$id ],
203 if ( !$dbw->affectedRows() ) {
204 $id = $dbw->selectField(
205 'updatelog',
'ul_value', [
'ul_key' =>
'PingBack' ], __METHOD__ );
231 $json = FormatJson::encode( $data );
232 $queryString = rawurlencode( str_replace(
' ',
'\u0020', $json ) ) .
';';
233 $url =
'https://www.mediawiki.org/beacon/event?' . $queryString;
234 return MediaWikiServices::getInstance()->getHttpRequestFactory()->post( $url, [], __METHOD__ ) !==
null;
254 $this->logger->debug( __METHOD__ .
": couldn't acquire lock" );
260 $this->logger->warning( __METHOD__ .
": failed to send pingback; check 'http' log" );
265 $this->logger->debug( __METHOD__ .
": pingback sent OK ({$this->key})" );
274 DeferredUpdates::addCallableUpdate(
function () {
276 if ( $instance->shouldSend() ) {
277 $instance->sendPingback();
const MW_VERSION
The running version of MediaWiki.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static generateHex( $chars)
Generate a run of cryptographically random data and return it in hexadecimal string format.
Send information about this MediaWiki instance to MediaWiki.org.
acquireLock()
Acquire lock for sending a pingback.
getOrCreatePingbackId()
Get a unique, stable identifier for this wiki.
sendPingback()
Send information about this MediaWiki instance to MediaWiki.org.
shouldSend()
Should a pingback be sent?
getData()
Get the EventLogging packet to be sent to the server.
postPingback(array $data)
Serialize pingback data and send it to MediaWiki.org via a POST to its event beacon endpoint.
string $id
Randomly-generated identifier for this wiki.
string $key
updatelog key (also used as cache/db lock key)
markSent()
Record the fact that we have sent a pingback for this MediaWiki version, to ensure we don't submit da...
__construct(Config $config=null, LoggerInterface $logger=null)
static schedulePingback()
Schedule a deferred callable that will check if a pingback should be sent and (if so) proceed to send...
checkIfSent()
Has a pingback been sent in the last month for this MediaWiki version?
getSystemInfo()
Collect basic data about this MediaWiki installation and return it as an associative array conforming...
Interface for configuration instances.