+
+ /**
+ * Parser function to extension tag adaptor
+ */
+ public static function tagObj( $parser, $frame, $args ) {
+ $xpath = false;
+ if ( !count( $args ) ) {
+ return '';
+ }
+ $tagName = strtolower( trim( $frame->expand( array_shift( $args ) ) ) );
+ $stripList = $parser->getStripList();
+ if ( !in_array( $tagName, $stripList ) ) {
+ return '<span class="error">' .
+ wfMsg( 'unknown_extension_tag', $tagName ) .
+ '</span>';
+ }
+
+ $lastNumberedNode = false;
+ $attributes = array();
+ foreach ( $args as $arg ) {
+ if ( !$xpath ) {
+ $xpath = new DOMXPath( $arg->ownerDocument );
+ }
+ $names = $xpath->query( 'name', $arg );
+ if ( $names->item( 0 )->hasAttributes() ) {
+ $lastNumberedNode = $arg;
+ } else {
+ $name = $frame->expand( $names->item( 0 ), PPFrame::STRIP_COMMENTS );
+ if ( preg_match( '/^\d+$/', $name ) ) {
+ // For = suppression syntax {{#tag|thing|1=2=3=4}}
+ $lastNumberedNode = $arg;
+ } else {
+ $values = $xpath->query( 'value', $arg );
+ $attributes[$name] = trim( $frame->expand( $values->item( 0 ) ) );
+ }
+ }
+ }
+
+ if ( !$lastNumberedNode ) {
+ $inner = null;
+ } else {
+ $values = $xpath->query( 'value', $lastNumberedNode );
+ $inner = $frame->expand( $values->item( 0 ) );
+ }
+ $params = array(
+ 'name' => $tagName,
+ 'inner' => $inner,
+ 'attributes' => $attributes
+ );
+ return $parser->extensionSubstitution( $params, $frame );
+ }