r24117 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24116‎ | r24117 | r24118 >
Date:11:14, 15 July 2007
Author:jeluf
Status:old
Tags:
Comment:
New Parser::setTransparentTagHook for parser extension and template compatibility
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/includes/Sanitizer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -97,7 +97,7 @@
9898 * @private
9999 */
100100 # Persistent:
101 - var $mTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables;
 101+ var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables;
102102
103103 # Cleared with clearState():
104104 var $mOutput, $mAutonumber, $mDTopen, $mStripState;
@@ -128,6 +128,7 @@
129129 */
130130 function Parser() {
131131 $this->mTagHooks = array();
 132+ $this->mTransparentTagHooks = array();
132133 $this->mFunctionHooks = array();
133134 $this->mFunctionSynonyms = array( 0 => array(), 1 => array() );
134135 $this->mFirstCall = true;
@@ -329,6 +330,33 @@
330331
331332 wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) );
332333
 334+//!JF Move to its own function
 335+
 336+ $uniq_prefix = $this->mUniqPrefix;
 337+ $matches = array();
 338+ $elements = array_keys( $this->mTransparentTagHooks );
 339+ $text = Parser::extractTagsAndParams( $elements, $text, $matches, $uniq_prefix );
 340+
 341+ foreach( $matches as $marker => $data ) {
 342+ list( $element, $content, $params, $tag ) = $data;
 343+ $tagName = strtolower( $element );
 344+ if( isset( $this->mTransparentTagHooks[$tagName] ) ) {
 345+ $output = call_user_func_array( $this->mTransparentTagHooks[$tagName],
 346+ array( $content, $params, $this ) );
 347+ } else {
 348+ $output = $tag;
 349+ }
 350+ $this->mStripState->general->setPair( $marker, $output );
 351+ }
 352+ $text = $this->mStripState->unstripGeneral( $text );
 353+
 354+
 355+
 356+
 357+
 358+
 359+
 360+
333361 $text = Sanitizer::normalizeCharReferences( $text );
334362
335363 if (($wgUseTidy and $this->mOptions->mTidy) or $wgAlwaysUseTidy) {
@@ -1006,7 +1034,7 @@
10071035 $text = strtr( $text, array( '<noinclude>' => '', '</noinclude>' => '') );
10081036 $text = StringUtils::delimiterReplace( '<includeonly>', '</includeonly>', '', $text );
10091037
1010 - $text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ) );
 1038+ $text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ), array(), array_keys( $this->mTransparentTagHooks ) );
10111039
10121040 $text = $this->replaceVariables( $text, $args );
10131041 wfRunHooks( 'InternalParseBeforeLinks', array( &$this, &$text, &$this->mStripState ) );
@@ -3963,6 +3991,14 @@
39643992 return $oldVal;
39653993 }
39663994
 3995+ function setTransparentTagHook( $tag, $callback ) {
 3996+ $tag = strtolower( $tag );
 3997+ $oldVal = isset( $this->mTransparentTagHooks[$tag] ) ? $this->mTransparentTagHooks[$tag] : null;
 3998+ $this->mTransparentTagHooks[$tag] = $callback;
 3999+
 4000+ return $oldVal;
 4001+ }
 4002+
39674003 /**
39684004 * Create a function, e.g. {{sum:1|2|3}}
39694005 * The callback function should have the form:
@@ -4601,7 +4637,7 @@
46024638 /**#@+
46034639 * Accessor
46044640 */
4605 - function getTags() { return array_keys( $this->mTagHooks ); }
 4641+ function getTags() { return array_merge( array_keys($this->mTransparentTagHooks), array_keys( $this->mTagHooks ) ); }
46064642 /**#@-*/
46074643
46084644
Index: trunk/phase3/includes/Sanitizer.php
@@ -339,7 +339,7 @@
340340 * @param array $args for the processing callback
341341 * @return string
342342 */
343 - static function removeHTMLtags( $text, $processCallback = null, $args = array() ) {
 343+ static function removeHTMLtags( $text, $processCallback = null, $args = array(), $extratags = array() ) {
344344 global $wgUseTidy;
345345
346346 static $htmlpairs, $htmlsingle, $htmlsingleonly, $htmlnest, $tabletags,
@@ -349,13 +349,13 @@
350350
351351 if ( !$staticInitialised ) {
352352
353 - $htmlpairs = array( # Tags that must be closed
 353+ $htmlpairs = array_merge( $extratags, array( # Tags that must be closed
354354 'b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1',
355355 'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's',
356356 'strike', 'strong', 'tt', 'var', 'div', 'center',
357357 'blockquote', 'ol', 'ul', 'dl', 'table', 'caption', 'pre',
358358 'ruby', 'rt' , 'rb' , 'rp', 'p', 'span', 'u'
359 - );
 359+ ) );
360360 $htmlsingle = array(
361361 'br', 'hr', 'li', 'dt', 'dd'
362362 );
Index: trunk/phase3/RELEASE-NOTES
@@ -138,6 +138,8 @@
139139 additional explanation in Special:Contributions
140140 * (bug 10520) Preview licences during upload via AJAX (toggle with
141141 $wgAjaxLicencePreview)
 142+* New Parser::setTransparentTagHook for parser extension and template
 143+ compatibility
142144
143145 == Bugfixes since 1.10 ==
144146

Follow-up revisions

RevisionCommit summaryAuthorDate
r24215Merged revisions 24095-24212 via svnmerge from...david21:19, 17 July 2007

Status & tagging log