r53109 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53108‎ | r53109 | r53110 >
Date:13:03, 11 July 2009
Author:vasilievvv
Status:deferred (Comments)
Tags:
Comment:
Add function-like tag hooks. They are tags, which content is not preprocessed. Those hooks has access to PPFrame and are parsed on preprocessing stage. They might be useful for built-in programming languages.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -92,7 +92,8 @@
9393 # Persistent:
9494 var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables,
9595 $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex, $mPreprocessor,
96 - $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList, $mVarCache, $mConf;
 96+ $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList, $mVarCache, $mConf,
 97+ $mFunctionTagHooks;
9798
9899
99100 # Cleared with clearState():
@@ -127,6 +128,7 @@
128129 $this->mTagHooks = array();
129130 $this->mTransparentTagHooks = array();
130131 $this->mFunctionHooks = array();
 132+ $this->mFunctionTagHooks = array();
131133 $this->mFunctionSynonyms = array( 0 => array(), 1 => array() );
132134 $this->mDefaultStripList = $this->mStripList = array( 'nowiki', 'gallery' );
133135 $this->mUrlProtocols = wfUrlProtocols();
@@ -3255,9 +3257,10 @@
32563258
32573259 $marker = "{$this->mUniqPrefix}-$name-" . sprintf('%08X', $this->mMarkerIndex++) . self::MARKER_SUFFIX;
32583260
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 ) {
32603264 $name = strtolower( $name );
3261 -
32623265 $attributes = Sanitizer::decodeTagAttributes( $attrText );
32633266 if ( isset( $params['attributes'] ) ) {
32643267 $attributes = $attributes + $params['attributes'];
@@ -3289,6 +3292,13 @@
32903293 }
32913294 $output = call_user_func_array( $this->mTagHooks[$name],
32923295 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 ) );
32933303 } else {
32943304 $output = '<span class="error">Invalid tag extension name: ' .
32953305 htmlspecialchars( $name ) . '</span>';
@@ -3312,7 +3322,9 @@
33133323 }
33143324 }
33153325
3316 - if ( $name === 'html' || $name === 'nowiki' ) {
 3326+ if( $isFunctionTag ) {
 3327+ return $output;
 3328+ } elseif ( $name === 'html' || $name === 'nowiki' ) {
33173329 $this->mStripState->nowiki->setPair( $marker, $output );
33183330 } else {
33193331 $this->mStripState->general->setPair( $marker, $output );
@@ -4234,6 +4246,24 @@
42354247 }
42364248
42374249 /**
 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+ /**
42384268 * FIXME: update documentation. makeLinkObj() is deprecated.
42394269 * Replace <!--LINK--> link placeholders with actual links, in the buffer
42404270 * Placeholders created in Skin::makeLinkObj()
Index: trunk/phase3/RELEASE-NOTES
@@ -120,6 +120,8 @@
121121 * (bug 19576) Moved id attribues from anchors accompanying section headers to
122122 the section headers themselves, removing the redundant anchor elements.
123123 * 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.
124126
125127 === Bug fixes in 1.16 ===
126128

Comments

#Comment by Platonides (talk | contribs)   18:32, 11 January 2011

r55682 adds them for normal tag hooks (with different parameter ordering), so this no longer seem to provide a benefit.

It also requires a useless $flags parameter and is undocumented. Only your r52717 InlineScripts extension seem to use it.

What are the odds of deprecating it?

Status & tagging log