2019-07-08 01:46:33 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string|null In-object cache for getJSONForDatabase()
|
|
|
|
*/
|
|
|
|
protected $jsonDB = null;
|
|
|
|
|
|
|
|
/**
|
2020-09-03 10:06:10 +00:00
|
|
|
* @inheritDoc
|
2019-07-08 01:46:33 +00:00
|
|
|
*/
|
2020-09-03 10:11:42 +00:00
|
|
|
protected function parse() : Status {
|
2019-07-08 01:46:33 +00:00
|
|
|
$status = parent::parse();
|
|
|
|
if ( $status->isOK() ) {
|
|
|
|
$length = strlen( $this->getJSONForDatabase() );
|
|
|
|
if ( $length > self::MAX_LENGTH ) {
|
|
|
|
return Status::newFatal( 'templatedata-invalid-length', $length, self::MAX_LENGTH );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string JSON (gzip compressed)
|
|
|
|
*/
|
2020-09-03 10:11:42 +00:00
|
|
|
public function getJSONForDatabase() : string {
|
2019-07-08 01:46:33 +00:00
|
|
|
if ( $this->jsonDB === null ) {
|
|
|
|
// Cache for repeat calls
|
|
|
|
$this->jsonDB = gzencode( $this->getJSON() );
|
|
|
|
}
|
|
|
|
return $this->jsonDB;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Just initialize the data, compression to be done later.
|
|
|
|
*
|
|
|
|
* @param stdClass|null $data Template data
|
|
|
|
*/
|
2020-09-03 10:18:43 +00:00
|
|
|
protected function __construct( $data ) {
|
|
|
|
parent::__construct( $data );
|
2019-07-08 01:46:33 +00:00
|
|
|
$this->jsonDB = null;
|
|
|
|
}
|
|
|
|
}
|