diff --git a/includes/parser/CoreTagHooks.php b/includes/parser/CoreTagHooks.php index 7d488c4..6c33cd5 100644 --- a/includes/parser/CoreTagHooks.php +++ b/includes/parser/CoreTagHooks.php @@ -18,7 +18,7 @@ class CoreTagHooks { global $wgRawHtml; $parser->setHook( 'pre', array( __CLASS__, 'pre' ) ); $parser->setHook( 'nowiki', array( __CLASS__, 'nowiki' ) ); - $parser->setHook( 'gallery', array( __CLASS__, 'gallery' ) ); + $parser->setHook( 'gallery', array( __CLASS__, 'gallery' ) , array('preSaveTrans' => true) ); if ( $wgRawHtml ) { $parser->setHook( 'html', array( __CLASS__, 'html' ) ); } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 20c8b95..3510d44 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -106,6 +106,7 @@ class Parser { var $mFunctionTagHooks = array(); var $mStripList = array(); var $mDefaultStripList = array(); + var $mPstAcceptableXmlTags = array(); var $mVarCache = array(); var $mImageParams = array(); var $mImageParamsMagicArray = array(); @@ -181,6 +182,11 @@ class Parser { var $mUniqPrefix; /** + * @var string + */ + var $mDuringPreSaveTransform = false; + + /** * Constructor * * @param $conf array @@ -845,7 +851,11 @@ class Parser { * @return array */ function getStripList() { - return $this->mStripList; + if ( $this->mDuringPreSaveTransform ) { + return $this->mStripList; + } else { + return array_merge($this->mStripList, $this->mPstAcceptableXmlTags); + } } /** @@ -4303,6 +4313,8 @@ class Parser { public function preSaveTransform( $text, Title $title, User $user, ParserOptions $options, $clearState = true ) { $this->startParse( $title, $options, self::OT_WIKI, $clearState ); $this->setUser( $user ); + + $this->mDuringPreSaveTransform = true; $pairs = array( "\r\n" => "\n", @@ -4314,6 +4326,8 @@ class Parser { $text = $this->mStripState->unstripBoth( $text ); $this->setUser( null ); #Reset + + $this->mDuringPreSaveTransform = false; return $text; } @@ -4609,16 +4623,21 @@ class Parser { * @param $callback Mixed: the callback function (and object) to use for the tag * @return Mixed|null The old value of the mTagHooks array associated with the hook */ - public function setHook( $tag, $callback ) { + public function setHook( $tag, $callback, $options = array() ) { $tag = strtolower( $tag ); if ( preg_match( '/[<>\r\n]/', $tag, $m ) ) { throw new MWException( "Invalid character {$m[0]} in setHook('$tag', ...) call" ); } $oldVal = isset( $this->mTagHooks[$tag] ) ? $this->mTagHooks[$tag] : null; $this->mTagHooks[$tag] = $callback; - if ( !in_array( $tag, $this->mStripList ) ) { - $this->mStripList[] = $tag; - } + + if ( isset($options['preSaveTrans']) && $options['preSaveTrans'] === true ) { + if ( !in_array( $tag, $this->mPstAcceptableXmlTags ) ) { + $this->mPstAcceptableXmlTags[] = $tag; + } + } elseif ( !in_array( $tag, $this->mStripList ) ) { + $this->mStripList[] = $tag; + } return $oldVal; } @@ -4657,6 +4676,8 @@ class Parser { $this->mTagHooks = array(); $this->mFunctionTagHooks = array(); $this->mStripList = $this->mDefaultStripList; + $this->mPstAcceptableXmlTags = array(); + $this->mDuringPreSaveTransform = false; } /**