Index: trunk/phase3/includes/Parser.php |
— | — | @@ -97,7 +97,7 @@ |
98 | 98 | * @private |
99 | 99 | */ |
100 | 100 | # Persistent: |
101 | | - var $mTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables; |
| 101 | + var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables; |
102 | 102 | |
103 | 103 | # Cleared with clearState(): |
104 | 104 | var $mOutput, $mAutonumber, $mDTopen, $mStripState; |
— | — | @@ -128,6 +128,7 @@ |
129 | 129 | */ |
130 | 130 | function Parser() { |
131 | 131 | $this->mTagHooks = array(); |
| 132 | + $this->mTransparentTagHooks = array(); |
132 | 133 | $this->mFunctionHooks = array(); |
133 | 134 | $this->mFunctionSynonyms = array( 0 => array(), 1 => array() ); |
134 | 135 | $this->mFirstCall = true; |
— | — | @@ -329,6 +330,33 @@ |
330 | 331 | |
331 | 332 | wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) ); |
332 | 333 | |
| 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 | + |
333 | 361 | $text = Sanitizer::normalizeCharReferences( $text ); |
334 | 362 | |
335 | 363 | if (($wgUseTidy and $this->mOptions->mTidy) or $wgAlwaysUseTidy) { |
— | — | @@ -1006,7 +1034,7 @@ |
1007 | 1035 | $text = strtr( $text, array( '<noinclude>' => '', '</noinclude>' => '') ); |
1008 | 1036 | $text = StringUtils::delimiterReplace( '<includeonly>', '</includeonly>', '', $text ); |
1009 | 1037 | |
1010 | | - $text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ) ); |
| 1038 | + $text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ), array(), array_keys( $this->mTransparentTagHooks ) ); |
1011 | 1039 | |
1012 | 1040 | $text = $this->replaceVariables( $text, $args ); |
1013 | 1041 | wfRunHooks( 'InternalParseBeforeLinks', array( &$this, &$text, &$this->mStripState ) ); |
— | — | @@ -3963,6 +3991,14 @@ |
3964 | 3992 | return $oldVal; |
3965 | 3993 | } |
3966 | 3994 | |
| 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 | + |
3967 | 4003 | /** |
3968 | 4004 | * Create a function, e.g. {{sum:1|2|3}} |
3969 | 4005 | * The callback function should have the form: |
— | — | @@ -4601,7 +4637,7 @@ |
4602 | 4638 | /**#@+ |
4603 | 4639 | * Accessor |
4604 | 4640 | */ |
4605 | | - function getTags() { return array_keys( $this->mTagHooks ); } |
| 4641 | + function getTags() { return array_merge( array_keys($this->mTransparentTagHooks), array_keys( $this->mTagHooks ) ); } |
4606 | 4642 | /**#@-*/ |
4607 | 4643 | |
4608 | 4644 | |
Index: trunk/phase3/includes/Sanitizer.php |
— | — | @@ -339,7 +339,7 @@ |
340 | 340 | * @param array $args for the processing callback |
341 | 341 | * @return string |
342 | 342 | */ |
343 | | - static function removeHTMLtags( $text, $processCallback = null, $args = array() ) { |
| 343 | + static function removeHTMLtags( $text, $processCallback = null, $args = array(), $extratags = array() ) { |
344 | 344 | global $wgUseTidy; |
345 | 345 | |
346 | 346 | static $htmlpairs, $htmlsingle, $htmlsingleonly, $htmlnest, $tabletags, |
— | — | @@ -349,13 +349,13 @@ |
350 | 350 | |
351 | 351 | if ( !$staticInitialised ) { |
352 | 352 | |
353 | | - $htmlpairs = array( # Tags that must be closed |
| 353 | + $htmlpairs = array_merge( $extratags, array( # Tags that must be closed |
354 | 354 | 'b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1', |
355 | 355 | 'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's', |
356 | 356 | 'strike', 'strong', 'tt', 'var', 'div', 'center', |
357 | 357 | 'blockquote', 'ol', 'ul', 'dl', 'table', 'caption', 'pre', |
358 | 358 | 'ruby', 'rt' , 'rb' , 'rp', 'p', 'span', 'u' |
359 | | - ); |
| 359 | + ) ); |
360 | 360 | $htmlsingle = array( |
361 | 361 | 'br', 'hr', 'li', 'dt', 'dd' |
362 | 362 | ); |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -138,6 +138,8 @@ |
139 | 139 | additional explanation in Special:Contributions |
140 | 140 | * (bug 10520) Preview licences during upload via AJAX (toggle with |
141 | 141 | $wgAjaxLicencePreview) |
| 142 | +* New Parser::setTransparentTagHook for parser extension and template |
| 143 | + compatibility |
142 | 144 | |
143 | 145 | == Bugfixes since 1.10 == |
144 | 146 | |