mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-27 17:20:01 +00:00
a09e939fe7
composer: * mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0 npm: * postcss: 7.0.35 → 7.0.36 * https://npmjs.com/advisories/1693 (CVE-2021-23368) * glob-parent: 5.1.0 → 5.1.2 * https://npmjs.com/advisories/1751 (CVE-2020-28469) * trim-newlines: 3.0.0 → 3.0.1 * https://npmjs.com/advisories/1753 (CVE-2021-33623) Change-Id: I23a441a089501a97f329b7b6d37bc658481e682f
58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?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 TemplateDataCompressedBlob extends TemplateDataBlob {
|
|
// Size of MySQL 'blob' field; page_props table where the data is stored uses one.
|
|
private const MAX_LENGTH = 65535;
|
|
|
|
/**
|
|
* @var string|null In-object cache for getJSONForDatabase()
|
|
*/
|
|
protected $jsonDB = null;
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
protected function parse(): Status {
|
|
$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)
|
|
*/
|
|
public function getJSONForDatabase(): string {
|
|
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
|
|
*/
|
|
protected function __construct( $data ) {
|
|
parent::__construct( $data );
|
|
$this->jsonDB = null;
|
|
}
|
|
}
|