Debian Codegraph @

extensions/TemplateData/includes/TemplateDataCompressedBlob.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\TemplateData;
4
5 use MediaWiki\Message\Message;
6
7 /**
8 * Represents the information about a template,
9 * coming from the JSON blob in the <templatedata> tags
10 * on wiki pages.
11 * This implementation stores the information as a compressed gzip blob
12 * in the database.
13 * @license GPL-2.0-or-later
14 */
15 class TemplateDataCompressedBlob extends TemplateDataBlob {
16
17 // Size of MySQL 'blob' field; page_props table where the data is stored uses one.
18 private const MAX_LENGTH = 65535;
19
20 /**
21 * @var string In-object cache for {@see getJSONForDatabase}
22 */
23 private string $jsonDB;
24
25 /**
26 * @inheritDoc
27 */
28 protected function __construct( string $json, string $lang ) {
29 parent::__construct( $json, $lang );
30 $this->jsonDB = gzencode( $this->json );
31
32 $length = strlen( $this->jsonDB );
33 if ( $length > self::MAX_LENGTH ) {
34 $this->status->fatal(
35 'templatedata-invalid-length',
36 Message::numParam( $length ),
37 Message::numParam( self::MAX_LENGTH )
38 );
39 }
40 }
41
42 /**
43 * @return string JSON (gzip compressed)
44 */
45 public function getJSONForDatabase(): string {
46 return $this->jsonDB;
47 }
48
49 }