MediaWiki  master
MediaWiki\Storage\PageEditStash Class Reference

Class for managing stashed edits used by the page updater classes. More...

Collaboration diagram for MediaWiki\Storage\PageEditStash:

Public Member Functions

 __construct (BagOStuff $cache, ILoadBalancer $lb, LoggerInterface $logger, StatsdDataFactoryInterface $stats, UserEditTracker $userEditTracker, UserFactory $userFactory, HookContainer $hookContainer, $initiator)
 
 checkCache (PageIdentity $page, Content $content, User $user)
 Check that a prepared edit is in cache and still up-to-date. More...
 
 fetchInputText ( $textHash)
 
 parseAndCache (WikiPage $page, Content $content, UserIdentity $user, string $summary)
 
 stashInputText ( $text, $textHash)
 

Public Attributes

const ERROR_BUSY = 'busy'
 
const ERROR_CACHE = 'error_cache'
 
const ERROR_NONE = 'stashed'
 
const ERROR_PARSE = 'error_parse'
 
const ERROR_UNCACHEABLE = 'uncacheable'
 
const INITIATOR_JOB_OR_CLI = 2
 
const INITIATOR_USER = 1
 
const MAX_CACHE_TTL = 300
 
const MAX_SIGNATURE_TTL = 60
 
const PRESUME_FRESH_TTL_SEC = 30
 

Private Member Functions

 getAndWaitForStashValue ( $key)
 
 getContentHash (Content $content)
 Get hash of the content, factoring in model/format. More...
 
 getStashKey (PageIdentity $page, $contentHash, UserIdentity $user)
 Get the temporary prepared edit stash key for a user. More...
 
 getStashValue ( $key)
 
 incrStatsByContent ( $subkey, Content $content)
 
 lastEditTime (UserIdentity $user)
 
 pruneExcessStashedEntries (UserIdentity $user, $newKey)
 
 recentStashEntryCount (UserIdentity $user)
 
 storeStashValue ( $key, Content $pstContent, ParserOutput $parserOutput, $timestamp, UserIdentity $user)
 Build a value to store in memcached based on the PST content and parser output. More...
 

Private Attributes

BagOStuff $cache
 
ParserOutputStashForEditHook $hookRunner
 
int $initiator
 
ILoadBalancer $lb
 
LoggerInterface $logger
 
StatsdDataFactoryInterface $stats
 
UserEditTracker $userEditTracker
 
UserFactory $userFactory
 
const MAX_CACHE_RECENT = 2
 

Detailed Description

Class for managing stashed edits used by the page updater classes.

Since
1.34

Definition at line 48 of file PageEditStash.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Storage\PageEditStash::__construct ( BagOStuff  $cache,
ILoadBalancer  $lb,
LoggerInterface  $logger,
StatsdDataFactoryInterface  $stats,
UserEditTracker  $userEditTracker,
UserFactory  $userFactory,
HookContainer  $hookContainer,
  $initiator 
)
Parameters
BagOStuff$cache
ILoadBalancer$lb
LoggerInterface$logger
StatsdDataFactoryInterface$stats
UserEditTracker$userEditTracker
UserFactory$userFactory
HookContainer$hookContainer
int$initiatorClass INITIATOR__* constant

Definition at line 91 of file PageEditStash.php.

References MediaWiki\Storage\PageEditStash\$cache, MediaWiki\Storage\PageEditStash\$initiator, MediaWiki\Storage\PageEditStash\$lb, MediaWiki\Storage\PageEditStash\$logger, MediaWiki\Storage\PageEditStash\$stats, MediaWiki\Storage\PageEditStash\$userEditTracker, and MediaWiki\Storage\PageEditStash\$userFactory.

Member Function Documentation

◆ checkCache()

MediaWiki\Storage\PageEditStash::checkCache ( PageIdentity  $page,
Content  $content,
User  $user 
)

Check that a prepared edit is in cache and still up-to-date.

This method blocks if the prepared edit is already being rendered, waiting until rendering finishes before doing final validity checks.

The cache is rejected if template or file changes are detected. Note that foreign template or file transclusions are not checked.

This returns an object with the following fields:

  • pstContent: the Content after pre-save-transform
  • output: the ParserOutput instance
  • timestamp: the timestamp of the parse
  • edits: author edit count if they are logged in or NULL otherwise
Parameters
PageIdentity$page
Content$content
User$userto get parser options from
Returns
stdClass|bool Returns edit stash object or false on cache miss

Definition at line 219 of file PageEditStash.php.

