2022-05-16 16:56:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-11-06 15:22:44 +00:00
|
|
|
namespace MediaWiki\Edit;
|
2022-05-16 16:56:20 +00:00
|
|
|
|
2022-09-09 09:32:17 +00:00
|
|
|
use InvalidArgumentException;
|
Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able
to identify a specific parse when there are dependencies (for example
in an edit based on that parse). This is recorded as a property added
to the ParserOutput, not the parent CacheTime interface. Even though
the render ID is /related/ to the CacheTime interface, CacheTime is
also used directly as a parser cache key, and the UUID should not be
part of the lookup key.
In general we are trying to move the location where these cache
properties are set as early as possible, so we check at each location
to ensure we don't overwrite a previously-set value. Eventually we
can convert most of these checks into assertions that the cache
properties have already been set (T350538). The primary location for
setting cache properties is the ContentRenderer.
Moved setting the revision timestamp into ContentRenderer as well, as
it was set along the same code paths. An extra parameter was added to
ContentRenderer::getParserOutput() to support this.
Added merge code to ParserOutput::mergeInternalMetaDataFrom() which
should ensure that cache time, revision, timestamp, and render id are
all set properly when multiple slots are combined together in MCR.
In order to ensure the render ID is set on all codepaths we needed to
plumb the GlobalIdGenerator service into ContentRenderer, ParserCache,
ParserCacheFactory, and RevisionOutputCache. Eventually (T350538) it
should only be necessary in the ContentRenderer.
Bug: T350538
Bug: T349868
Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
2023-09-14 16:11:20 +00:00
|
|
|
use MediaWiki\Parser\ParserOutput;
|
2024-06-12 23:59:33 +00:00
|
|
|
use Stringable;
|
2022-09-09 09:32:17 +00:00
|
|
|
|
2022-05-16 16:56:20 +00:00
|
|
|
/**
|
|
|
|
|
* Represents the identity of a specific rendering of a specific revision
|
|
|
|
|
* at some point in time.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.39
|
|
|
|
|
* @unstable since 1.39, should be stable by 1.39 release.
|
|
|
|
|
*/
|
2024-06-12 23:59:33 +00:00
|
|
|
class ParsoidRenderID implements Stringable {
|
2023-10-23 21:22:54 +00:00
|
|
|
private int $revisionID;
|
|
|
|
|
private string $uniqueID;
|
|
|
|
|
private string $stashKey;
|
2022-05-16 16:56:20 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param int $revisionID Revision that was rendered
|
|
|
|
|
* @param string $uniqueID An identifier for a point in time.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct( int $revisionID, string $uniqueID ) {
|
|
|
|
|
$this->revisionID = $revisionID;
|
|
|
|
|
$this->uniqueID = $uniqueID;
|
|
|
|
|
$this->stashKey = $revisionID . '/' . $uniqueID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $key String representation of render ID
|
|
|
|
|
* (synonymous with an etag with double quotes) as returned by ::getKey().
|
|
|
|
|
*
|
|
|
|
|
* @return self
|
|
|
|
|
* @see newFromETag()
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static function newFromKey( string $key ): self {
|
2022-09-09 09:32:17 +00:00
|
|
|
[ $revisionID, $uniqueID ] = explode( '/', $key, 2 );
|
|
|
|
|
|
|
|
|
|
if ( $revisionID === null || $uniqueID === null ) {
|
|
|
|
|
throw new InvalidArgumentException( 'Bad key: ' . $key );
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-16 16:56:20 +00:00
|
|
|
return new self( (int)$revisionID, $uniqueID );
|
|
|
|
|
}
|
|
|
|
|
|
Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able
to identify a specific parse when there are dependencies (for example
in an edit based on that parse). This is recorded as a property added
to the ParserOutput, not the parent CacheTime interface. Even though
the render ID is /related/ to the CacheTime interface, CacheTime is
also used directly as a parser cache key, and the UUID should not be
part of the lookup key.
In general we are trying to move the location where these cache
properties are set as early as possible, so we check at each location
to ensure we don't overwrite a previously-set value. Eventually we
can convert most of these checks into assertions that the cache
properties have already been set (T350538). The primary location for
setting cache properties is the ContentRenderer.
Moved setting the revision timestamp into ContentRenderer as well, as
it was set along the same code paths. An extra parameter was added to
ContentRenderer::getParserOutput() to support this.
Added merge code to ParserOutput::mergeInternalMetaDataFrom() which
should ensure that cache time, revision, timestamp, and render id are
all set properly when multiple slots are combined together in MCR.
In order to ensure the render ID is set on all codepaths we needed to
plumb the GlobalIdGenerator service into ContentRenderer, ParserCache,
ParserCacheFactory, and RevisionOutputCache. Eventually (T350538) it
should only be necessary in the ContentRenderer.
Bug: T350538
Bug: T349868
Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
2023-09-14 16:11:20 +00:00
|
|
|
/**
|
|
|
|
|
* Create a ParsoidRenderID from the revision and render id stored in
|
|
|
|
|
* a ParserOutput.
|
|
|
|
|
* @param ParserOutput $parserOutput
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public static function newFromParserOutput( ParserOutput $parserOutput ): self {
|
|
|
|
|
$revisionID = $parserOutput->getCacheRevisionId();
|
|
|
|
|
$uniqueID = $parserOutput->getRenderId();
|
|
|
|
|
|
|
|
|
|
if ( $revisionID === null || $uniqueID === null ) {
|
|
|
|
|
throw new InvalidArgumentException( 'Missing render id' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new self( $revisionID, $uniqueID );
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-16 16:56:20 +00:00
|
|
|
/**
|
|
|
|
|
* This constructs a new render ID from the given ETag.
|
|
|
|
|
*
|
|
|
|
|
* Any suffix after a second forward slash will be ignored e.g.
|
|
|
|
|
* ->newFromEtag( '1/abc/stash' ) will return '1/abc' when ->getKey()
|
|
|
|
|
* is called on the ParsoidRenderID object instance.
|
|
|
|
|
*
|
|
|
|
|
* @param string $eTag ETag with double quotes,
|
|
|
|
|
* see https://www.rfc-editor.org/rfc/rfc7232#section-2.3
|
|
|
|
|
*
|
2023-03-10 19:44:40 +00:00
|
|
|
* @return ParsoidRenderID|null The render ID embedded in the ETag,
|
|
|
|
|
* or null if the ETag was malformed.
|
2022-05-16 16:56:20 +00:00
|
|
|
* @see newFromKey() if ETag already has outside quotes trimmed
|
|
|
|
|
*
|
|
|
|
|
*/
|
2023-03-10 19:44:40 +00:00
|
|
|
public static function newFromETag( string $eTag ): ?self {
|
|
|
|
|
if ( !preg_match( '@^(?:W/)?"(\d+)/([^/]+)(:?/.*)?"$@', $eTag, $m ) ) {
|
|
|
|
|
return null;
|
2023-03-09 15:21:44 +00:00
|
|
|
}
|
2022-11-15 22:57:38 +00:00
|
|
|
|
2023-03-10 19:44:40 +00:00
|
|
|
[ , $revisionID, $uniqueID ] = $m;
|
|
|
|
|
|
2022-05-16 16:56:20 +00:00
|
|
|
return new self( (int)$revisionID, $uniqueID );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This returns the canonical string representation from
|
|
|
|
|
* the parsoid render ID which can be used to in newFromString().
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getKey(): string {
|
|
|
|
|
return $this->stashKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function __toString() {
|
|
|
|
|
return $this->stashKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the revision ID from the parsoid render ID object.
|
|
|
|
|
*
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function getRevisionID(): int {
|
|
|
|
|
return $this->revisionID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the unique identifier from the parsoid render ID object.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getUniqueID(): string {
|
|
|
|
|
return $this->uniqueID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2023-11-06 15:22:44 +00:00
|
|
|
|
2024-03-07 21:56:58 +00:00
|
|
|
/** @deprecated class alias since 1.42 */
|
2023-11-06 15:22:44 +00:00
|
|
|
class_alias( ParsoidRenderID::class, 'MediaWiki\\Parser\\Parsoid\\ParsoidRenderID' );
|