23use Psr\Log\LoggerInterface;
39 const SCHEMA_REV = 15781718;
58 $this->config =
$config ?: RequestContext::getMain()->getConfig();
59 $this->logger =
$logger ?: LoggerFactory::getInstance( __CLASS__ );
60 $this->key =
'Pingback-' . $this->config->get(
'Version' );
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 ) {
102 [
'ul_key' => $this->key,
'ul_value' => $timestamp ],
104 [
'ul_value' => $timestamp ],
118 $cache = ObjectCache::getLocalClusterInstance();
119 if ( !
$cache->add( $this->key, 1, 60 * 60 ) ) {
124 if ( !$dbw->lock( $this->key, __METHOD__, 0 ) ) {
145 'database' => $this->config->get(
'DBtype' ),
146 'MediaWiki' => $this->config->get(
'Version' ),
147 'PHP' => PHP_VERSION,
148 'OS' => PHP_OS .
' ' . php_uname(
'r' ),
149 'arch' => PHP_INT_SIZE === 8 ? 64 : 32,
150 'machine' => php_uname(
'm' ),
153 if ( isset( $_SERVER[
'SERVER_SOFTWARE'] ) ) {
154 $event[
'serverSoftware'] = $_SERVER[
'SERVER_SOFTWARE'];
157 $limit = ini_get(
'memory_limit' );
158 if ( $limit && $limit != -1 ) {
159 $event[
'memoryLimit'] = $limit;
172 'schema' =>
'MediaWikiPingback',
173 'revision' => self::SCHEMA_REV,
190 'updatelog',
'ul_value', [
'ul_key' =>
'PingBack' ] );
192 if (
$id ==
false ) {
197 [
'ul_key' =>
'PingBack',
'ul_value' =>
$id ],
202 if ( !$dbw->affectedRows() ) {
203 $id = $dbw->selectField(
204 'updatelog',
'ul_value', [
'ul_key' =>
'PingBack' ] );
230 $json = FormatJson::encode( $data );
231 $queryString = rawurlencode( str_replace(
' ',
'\u0020', $json ) ) .
';';
232 $url =
'https://www.mediawiki.org/beacon/event?' . $queryString;
233 return MediaWikiServices::getInstance()->getHttpRequestFactory()->post( $url ) !==
null;
253 $this->logger->debug( __METHOD__ .
": couldn't acquire lock" );
259 $this->logger->warning( __METHOD__ .
": failed to send pingback; check 'http' log" );
264 $this->logger->debug( __METHOD__ .
": pingback sent OK ({$this->key})" );
273 DeferredUpdates::addCallableUpdate(
function () {
275 if ( $instance->shouldSend() ) {
276 $instance->sendPingback();
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.