* * attribute nodes are children
* * "<h>" nodes that aren't at the top are replaced with <possible-h>
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
-class Preprocessor_Hash implements Preprocessor {
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
+class Preprocessor_Hash extends Preprocessor {
// @codingStandardsIgnoreEnd
/**
*/
public $parser;
- const CACHE_VERSION = 1;
+ const CACHE_PREFIX = 'preprocess-hash';
public function __construct( $parser ) {
$this->parser = $parser;
return $node;
}
+
/**
* Preprocess some wikitext and return the document tree.
* This is the ghost of Parser::replace_variables().
* @return PPNode_Hash_Tree
*/
public function preprocessToObj( $text, $flags = 0 ) {
- // Check cache.
- global $wgMemc, $wgPreprocessorCacheThreshold;
-
- $cacheable = $wgPreprocessorCacheThreshold !== false
- && strlen( $text ) > $wgPreprocessorCacheThreshold;
-
- if ( $cacheable ) {
- $cacheKey = wfMemcKey( 'preprocess-hash', md5( $text ), $flags );
- $cacheValue = $wgMemc->get( $cacheKey );
- if ( $cacheValue ) {
- $version = substr( $cacheValue, 0, 8 );
- if ( intval( $version ) == self::CACHE_VERSION ) {
- $hash = unserialize( substr( $cacheValue, 8 ) );
- // From the cache
- wfDebugLog( "Preprocessor",
- "Loaded preprocessor hash from memcached (key $cacheKey)" );
- return $hash;
- }
- }
+ $tree = $this->cacheGetTree( $text, $flags );
+ if ( $tree !== false ) {
+ return unserialize( $tree );
}
- $rules = array(
- '{' => array(
- 'end' => '}',
- 'names' => array(
- 2 => 'template',
- 3 => 'tplarg',
- ),
- 'min' => 2,
- 'max' => 3,
- ),
- '[' => array(
- 'end' => ']',
- 'names' => array( 2 => null ),
- 'min' => 2,
- 'max' => 2,
- )
- );
-
$forInclusion = $flags & Parser::PTD_FOR_INCLUSION;
$xmlishElements = $this->parser->getStripList();
$fakeLineStart = true;
while ( true ) {
- //$this->memCheck();
+ // $this->memCheck();
if ( $findOnlyinclude ) {
// Ignore all input up to the next <onlyinclude>
}
} elseif ( $curChar == $currentClosing ) {
$found = 'close';
- } elseif ( isset( $rules[$curChar] ) ) {
+ } elseif ( isset( $this->rules[$curChar] ) ) {
$found = 'open';
- $rule = $rules[$curChar];
+ $rule = $this->rules[$curChar];
} else {
# Some versions of PHP have a strcspn which stops on null characters
# Ignore and continue
# check for maximum matching characters (if there are 5 closing
# characters, we will probably need only 3 - depending on the rules)
- $rule = $rules[$piece->open];
+ $rule = $this->rules[$piece->open];
if ( $count > $rule['max'] ) {
# The specified maximum exists in the callback array, unless the caller
# has made an error
$lastNode = $node;
}
if ( !$node ) {
- if ( $cacheable ) {
- }
+ // if ( $cacheable ) { ... }
throw new MWException( __METHOD__ . ': eqpos not found' );
}
if ( $node->name !== 'equals' ) {
- if ( $cacheable ) {
- }
+ // if ( $cacheable ) { ... }
throw new MWException( __METHOD__ . ': eqpos is not equals' );
}
$equalsNode = $node;
$piece->parts = array( new PPDPart_Hash );
$piece->count -= $matchingCount;
# do we still qualify for any callback with remaining count?
- $min = $rules[$piece->open]['min'];
+ $min = $this->rules[$piece->open]['min'];
if ( $piece->count >= $min ) {
$stack->push( $piece );
$accum =& $stack->getAccum();
$rootNode->lastChild = $stack->rootAccum->lastNode;
// Cache
- if ( $cacheable ) {
- $cacheValue = sprintf( "%08d", self::CACHE_VERSION ) . serialize( $rootNode );
-
- // T111289: Cache values should not exceed 1 Mb, but they do.
- if ( strlen( $cacheValue ) <= 1e6 ) {
- $wgMemc->set( $cacheKey, $cacheValue, 86400 );
- wfDebugLog( "Preprocessor", "Saved preprocessor Hash to memcached (key $cacheKey)" );
- }
- }
+ $this->cacheSetTree( $text, $flags, serialize( $rootNode ) );
return $rootNode;
}
/**
* Stack class to help Preprocessor::preprocessToObj()
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPDStack_Hash extends PPDStack {
// @codingStandardsIgnoreEnd
/**
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPDStackElement_Hash extends PPDStackElement {
// @codingStandardsIgnoreENd
/**
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPDPart_Hash extends PPDPart {
// @codingStandardsIgnoreEnd
/**
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPDAccum_Hash {
// @codingStandardsIgnoreEnd
/**
* An expansion frame, used as a context to expand the result of preprocessToObj()
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPFrame_Hash implements PPFrame {
// @codingStandardsIgnoreEnd
) {
$out .= $contextNode->firstChild->value;
} else {
- //$out .= '';
+ // $out .= '';
}
} elseif ( $contextNode->name == 'ext' ) {
# Extension tag
/**
* Expansion frame with template arguments
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPTemplateFrame_Hash extends PPFrame_Hash {
// @codingStandardsIgnoreEnd
/**
* Expansion frame with custom arguments
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPCustomFrame_Hash extends PPFrame_Hash {
// @codingStandardsIgnoreEnd
/**
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPNode_Hash_Tree implements PPNode {
// @codingStandardsIgnoreEnd
/**
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPNode_Hash_Text implements PPNode {
// @codingStandardsIgnoreEnd
/**
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPNode_Hash_Array implements PPNode {
// @codingStandardsIgnoreEnd
/**
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPNode_Hash_Attr implements PPNode {
// @codingStandardsIgnoreEnd