References MediaWiki\Storage\PageEditStash\$logger, MediaWiki\Storage\PageEditStash\getAndWaitForStashValue(), MediaWiki\Storage\PageEditStash\getContentHash(), User\getName(), User\getRequest(), MediaWiki\Storage\PageEditStash\getStashKey(), MediaWiki\Storage\PageEditStash\incrStatsByContent(), User\isAnon(), User\isBot(), MediaWiki\Storage\PageEditStash\lastEditTime(), MediaWiki\Storage\PageEditStash\recentStashEntryCount(), and wfTimestamp().

◆ fetchInputText()

MediaWiki\Storage\PageEditStash::fetchInputText (   $textHash)
Parameters
string$textHash
Returns
string|bool Text or false if missing

Definition at line 359 of file PageEditStash.php.

◆ getAndWaitForStashValue()

MediaWiki\Storage\PageEditStash::getAndWaitForStashValue (   $key)
private
Parameters
string$key
Returns
bool|stdClass

Definition at line 333 of file PageEditStash.php.

References MediaWiki\Storage\PageEditStash\getStashValue().

Referenced by MediaWiki\Storage\PageEditStash\checkCache().

◆ getContentHash()

MediaWiki\Storage\PageEditStash::getContentHash ( Content  $content)
private

Get hash of the content, factoring in model/format.

Parameters
Content$content
Returns
string

Definition at line 405 of file PageEditStash.php.

References $content.

Referenced by MediaWiki\Storage\PageEditStash\checkCache(), and MediaWiki\Storage\PageEditStash\parseAndCache().

◆ getStashKey()

MediaWiki\Storage\PageEditStash::getStashKey ( PageIdentity  $page,
  $contentHash,
UserIdentity  $user 
)
private

Get the temporary prepared edit stash key for a user.

This key can be used for caching prepared edits provided:

  • a) The $user was used for PST options
  • b) The parser output was made from the PST using cannonical matching options
Parameters
PageIdentity$page
string$contentHashResult of getContentHash()
UserIdentity$userUser to get parser options from
Returns
string

Definition at line 425 of file PageEditStash.php.

Referenced by MediaWiki\Storage\PageEditStash\checkCache(), and MediaWiki\Storage\PageEditStash\parseAndCache().

◆ getStashValue()

MediaWiki\Storage\PageEditStash::getStashValue (   $key)
private
Parameters
string$key
Returns
stdClass|bool Object map (pstContent,output,outputID,timestamp,edits) or false

Definition at line 440 of file PageEditStash.php.

Referenced by MediaWiki\Storage\PageEditStash\getAndWaitForStashValue(), and MediaWiki\Storage\PageEditStash\parseAndCache().

◆ incrStatsByContent()

MediaWiki\Storage\PageEditStash::incrStatsByContent (   $subkey,
Content  $content 
)
private
Parameters
string$subkey
Content$content

Definition at line 324 of file PageEditStash.php.

References $content.

Referenced by MediaWiki\Storage\PageEditStash\checkCache().

◆ lastEditTime()

MediaWiki\Storage\PageEditStash::lastEditTime ( UserIdentity  $user)
private
Parameters
UserIdentity$user
Returns
string|null TS_MW timestamp or null

Definition at line 385 of file PageEditStash.php.

References DB_REPLICA, MediaWiki\User\UserIdentity\getName(), and wfTimestampOrNull().

Referenced by MediaWiki\Storage\PageEditStash\checkCache().

◆ parseAndCache()

◆ pruneExcessStashedEntries()

MediaWiki\Storage\PageEditStash::pruneExcessStashedEntries ( UserIdentity  $user,
  $newKey 
)
private
Parameters
UserIdentity$user
string$newKey

Definition at line 502 of file PageEditStash.php.

References MediaWiki\User\UserIdentity\getName(), and BagOStuff\WRITE_PRUNE_SEGMENTS.

Referenced by MediaWiki\Storage\PageEditStash\storeStashValue().

◆ recentStashEntryCount()

MediaWiki\Storage\PageEditStash::recentStashEntryCount ( UserIdentity  $user)
private
Parameters
UserIdentity$user
Returns
int

Definition at line 519 of file PageEditStash.php.

References MediaWiki\User\UserIdentity\getName().

Referenced by MediaWiki\Storage\PageEditStash\checkCache().

◆ stashInputText()

MediaWiki\Storage\PageEditStash::stashInputText (   $text,
  $textHash 
)
Parameters
string$text
string$textHash
Returns
bool Success

Definition at line 370 of file PageEditStash.php.

References BagOStuff\WRITE_ALLOW_SEGMENTS.

◆ storeStashValue()

MediaWiki\Storage\PageEditStash::storeStashValue (   $key,
Content  $pstContent,
ParserOutput  $parserOutput,
  $timestamp,
UserIdentity  $user 
)
private

Build a value to store in memcached based on the PST content and parser output.

This makes a simple version of WikiPage::prepareContentForEdit() as stash info

