2019-07-08 01:46:33 +00:00
|
|
|
<?php
|
|
|
|
|
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.
|
2023-08-23 07:29:25 +00:00
|
|
|
* @license GPL-2.0-or-later
|
2019-07-08 01:46:33 +00:00
|
|
|
*/
|
|
|
|
class TemplateDataCompressedBlob extends TemplateDataBlob {
|
2023-08-23 07:29:25 +00:00
|
|
|
|
2019-07-08 01:46:33 +00:00
|
|
|
// 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
|
|
|
*/
|
2023-08-23 07:29:25 +00:00
|
|
|
private string $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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|