[Mediawiki-l] PATCH: Using template variables in extensions calls
Mikesch Nepomuk
mikesch.nepomuk at gmx.net
Thu Jan 6 21:28:46 UTC 2005
Sorry, Mailman dropped the attachment ;-)
Mikesch
---snipp---
diff -u -r -w -N wikipedia/phase3/includes/Parser.php mywikipedia/phase3/includes/Parser.php
--- wikipedia/phase3/includes/Parser.php 2005-01-06 20:25:14.000000000 +0100
+++ mywikipedia/phase3/includes/Parser.php 2005-01-06 20:54:46.000000000 +0100
@@ -96,7 +96,7 @@
var $mTagHooks;
# Cleared with clearState():
- var $mOutput, $mAutonumber, $mDTopen, $mStripState = array();
+ var $mOutput, $mAutonumber, $mDTopen, $mStripState = array(), $mStripStateClear;
var $mVariables, $mIncludeCount, $mArgStack, $mLastSection, $mInPre;
# Temporary:
@@ -163,6 +163,7 @@
// VOODOO MAGIC FIX! Sometimes the above segfaults in PHP5.
$x =& $this->mStripState;
$text = $this->strip( $text, $x );
+ $text = $this->stripExtensions( $text, $x );
$text = $this->internalParse( $text, $linestart );
$text = $this->unstrip( $text, $this->mStripState );
@@ -286,7 +287,6 @@
$math_content = array();
$pre_content = array();
$comment_content = array();
- $ext_content = array();
$gallery_content = array();
# Replace any instances of the placeholders
@@ -360,6 +360,49 @@
}
}
+ # Merge state with the pre-existing state, if there is one
+ if ( $state ) {
+ $this->mStripStateClear = false;
+ $state['html'] = $state['html'] + $html_content;
+ $state['nowiki'] = $state['nowiki'] + $nowiki_content;
+ $state['math'] = $state['math'] + $math_content;
+ $state['pre'] = $state['pre'] + $pre_content;
+ $state['comment'] = $state['comment'] + $comment_content;
+ $state['gallery'] = $state['gallery'] + $gallery_content;
+ } else {
+ $this->mStripStateClear = true;
+ $state = array(
+ 'html' => $html_content,
+ 'nowiki' => $nowiki_content,
+ 'math' => $math_content,
+ 'pre' => $pre_content,
+ 'comment' => $comment_content,
+ 'gallery' => $gallery_content,
+ );
+ }
+ return $text;
+ }
+
+ /**
+ * Strips and renders extensions
+ * If $render is set, performs necessary rendering operations on plugins
+ * Returns the text, and fills an array with data needed in unstrip()
+ * If the $state is already a valid strip state, it adds to the state
+ *
+ * @param bool $stripcomments when set, HTML comments <!-- like this -->
+ * will be stripped in addition to other tags. This is important
+ * for section editing, where these comments cause confusion when
+ * counting the sections in the wikisource
+ *
+ * @access private
+ */
+ function stripExtensions( $text, &$state, $stripcomments = false ) {
+ $render = ($this->mOutputType == OT_HTML);
+ $ext_content = array();
+
+ # Replace any instances of the placeholders
+ $uniq_prefix = UNIQ_PREFIX;
+
# Extensions
foreach ( $this->mTagHooks as $tag => $callback ) {
$ext_contents[$tag] = array();
@@ -374,28 +417,14 @@
}
# Merge state with the pre-existing state, if there is one
- if ( $state ) {
- $state['html'] = $state['html'] + $html_content;
- $state['nowiki'] = $state['nowiki'] + $nowiki_content;
- $state['math'] = $state['math'] + $math_content;
- $state['pre'] = $state['pre'] + $pre_content;
- $state['comment'] = $state['comment'] + $comment_content;
- $state['gallery'] = $state['gallery'] + $gallery_content;
-
+ if ( !$this->mStripStateClear ) {
foreach( $ext_content as $tag => $array ) {
if ( array_key_exists( $tag, $state ) ) {
$state[$tag] = $state[$tag] + $array;
}
}
} else {
- $state = array(
- 'html' => $html_content,
- 'nowiki' => $nowiki_content,
- 'math' => $math_content,
- 'pre' => $pre_content,
- 'comment' => $comment_content,
- 'gallery' => $gallery_content,
- ) + $ext_content;
+ $state = $state + $ext_content;
}
return $text;
}
@@ -2109,8 +2138,9 @@
$this->mTemplatePath[$part1] = 1;
$text = $this->strip( $text, $this->mStripState );
- $text = $this->removeHTMLtags( $text );
$text = $this->replaceVariables( $text, $assocArgs );
+ $text = $this->stripExtensions( $text, $this->mStripState );
+ $text = $this->removeHTMLtags( $text );
# Resume the link cache and register the inclusion as a link
if ( $this->mOutputType == OT_HTML && !is_null( $title ) ) {
@@ -2801,6 +2831,7 @@
);
$text = str_replace( array_keys( $pairs ), array_values( $pairs ), $text );
$text = $this->strip( $text, $stripState, false );
+ $text = $this->stripExtensions( $text, $stripState, false );
$text = $this->pstPass2( $text, $user );
$text = $this->unstrip( $text, $stripState );
$text = $this->unstripNoWiki( $text, $stripState );
---snipp---
More information about the MediaWiki-l
mailing list