2019-07-08 01:46:33 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
*/
|
|
|
|
|
2021-11-25 21:35:46 +00:00
|
|
|
namespace MediaWiki\Extension\TemplateData;
|
|
|
|
|
2022-01-31 07:34:57 +00:00
|
|
|
use Message;
|
2021-11-25 21:35:46 +00:00
|
|
|
|
2019-07-08 01:46:33 +00:00
|
|
|
/**
|
|
|
|
* Represents the information about a template,
|
|
|
|
* coming from the JSON blob in the <templatedata> tags
|
|
|
|
* on wiki pages.
|
|
|
|
* This implementation stores the information as a compressed gzip blob
|
|
|
|
* in the database.
|
|
|
|
*/
|
|
|
|
class TemplateDataCompressedBlob extends TemplateDataBlob {
|
|
|
|
// Size of MySQL 'blob' field; page_props table where the data is stored uses one.
|
2020-05-20 00:06:40 +00:00
|
|
|
private const MAX_LENGTH = 65535;
|
2019-07-08 01:46:33 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-26 11:25:10 +00:00
|
|
|
* @var string In-object cache for {@see getJSONForDatabase}
|
2019-07-08 01:46:33 +00:00
|
|
|
*/
|
2020-08-26 11:25:10 +00:00
|
|
|
private $jsonDB;
|
2019-07-08 01:46:33 +00:00
|
|
|
|
|
|
|
/**
|
2020-09-03 10:06:10 +00:00
|
|
|
* @inheritDoc
|
2019-07-08 01:46:33 +00:00
|
|
|
*/
|
2020-08-26 11:25:10 +00:00
|
|
|
protected function __construct( string $json ) {
|
|
|
|
parent::__construct( $json );
|
|
|
|
$this->jsonDB = gzencode( $this->json );
|
|
|
|
|
|
|
|
$length = strlen( $this->jsonDB );
|
|
|
|
if ( $length > self::MAX_LENGTH ) {
|
|
|
|
$this->status->fatal(
|
|
|
|
'templatedata-invalid-length',
|
|
|
|
Message::numParam( $length ),
|
|
|
|
Message::numParam( self::MAX_LENGTH )
|
|
|
|
);
|
2019-07-08 01:46:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string JSON (gzip compressed)
|
|
|
|
*/
|
2021-07-23 22:51:45 +00:00
|
|
|
public function getJSONForDatabase(): string {
|
2019-07-08 01:46:33 +00:00
|
|
|
return $this->jsonDB;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|