Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -92,7 +92,8 @@ |
93 | 93 | # Persistent: |
94 | 94 | var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables, |
95 | 95 | $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex, $mPreprocessor, |
96 | | - $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList, $mVarCache, $mConf; |
| 96 | + $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList, $mVarCache, $mConf, |
| 97 | + $mFunctionTagHooks; |
97 | 98 | |
98 | 99 | |
99 | 100 | # Cleared with clearState(): |
— | — | @@ -127,6 +128,7 @@ |
128 | 129 | $this->mTagHooks = array(); |
129 | 130 | $this->mTransparentTagHooks = array(); |
130 | 131 | $this->mFunctionHooks = array(); |
| 132 | + $this->mFunctionTagHooks = array(); |
131 | 133 | $this->mFunctionSynonyms = array( 0 => array(), 1 => array() ); |
132 | 134 | $this->mDefaultStripList = $this->mStripList = array( 'nowiki', 'gallery' ); |
133 | 135 | $this->mUrlProtocols = wfUrlProtocols(); |
— | — | @@ -3255,9 +3257,10 @@ |
3256 | 3258 | |
3257 | 3259 | $marker = "{$this->mUniqPrefix}-$name-" . sprintf('%08X', $this->mMarkerIndex++) . self::MARKER_SUFFIX; |
3258 | 3260 | |
3259 | | - if ( $this->ot['html'] ) { |
| 3261 | + $isFunctionTag = isset( $this->mFunctionTagHooks[strtolower($name)] ) && |
| 3262 | + ( $this->ot['html'] || $this->ot['pre'] ); |
| 3263 | + if ( $this->ot['html'] || $isFunctionTag ) { |
3260 | 3264 | $name = strtolower( $name ); |
3261 | | - |
3262 | 3265 | $attributes = Sanitizer::decodeTagAttributes( $attrText ); |
3263 | 3266 | if ( isset( $params['attributes'] ) ) { |
3264 | 3267 | $attributes = $attributes + $params['attributes']; |
— | — | @@ -3289,6 +3292,13 @@ |
3290 | 3293 | } |
3291 | 3294 | $output = call_user_func_array( $this->mTagHooks[$name], |
3292 | 3295 | array( $content, $attributes, $this ) ); |
| 3296 | + } elseif( isset( $this->mFunctionTagHooks[$name] ) ) { |
| 3297 | + list( $callback, $flags ) = $this->mFunctionTagHooks[$name]; |
| 3298 | + if( !is_callable( $callback ) ) |
| 3299 | + throw new MWException( "Tag hook for $name is not callable\n" ); |
| 3300 | + |
| 3301 | + $output = call_user_func_array( $callback, |
| 3302 | + array( &$this, $frame, $content, $attributes ) ); |
3293 | 3303 | } else { |
3294 | 3304 | $output = '<span class="error">Invalid tag extension name: ' . |
3295 | 3305 | htmlspecialchars( $name ) . '</span>'; |
— | — | @@ -3312,7 +3322,9 @@ |
3313 | 3323 | } |
3314 | 3324 | } |
3315 | 3325 | |
3316 | | - if ( $name === 'html' || $name === 'nowiki' ) { |
| 3326 | + if( $isFunctionTag ) { |
| 3327 | + return $output; |
| 3328 | + } elseif ( $name === 'html' || $name === 'nowiki' ) { |
3317 | 3329 | $this->mStripState->nowiki->setPair( $marker, $output ); |
3318 | 3330 | } else { |
3319 | 3331 | $this->mStripState->general->setPair( $marker, $output ); |
— | — | @@ -4234,6 +4246,24 @@ |
4235 | 4247 | } |
4236 | 4248 | |
4237 | 4249 | /** |
| 4250 | + * Create a tag function, e.g. <test>some stuff</test>. |
| 4251 | + * Unlike tag hooks, tag functions are parsed at preprocessor level. |
| 4252 | + * Unlike parser functions, their content is not preprocessed. |
| 4253 | + */ |
| 4254 | + function setFunctionTagHook( $tag, $callback, $flags ) { |
| 4255 | + $tag = strtolower( $tag ); |
| 4256 | + $old = isset( $this->mFunctionTagHooks[$tag] ) ? |
| 4257 | + $this->mFunctionTagHooks[$tag] : null; |
| 4258 | + $this->mFunctionTagHooks[$tag] = array( $callback, $flags ); |
| 4259 | + |
| 4260 | + if( !in_array( $tag, $this->mStripList ) ) { |
| 4261 | + $this->mStripList[] = $tag; |
| 4262 | + } |
| 4263 | + |
| 4264 | + return $old; |
| 4265 | + } |
| 4266 | + |
| 4267 | + /** |
4238 | 4268 | * FIXME: update documentation. makeLinkObj() is deprecated. |
4239 | 4269 | * Replace <!--LINK--> link placeholders with actual links, in the buffer |
4240 | 4270 | * Placeholders created in Skin::makeLinkObj() |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -120,6 +120,8 @@ |
121 | 121 | * (bug 19576) Moved id attribues from anchors accompanying section headers to |
122 | 122 | the section headers themselves, removing the redundant anchor elements. |
123 | 123 | * Removed name attribute from <a id="top"></a>. |
| 124 | +* Parser::setFunctionTagHook now can be used to add a new tag which is parsed at |
| 125 | + preprocesor level. |
124 | 126 | |
125 | 127 | === Bug fixes in 1.16 === |
126 | 128 | |