Add PPFrame::getTTL() and setTTL()
Add functions to frames to control the TTL of their output, and expose this via expandtemplates in the API. Bug: 49803 Change-Id: I412febf3469503bf4839fb1ef4dca098a8c79457
This commit is contained in:
parent
19f3a60085
commit
18d15fa138
4 changed files with 90 additions and 2 deletions
|
|
@ -109,10 +109,13 @@ class ApiExpandTemplates extends ApiBase {
|
|||
$retval['categories'] = $categories_result;
|
||||
}
|
||||
}
|
||||
if ( isset ( $prop['volatile'] ) && $frame->isVolatile() ) {
|
||||
if ( isset( $prop['volatile'] ) && $frame->isVolatile() ) {
|
||||
$retval['volatile'] = '';
|
||||
}
|
||||
if ( isset ( $prop['wikitext'] ) ) {
|
||||
if ( isset( $prop['ttl'] ) && $frame->getTTL() !== null ) {
|
||||
$retval['ttl'] = $frame->getTTL();
|
||||
}
|
||||
if ( isset( $prop['wikitext'] ) ) {
|
||||
$retval['wikitext'] = $wikitext;
|
||||
}
|
||||
}
|
||||
|
|
@ -135,6 +138,7 @@ class ApiExpandTemplates extends ApiBase {
|
|||
'wikitext',
|
||||
'categories',
|
||||
'volatile',
|
||||
'ttl',
|
||||
'parsetree',
|
||||
),
|
||||
ApiBase::PARAM_ISMULTI => true,
|
||||
|
|
@ -156,6 +160,7 @@ class ApiExpandTemplates extends ApiBase {
|
|||
' wikitext - The expanded wikitext',
|
||||
' categories - Any categories present in the input that are not represented in the wikitext output',
|
||||
' volatile - Whether the output is volatile and should not be reused elsewhere within the page',
|
||||
' ttl - The maximum time after which caches of the result should be invalidated',
|
||||
' parsetree - The XML parse tree of the input',
|
||||
'Note that if no values are selected, the result will contain the wikitext,',
|
||||
'but the output will be in a deprecated format.',
|
||||
|
|
@ -182,6 +187,12 @@ class ApiExpandTemplates extends ApiBase {
|
|||
ApiBase::PROP_NULLABLE => true,
|
||||
),
|
||||
),
|
||||
'ttl' => array(
|
||||
'ttl' => array(
|
||||
ApiBase::PROP_TYPE => 'integer',
|
||||
ApiBase::PROP_NULLABLE => true,
|
||||
),
|
||||
),
|
||||
'parsetree' => array(
|
||||
'parsetree' => 'string',
|
||||
),
|
||||
|
|
|
|||
|
|
@ -189,6 +189,31 @@ interface PPFrame {
|
|||
*/
|
||||
function isVolatile();
|
||||
|
||||
/**
|
||||
* Get the TTL of the frame's output.
|
||||
*
|
||||
* This is the maximum amount of time, in seconds, that this frame's
|
||||
* output should be cached for. A value of null indicates that no
|
||||
* maximum has been specified.
|
||||
*
|
||||
* Note that this TTL only applies to caching frames as parts of pages.
|
||||
* It is not relevant to caching the entire rendered output of a page.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
function getTTL();
|
||||
|
||||
/**
|
||||
* Set the TTL of the output of this frame and all of its ancestors.
|
||||
* Has no effect if the new TTL is greater than the one already set.
|
||||
* Note that it is the caller's responsibility to change the cache
|
||||
* expiry of the page as a whole, if such behavior is desired.
|
||||
*
|
||||
* @see self::getTTL()
|
||||
* @param int $ttl
|
||||
*/
|
||||
function setTTL( $ttl );
|
||||
|
||||
/**
|
||||
* Get a title of frame
|
||||
*
|
||||
|
|
|
|||
|
|
@ -984,6 +984,7 @@ class PPFrame_DOM implements PPFrame {
|
|||
var $depth;
|
||||
|
||||
private $volatile = false;
|
||||
private $ttl = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
|
|
@ -1505,6 +1506,26 @@ class PPFrame_DOM implements PPFrame {
|
|||
function isVolatile() {
|
||||
return $this->volatile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the TTL
|
||||
*
|
||||
* @param int $ttl
|
||||
*/
|
||||
function setTTL( $ttl ) {
|
||||
if ( $ttl !== null && ( $this->ttl === null || $ttl < $this->ttl ) ) {
|
||||
$this->ttl = $ttl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the TTL
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
function getTTL() {
|
||||
return $this->ttl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1664,6 +1685,11 @@ class PPTemplateFrame_DOM extends PPFrame_DOM {
|
|||
parent::setVolatile( $flag );
|
||||
$this->parent->setVolatile( $flag );
|
||||
}
|
||||
|
||||
function setTTL( $ttl ) {
|
||||
parent::setTTL( $ttl );
|
||||
$this->parent->setTTL( $ttl );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -920,6 +920,7 @@ class PPFrame_Hash implements PPFrame {
|
|||
var $depth;
|
||||
|
||||
private $volatile = false;
|
||||
private $ttl = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
|
|
@ -1410,6 +1411,26 @@ class PPFrame_Hash implements PPFrame {
|
|||
function isVolatile() {
|
||||
return $this->volatile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the TTL
|
||||
*
|
||||
* @param int $ttl
|
||||
*/
|
||||
function setTTL( $ttl ) {
|
||||
if ( $ttl !== null && ( $this->ttl === null || $ttl < $this->ttl ) ) {
|
||||
$this->ttl = $ttl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the TTL
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
function getTTL() {
|
||||
return $this->ttl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1585,6 +1606,11 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
|
|||
parent::setVolatile( $flag );
|
||||
$this->parent->setVolatile( $flag );
|
||||
}
|
||||
|
||||
function setTTL( $ttl ) {
|
||||
parent::setTTL( $ttl );
|
||||
$this->parent->setTTL( $ttl );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue