mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-12-18 02:40:38 +00:00
8f81812242
This is not really anything new. Most code already followed these sniffs. This patch just fixes the remaining exceptions. Also: * Remove PHPDoc blocks that don't add anything but just repeat the strict types. * Remove @file comments in favor of class-level comments. * Add strict types where possible, most notably some `void`. Change-Id: Iff6872dff68170b0fc4e82ac2ba3cad385e8773e
50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\TemplateData;
|
|
|
|
use Message;
|
|
|
|
/**
|
|
* 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.
|
|
* @license GPL-2.0-or-later
|
|
*/
|
|
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 In-object cache for {@see getJSONForDatabase}
|
|
*/
|
|
private string $jsonDB;
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
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 )
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return string JSON (gzip compressed)
|
|
*/
|
|
public function getJSONForDatabase(): string {
|
|
return $this->jsonDB;
|
|
}
|
|
|
|
}
|