Parameters
string$key
Content$pstContentPre-Save transformed content
ParserOutput$parserOutput
string$timestampTS_MW
UserIdentity$user
Returns
string|bool True or an error code

Definition at line 461 of file PageEditStash.php.

References CacheTime\getCacheExpiry(), CacheTime\getCacheTime(), ParserOutput\getFlag(), MediaWiki\User\UserIdentity\isRegistered(), MediaWiki\Storage\PageEditStash\pruneExcessStashedEntries(), true, wfTimestamp(), and BagOStuff\WRITE_ALLOW_SEGMENTS.

Referenced by MediaWiki\Storage\PageEditStash\parseAndCache().

Member Data Documentation

◆ $cache

BagOStuff MediaWiki\Storage\PageEditStash::$cache
private

Definition at line 50 of file PageEditStash.php.

Referenced by MediaWiki\Storage\PageEditStash\__construct().

◆ $hookRunner

ParserOutputStashForEditHook MediaWiki\Storage\PageEditStash::$hookRunner
private

Definition at line 58 of file PageEditStash.php.

◆ $initiator

int MediaWiki\Storage\PageEditStash::$initiator
private

Definition at line 64 of file PageEditStash.php.

Referenced by MediaWiki\Storage\PageEditStash\__construct().

◆ $lb

ILoadBalancer MediaWiki\Storage\PageEditStash::$lb
private

Definition at line 52 of file PageEditStash.php.

Referenced by MediaWiki\Storage\PageEditStash\__construct().

◆ $logger

LoggerInterface MediaWiki\Storage\PageEditStash::$logger
private

◆ $stats

StatsdDataFactoryInterface MediaWiki\Storage\PageEditStash::$stats
private

Definition at line 56 of file PageEditStash.php.

Referenced by MediaWiki\Storage\PageEditStash\__construct().

◆ $userEditTracker

UserEditTracker MediaWiki\Storage\PageEditStash::$userEditTracker
private

Definition at line 60 of file PageEditStash.php.

Referenced by MediaWiki\Storage\PageEditStash\__construct().

◆ $userFactory

UserFactory MediaWiki\Storage\PageEditStash::$userFactory
private

Definition at line 62 of file PageEditStash.php.

Referenced by MediaWiki\Storage\PageEditStash\__construct().

◆ ERROR_BUSY

const MediaWiki\Storage\PageEditStash::ERROR_BUSY = 'busy'

Definition at line 70 of file PageEditStash.php.

Referenced by MediaWiki\Storage\PageEditStash\parseAndCache().

◆ ERROR_CACHE

const MediaWiki\Storage\PageEditStash::ERROR_CACHE = 'error_cache'

Definition at line 68 of file PageEditStash.php.

Referenced by MediaWiki\Storage\PageEditStash\parseAndCache().

◆ ERROR_NONE

const MediaWiki\Storage\PageEditStash::ERROR_NONE = 'stashed'

Definition at line 66 of file PageEditStash.php.

Referenced by MediaWiki\Storage\PageEditStash\parseAndCache().

◆ ERROR_PARSE

const MediaWiki\Storage\PageEditStash::ERROR_PARSE = 'error_parse'

Definition at line 67 of file PageEditStash.php.

Referenced by MediaWiki\Storage\PageEditStash\parseAndCache().

◆ ERROR_UNCACHEABLE

const MediaWiki\Storage\PageEditStash::ERROR_UNCACHEABLE = 'uncacheable'

Definition at line 69 of file PageEditStash.php.

Referenced by MediaWiki\Storage\PageEditStash\parseAndCache().

◆ INITIATOR_JOB_OR_CLI

const MediaWiki\Storage\PageEditStash::INITIATOR_JOB_OR_CLI = 2

Definition at line 79 of file PageEditStash.php.

◆ INITIATOR_USER

const MediaWiki\Storage\PageEditStash::INITIATOR_USER = 1

Definition at line 78 of file PageEditStash.php.

◆ MAX_CACHE_RECENT

const MediaWiki\Storage\PageEditStash::MAX_CACHE_RECENT = 2
private

Definition at line 76 of file PageEditStash.php.

◆ MAX_CACHE_TTL

const MediaWiki\Storage\PageEditStash::MAX_CACHE_TTL = 300

Definition at line 73 of file PageEditStash.php.

◆ MAX_SIGNATURE_TTL

const MediaWiki\Storage\PageEditStash::MAX_SIGNATURE_TTL = 60

Definition at line 74 of file PageEditStash.php.

◆ PRESUME_FRESH_TTL_SEC

const MediaWiki\Storage\PageEditStash::PRESUME_FRESH_TTL_SEC = 30

Definition at line 72 of file PageEditStash.php.

Referenced by MediaWiki\Storage\PageEditStash\parseAndCache().


The documentation for this class was generated from the following file: