MediaWiki REL1_39
SimpleParsoidOutputStash.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Edit;
4
5use BagOStuff;
6use FormatJson;
7use MediaWiki\Parser\Parsoid\PageBundleJsonTrait;
9use Wikimedia\Parsoid\Core\PageBundle;
10
16 use PageBundleJsonTrait;
17
19 private $bagOfStuff;
20
22 private $duration;
23
28 public function __construct( BagOStuff $bagOfStuff, int $duration ) {
29 $this->bagOfStuff = $bagOfStuff;
30 $this->duration = $duration;
31 }
32
42 public function set( ParsoidRenderId $renderId, PageBundle $bundle ): bool {
43 $pageBundleJson = FormatJson::encode( $this->jsonSerializePageBundle( $bundle ) );
44
45 return $this->bagOfStuff->set( $renderId->getKey(), $pageBundleJson, $this->duration );
46 }
47
57 public function get( ParsoidRenderId $renderId ): ?PageBundle {
58 $jsonString = $this->bagOfStuff->get( $renderId->getKey() );
59 if ( !is_string( $jsonString ) ) {
60 // Protect against rollback from MW >= 1.43
61 return null;
62 }
63 $pageBundleArray = FormatJson::decode(
64 $jsonString,
65 true
66 ) ?? [];
67 $pageBundle = $this->newPageBundleFromJson( $pageBundleArray );
68
69 return $pageBundle ?: null;
70 }
71
72}
Class representing a cache/ephemeral data store.
Definition BagOStuff.php:85
JSON formatter wrapper class.
static decode( $value, $assoc=false)
Decodes a JSON string.
__construct(BagOStuff $bagOfStuff, int $duration)
Represents the identity of a specific rendering of a specific revision at some point in time.
Interface for saving and retrieval of Parsoid HTML and Parsoid metadata from storage.