/**
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
-class Preprocessor_DOM implements Preprocessor {
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
+class Preprocessor_DOM extends Preprocessor {
// @codingStandardsIgnoreEnd
/**
public $memoryLimit;
- const CACHE_VERSION = 1;
+ const CACHE_PREFIX = 'preprocess-xml';
public function __construct( $parser ) {
$this->parser = $parser;
* @throws MWException
*/
public function newPartNodeArray( $values ) {
- //NOTE: DOM manipulation is slower than building & parsing XML! (or so Tim sais)
+ // NOTE: DOM manipulation is slower than building & parsing XML! (or so Tim sais)
$xml = "<list>";
foreach ( $values as $k => $val ) {
$xml .= "</list>";
$dom = new DOMDocument();
- wfSuppressWarnings();
+ MediaWiki\suppressWarnings();
$result = $dom->loadXML( $xml );
- wfRestoreWarnings();
+ MediaWiki\restoreWarnings();
if ( !$result ) {
// Try running the XML through UtfNormal to get rid of invalid characters
$xml = UtfNormal\Validator::cleanUp( $xml );
* @return PPNode_DOM
*/
public function preprocessToObj( $text, $flags = 0 ) {
- global $wgMemc, $wgPreprocessorCacheThreshold;
-
- $xml = false;
- $cacheable = ( $wgPreprocessorCacheThreshold !== false
- && strlen( $text ) > $wgPreprocessorCacheThreshold );
- if ( $cacheable ) {
-
- $cacheKey = wfMemcKey( 'preprocess-xml', md5( $text ), $flags );
- $cacheValue = $wgMemc->get( $cacheKey );
- if ( $cacheValue ) {
- $version = substr( $cacheValue, 0, 8 );
- if ( intval( $version ) == self::CACHE_VERSION ) {
- $xml = substr( $cacheValue, 8 );
- // From the cache
- wfDebugLog( "Preprocessor", "Loaded preprocessor XML from memcached (key $cacheKey)" );
- }
- }
- if ( $xml === false ) {
- $xml = $this->preprocessToXml( $text, $flags );
- $cacheValue = sprintf( "%08d", self::CACHE_VERSION ) . $xml;
- $wgMemc->set( $cacheKey, $cacheValue, 86400 );
- wfDebugLog( "Preprocessor", "Saved preprocessor XML to memcached (key $cacheKey)" );
- }
- } else {
+
+ $xml = $this->cacheGetTree( $text, $flags );
+ if ( $xml === false ) {
$xml = $this->preprocessToXml( $text, $flags );
+ $this->cacheSetTree( $text, $flags, $xml );
}
// Fail if the number of elements exceeds acceptable limits
$this->parser->mGeneratedPPNodeCount += substr_count( $xml, '<' );
$max = $this->parser->mOptions->getMaxGeneratedPPNodeCount();
if ( $this->parser->mGeneratedPPNodeCount > $max ) {
- if ( $cacheable ) {
- }
+ // if ( $cacheable ) { ... }
throw new MWException( __METHOD__ . ': generated node count limit exceeded' );
}
$dom = new DOMDocument;
- wfSuppressWarnings();
+ MediaWiki\suppressWarnings();
$result = $dom->loadXML( $xml );
- wfRestoreWarnings();
+ MediaWiki\restoreWarnings();
if ( !$result ) {
// Try running the XML through UtfNormal to get rid of invalid characters
$xml = UtfNormal\Validator::cleanUp( $xml );
$obj = new PPNode_DOM( $dom->documentElement );
}
- if ( $cacheable ) {
- }
+ // if ( $cacheable ) { ... }
if ( !$result ) {
throw new MWException( __METHOD__ . ' generated invalid XML' );
$stack = new PPDStack;
- $searchBase = "[{<\n"; #}
+ $searchBase = "[{<\n"; # }
// For fast reverse searches
$revText = strrev( $text );
$lengthText = strlen( $text );
$fakeLineStart = true;
while ( true ) {
- //$this->memCheck();
+ // $this->memCheck();
if ( $findOnlyinclude ) {
// Ignore all input up to the next <onlyinclude>
* @ingroup Parser
*/
class PPDStackElement {
- public $open, // Opening character (\n for heading)
- $close, // Matching closing character
- $count, // Number of opening characters found (number of "=" for heading)
- $parts, // Array of PPDPart objects describing pipe-separated parts.
- $lineStart; // True if the open char appeared at the start of the input line.
- // Not set for headings.
+ /**
+ * @var string Opening character (\n for heading)
+ */
+ public $open;
+
+ /**
+ * @var string Matching closing character
+ */
+ public $close;
+
+ /**
+ * @var int Number of opening characters found (number of "=" for heading)
+ */
+ public $count;
+
+ /**
+ * @var PPDPart[] Array of PPDPart objects describing pipe-separated parts.
+ */
+ public $parts;
+
+ /**
+ * @var bool True if the open char appeared at the start of the input line.
+ * Not set for headings.
+ */
+ public $lineStart;
public $partClass = 'PPDPart';
* @ingroup Parser
*/
class PPDPart {
- public $out; // Output accumulator string
+ /**
+ * @var string Output accumulator string
+ */
+ public $out;
// Optional member variables:
// eqpos Position of equals sign in output accumulator
/**
* An expansion frame, used as a context to expand the result of preprocessToObj()
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPFrame_DOM implements PPFrame {
// @codingStandardsIgnoreEnd
} elseif ( $contextNode->nodeName == 'comment' ) {
# HTML-style comment
# Remove it in HTML, pre+remove and STRIP_COMMENTS modes
- if ( $this->parser->ot['html']
+ # Not in RECOVER_COMMENTS mode (msgnw) though.
+ if ( ( $this->parser->ot['html']
|| ( $this->parser->ot['pre'] && $this->parser->mOptions->getRemoveComments() )
|| ( $flags & PPFrame::STRIP_COMMENTS )
+ ) && !( $flags & PPFrame::RECOVER_COMMENTS )
) {
$out .= '';
} elseif ( $this->parser->ot['wiki'] && !( $flags & PPFrame::RECOVER_COMMENTS ) ) {
/**
* Expansion frame with template arguments
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPTemplateFrame_DOM extends PPFrame_DOM {
// @codingStandardsIgnoreEnd
/**
* Expansion frame with custom arguments
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPCustomFrame_DOM extends PPFrame_DOM {
// @codingStandardsIgnoreEnd
/**
* @ingroup Parser
- * @codingStandardsIgnoreStart
*/
+// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
class PPNode_DOM implements PPNode {
// @codingStandardsIgnoreEnd