Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F6085967
SimpleParsoidOutputStash.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
SimpleParsoidOutputStash.php
View Options
<?php
namespace
MediaWiki\Edit
;
use
MediaWiki\Content\IContentHandlerFactory
;
use
MediaWiki\Parser\Parsoid\PageBundleJsonTrait
;
use
Wikimedia\ObjectCache\BagOStuff
;
/**
* @internal
* @since 1.39
*/
class
SimpleParsoidOutputStash
implements
ParsoidOutputStash
{
use
PageBundleJsonTrait
;
/** @var BagOStuff */
private
$bagOfStuff
;
/** @var int */
private
$duration
;
/** @var IContentHandlerFactory */
private
$contentHandlerFactory
;
/**
* @param IContentHandlerFactory $contentHandlerFactory
* @param BagOStuff $bagOfStuff storage backend
* @param int $duration cache duration in seconds
*/
public
function
__construct
(
IContentHandlerFactory
$contentHandlerFactory
,
BagOStuff
$bagOfStuff
,
int
$duration
)
{
$this
->
bagOfStuff
=
$bagOfStuff
;
$this
->
duration
=
$duration
;
$this
->
contentHandlerFactory
=
$contentHandlerFactory
;
}
private
function
makeCacheKey
(
ParsoidRenderID
$renderId
):
string
{
return
$this
->
bagOfStuff
->
makeKey
(
'ParsoidOutputStash'
,
$renderId
->
getKey
()
);
}
/**
* Before we stash, we serialize & encode into JSON the relevant
* parts of the data we need to construct a page bundle in the future.
*
* @param ParsoidRenderID $renderId Combination of revision ID and revision's time ID
* @param SelserContext $selserContext
*
* @return bool
*/
public
function
set
(
ParsoidRenderID
$renderId
,
SelserContext
$selserContext
):
bool
{
$jsonic
=
$this
->
selserContextToJsonArray
(
$selserContext
);
$key
=
$this
->
makeCacheKey
(
$renderId
);
return
$this
->
bagOfStuff
->
set
(
$key
,
$jsonic
,
$this
->
duration
);
}
/**
* This will decode the JSON data and create a page bundle from it
* if we have something in the stash that matches a given rendering or
* will just return an empty array if no entry in the stash.
*
* @param ParsoidRenderID $renderId
*
* @return SelserContext|null
*/
public
function
get
(
ParsoidRenderID
$renderId
):
?
SelserContext
{
$key
=
$this
->
makeCacheKey
(
$renderId
);
$jsonic
=
$this
->
bagOfStuff
->
get
(
$key
)
??
[];
if
(
!
is_array
(
$jsonic
)
)
{
// Defend against old stashed data.
// Only needed for a couple of days after this code has been deployed.
return
null
;
}
$selserContext
=
$this
->
newSelserContextFromJson
(
$jsonic
);
return
$selserContext
?:
null
;
}
private
function
newSelserContextFromJson
(
array
$json
):
?
SelserContext
{
if
(
!
isset
(
$json
[
'pb'
]
)
)
{
return
null
;
}
$pb
=
$this
->
newPageBundleFromJson
(
$json
[
'pb'
]
);
if
(
!
$pb
)
{
return
null
;
}
$revId
=
(
int
)
$json
[
'revId'
];
if
(
isset
(
$json
[
'content'
]
)
)
{
$contentHandler
=
$this
->
contentHandlerFactory
->
getContentHandler
(
$json
[
'content'
][
'model'
]
);
$content
=
$contentHandler
->
unserializeContent
(
$json
[
'content'
][
'data'
]
);
}
else
{
$content
=
null
;
}
return
new
SelserContext
(
$pb
,
$revId
,
$content
);
}
private
function
selserContextToJsonArray
(
SelserContext
$selserContext
):
array
{
$json
=
[
'revId'
=>
$selserContext
->
getRevisionID
(),
];
$json
[
'pb'
]
=
$this
->
jsonSerializePageBundle
(
$selserContext
->
getPageBundle
()
);
$content
=
$selserContext
->
getContent
();
if
(
$content
)
{
$json
[
'content'
]
=
[
'model'
=>
$content
->
getModel
(),
'data'
=>
$content
->
serialize
()
];
}
return
$json
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Oct 5 2026, 14:10 (6 w, 1 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
4d/d2/4e67b1349383ee871b02c888462e
Default Alt Text
SimpleParsoidOutputStash.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment