ATTENTION: This hook is likely to be removed soon due to overall design of the system.
* (bug 17367) It is now possible to add pages to your watchlist from
Special:UnwatchedPages without reloading the special page.
+* New methods setVolatile and isVolatile are added to PPFrame, so that
+ extensions such as Cite.php can mark that their output is volatile and
+ shouldn't be cached.
=== Bug fixes in 1.24 ===
* (bug 49116) Footer copyright notice is now always displayed in user language
ApiResult::setContent( $xml_result, $xml );
$result->addValue( null, 'parsetree', $xml_result );
}
- $retval = $wgParser->preprocess( $params['text'], $title_obj, $options );
+ $frame = $wgParser->getPreprocessor()->newFrame();
+ $retval = $wgParser->preprocess( $params['text'], $title_obj, $options, null, $frame );
// Return result
$retval_array = array();
ApiResult::setContent( $retval_array, $retval );
+ if ( $frame->isVolatile() ) {
+ $retval_array['volatile'] = '';
+ }
$result->addValue( null, $this->getModuleName(), $retval_array );
}
/**
* Expand templates and variables in the text, producing valid, static wikitext.
* Also removes comments.
+ * Do not call this function recursively.
* @param string $text
* @param Title $title
* @param ParserOptions $options
* @param int|null $revid
+ * @param bool|PPFrame $frame
* @return mixed|string
*/
- function preprocess( $text, Title $title = null, ParserOptions $options, $revid = null ) {
+ function preprocess( $text, Title $title = null, ParserOptions $options, $revid = null, $frame = false ) {
wfProfileIn( __METHOD__ );
$magicScopeVariable = $this->lock();
$this->startParse( $title, $options, self::OT_PREPROCESS, true );
}
wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
- $text = $this->replaceVariables( $text );
+ $text = $this->replaceVariables( $text, $frame );
$text = $this->mStripState->unstripBoth( $text );
wfProfileOut( __METHOD__ );
return $text;
*/
function isTemplate();
+ /**
+ * Set the "volatile" flag.
+ *
+ * Note that this is somewhat of a "hack" in order to make extensions
+ * with side effects (such as Cite) work with the PHP parser. New
+ * extensions should be written in a way that they do not need this
+ * function, because other parsers (such as Parsoid) are not guaranteed
+ * to respect it, and it may be removed in the future.
+ *
+ * @param bool $flag
+ */
+ function setVolatile( $flag = true );
+
+ /**
+ * Get the "volatile" flag.
+ *
+ * Callers should avoid caching the result of an expansion if it has the
+ * volatile flag set.
+ *
+ * @see self::setVolatile()
+ * @return bool
+ */
+ function isVolatile();
+
/**
* Get a title of frame
*
*/
var $depth;
+ private $volatile = false;
+
/**
* @var array
*/
function getTitle() {
return $this->title;
}
+
+ /**
+ * Set the volatile flag
+ *
+ * @param bool $flag
+ */
+ function setVolatile( $flag = true ) {
+ $this->volatile = $flag;
+ }
+
+ /**
+ * Get the volatile flag
+ *
+ * @return bool
+ */
+ function isVolatile() {
+ return $this->volatile;
+ }
}
/**
* @return string
*/
function cachedExpand( $key, $root, $flags = 0 ) {
- if ( !isset( $this->parent->childExpansionCache[$key] ) ) {
- $this->parent->childExpansionCache[$key] = $this->expand( $root, $flags );
+ if ( isset( $this->parent->childExpansionCache[$key] ) ) {
+ return $this->parent->childExpansionCache[$key];
}
- return $this->parent->childExpansionCache[$key];
+ $retval = $this->expand( $root, $flags );
+ if ( !$this->isVolatile() ) {
+ $this->parent->childExpansionCache[$key] = $retval;
+ }
+ return $retval;
}
/**
function isTemplate() {
return true;
}
+
+ function setVolatile( $flag = true ) {
+ parent::setVolatile( $flag );
+ $this->parent->setVolatile( $flag );
+ }
}
/**
*/
var $depth;
+ private $volatile = false;
+
/**
* @var array
*/
function getTitle() {
return $this->title;
}
+
+ /**
+ * Set the volatile flag
+ *
+ * @param bool $flag
+ */
+ function setVolatile( $flag = true ) {
+ $this->volatile = $flag;
+ }
+
+ /**
+ * Get the volatile flag
+ *
+ * @return bool
+ */
+ function isVolatile() {
+ return $this->volatile;
+ }
}
/**
* @return string
*/
function cachedExpand( $key, $root, $flags = 0 ) {
- if ( !isset( $this->parent->childExpansionCache[$key] ) ) {
- $this->parent->childExpansionCache[$key] = $this->expand( $root, $flags );
+ if ( isset( $this->parent->childExpansionCache[$key] ) ) {
+ return $this->parent->childExpansionCache[$key];
}
- return $this->parent->childExpansionCache[$key];
+ $retval = $this->expand( $root, $flags );
+ if ( !$this->isVolatile() ) {
+ $this->parent->childExpansionCache[$key] = $retval;
+ }
+ return $retval;
}
/**
function isTemplate() {
return true;
}
+
+ function setVolatile( $flag = true ) {
+ parent::setVolatile( $flag );
+ $this->parent->setVolatile( $flag );
+ }
}
/**